commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r4925 - in gnuradio/branches/developers/eb/ibu: mblock


From: eb
Subject: [Commit-gnuradio] r4925 - in gnuradio/branches/developers/eb/ibu: mblock/src/lib omnithread
Date: Sun, 8 Apr 2007 00:01:59 -0600 (MDT)

Author: eb
Date: 2007-04-08 00:01:59 -0600 (Sun, 08 Apr 2007)
New Revision: 4925

Added:
   gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_mblock_sys.cc
   gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_mblock_sys.h
Modified:
   gnuradio/branches/developers/eb/ibu/mblock/src/lib/Makefile.am
   gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_mblock.cc
   gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_mblock.h
   gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime.cc
   gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime.h
   gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_nop.cc
   gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_nop.h
   
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_thread_per_block.cc
   
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_thread_per_block.h
   gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_worker.cc
   gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_worker.h
   gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_mblock.cc
   gnuradio/branches/developers/eb/ibu/omnithread/posix.cc
Log:
More mblock work-in-progress


Modified: gnuradio/branches/developers/eb/ibu/mblock/src/lib/Makefile.am
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/Makefile.am      
2007-04-08 00:49:35 UTC (rev 4924)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/Makefile.am      
2007-04-08 06:01:59 UTC (rev 4925)
@@ -88,7 +88,8 @@
        mbi_runtime_lock.h              \
        qa_mblock.h                     \
        qa_mblock_prims.h               \
-       qa_mblock_send.h                
+       qa_mblock_send.h                \
+       qa_mblock_sys.h                 
 
 
 # Build the qa code into its own library
@@ -96,7 +97,8 @@
 libmblock_qa_la_SOURCES =              \
        qa_mblock.cc                    \
        qa_mblock_prims.cc              \
-       qa_mblock_send.cc               
+       qa_mblock_send.cc               \
+       qa_mblock_sys.cc                
 
 
 # magic flags

Modified: gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_mblock.cc
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_mblock.cc     
2007-04-08 00:49:35 UTC (rev 4924)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_mblock.cc     
2007-04-08 06:01:59 UTC (rev 4925)
@@ -191,8 +191,7 @@
 }
 
 void
-mb_mblock::shutdown_all()
+mb_mblock::shutdown_all(pmt_t result)
 {
-  d_impl->runtime()->request_shutdown();
-  exit();
+  d_impl->runtime()->request_shutdown(result);
 }

Modified: gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_mblock.h
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_mblock.h      
2007-04-08 00:49:35 UTC (rev 4924)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_mblock.h      
2007-04-08 06:01:59 UTC (rev 4925)
@@ -197,6 +197,8 @@
   /*!
    * \brief Ask runtime to execute the shutdown procedure for all blocks.
    * 
+   * \param result sets value of \p result output argument of runtime->run(...)
+   *
    * The runtime first sends a maximum priority %shutdown message to
    * all blocks.  All blocks should handle the %shutdown message,
    * perform whatever clean up is required, and call this->exit();
@@ -212,11 +214,9 @@
    * runtime-provided exception handler will call this->exit() to
    * finish the process.
    *
-   * This method does not return.
-   *
    * runtime->run(...) returns when all blocks have called exit.
    */
-  void shutdown_all();
+  void shutdown_all(pmt_t result);
 
   /*!
    * \brief main event dispatching loop

Modified: gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime.cc
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime.cc    
2007-04-08 00:49:35 UTC (rev 4924)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime.cc    
2007-04-08 06:01:59 UTC (rev 4925)
@@ -38,7 +38,7 @@
 }
 
 void
-mb_runtime::request_shutdown()
+mb_runtime::request_shutdown(pmt_t result)
 {
   // nop
 }

Modified: gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime.h
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime.h     
2007-04-08 00:49:35 UTC (rev 4924)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime.h     
2007-04-08 06:01:59 UTC (rev 4925)
@@ -59,7 +59,8 @@
    */
   virtual bool run(const std::string &instance_name,
                   const std::string &class_name,
-                  pmt_t user_arg) = 0;
+                  pmt_t user_arg,
+                  pmt_t *result = 0) = 0;
 
 
   // ----------------------------------------------------------------
