commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r4887 - gnuradio/branches/developers/eb/ibu/mblock/src


From: eb
Subject: [Commit-gnuradio] r4887 - gnuradio/branches/developers/eb/ibu/mblock/src/lib
Date: Thu, 5 Apr 2007 18:10:15 -0600 (MDT)

Author: eb
Date: 2007-04-05 18:10:15 -0600 (Thu, 05 Apr 2007)
New Revision: 4887

Modified:
   gnuradio/branches/developers/eb/ibu/mblock/src/lib/Makefile.am
   gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_class_registry.h
   gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_exception.cc
   gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_exception.h
   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_mblock_impl.cc
   gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_mblock_impl.h
   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_mblock.cc
   
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_thread_per_mblock.h
   gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_mblock_prims.cc
   gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_mblock_send.cc
Log:
work-in-progress on mblocks.  Refactored define_component such that it
now takes a string naming the class to create, not an instance of the
class.  On NUMA and distributed multicomputers this will allow the
runtime to control the placement of the thread and the associated
memory.



Modified: gnuradio/branches/developers/eb/ibu/mblock/src/lib/Makefile.am
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/Makefile.am      
2007-04-05 21:37:35 UTC (rev 4886)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/Makefile.am      
2007-04-06 00:10:15 UTC (rev 4887)
@@ -48,7 +48,6 @@
        mb_protocol_class.cc            \
        mb_runtime.cc                   \
        mb_runtime_nop.cc               \
-       mb_runtime_placeholder.cc       \
        mb_runtime_thread_per_mblock.cc \
        mb_util.cc                      
 
@@ -75,7 +74,6 @@
        mb_protocol_class.h             \
        mb_runtime.h                    \
        mb_runtime_nop.h                \
-       mb_runtime_placeholder.h        \
        mb_runtime_thread_per_mblock.h  \
        mb_util.h                       
 

Modified: gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_class_registry.h
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_class_registry.h      
2007-04-05 21:37:35 UTC (rev 4886)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_class_registry.h      
2007-04-06 00:10:15 UTC (rev 4887)
@@ -23,8 +23,14 @@
 
 #include <mb_common.h>
 
-typedef mb_mblock_sptr (*mb_mblock_maker_t)(); // conceptually, pointer to 
constructor
+//! conceptually, pointer to constructor
+typedef mb_mblock_sptr (*mb_mblock_maker_t)(mb_runtime *runtime,
+                                           const std::string &instance_name,
+                                           pmt_t constructor_arg);
 
+/*
+ * \brief Maintain mapping between mblock class_name and factory (maker)
+ */
 class mb_class_registry : public boost::noncopyable {
 public:
   static bool register_maker(const std::string &name, mb_mblock_maker_t maker);
@@ -32,9 +38,11 @@
 };
 
 template<class mblock>
-mb_mblock_sptr mb_mblock_maker()
+mb_mblock_sptr mb_mblock_maker(mb_runtime *runtime,
+                              const std::string &instance_name,
+                              pmt_t constructor_arg)
 {
-  return mb_mblock_sptr(new mblock());
+  return mb_mblock_sptr(new mblock(runtime, instance_name, constructor_arg));
 }
 
 #define REGISTER_MBLOCK_CLASS(name) \

Modified: gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_exception.cc
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_exception.cc  
2007-04-05 21:37:35 UTC (rev 4886)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_exception.cc  
2007-04-06 00:10:15 UTC (rev 4887)
@@ -38,6 +38,11 @@
 {
 }
 
+mbe_no_such_class::mbe_no_such_class(mb_mblock *mb, const std::string 
&class_name)
+  : mbe_base(mb, "No such class: " + class_name)
+{
+}
+
 mbe_no_such_component::mbe_no_such_component(mb_mblock *mb, const std::string 
&component_name)
   : mbe_base(mb, "No such component: " + component_name)
 {

Modified: gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_exception.h
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_exception.h   
2007-04-05 21:37:35 UTC (rev 4886)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_exception.h   
2007-04-06 00:10:15 UTC (rev 4887)
@@ -38,6 +38,11 @@
   mbe_not_implemented(mb_mblock *mb, const std::string &msg);
 };
 
