removed is_running method from gr_top_block
authoreb <eb@221aa14e-8319-0410-a670-987f0aec2ac5>
Tue, 24 Jun 2008 20:48:39 +0000 (20:48 +0000)
committereb <eb@221aa14e-8319-0410-a670-987f0aec2ac5>
Tue, 24 Jun 2008 20:48:39 +0000 (20:48 +0000)
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@8689 221aa14e-8319-0410-a670-987f0aec2ac5

gnuradio-core/src/lib/runtime/gr_top_block.cc
gnuradio-core/src/lib/runtime/gr_top_block.h
gnuradio-core/src/lib/runtime/gr_top_block.i
gnuradio-core/src/lib/runtime/gr_top_block_impl.cc
gnuradio-core/src/lib/runtime/gr_top_block_impl.h
gnuradio-core/src/lib/runtime/gr_top_block_impl_sts.cc
gr-gpio/src/python/gpio_usrp_siggen.py
gr-utils/src/python/usrp_siggen.py

index 473ea58832b283aaf9e9534e05e109099517c863..339f3cb89e1ef0c853e992cec5204257a7447b57 100644 (file)
@@ -96,9 +96,3 @@ gr_top_block::dump()
 {
   d_impl->dump();
 }
-
-bool
-gr_top_block::is_running()
-{
-  return d_impl->is_running();
-}
index 637a3846822b8004f26092af7aa1b4b0c459b8a9..b47ec019c8f68e0c38c4572145ded27cfff69080 100644 (file)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2007 Free Software Foundation, Inc.
+ * Copyright 2007,2008 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
@@ -103,11 +103,6 @@ public:
    * Displays flattened flowgraph edges and block connectivity
    */
   void dump();
-
-  /*!
-   * Returns true if flowgraph is running
-   */
-  bool is_running();
 };
 
 #endif /* INCLUDED_GR_TOP_BLOCK_H */
index d2e8e3b41338a8ab30d104aac2534838afd339f1..670e5b5e54eb65ae37c955b67f20022b680787d4 100644 (file)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2007 Free Software Foundation, Inc.
+ * Copyright 2007,2008 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
@@ -46,7 +46,6 @@ public:
   void run();
   void lock();
   void unlock() throw (std::runtime_error);
-  bool is_running();
   void dump();
 };
 
index 857e9fa2dfacf5c2acd766d46083861208379a49..5914379384cfd51e5b61617cec3c11249134a613 100644 (file)
@@ -57,7 +57,10 @@ gr_top_block_impl::start()
     std::cout << "start: entered " << this << std::endl;
 
   if (d_running)
-    throw std::runtime_error("top block already running or wait() not called after previous stop()");
+    throw std::runtime_error("top_block::start: top block already running or wait() not called after previous stop()");
+
+  if (d_lock_count > 0)
+    throw std::runtime_error("top_block::start: can't call start with flow graph locked");
 
   // Create new flat flow graph by flattening hierarchy
   d_ffg = d_owner->flatten();
@@ -68,6 +71,7 @@ gr_top_block_impl::start()
 
   // Execute scheduler threads
   start_threads();
+  d_running = true;
 }
 
 
@@ -86,8 +90,10 @@ void
 gr_top_block_impl::unlock()
 {
   omni_mutex_lock lock(d_reconf);
-  if (d_lock_count <= 0)
+  if (d_lock_count <= 0){
+    d_lock_count = 0;          // fix it, then complain
     throw std::runtime_error("unpaired unlock() call");
+  }
 
   d_lock_count--;
   if (GR_TOP_BLOCK_IMPL_DEBUG)
@@ -107,7 +113,7 @@ gr_top_block_impl::restart()
     std::cout << "restart: entered" << std::endl;
 
   if (!d_running)
-    throw std::runtime_error("top block is not running");
+    return;            // nothing to do
 
   // Stop scheduler threads and wait for completion
   stop();
@@ -133,6 +139,7 @@ gr_top_block_impl::restart()
   d_ffg = new_ffg;
 
   start_threads();
+  d_running = true;
 }
 
 void
index 003afec9382ed791e66de4207ac542eaefdf0ac0..869f788ef4feca5983de140583eb1ae90ec0ec4c 100644 (file)
@@ -49,16 +49,13 @@ public:
   virtual void wait() = 0;
 
   // Lock the top block to allow reconfiguration
-  virtual void lock();
+  void lock();
 
   // Unlock the top block at end of reconfiguration
-  virtual void unlock();
+  void unlock();
 
   // Dump the flowgraph to stdout
   void dump();