@@ -78,7 +79,7 @@
    */
   inline void unlock() { d_brl.unlock(); }
 
-  virtual void request_shutdown();
+  virtual void request_shutdown(pmt_t result);
 
 protected:
   virtual mb_mblock_sptr

Modified: gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_nop.cc
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_nop.cc        
2007-04-08 00:49:35 UTC (rev 4924)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_nop.cc        
2007-04-08 06:01:59 UTC (rev 4925)
@@ -48,7 +48,7 @@
 bool
 mb_runtime_nop::run(const std::string &instance_name,
                    const std::string &class_name,
-                   pmt_t user_arg)
+                   pmt_t user_arg, pmt_t *result)
 {
   class initial_visitor : public mb_visitor
   {
@@ -62,6 +62,9 @@
 
   initial_visitor visitor;
 
+  if (result)
+    *result = PMT_T;
+
   d_top = create_component(instance_name, class_name, user_arg);
   d_top->walk_tree(&visitor);
 

Modified: gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_nop.h
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_nop.h 
2007-04-08 00:49:35 UTC (rev 4924)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_nop.h 
2007-04-08 06:01:59 UTC (rev 4925)
@@ -41,7 +41,8 @@
 
   bool run(const std::string &instance_name,
           const std::string &class_name,
-          pmt_t user_arg);
+          pmt_t user_arg,
+          pmt_t *result);
 
   // QA only
   mb_mblock_sptr top() { return d_top; }

Modified: 
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_thread_per_block.cc
===================================================================
--- 
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_thread_per_block.cc
   2007-04-08 00:49:35 UTC (rev 4924)
+++ 
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_thread_per_block.cc
   2007-04-08 06:01:59 UTC (rev 4925)
@@ -30,11 +30,27 @@
 #include <mb_worker.h>
 #include <omnithread.h>
 
+static pmt_t s_sys_port = pmt_intern("%sys-port");
+static pmt_t s_shutdown = pmt_intern("%shutdown");
+static pmt_t s_halt = pmt_intern("%halt");
 
+
+static void
+send_sys_msg(mb_msg_queue &msgq, pmt_t signal,
+            pmt_t data = PMT_F, pmt_t metadata = PMT_F,
+            mb_pri_t priority = MB_PRI_BEST)
+{
+  mb_message_sptr msg = mb_make_message(signal, data, metadata, priority);
+  msg->set_port_id(s_sys_port);
+  msgq.insert(msg);
+}
+
+
 mb_runtime_thread_per_block::mb_runtime_thread_per_block()
-  : d_runtime_cond(&d_mutex), d_shutdown_requested(false)
+  : d_runtime_cond(&d_mutex),
+    d_shutdown_requested(false), d_shutdown_in_progress(false),
+    d_shutdown_result(PMT_T)
 {
-  // nop for now
 }
 
 mb_runtime_thread_per_block::~mb_runtime_thread_per_block()
@@ -46,53 +62,103 @@
 }
 
 void
