commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r3994 - gnuradio/branches/developers/jcorgan/hier/gnur


From: jcorgan
Subject: [Commit-gnuradio] r3994 - gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime
Date: Thu, 16 Nov 2006 15:36:37 -0700 (MST)

Author: jcorgan
Date: 2006-11-16 15:36:36 -0700 (Thu, 16 Nov 2006)
New Revision: 3994

Modified:
   
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_basic_block.cc
   
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_basic_block.h
   
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_hier_block2.cc
   
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_hier_block2.h
   
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_hier_block2_impl.cc
   
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_hier_block2_impl.h
   
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc
   
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_runtime_impl.h
Log:
Work in progress.

Modified: 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_basic_block.cc
===================================================================
--- 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_basic_block.cc
   2006-11-16 21:42:14 UTC (rev 3993)
+++ 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_basic_block.cc
   2006-11-16 22:36:36 UTC (rev 3994)
@@ -43,13 +43,15 @@
     d_parent(0),
     d_input_signature(input_signature),
     d_output_signature(output_signature),
-    d_unique_id(s_next_id++)
+    d_unique_id(s_next_id++),
+    d_terminal(true)
 {
     s_ncurrently_allocated++;
 }
   
 gr_basic_block::~gr_basic_block()
 {
+    d_parent = 0; // We don't own this, don't call delete
     s_ncurrently_allocated--;
 }
 
@@ -67,7 +69,7 @@
 
     int ninputs = 0, noutputs = 0;
     if (d_parent)
-       d_parent->get_child_topology(shared_from_this(), ninputs, noutputs);
+       d_parent->get_child_topology(shared_from_this(), &ninputs, &noutputs);
 
     return check_topology(ninputs, noutputs);
 }

Modified: 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_basic_block.h
===================================================================
--- 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_basic_block.h
    2006-11-16 21:42:14 UTC (rev 3993)
+++ 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_basic_block.h
    2006-11-16 22:36:36 UTC (rev 3994)
@@ -56,13 +56,16 @@
 protected:
     friend class gr_tree_visitor;
     friend class gr_runtime_impl;
-        
+    friend class validation_visitor;
+    friend class connect_visitor;
+            
     std::string                 d_name;
     gr_basic_block      *d_parent;     // Temp until shared pointer method 
works
     gr_io_signature_sptr d_input_signature;
     gr_io_signature_sptr d_output_signature;
     long                d_unique_id;
-        
+    bool                d_terminal;
+            
     gr_basic_block(const std::string &name,
                    gr_io_signature_sptr input_signature,
                    gr_io_signature_sptr output_signature);
@@ -79,14 +82,20 @@
 
     // Adjusts arguments to reflect topology of passed child pointer
     // Overridden in gr_hier_block2 to calculate from connection database
-    virtual void get_child_topology(gr_basic_block_sptr child, int &ninputs, 
int &noutputs)
-        { };
+    virtual void get_child_topology(gr_basic_block_sptr child, int *ninputs, 
int *noutputs)
+        { ninputs=0; noutputs=0; }
         
     /*! overridden in gr_hier_block2 to implement tree traversal
      *  otherwise invoke callback with shared pointer to this object
      */
     virtual bool visit(gr_tree_visitor &visitor) { return 
visitor(shared_from_this()); }
 
+    /*! overriden in descendent classes to verify correct topology, etc. */
+    virtual bool validate();
+
+    /*! overriden in gr_hier_block2 to create and connect buffers for children 
*/
+    virtual void connect_children() { };
+
 public:
     virtual ~gr_basic_block();
     long unique_id() const { return d_unique_id; }
@@ -96,8 +105,8 @@
     gr_basic_block_sptr basic_block(); // Needed for Python type coercion
     void set_parent(gr_basic_block *parent) { d_parent = parent; }
     gr_basic_block *parent() const { return d_parent; }
-    virtual bool validate();
-
+    bool is_terminal_p() { return d_terminal; }
+        
     /*!
      * \brief Confirm that ninputs and noutputs is an acceptable combination.
      *

Modified: 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_hier_block2.cc
===================================================================
--- 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_hier_block2.cc
   2006-11-16 21:42:14 UTC (rev 3993)
+++ 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_hier_block2.cc
   2006-11-16 22:36:36 UTC (rev 3994)
@@ -42,6 +42,7 @@
   : gr_basic_block(name, input_signature, output_signature),
     d_impl(new gr_hier_block2_impl())
 {
+    d_terminal = false;
 }
 
 gr_hier_block2::~gr_hier_block2()
@@ -100,6 +101,15 @@
 }
 
 bool
+gr_hier_block2::visit(gr_tree_visitor &visitor)
+{
+    if (!visitor(shared_from_this()))
+       return false;
+       
+    return d_impl->visit(visitor);
+}
+
+bool
 gr_hier_block2::validate()
 {
     // Make sure base class is ok, then do my stuff
@@ -107,17 +117,14 @@
            d_impl->validate();
 }
 
-bool
-gr_hier_block2::visit(gr_tree_visitor &visitor)
+void
+gr_hier_block2::connect_children()
 {
-    if (!visitor(shared_from_this()))
-       return false;
-       
-    return d_impl->visit(visitor);
+    d_impl->connect_children();
 }
 
 void
-gr_hier_block2::get_child_topology(gr_basic_block_sptr child, int &ninputs, 
int &noutputs)
+gr_hier_block2::get_child_topology(gr_basic_block_sptr child, int *ninputs, 
int *noutputs)
 {
     d_impl->get_child_topology(child, ninputs, noutputs);
 }

Modified: 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_hier_block2.h
===================================================================
--- 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_hier_block2.h
    2006-11-16 21:42:14 UTC (rev 3993)
+++ 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_hier_block2.h
    2006-11-16 22:36:36 UTC (rev 3994)
@@ -50,11 +50,14 @@
      */
     gr_hier_block2_impl *d_impl;
 