+class mbe_no_such_class : public mbe_base
+{
+public:
+  mbe_no_such_class(mb_mblock *, const std::string &class_name);
+};
 
 class mbe_no_such_component : public mbe_base
 {
@@ -57,6 +62,7 @@
   mbe_no_such_port(mb_mblock *, const std::string &port_name);
 };
 
+
 class mbe_duplicate_port : public mbe_base
 {
 public:

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-05 21:37:35 UTC (rev 4886)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_mblock.cc     
2007-04-06 00:10:15 UTC (rev 4887)
@@ -33,8 +33,10 @@
 }
 
 
-mb_mblock::mb_mblock()
-  : d_impl(mb_mblock_impl_sptr(new mb_mblock_impl(this)))
+mb_mblock::mb_mblock(mb_runtime *runtime,
+                    const std::string &instance_name,
+                    pmt_t user_arg)
+  : d_impl(mb_mblock_impl_sptr(new mb_mblock_impl(runtime, this, 
instance_name)))
 {
 }
 
@@ -74,9 +76,11 @@
 
 void
 mb_mblock::define_component(const std::string &component_name,
-                           mb_mblock_sptr component)
+                           const std::string &class_name,
+                           pmt_t constructor_arg)
+               
 {
-  d_impl->define_component(component_name, component);
+  d_impl->define_component(component_name, class_name, constructor_arg);
 }
 
 void
@@ -97,7 +101,7 @@
 }
 
 void
-mb_mblock::disconnect_component(const std::string component_name)
+mb_mblock::disconnect_component(const std::string &component_name)
 {
   d_impl->disconnect_component(component_name);
 }
@@ -115,9 +119,9 @@
 }
 
 bool
-mb_mblock::walk_tree(mb_visitor *visitor, const std::string &path)
+mb_mblock::walk_tree(mb_visitor *visitor)
 {
-  return d_impl->walk_tree(visitor, path);
+  return d_impl->walk_tree(visitor);
 }
 
 std::string
@@ -127,7 +131,7 @@
 }
 
 void
-mb_mblock::set_instance_name(const std::string name)
+mb_mblock::set_instance_name(const std::string &name)
 {
   d_impl->set_instance_name(name);
 }
@@ -139,7 +143,7 @@
 }
 
 void
-mb_mblock::set_class_name(const std::string name)
+mb_mblock::set_class_name(const std::string &name)
 {
   d_impl->set_class_name(name);
 }

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-05 21:37:35 UTC (rev 4886)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_mblock.h      
2007-04-06 00:10:15 UTC (rev 4887)
@@ -34,7 +34,7 @@
 {
 public:
   virtual ~mb_visitor();
-  virtual bool operator()(mb_mblock *mblock, const std::string &path) = 0;
+  virtual bool operator()(mb_mblock *mblock) = 0;
 };
 
 // ----------------------------------------------------------------------
@@ -59,13 +59,18 @@
    *
    * Initializing all mblocks in the system is a 3 step procedure.
    *
-   * The top level mblock's constructor is run.  That constructor (a)
-   * registers all of its ports using define_port, (b) constructs and
-   * registers any subcomponents it may have via the define_component
-   * method, and then (c) issues connect calls to wire its
-   * subcomponents together.
+   * The top level mblock's constructor is run.  That constructor 
+   * (a) registers all of its ports using define_port, (b) registers any
+   * subcomponents it may have via the define_component method, and
+   * then (c) issues connect calls to wire its subcomponents together.
+   *
+   * \param runtime the runtime associated with this mblock
+   * \param instance_name specify the name of this instance
+   *        (for debugging, NUMA mapping, etc)
+   * \param user_arg argument passed by user to constructor
+   *        (ignored by the mb_mblock base class)
    */
-  mb_mblock();
+  mb_mblock(mb_runtime *runtime, const std::string &instance_name, pmt_t 
user_arg);
 
 public:
   /*!
@@ -115,11 +120,13 @@
    * names and identities of our sub-component mblocks.
    *
    * \param component_name  The name of the sub-component (must be unique with 
this mblock).
-   * \param component       The sub-component instance.
+   * \param class_name      The class of the instance that is to be created.
+   * \param constructor_arg The argument to pass to the constructor of the 
component.
    */
   void
   define_component(const std::string &component_name,
-                  mb_mblock_sptr component);
+                  const std::string &class_name,
+                  pmt_t constructor_arg = PMT_NIL);
 
   /*!
    * \brief connect endpoint_1 to endpoint_2
@@ -162,7 +169,7 @@
    * \param component_name component to disconnect
    */
   void