-mb_runtime_thread_per_block::request_shutdown()
+mb_runtime_thread_per_block::request_shutdown(pmt_t result)
 {
   omni_mutex_lock l1(d_mutex);
-  d_shutdown_requested = true;
-  d_runtime_cond.broadcast();
+
+  if (!d_shutdown_requested){
+    d_shutdown_result = result;
+    d_shutdown_requested = true;
+    d_runtime_cond.broadcast();
+  }
 }
 
 bool
 mb_runtime_thread_per_block::run(const std::string &instance_name,
                                 const std::string &class_name,
-                                pmt_t user_arg)
+                                pmt_t user_arg, pmt_t *result)
 {
-  // Create the top-level component, and recursively all of its
-  // subcomponents.
+  if (result)          // set it to something now, in case we throw
+    *result = PMT_F;
+  
+  // reset the shutdown state
+  d_shutdown_requested = false;
+  d_shutdown_in_progress = false;
+  d_shutdown_result = PMT_T;
+
+  assert(d_workers.empty());
+
+  /*
+   * Create the top-level component, and recursively all of its
+   * subcomponents.
+   */
   mb_mblock_sptr top = create_component(instance_name, class_name, user_arg);
 
+  run_loop();
+
+  if (result)
+    *result = d_shutdown_result;
+  
+  return true;
+}
+
+void
+mb_runtime_thread_per_block::run_loop()
+{
+  /*
+   * FIXME probably ought to recode this to use a message queue
+   * and state machine like the rest of the world ;)
+   */
   while (1){
-    omni_mutex_lock l1(d_mutex);
+    reap_dead_workers();
+    {
+      omni_mutex_lock l1(d_mutex);
+      if (d_workers.empty())   // no work left to do...
+       return;         
 
-    //
-    // reap dead threads
-    //
-    for (worker_iter_t wi = d_workers.begin(); wi != d_workers.end(); ){
-      omni_mutex_lock l2((*wi)->d_mutex);
-      if ((*wi)->d_state == mb_worker::TS_DEAD){
-       std::cerr << "\nruntime: "
-                 << (*wi)->d_mblock->instance_name() << "is TS_DEAD\n";
-       void *ignore;
-       (*wi)->join(&ignore);
-       wi = d_workers.erase(wi);
+      if (d_shutdown_requested && !d_shutdown_in_progress){
+       d_shutdown_in_progress = true;
+
+       // FIXME state machine, delay before sending %halt
+       send_all_sys_msg(s_shutdown);
+       send_all_sys_msg(s_halt);
+
        continue;
       }
-      ++wi;
+
+      d_runtime_cond.wait();   // wait for something to do.
     }
+  }
+}
 
-    if (d_workers.empty())     // no work left to do...
-      return true;             
+void
+mb_runtime_thread_per_block::reap_dead_workers()
+{
+  omni_mutex_lock l1(d_mutex);
 
-    if (d_shutdown_requested){
-      // FIXME implement something...
+  for (worker_iter_t wi = d_workers.begin(); wi != d_workers.end(); ){
+    bool is_dead;
+
+    // We can't join while holding the worker mutex, since that would
+    // attempt to destroy the mutex we're holding (omnithread's join
+    // deletes the omni_thread object after the pthread_join
+    // completes) Instead, we lock just long enough to figure out if
+    // the worker is dead.
+    {
+      omni_mutex_lock l2((*wi)->d_mutex);
+      is_dead = (*wi)->d_state == mb_worker::TS_DEAD;
+    }
+      
+    if (is_dead){
+      std::cerr << "\nruntime: "
+               << (*wi)->d_mblock->instance_name() << " is TS_DEAD\n";
+      void *ignore;
+      (*wi)->join(&ignore);
+      wi = d_workers.erase(wi);
       continue;
     }
-
-    d_runtime_cond.wait();     // wait for something to do.
+    ++wi;
   }
-
-  return true;
 }
 
 //
@@ -112,30 +178,40 @@
   // priorities and communicate them to the worker we're creating...
 
   // Create the worker thread
-  mb_worker_sptr w =
-    mb_worker_sptr(new mb_worker(this, maker, instance_name, user_arg));
+  mb_worker *w =
+    new mb_worker(this, maker, instance_name, user_arg);
 
   w->start_undetached();  // start it
 
   // Wait for it to reach TS_RUNNING or TS_DEAD
+
+  bool                                 is_dead;
+  mb_worker::cause_of_death_t  why_dead;
   {
     omni_mutex_lock l(w->d_mutex);
     while (!(w->d_state == mb_worker::TS_RUNNING
             || w->d_state == mb_worker::TS_DEAD))
       w->d_state_cond.wait();
+
+    is_dead = w->d_state == mb_worker::TS_DEAD;
+    why_dead = w->d_why_dead;
   }
 
-  if (w->d_state == mb_worker::TS_DEAD){  // failed to init
+  // If the worker failed to init (constructor or initial_transition
+  // raised an exception), reap the worker now and raise an exception.
+
+  if (is_dead && why_dead != mb_worker::RIP_EXIT){
+
     void *ignore;
-    w->join(&ignore);          // reap it now
+    w->join(&ignore);
 
     // FIXME with some work we ought to be able to propagate the
     // exception from the worker.
     throw mbe_mblock_failed(0, instance_name);
   }
 
-  // The worker has successfully constructed the mblock and
-  // is blocked waiting to be told to run its initial_transition.
+  assert(w->d_mblock);
+
   // Add w to the vector of workers, and return the mblock.
   {
     omni_mutex_lock l(d_mutex);
@@ -145,3 +221,17 @@
   return w->d_mblock;
 }
 
+void
+mb_runtime_thread_per_block::send_all_sys_msg(pmt_t signal,
+                                             pmt_t data,
+                                             pmt_t metadata,
+                                             mb_pri_t priority)
+{
+  // Already holding lock
+  // omni_mutex_lock l1(d_mutex);
+
+  for (worker_iter_t wi = d_workers.begin(); wi != d_workers.end(); ++wi){
+    send_sys_msg((*wi)->d_mblock->impl()->msgq(),
+                signal, data, metadata, priority);
+  }
+}

Modified: 
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_thread_per_block.h
===================================================================
--- 
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_thread_per_block.h
    2007-04-08 00:49:35 UTC (rev 4924)
+++ 
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_thread_per_block.h
    2007-04-08 06:01:59 UTC (rev 4925)
@@ -35,25 +35,38 @@
 public:
   omni_mutex                 d_mutex;
   omni_condition             d_runtime_cond;  // runtime waits here
-  std::vector<mb_worker_sptr> d_workers;
+  //std::vector<mb_worker_sptr> d_workers;
+  std::vector<mb_worker*>     d_workers;
   bool                       d_shutdown_requested;
+  bool                       d_shutdown_in_progress;
+  pmt_t                              d_shutdown_result;
 
-  typedef std::vector<mb_worker_sptr>::iterator  worker_iter_t;
+  //typedef std::vector<mb_worker_sptr>::iterator  worker_iter_t;
+  typedef std::vector<mb_worker*>::iterator  worker_iter_t;
 
   mb_runtime_thread_per_block();
   ~mb_runtime_thread_per_block();
 
   bool run(const std::string &instance_name,
           const std::string &class_name,
-          pmt_t user_arg);
+          pmt_t user_arg,
+          pmt_t *result);
 
-  void request_shutdown();
+  void request_shutdown(pmt_t result);
 
 protected:
   mb_mblock_sptr
   create_component(const std::string &instance_name,
                   const std::string &class_name,
                   pmt_t user_arg);
+
+  void reap_dead_workers();
+  void run_loop();
+
+  void send_all_sys_msg(pmt_t signal, pmt_t data = PMT_F,
+                       pmt_t metadata = PMT_F,
+                       mb_pri_t priority = MB_PRI_BEST);
+
 };
 
 #endif /* INCLUDED_MB_RUNTIME_THREAD_PER_BLOCK_H */

Modified: gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_worker.cc
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_worker.cc     
2007-04-08 00:49:35 UTC (rev 4924)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_worker.cc     
2007-04-08 06:01:59 UTC (rev 4925)
@@ -28,6 +28,8 @@
 #include <mb_mblock.h>
 #include <iostream>
 
+#define VERBOSE 0              // define to 0 or 1
+
 #include <sys/syscall.h>       // Move this somewhere else and autoconf
 #include <unistd.h>
 
@@ -56,9 +58,11 @@
 {
 }
 
+#if 0
 mb_worker::~mb_worker()
 {
 }
+#endif
 
 void
 mb_worker::set_state(worker_state_t state)
@@ -91,6 +95,10 @@
       d_why_dead = RIP_UNHANDLED_EXCEPTION;
   }
 
+  if (VERBOSE)
+    std::cerr << "\nrun_undetached: about to return, d_why_dead = "
+             << d_why_dead << std::endl;
+
   set_state(TS_DEAD);
   return 0;
 }