-    void get_child_topology(gr_basic_block_sptr child, int &ninputs, int 
&noutputs);
+    void get_child_topology(gr_basic_block_sptr child, int *ninputs, int 
*noutputs);
         
     // Overrides gr_basic_block, invokes visitor call back on self and all 
children
     virtual bool visit(gr_tree_visitor &visitor);
 
+    // Overrides gr_basic_block, connects i/o on child components
+    virtual void connect_children();
+    
 protected: 
     gr_hier_block2(const std::string &name,
                   gr_io_signature_sptr input_signature,

Modified: 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_hier_block2_impl.cc
===================================================================
--- 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_hier_block2_impl.cc
      2006-11-16 21:42:14 UTC (rev 3993)
+++ 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_hier_block2_impl.cc
      2006-11-16 22:36:36 UTC (rev 3994)
@@ -188,7 +188,7 @@
 }
 
 void
-gr_hier_block2_impl::get_child_topology(gr_basic_block_sptr child, int 
&ninputs, int &noutputs)
+gr_hier_block2_impl::get_child_topology(gr_basic_block_sptr child, int 
*ninputs, int *noutputs)
 {
     std::string name = get_name_by_block(child);
     if (name == "")
@@ -196,9 +196,9 @@
 
     std::vector<int> used_ports;
     calc_used_ports(calc_connections(name, true), used_ports, true);
-    ninputs = used_ports.size();
+    *ninputs = used_ports.size();
     calc_used_ports(calc_connections(name, false), used_ports, false);
-    noutputs = used_ports.size();    
+    *noutputs = used_ports.size();    
 
     if (GR_HIER_BLOCK2_IMPL_DEBUG)
        std::cout << name << " has " << ninputs << " inputs and " 
@@ -293,3 +293,10 @@
     std::sort(tmp.begin(), tmp.end());
     std::unique_copy(tmp.begin(), tmp.end(), inserter);
 }
+
+void
+gr_hier_block2_impl::connect_children()
+{
+    if (GR_HIER_BLOCK2_IMPL_DEBUG)
+       std::cout << "gr_hier_block2_impl:connect_children()" << std::endl;
+}

Modified: 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_hier_block2_impl.h
===================================================================
--- 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_hier_block2_impl.h
       2006-11-16 21:42:14 UTC (rev 3993)
+++ 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_hier_block2_impl.h
       2006-11-16 22:36:36 UTC (rev 3994)
@@ -95,7 +95,8 @@
     gr_basic_block_vector_t get_connected_blocks();
     bool visit(gr_tree_visitor &visitor);
     bool validate();
-    void get_child_topology(gr_basic_block_sptr child, int &ninputs, int 
&noutputs);
+    void connect_children();
+    void get_child_topology(gr_basic_block_sptr child, int *ninputs, int 
*noutputs);
     gr_connection_vector_t calc_connections(const std::string &name, bool dir);
     void calc_used_ports(gr_connection_vector_t connections,
                         std::vector<int> &used_ports, bool dir); // 
true=inputs, false=outputs

Modified: 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc
===================================================================
--- 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc
  2006-11-16 21:42:14 UTC (rev 3993)
+++ 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc
  2006-11-16 22:36:36 UTC (rev 3994)
@@ -60,6 +60,28 @@
     return d_top_block->visit(visitor);
 }
 
+class connect_visitor : public gr_tree_visitor
+{
+public:
+    virtual bool visit(gr_basic_block_sptr block)
+    { 
+       if (GR_RUNTIME_IMPL_DEBUG)
+           std::cout << "Connecting block: " << block << std::endl;
+
+       block->connect_children();
+       return true; // failures are exceptions are this point
+    }
+};
+
+void
+gr_runtime_impl::connect_blocks()
+{
+    // Visit every node in the tree and wire inputs and outputs of
+    // leaf nodes (gr_block's)
+    connect_visitor visitor;
+    d_top_block->visit(visitor);
+}
+
 void 
 gr_runtime_impl::start()
 {
@@ -73,8 +95,8 @@
 
     if (!validate())
        throw std::runtime_error("tree failed validation");
-       
-    // Do stuff here
+
+    connect_blocks();  
 }
 
 void 
@@ -96,3 +118,4 @@
     if (GR_RUNTIME_IMPL_DEBUG)
        std::cout << "gr_runtime_impl::wait()" << std::endl;
 }
+

Modified: 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_runtime_impl.h
===================================================================
--- 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_runtime_impl.h
   2006-11-16 21:42:14 UTC (rev 3993)
+++ 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_runtime_impl.h
   2006-11-16 22:36:36 UTC (rev 3994)
@@ -35,6 +35,8 @@
     gr_hier_block2_sptr d_top_block;
 
     bool validate();
+    void connect_blocks();
+
     void start();
     void stop();
     void wait();





reply via email to

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