-  disconnect_component(const std::string component_name);
+  disconnect_component(const std::string &component_name);
 
   /*!
    * \brief disconnect all connections to all components
@@ -177,7 +184,7 @@
   nconnections() const;
 
   //! Set the class name
-  void set_class_name(const std::string name);
+  void set_class_name(const std::string &name);
 
 public:
   virtual ~mb_mblock();
@@ -189,7 +196,7 @@
   std::string class_name() const;
 
   //! Set the instance name of this block.
-  void set_instance_name(const std::string name);
+  void set_instance_name(const std::string &name);
   
   //! Return the parent of this mblock, or 0 if we're the top-level block.
   mb_mblock *parent() const;
@@ -200,7 +207,7 @@
    * The traversal stops and returns false if any call to visitor returns 
false.
    */
   bool
-  walk_tree(mb_visitor *visitor, const std::string &path="top");
+  walk_tree(mb_visitor *visitor);
 
 
   //! \implementation

Modified: gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_mblock_impl.cc
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_mblock_impl.cc        
2007-04-05 21:37:35 UTC (rev 4886)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_mblock_impl.cc        
2007-04-06 00:10:15 UTC (rev 4887)
@@ -30,7 +30,7 @@
 #include <mb_exception.h>
 #include <mb_util.h>
 #include <mb_msg_accepter_smp.h>
-#include <mb_runtime_placeholder.h>
+//#include <mb_runtime_placeholder.h>
 #include <mbi_runtime_lock.h>
 
 
@@ -52,9 +52,10 @@
 
 ////////////////////////////////////////////////////////////////////////
 
-mb_mblock_impl::mb_mblock_impl(mb_mblock *mb)
-  : d_mb(mb), d_mb_parent(0), d_runtime(mb_runtime_placeholder::singleton()),
-    d_instance_name("<unknown>"), d_class_name("mblock")
+mb_mblock_impl::mb_mblock_impl(mb_runtime *runtime, mb_mblock *mb,
+                              const std::string &instance_name)
+  : d_runtime(runtime), d_mb(mb), d_mb_parent(0), 
+    d_instance_name(instance_name), d_class_name("mblock")
 {
 }
 
@@ -85,15 +86,28 @@
 
 void
 mb_mblock_impl::define_component(const std::string &name,
-                                mb_mblock_sptr component)
+                                const std::string &class_name,
+                                pmt_t constructor_arg)
 {
-  mbi_runtime_lock     l(this);
+  {
+    mbi_runtime_lock   l(this);
 
-  if (comp_is_defined(name))   // check for duplicate name
-    throw mbe_duplicate_component(d_mb, name);
+    if (comp_is_defined(name)) // check for duplicate name
+      throw mbe_duplicate_component(d_mb, name);
+  }
 
-  component->d_impl->d_mb_parent = d_mb;     // set component's parent link
-  d_comp_map[name] = component;
+  // We ask the runtime to create the component so that it can worry about
+  // mblock placement on a NUMA machine or on a distributed multicomputer
+
+  mb_mblock_sptr component =
+    d_runtime->create_component(instance_name() + "/" + name,
+                               class_name, constructor_arg);
+  {
+    mbi_runtime_lock   l(this);
+
+    component->d_impl->d_mb_parent = d_mb;     // set component's parent link
+    d_comp_map[name] = component;
+  }
 }
 
 void
@@ -220,14 +234,14 @@
 }
 
 bool