@@ -98,11 +106,12 @@
 void
 mb_worker::worker_thread_top_level()
 {
-  std::cerr << "worker_thread_top_level (enter):" << std::endl
-           << "  instance_name: " << d_instance_name << std::endl
-           << "  omnithread id: " << id() << std::endl
-           << "  gettid:        " << mb_gettid() << std::endl
-           << "  getpid:        " << getpid() << std::endl;
+  if (VERBOSE)
+    std::cerr << "worker_thread_top_level (enter):" << std::endl
+             << "  instance_name: " << d_instance_name << std::endl
+             << "  omnithread id: " << id() << std::endl
+             << "  gettid:        " << mb_gettid() << std::endl
+             << "  getpid:        " << getpid() << std::endl;
 
   cause_of_death_t pending_cause_of_death = RIP_NOT_DEAD_YET;
   
@@ -110,14 +119,16 @@
     pending_cause_of_death = RIP_CTOR_EXCEPTION;
     d_mblock = d_maker(d_runtime, d_instance_name, d_user_arg);
 
-    std::cerr << "worker_thread_top_level (post-construction):" << std::endl
-             << "  instance_name: " << d_instance_name << std::endl;
+    if (VERBOSE)
+      std::cerr << "worker_thread_top_level (post-construction):" << std::endl
+               << "  instance_name: " << d_instance_name << std::endl;
 
     pending_cause_of_death = RIP_INIT_EXCEPTION;
     d_mblock->initial_transition();
 
-    std::cerr << "worker_thread_top_level (post-initial-transition):" << 
std::endl
-             << "  instance_name: " << d_instance_name << std::endl;
+    if (VERBOSE)
+      std::cerr << "worker_thread_top_level (post-initial-transition):" << 
std::endl
+               << "  instance_name: " << d_instance_name << std::endl;
 
     set_state(TS_RUNNING);
 
@@ -129,6 +140,7 @@
     throw;
   }
 
