commit-gnuradio
[Top][All Lists]
Advanced

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

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


From: jcorgan
Subject: [Commit-gnuradio] r3995 - gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime
Date: Thu, 16 Nov 2006 16:13:31 -0700 (MST)

Author: jcorgan
Date: 2006-11-16 16:13:31 -0700 (Thu, 16 Nov 2006)
New Revision: 3995

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.h
Log:
Work in progress, clean-up.

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 22:36:36 UTC (rev 3994)
+++ 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_hier_block2_impl.cc
      2006-11-16 23:13:31 UTC (rev 3995)
@@ -111,21 +111,6 @@
 bool
 gr_hier_block2_impl::validate()
 {
-    /* General strategy for validating a hierarchical tree
-
-       The runtime will call 'visit' with a visitor function that calls 
validate() 
-       on the basic block that it gets passed at each node in the traversal.
-
-       For hierarchical blocks, we get here.  To be valid, we must check:
-               
-       1. Each of our inputs and outputs are wired according to our external
-          connectivity. This is already checked by our base class.
-       2. Each actually connected (sub)component has between min and max 
number of inputs connected
-       3. Each actually connected (sub)component has its input ports 
contiguously assigned
-       4. Each actually connected (sub)component has between min and max 
number of outputs connected
-       5. Each actually connected (sub)component has its output ports 
contiguously assigned
-    */
-
     // Only process actually connected blocks...
     gr_basic_block_vector_t blocks(get_connected_blocks());
 
@@ -184,6 +169,7 @@
            if (block_iter == blocks.end())
                blocks.push_back(dst_block);
     }
+
     return blocks;
 }
 
@@ -194,25 +180,22 @@
     if (name == "")
        throw std::invalid_argument("unknown child passed to parent");
 
-    std::vector<int> used_ports;
-    calc_used_ports(calc_connections(name, true), used_ports, true);
-    *ninputs = used_ports.size();
-    calc_used_ports(calc_connections(name, false), used_ports, false);
-    *noutputs = used_ports.size();    
+    *ninputs =  calc_used_ports(name, true).size();
+    *noutputs = calc_used_ports(name, false).size();
 
     if (GR_HIER_BLOCK2_IMPL_DEBUG)
-       std::cout << name << " has " << ninputs << " inputs and " 
-                 << noutputs << " outputs assigned." << std::endl;
+       std::cout << name << " has " << *ninputs << " inputs and " 
+                 << *noutputs << " outputs assigned." << std::endl;
 }
 
 gr_connection_vector_t
-gr_hier_block2_impl::calc_connections(const std::string &name, bool dir)
+gr_hier_block2_impl::calc_connections(const std::string &name, bool 
check_inputs)
 {
     gr_connection_vector_t result;
     for (gr_connection_viter_t p = d_connections.begin();
          p != d_connections.end(); p++) {
 
-       if (dir) {
+       if (check_inputs) {
            if (p->dst().name() == name)
                result.push_back(*p);
        }
@@ -226,22 +209,20 @@
 }
 
 bool
-gr_hier_block2_impl::check_contiguity(gr_basic_block_sptr block, bool dir)
+gr_hier_block2_impl::check_contiguity(gr_basic_block_sptr block, bool 
check_inputs)
 {
     gr_io_signature_sptr sig = 
-       dir ? block->input_signature() : block->output_signature();
+       check_inputs ? block->input_signature() : block->output_signature();
        
     std::string name(get_name_by_block(block));
 
-    std::vector<int> used_ports;
-    calc_used_ports(calc_connections(name, dir), used_ports, dir);
-
+    std::vector<int> used_ports = calc_used_ports(name, check_inputs);
     int nports = used_ports.size();
     int min_ports = sig->min_streams();
     
     if (GR_HIER_BLOCK2_IMPL_DEBUG)
        std::cout << "Block " << block << " has " << nports 
-                 << " used " << (dir ? "inputs.":"outputs.") << std::endl;
+                 << " used " << (check_inputs ? "inputs.":"outputs.") << 
std::endl;
 
     // If none used, just make sure that's ok and exit
     if (nports == 0) {
@@ -250,7 +231,7 @@
         else {
            if (GR_HIER_BLOCK2_IMPL_DEBUG)
                std::cout << "Block " << block << " needs " << min_ports 
-                         << (dir ? "inputs":"outputs") << ", only has "
+                         << (check_inputs ? "inputs":"outputs") << ", only has 
"
                          << nports << std::endl;
            return false;
        }
@@ -261,7 +242,7 @@
            if (used_ports[i] != i) {
                if (GR_HIER_BLOCK2_IMPL_DEBUG)
                    std::cout << "Block " << block << " missing " 
-                             << (dir ? "input ":"output ") 
+                             << (check_inputs ? "input ":"output ") 
                              << i << std::endl;
                
                throw std::runtime_error("block is missing input assignment");
@@ -272,18 +253,18 @@
     return true;
 }
 
-void
-gr_hier_block2_impl::calc_used_ports(gr_connection_vector_t connections, 
-                                     std::vector<int> &used_ports, bool dir)
+std::vector<int>
+gr_hier_block2_impl::calc_used_ports(const std::string &name, bool 
check_inputs)
 {
-    std::vector<int> tmp;
-    std::insert_iterator<std::vector<int> > inserter(used_ports, 
used_ports.begin());
+    std::vector<int> tmp, result;
+    std::insert_iterator<std::vector<int> > inserter(result, result.begin());
 
-    used_ports.clear();
+    gr_connection_vector_t connections = calc_connections(name, check_inputs);
+
     for (gr_connection_viter_t p = connections.begin();
         p != connections.end(); p++) {
 
-       if (dir == true)  // check inputs
+       if (check_inputs == true)  // check inputs
            tmp.push_back(p->dst().port());
        else              // check outputs
            tmp.push_back(p->src().port());
@@ -292,6 +273,8 @@
     // Remove duplicates
     std::sort(tmp.begin(), tmp.end());
     std::unique_copy(tmp.begin(), tmp.end(), inserter);
+
+    return result;
 }
 
 void

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 22:36:36 UTC (rev 3994)
+++ 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_hier_block2_impl.h
       2006-11-16 23:13:31 UTC (rev 3995)
@@ -97,10 +97,9 @@
     bool validate();
     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
-    bool check_contiguity(gr_basic_block_sptr block, bool dir);
+    gr_connection_vector_t calc_connections(const std::string &name, bool 
check_inputs);
+    std::vector<int> calc_used_ports(const std::string &name, bool 
check_inputs);
+    bool check_contiguity(gr_basic_block_sptr block, bool check_inputs);
                                         
 public:
     ~gr_hier_block2_impl();





reply via email to

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