-mb_mblock_impl::walk_tree(mb_visitor *visitor, const std::string &path)
+mb_mblock_impl::walk_tree(mb_visitor *visitor)
 {
-  if (!(*visitor)(d_mb, path))
+  if (!(*visitor)(d_mb))
     return false;
 
   mb_comp_map_t::iterator it;
   for (it = d_comp_map.begin(); it != d_comp_map.end(); ++it)
-    if (!(it->second->walk_tree(visitor, path + "/" + it->first)))
+    if (!(it->second->walk_tree(visitor)))
       return false;
 
   return true;

Modified: gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_mblock_impl.h
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_mblock_impl.h 
2007-04-05 21:37:35 UTC (rev 4886)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_mblock_impl.h 
2007-04-06 00:10:15 UTC (rev 4887)
@@ -37,9 +37,9 @@
  */
 class mb_mblock_impl : boost::noncopyable
 {
+  mb_runtime                  *d_runtime;      // pointer to runtime
   mb_mblock                   *d_mb;           // pointer to our associated 
mblock
   mb_mblock                   *d_mb_parent;    // pointer to our parent
-  mb_runtime                  *d_runtime;      // pointer to runtime
 
   std::string                  d_instance_name;    // hierarchical name
   std::string                  d_class_name;       // name of this (derived) 
class
@@ -51,7 +51,7 @@
   mb_msg_queue                 d_msgq;         // incoming messages for us
 
 public:
-  mb_mblock_impl(mb_mblock *mb);
+  mb_mblock_impl(mb_runtime *runtime, mb_mblock *mb, const std::string 
&instance_name);
   ~mb_mblock_impl();
 
   /*!
@@ -79,11 +79,13 @@
    * names and identities of our sub-component mblocks.
    *
    * \param component_name  The name of the sub-component (must be unique with 
this mblock).
-   * \param component       The sub-component instance.
+   * \param class_name      The class of the instance that is to be created.
+   * \param constructor_arg The argument to pass to the constructor of the 
component.
    */
   void
   define_component(const std::string &component_name,
-                  mb_mblock_sptr component);
+                  const std::string &class_name,
+                  pmt_t constructor_arg);
 
   /*!
    * \brief connect endpoint_1 to endpoint_2
@@ -141,7 +143,7 @@
   nconnections();
 
   bool
-  walk_tree(mb_visitor *visitor, const std::string &path="");
+  walk_tree(mb_visitor *visitor);
   
   mb_msg_accepter_sptr
   make_accepter(const std::string port_name);

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-05 21:37:35 UTC (rev 4886)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime.h     
2007-04-06 00:10:15 UTC (rev 4887)
@@ -37,6 +37,8 @@
 class mb_runtime : boost::noncopyable,
                   public boost::enable_shared_from_this<mb_runtime>
 {
+  friend class mb_mblock_impl;
+
   omni_mutex   d_brl;          // big runtime lock (avoid using this if 
possible...)
 
 public:
@@ -44,15 +46,20 @@
   virtual ~mb_runtime();
 
   /*!
-   * \brief Run the mblock hierarchy rooted at \p top
+   * \brief Construct and run the specified mblock hierarchy.
    *
    * This routine turns into the m-block scheduler, and
    * blocks until the system is shutdown.
    *
-   * \param top top-level mblock
+   * \param name name of the top-level mblock (conventionally "top")
+   * \param class_name The class of the top-level mblock to create.
+   * \param user_arg The argument to pass to the top-level mblock constructor
+   *
    * \returns true if the system ran successfully.
    */
-  virtual bool run(mb_mblock_sptr top) = 0;
+  virtual bool run(const std::string &instance_name,
+                  const std::string &class_name,
+                  pmt_t user_arg) = 0;
 
 
   // ----------------------------------------------------------------
@@ -71,6 +78,11 @@
    */
   inline void unlock() { d_brl.unlock(); }
 
+protected:
+  virtual mb_mblock_sptr
+  create_component(const std::string &instance_name,
+                  const std::string &class_name,
+                  pmt_t constructor_arg) = 0;
 };
 
 #endif /* INCLUDED_MB_RUNTIME_H */

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-05 21:37:35 UTC (rev 4886)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_nop.cc        
2007-04-06 00:10:15 UTC (rev 4887)
@@ -24,6 +24,8 @@
 #endif
 #include <mb_runtime_nop.h>
 #include <mb_mblock.h>
+#include <mb_class_registry.h>
+#include <mb_exception.h>
 
 mb_runtime_sptr 
 mb_make_runtime_nop()
@@ -42,23 +44,26 @@
   // nop for now
 }
 
+
 bool
-mb_runtime_nop::run(mb_mblock_sptr top)
+mb_runtime_nop::run(const std::string &instance_name,
+                   const std::string &class_name,
+                   pmt_t constructor_arg)
 {
-  class initial_visitor : public mb_visitor
-  {
-  public:
-    bool operator()(mb_mblock *mblock, const std::string &path)
-    {
-      mblock->set_instance_name(path);
-      mblock->initial_transition();
-      return true;
-    }
-  };
+  mb_mblock_sptr component =
+    create_component(instance_name, class_name, constructor_arg);
 
-  initial_visitor      visitor;
+  return true;
+}
 