-
-  // Return true if flowgraph is running
-  bool is_running() const { return d_running; }
   
 protected:
     
@@ -70,7 +67,6 @@ protected:
   int                            d_lock_count;
 
   virtual void start_threads() = 0;
-  virtual void restart();
 
 /*!
  * Make a vector of gr_block from a vector of gr_basic_block
@@ -79,6 +75,8 @@ protected:
  */
   static gr_block_vector_t make_gr_block_vector(gr_basic_block_vector_t blocks);
 
+private:
+  void restart();
 };
 
 #endif /* INCLUDED_GR_TOP_BLOCK_IMPL_H */
index 39289ce5b2c955f02e0c7031379519be841ca0e4..b3e9da6275e4d5420c3ca73866ba06f1b6fe52e2 100644 (file)
@@ -85,8 +85,6 @@ gr_top_block_impl_sts::start_threads()
       std::cout << "start_threads: starting " << thread << std::endl;
     thread->start();
   }
-
-  d_running = true;
 }
 
 /*
index 0a0ea685b0d0fc4bd5e89456a86c086cbfef0609..0e483c35db6959e21cd16d083bed16674050110d 100755 (executable)
@@ -90,26 +90,25 @@ class my_top_block(gr.top_block):
         # self.file_sink = gr.file_sink (gr.sizeof_gr_complex, "siggen.dat")
 
     def _configure_graph (self, type):
-        was_running = self.is_running ()
-        if was_running:
-            self.stop ()
-        self.disconnect_all ()
-        if type == gr.GR_SIN_WAVE:
-            self.connect (self.siggen, self.u)
-            # self.connect (self.siggen, self.file_sink)
-            self.siggen.set_waveform (type)
-            self.src = self.siggen
-        elif type == gr.GR_UNIFORM or type == gr.GR_GAUSSIAN:
-            self.connect (self.noisegen, self.u)
-            self.noisegen.set_type (type)
-            self.src = self.noisegen
-        elif type == gr.GR_CONST_WAVE:
-            self.connect (self.vecgen, self.u)
-            self.src = self.vecgen
-        else:
-            raise ValueError, type
-        if was_running:
-            self.start ()
+        try:
+            self.lock()
+            self.disconnect_all ()
+            if type == gr.GR_SIN_WAVE:
+                self.connect (self.siggen, self.u)
+                # self.connect (self.siggen, self.file_sink)
+                self.siggen.set_waveform (type)
+                self.src = self.siggen
+            elif type == gr.GR_UNIFORM or type == gr.GR_GAUSSIAN:
+                self.connect (self.noisegen, self.u)
+                self.noisegen.set_type (type)
+                self.src = self.noisegen
+            elif type == gr.GR_CONST_WAVE:
+                self.connect (self.vecgen, self.u)
+                self.src = self.vecgen
+            else:
+                raise ValueError, type
+        finally:
+            self.unlock()
 
     def set_freq(self, target_freq):
         """
index f0a096e2d259b3f0c3404e0b5d386d922af9165e..add3888ba277de2c792377c13973bd4aa0a0cd3c 100755 (executable)
@@ -69,23 +69,22 @@ class my_top_block(gr.top_block):
         # self.file_sink = gr.file_sink (gr.sizeof_gr_complex, "siggen.dat")
 
     def _configure_graph (self, type):
-        was_running = self.is_running ()
-        if was_running:
-            self.stop ()
-        self.disconnect_all ()
-        if type == gr.GR_SIN_WAVE or type == gr.GR_CONST_WAVE:
-            self.connect (self.siggen, self.u)
-            # self.connect (self.siggen, self.file_sink)
-            self.siggen.set_waveform (type)
-            self.src = self.siggen
-        elif type == gr.GR_UNIFORM or type == gr.GR_GAUSSIAN:
-            self.connect (self.noisegen, self.u)
-            self.noisegen.set_type (type)
-            self.src = self.noisegen
-        else:
-            raise ValueError, type
-        if was_running:
-            self.start ()
+        try:
+            self.lock()
+            self.disconnect_all ()
+            if type == gr.GR_SIN_WAVE or type == gr.GR_CONST_WAVE:
+                self.connect (self.siggen, self.u)
+                # self.connect (self.siggen, self.file_sink)
+                self.siggen.set_waveform (type)
+                self.src = self.siggen
+            elif type == gr.GR_UNIFORM or type == gr.GR_GAUSSIAN:
+                self.connect (self.noisegen, self.u)
+                self.noisegen.set_type (type)
+                self.src = self.noisegen
+            else:
+                raise ValueError, type
+        finally:
+            self.unlock()
 
     def set_freq(self, target_freq):
         """