commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r10869 - in gnuradio/trunk/gnuradio-core/src: lib/runt


From: jcorgan
Subject: [Commit-gnuradio] r10869 - in gnuradio/trunk/gnuradio-core/src: lib/runtime python/gnuradio/gr
Date: Fri, 17 Apr 2009 12:45:58 -0600 (MDT)

Author: jcorgan
Date: 2009-04-17 12:45:58 -0600 (Fri, 17 Apr 2009)
New Revision: 10869

Modified:
   gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc
   gnuradio/trunk/gnuradio-core/src/python/gnuradio/gr/qa_hier_block2.py
Log:
Fixes ticket:386

Modified: gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc
===================================================================
--- gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc       
2009-04-17 18:45:36 UTC (rev 10868)
+++ gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc       
2009-04-17 18:45:58 UTC (rev 10869)
@@ -146,16 +146,44 @@
 void
 gr_hier_block2_detail::disconnect(gr_basic_block_sptr block)
 {
+  // Check on singleton list
   for (gr_basic_block_viter_t p = d_blocks.begin(); p != d_blocks.end(); p++) {
     if (*p == block) {
       d_blocks.erase(p);
+      
+      gr_hier_block2_sptr hblock(cast_to_hier_block2_sptr(block));
+      if (block && block.get() != d_owner) {
+       if (GR_HIER_BLOCK2_DETAIL_DEBUG)
+         std::cout << "disconnect: block is hierarchical, clearing parent" << 
std::endl;
+       hblock->d_detail->d_parent_detail = 0;
+      }
+    
       return;
     }
   }
 
-  std::stringstream msg;
-  msg << "cannot disconnect block " << block << ", not found";
-  throw std::invalid_argument(msg.str());
+  // Otherwise find all edges containing block
+  gr_edge_vector_t edges, tmp = d_fg->edges();
+  gr_edge_vector_t::iterator p;
+  for (p = tmp.begin(); p != tmp.end(); p++) {
+    if ((*p).src().block() == block || (*p).dst().block() == block) {
+      edges.push_back(*p);
+
+      if (GR_HIER_BLOCK2_DETAIL_DEBUG)
+       std::cout << "disconnect: block found in edge " << (*p) << std::endl;  
+    }
+  }
+
+  if (edges.size() == 0) {
+    std::stringstream msg;
+    msg << "cannot disconnect block " << block << ", not found";
+    throw std::invalid_argument(msg.str());
+  }
+
+  for (p = edges.begin(); p != edges.end(); p++) {
+    disconnect((*p).src().block(), (*p).src().port(),
+              (*p).dst().block(), (*p).dst().port());
+  }
 }
 
 void 
@@ -174,13 +202,13 @@
 
   if (src_block && src.get() != d_owner) {
     if (GR_HIER_BLOCK2_DETAIL_DEBUG)
-      std::cout << "connect: src is hierarchical, clearing parent" << 
std::endl;
+      std::cout << "disconnect: src is hierarchical, clearing parent" << 
std::endl;
     src_block->d_detail->d_parent_detail = 0;
   }
                
   if (dst_block && dst.get() != d_owner) {
     if (GR_HIER_BLOCK2_DETAIL_DEBUG)
-      std::cout << "connect: dst is hierarchical, clearing parent" << 
std::endl;
+      std::cout << "disconnect: dst is hierarchical, clearing parent" << 
std::endl;
     dst_block->d_detail->d_parent_detail = 0;
   }
 

Modified: gnuradio/trunk/gnuradio-core/src/python/gnuradio/gr/qa_hier_block2.py
===================================================================
--- gnuradio/trunk/gnuradio-core/src/python/gnuradio/gr/qa_hier_block2.py       
2009-04-17 18:45:36 UTC (rev 10868)
+++ gnuradio/trunk/gnuradio-core/src/python/gnuradio/gr/qa_hier_block2.py       
2009-04-17 18:45:58 UTC (rev 10869)
@@ -263,6 +263,16 @@
         tb.disconnect_all()
         tb.connect(src, dst)
         tb.unlock()
+
+    def test_029_singleton_disconnect(self):
+        tb = gr.top_block()
+        src = gr.vector_source_b([1, ])
+        dst = gr.vector_sink_b()
+        tb.connect(src, dst)
+        tb.disconnect(src)   # Singleton disconnect
+        tb.connect(src, dst)
+        tb.run()
+        self.assertEquals(dst.data(), (1,))
     
 if __name__ == "__main__":
     gr_unittest.main()





reply via email to

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