-  top->walk_tree(&visitor);
+mb_mblock_sptr
+mb_runtime_nop::create_component(const std::string &instance_name,
+                                const std::string &class_name,
+                                pmt_t constructor_arg)
+{
+  mb_mblock_maker_t maker;
+  if (!mb_class_registry::lookup_maker(class_name, &maker))
+    throw mbe_no_such_class(0, class_name + " (in " + instance_name + ")");
 
-  return true;
+  return maker(this, instance_name, constructor_arg);
 }

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-05 21:37:35 UTC (rev 4886)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_nop.h 
2007-04-06 00:10:15 UTC (rev 4887)
@@ -38,7 +38,15 @@
   mb_runtime_nop();
   ~mb_runtime_nop();
 
-  bool run(mb_mblock_sptr top);
+  bool run(const std::string &instance_name,
+          const std::string &class_name,
+          pmt_t constructor_arg);
+
+protected:
+  mb_mblock_sptr
+  create_component(const std::string &instance_name,
+                  const std::string &class_name,
+                  pmt_t constructor_arg);
 };
 
 #endif /* INCLUDED_MB_RUNTIME_NOP_H */

Modified: 
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_thread_per_mblock.cc
===================================================================
--- 
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_thread_per_mblock.cc
  2007-04-05 21:37:35 UTC (rev 4886)
+++ 
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_thread_per_mblock.cc
  2007-04-06 00:10:15 UTC (rev 4887)
@@ -25,6 +25,8 @@
 #include <mb_runtime_thread_per_mblock.h>
 #include <mb_mblock.h>
 #include <mb_mblock_impl.h>
+#include <mb_class_registry.h>
+#include <mb_exception.h>
 #include <omnithread.h>
 
 
@@ -40,30 +42,46 @@
   // nop for now
 }
 
+
 bool
-mb_runtime_thread_per_mblock::run(mb_mblock_sptr top)
+mb_runtime_thread_per_mblock::run(const std::string &instance_name,
+                                 const std::string &class_name,
+                                 pmt_t user_arg)
 {
+#if 0
   class initial_visitor : public mb_visitor
   {
-    mb_runtime  *d_rt;
-
   public:
-    initial_visitor(mb_runtime *rt) : d_rt(rt) {}
-    bool operator()(mb_mblock *mblock, const std::string &path)
+    initial_visitor(){}
+    bool operator()(mb_mblock *mblock)
     {
-      mblock->impl()->set_runtime(d_rt);
-      mblock->set_instance_name(path);
       mblock->initial_transition();
       return true;
     }
   };
 
-  initial_visitor      visitor(this);
+  initial_visitor      visitor();
+#endif
 
-  d_top = top;         // remember top of tree
+  mb_mblock_sptr top =
+    create_component(instance_name, class_name, user_arg);
 
-  d_top->walk_tree(&visitor);
+  // FIXME wait for barrier, then ask each mblock to run its initial_transition
 
   return true;
 }
 
+//
+// FIXME create the thread, then create the component in the thread
+//
+mb_mblock_sptr
+mb_runtime_thread_per_mblock::create_component(const std::string 
&instance_name,
+                                              const std::string &class_name,
+                                              pmt_t user_arg)
+{
+  mb_mblock_maker_t maker;
+  if (!mb_class_registry::lookup_maker(class_name, &maker))
+    throw mbe_no_such_class(0, class_name + " (in " + instance_name + ")");
+
+  return maker(this, instance_name, user_arg);
+}

Modified: 
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_thread_per_mblock.h
===================================================================
--- 
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_thread_per_mblock.h
   2007-04-05 21:37:35 UTC (rev 4886)
+++ 
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_thread_per_mblock.h
   2007-04-06 00:10:15 UTC (rev 4887)
@@ -28,13 +28,19 @@
  */
 class mb_runtime_thread_per_mblock : public mb_runtime
 {
-  mb_mblock_sptr       d_top;          // top mblock
-
 public:
   mb_runtime_thread_per_mblock();
   ~mb_runtime_thread_per_mblock();
 
-  bool run(mb_mblock_sptr top);
+  bool run(const std::string &instance_name,
+          const std::string &class_name,
+          pmt_t constructor_arg);
+
+protected:
+  mb_mblock_sptr
+  create_component(const std::string &instance_name,
+                  const std::string &class_name,
+                  pmt_t constructor_arg);
 };
 
 #endif /* INCLUDED_MB_RUNTIME_THREAD_PER_MBLOCK_H */