-  std::cerr << "worker_thread_top_level (exit):" << std::endl
-           << "  instance_name: " << d_instance_name << std::endl;
+  if (VERBOSE)
+    std::cerr << "worker_thread_top_level (exit):" << std::endl
+             << "  instance_name: " << d_instance_name << std::endl;
 }

Modified: gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_worker.h
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_worker.h      
2007-04-08 00:49:35 UTC (rev 4924)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_worker.h      
2007-04-08 06:01:59 UTC (rev 4925)
@@ -28,7 +28,7 @@
 
 
 class mb_worker;
-typedef boost::shared_ptr<mb_worker> mb_worker_sptr;
+//typedef boost::shared_ptr<mb_worker> mb_worker_sptr;
 
 class mb_runtime_thread_per_block;
 
@@ -82,7 +82,7 @@
            const std::string &instance_name,
            pmt_t user_arg);
 
-  ~mb_worker();
+  // ~mb_worker();
 
 
   /*!

Modified: gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_mblock.cc
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_mblock.cc     
2007-04-08 00:49:35 UTC (rev 4924)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_mblock.cc     
2007-04-08 06:01:59 UTC (rev 4925)
@@ -27,6 +27,7 @@
 #include <qa_mblock.h>
 #include <qa_mblock_prims.h>
 #include <qa_mblock_send.h>
+#include <qa_mblock_sys.h>
 
 CppUnit::TestSuite *
 qa_mblock::suite()
@@ -35,6 +36,7 @@
 
   s->addTest (qa_mblock_prims::suite());
   s->addTest (qa_mblock_send::suite());
+  s->addTest (qa_mblock_sys::suite());
   
   return s;
 }

Added: gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_mblock_sys.cc
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_mblock_sys.cc         
                (rev 0)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_mblock_sys.cc 
2007-04-08 06:01:59 UTC (rev 4925)
@@ -0,0 +1,136 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2006,2007 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <qa_mblock_sys.h>
+#include <cppunit/TestAssert.h>
+#include <mb_mblock.h>
+#include <mb_runtime.h>
+#include <mb_runtime_nop.h>            // QA only
+#include <mb_protocol_class.h>
+#include <mb_exception.h>
+#include <mb_msg_queue.h>
+#include <mb_message.h>
+#include <mb_mblock_impl.h>
+#include <mb_msg_accepter.h>
+#include <mb_class_registry.h>
+#include <stdio.h>
+#include <string.h>
+
+
+static pmt_t s_data    = pmt_intern("data");
+static pmt_t s_status  = pmt_intern("status");
+static pmt_t s_control = pmt_intern("control");
+static pmt_t s_p0   = pmt_intern("p0");
+static pmt_t s_p1   = pmt_intern("p1");
+static pmt_t s_p2   = pmt_intern("p2");
+static pmt_t s_p3   = pmt_intern("p3");
+static pmt_t s_e1   = pmt_intern("e1");
+static pmt_t s_r1   = pmt_intern("r1");
+
+static void
+define_protocol_classes()
+{
+  mb_make_protocol_class(s_data,               // name
+                        pmt_list1(s_data),     // incoming
+                        pmt_list1(s_data));    // outgoing
+}
+
+
+// ================================================================
+//                       test_sys_1
+// ================================================================
+
+class sys_1 : public mb_mblock
+{
+  pmt_t                d_user_arg;
+  mb_port_sptr p_data;
+
+public:
+  sys_1(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg);
+  ~sys_1();
+  void initial_transition();
+};
+
+sys_1::sys_1(mb_runtime *runtime, const std::string &instance_name, pmt_t 
user_arg)
+  : mb_mblock(runtime, instance_name, user_arg),
+    d_user_arg(user_arg)
+{
+  p_data = define_port("data", "data", true, mb_port::EXTERNAL);
+}
+
+sys_1::~sys_1(){}
+  
+void
+sys_1::initial_transition()
+{
+  shutdown_all(d_user_arg);
+}
+
+REGISTER_MBLOCK_CLASS(sys_1);
+
+void
+qa_mblock_sys::test_sys_1()
+{
+  define_protocol_classes();
+
+  pmt_t        result;
+  pmt_t        n1 = pmt_from_long(1);
+  pmt_t        n2 = pmt_from_long(2);
+
+  mb_runtime_sptr rt1 = mb_make_runtime();
+
+#if 0
+  try {
+    rt1->run("top-1", "sys_1", n1, &result);
+  }
+  catch (omni_thread_fatal e){
+    std::cerr << "caught omni_thread_fatal: error = " << e.error
+             << ": " << strerror(e.error) << std::endl;
+  }
+  catch (omni_thread_invalid){
+    std::cerr << "caught omni_thread_invalid\n";
+  }
+#else
+    rt1->run("top-1", "sys_1", n1, &result);
+#endif
+  CPPUNIT_ASSERT(pmt_equal(n1, result));
+  
+  // Execute run a second time, with the same rt, to ensure sanity.
+  rt1->run("top-2", "sys_1", n2, &result);
+  CPPUNIT_ASSERT(pmt_equal(n2, result));
+}
+
+
+void
+qa_mblock_sys::test_sys_2()
+{
+}
+
+void
+qa_mblock_sys::test_sys_3()
+{
+}
+

Added: gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_mblock_sys.h
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_mblock_sys.h          
                (rev 0)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_mblock_sys.h  
2007-04-08 06:01:59 UTC (rev 4925)
@@ -0,0 +1,43 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2006,2007 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#ifndef INCLUDED_QA_MBLOCK_SYS_H
+#define INCLUDED_QA_MBLOCK_SYS_H
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/TestCase.h>
+
+class qa_mblock_sys : public CppUnit::TestCase {
+
+  CPPUNIT_TEST_SUITE(qa_mblock_sys);
+  CPPUNIT_TEST(test_sys_1);
+  CPPUNIT_TEST(test_sys_2);
+  CPPUNIT_TEST(test_sys_3);
+  CPPUNIT_TEST_SUITE_END();
+
+ private:
+  void test_sys_1();
+  void test_sys_2();
+  void test_sys_3();
+};
+
+#endif /* INCLUDED_QA_MBLOCK_SYS_H */
+

Modified: gnuradio/branches/developers/eb/ibu/omnithread/posix.cc
===================================================================
--- gnuradio/branches/developers/eb/ibu/omnithread/posix.cc     2007-04-08 
00:49:35 UTC (rev 4924)
+++ gnuradio/branches/developers/eb/ibu/omnithread/posix.cc     2007-04-08 
06:01:59 UTC (rev 4925)
@@ -77,8 +77,14 @@
 #endif
 #endif
 
+#if 1
 #define DB(x) // x
-//#include <iostream.h> or #include <iostream> if DB is on.
+#else
+#define DB(x) x
+#include <iostream>
+using std::cerr;
+using std::endl;
+#endif
 
 #if (PthreadDraftVersion <= 6)
 #define ERRNO(x) (((x) != 0) ? (errno) : 0)





reply via email to

[Prev in Thread] Current Thread [Next in Thread]