Modified: gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_mblock_prims.cc
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_mblock_prims.cc       
2007-04-05 21:37:35 UTC (rev 4886)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_mblock_prims.cc       
2007-04-06 00:10:15 UTC (rev 4887)
@@ -34,6 +34,7 @@
 #include <mb_message.h>
 #include <mb_mblock_impl.h>
 #include <mb_msg_accepter.h>
+#include <mb_class_registry.h>
 #include <stdio.h>
 
 static pmt_t s_cs = pmt_intern("cs");
@@ -47,42 +48,49 @@
 class dp_1 : public mb_mblock
 {
 public:
-  dp_1();
+  dp_1(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg);
   ~dp_1();
 };
 
-dp_1::dp_1()
+dp_1::dp_1(mb_runtime *runtime, const std::string &instance_name, pmt_t 
user_arg)
+  : mb_mblock(runtime, instance_name, user_arg)
 {
 }
 
 dp_1::~dp_1(){}
 
+REGISTER_MBLOCK_CLASS(dp_1);
+
 // ----------------------------------------------------------------
 
 class dp_2 : public mb_mblock
 {
 public:
-  dp_2();
+  dp_2(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg);
   ~dp_2();
 };
 
-dp_2::dp_2()
+dp_2::dp_2(mb_runtime *runtime, const std::string &instance_name, pmt_t 
user_arg)
+  : mb_mblock(runtime, instance_name, user_arg)
 {
   define_port("cs", "cs-protocol", false, mb_port::EXTERNAL);
 }
 
 dp_2::~dp_2(){}
 
+REGISTER_MBLOCK_CLASS(dp_2);
+
 // ----------------------------------------------------------------
 
 class dp_3 : public mb_mblock
 {
 public:
-  dp_3();
+  dp_3(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg);
   ~dp_3();
 };
 
-dp_3::dp_3()
+dp_3::dp_3(mb_runtime *runtime, const std::string &instance_name, pmt_t 
user_arg)
+  : mb_mblock(runtime, instance_name, user_arg)
 {
   define_port("cs", "cs-protocol", false, mb_port::EXTERNAL);
   define_port("cs", "cs-protocol", false, mb_port::EXTERNAL);  // duplicate def
@@ -90,19 +98,23 @@
 
 dp_3::~dp_3(){}
 
+REGISTER_MBLOCK_CLASS(dp_3);
+
 // ----------------------------------------------------------------
 
 void
 qa_mblock_prims::test_define_ports()
 {
-  // std::vector<mb_port_sptr> intf;
+  
+  mb_runtime_sptr rts = mb_make_runtime();
+  mb_runtime *rt = rts.get();
+  
+  // Should work
+  mb_mblock_sptr  mb1 = mb_mblock_sptr(new dp_1(rt, "top", PMT_F));
 
-  mb_mblock_sptr       mb1 = mb_mblock_sptr(new dp_1());
-  // intf = mb1->peer_interface();
-  // CPPUNIT_ASSERT_EQUAL(size_t(0), intf.size());
-
   // raises runtime_error because of unknown protocol "cs-protocol"
-  CPPUNIT_ASSERT_THROW(mb_mblock_sptr(new dp_2()), std::runtime_error);
+  CPPUNIT_ASSERT_THROW(mb_mblock_sptr(new dp_2(rt, "top", PMT_F)),
+                      std::runtime_error);
 
   // define the protocol class
   pmt_t pc = mb_make_protocol_class(pmt_intern("cs-protocol"),
@@ -112,10 +124,11 @@
 
   // std::cout << "pc = " << pc << '\n';
 
-  mb_mblock_sptr mb2 = mb_mblock_sptr(new dp_2());
+  mb_mblock_sptr mb2 = mb_mblock_sptr(new dp_2(rt, "top", PMT_F));
 
   // raises pmt_exception because of duplicate port definition of "cs"
-  CPPUNIT_ASSERT_THROW(mb_mblock_sptr(new dp_3()), mbe_duplicate_port);
+  CPPUNIT_ASSERT_THROW(mb_mblock_sptr(new dp_3(rt, "top", PMT_F)),
+                      mbe_duplicate_port);
 }
 
 // ================================================================
@@ -123,61 +136,74 @@
 class dc_0 : public mb_mblock
 {
 public:
-  dc_0();
+  dc_0(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg);
   ~dc_0();
 };
 
-dc_0::dc_0()
+dc_0::dc_0(mb_runtime *runtime, const std::string &instance_name, pmt_t 
user_arg)
+  : mb_mblock(runtime, instance_name, user_arg)
 {
 }
 
 dc_0::~dc_0() {}
 
+REGISTER_MBLOCK_CLASS(dc_0);
+
 // ----------------------------------------------------------------
 
 class dc_ok : public mb_mblock
 {
 public:
-  dc_ok();
+  dc_ok(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg);
   ~dc_ok();
 };
 
-dc_ok::dc_ok()
+dc_ok::dc_ok(mb_runtime *runtime, const std::string &instance_name, pmt_t 
user_arg)
+  : mb_mblock(runtime, instance_name, user_arg)
 {
-  define_component("c0", mb_mblock_sptr(new dc_0()));
-  define_component("c1", mb_mblock_sptr(new dc_0()));
-  define_component("c2", mb_mblock_sptr(new dc_0()));
+  define_component("c0", "dc_0");
+  define_component("c1", "dc_0");
+  define_component("c2", "dc_0");
 }
 
 dc_ok::~dc_ok(){}
 
+REGISTER_MBLOCK_CLASS(dc_ok);
+
 // ----------------------------------------------------------------
 
 class dc_not_ok : public mb_mblock
 {
 public:
-  dc_not_ok();
+  dc_not_ok(mb_runtime *runtime, const std::string &instance_name, pmt_t 
user_arg);
   ~dc_not_ok();
 };
 
-dc_not_ok::dc_not_ok()
-  : mb_mblock()
+dc_not_ok::dc_not_ok(mb_runtime *runtime, const std::string &instance_name, 
pmt_t user_arg)
+  : mb_mblock(runtime, instance_name, user_arg)
 {
-  define_component("c0", mb_mblock_sptr(new dc_0()));
-  define_component("c0", mb_mblock_sptr(new dc_0()));  // duplicate name
+  define_component("c0", "dc_0");
+  define_component("c0", "dc_0");      // duplicate name
 }
 
 dc_not_ok::~dc_not_ok(){}
 
+REGISTER_MBLOCK_CLASS(dc_not_ok);
+
 // ----------------------------------------------------------------
 
 void
 qa_mblock_prims::test_define_components()
 {
-  mb_mblock_sptr       mb1 = mb_mblock_sptr(new dc_ok());      // OK
+  mb_runtime_sptr rts = mb_make_runtime();
+  mb_runtime *rt = rts.get();
+  
+  // Should work
+  mb_mblock_sptr  mb1 = mb_mblock_sptr(new dc_ok(rt, "top", PMT_F));
 
   // raises pmt_exception because of duplicate component definition of "c0"
-  CPPUNIT_ASSERT_THROW(mb_mblock_sptr(new dc_not_ok()), 
mbe_duplicate_component);
+  CPPUNIT_ASSERT_THROW(mb_mblock_sptr(new dc_not_ok(rt, "top", PMT_F)),
+                      mbe_duplicate_component);
 }
 
 // ================================================================
@@ -185,7 +211,9 @@
 class tc_norm : public mb_mblock
 {
 public:
-  tc_norm(){
+  tc_norm(mb_runtime *runtime, const std::string &instance_name, pmt_t 
user_arg)
+    : mb_mblock(runtime, instance_name, user_arg)
+  {
     define_port("data", "i/o", false, mb_port::EXTERNAL);
     define_port("norm", "i/o", false, mb_port::EXTERNAL);
     define_port("conj", "i/o", true,  mb_port::EXTERNAL);
@@ -197,22 +225,26 @@
 
 tc_norm::~tc_norm(){}
 
+REGISTER_MBLOCK_CLASS(tc_norm);
+
 ////////////////////////////////////////////////////////////////
 
 class tc_0 : public mb_mblock
 {
 public:
-  tc_0(){
+  tc_0(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg)
+    : mb_mblock(runtime, instance_name, user_arg)
+  {
     define_port("norm", "i/o", false, mb_port::EXTERNAL);
     define_port("conj", "i/o", true,  mb_port::EXTERNAL);
     define_port("int",  "i/o", false, mb_port::INTERNAL);
 
-    define_component("c0", mb_mblock_sptr(new tc_norm()));
-    define_component("c1", mb_mblock_sptr(new tc_norm()));
-    define_component("c2", mb_mblock_sptr(new tc_norm()));
-    define_component("c3", mb_mblock_sptr(new tc_norm()));
-    define_component("c4", mb_mblock_sptr(new tc_norm()));
-    define_component("c5", mb_mblock_sptr(new tc_norm()));
+    define_component("c0", "tc_norm");
+    define_component("c1", "tc_norm");
+    define_component("c2", "tc_norm");
+    define_component("c3", "tc_norm");
+    define_component("c4", "tc_norm");
+    define_component("c5", "tc_norm");
 
     // OK
     connect("c0", "norm", "c1", "conj");
@@ -284,14 +316,18 @@
 
 tc_0::~tc_0(){}
 
+REGISTER_MBLOCK_CLASS(tc_0);
+
 ////////////////////////////////////////////////////////////////
 
 class tc_1 : public mb_mblock
 {
 public:
-  tc_1(){
-    define_component("c0", mb_mblock_sptr(new tc_norm()));
-    define_component("c1", mb_mblock_sptr(new tc_norm()));
+  tc_1(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg)
+    : mb_mblock(runtime, instance_name, user_arg)
+  {
+    define_component("c0", "tc_norm");
+    define_component("c1", "tc_norm");
 
     connect("c0", "norm", "c1", "conj");
   }
@@ -301,6 +337,8 @@
 
 tc_1::~tc_1(){}
 
+REGISTER_MBLOCK_CLASS(tc_1);
+
 ////////////////////////////////////////////////////////////////
 
 void
@@ -315,7 +353,10 @@
                         pmt_list1(pmt_intern("in")),           // in
                         pmt_list1(pmt_intern("out")));         // out
 
-  mb_mblock_sptr       mb0 = mb_mblock_sptr(new tc_0());
+  mb_runtime_sptr rts = mb_make_runtime();
+  mb_runtime *rt = rts.get();
+
+  mb_mblock_sptr       mb0 = mb_mblock_sptr(new tc_0(rt, "top", PMT_F));
 }
 
 ////////////////////////////////////////////////////////////////
@@ -377,8 +418,11 @@
 void
 qa_mblock_prims::test_make_accepter()
 {
+  mb_runtime_sptr rts = mb_make_runtime();
+  mb_runtime *rt = rts.get();
+
   // create a block
-  mb_mblock_sptr mb = mb_mblock_sptr(new dp_2());
+  mb_mblock_sptr mb = mb_mblock_sptr(new dp_2(rt, "top", PMT_F));
 
   // use "internal use only" method...
   mb_msg_accepter_sptr accepter = mb->impl()->make_accepter("cs");

Modified: gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_mblock_send.cc
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_mblock_send.cc        
2007-04-05 21:37:35 UTC (rev 4886)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_mblock_send.cc        
2007-04-06 00:10:15 UTC (rev 4887)
@@ -58,6 +58,14 @@
 
 }
 
+#if 1  // stubs for now...
+
+void qa_mblock_send::test_simple_routing(){}
+void qa_mblock_send::test_relay_routing_1(){}
+void qa_mblock_send::test_relay_routing_2(){}
+
+#else
+
 // ================================================================
 //                    test_simple_routing
 // ================================================================
@@ -71,11 +79,13 @@
   mb_port_sptr d_p3;
 
 public:
-  sr1();
+  sr1(std::string &instance_name, pmt_t arg) : mb_mblock(instance_name, arg) {}
   ~sr1();
   void initial_transition();
 };
 
+REGISTER_MBLOCK_CLASS(sr1);
+
 sr1::sr1()
 {
   d_p1 = define_port("p1", "qa-send-cs", true, mb_port::EXTERNAL);
@@ -99,7 +109,6 @@
   d_p2->send(s_status, pmt_list3(our_name, s_p2, pmt_from_long(1)));
 }
 
-REGISTER_MBLOCK_CLASS(sr1);
 
 // ----------------------------------------------------------------
 
@@ -459,3 +468,4 @@
                           msg->data()));
 }
 
+#endif





reply via email to

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