commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r6181 - in gnuradio/branches/developers/jcorgan/fg/gnu


From: jcorgan
Subject: [Commit-gnuradio] r6181 - in gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src: lib/runtime python/gnuradio/gr
Date: Mon, 27 Aug 2007 00:22:53 -0600 (MDT)

Author: jcorgan
Date: 2007-08-27 00:22:53 -0600 (Mon, 27 Aug 2007)
New Revision: 6181

Added:
   
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/python/gnuradio/gr/top_block.py
Removed:
   
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_runtime.cc
   
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_runtime.h
   
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_runtime.i
   
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc
   
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_runtime_impl.h
   
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/python/gnuradio/gr/qa_runtime.py
Modified:
   
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/Makefile.am
   
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_hier_block2.cc
   
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_hier_block2.h
   
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc
   
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h
   
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_runtime_types.h
   
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_top_block.h
   
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/runtime.i
   
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/python/gnuradio/gr/Makefile.am
   
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/python/gnuradio/gr/__init__.py
   
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/python/gnuradio/gr/hier_block2.py
   
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/python/gnuradio/gr/qa_hier_block2.py
Log:
Refactored surrounding code to use gr_top_block instead of gr_runtime.

This creates an external API change: the user no longer needs to
create a gr.runtime and call run() on it; instead he just calls run() 
on the top_block.  This completes the reversion to the old flowgraph
semantics, so porting from the old flowgraph to the new top_block code
may be as simple as a search and replace from 'gr.flowgraph' to 'gr.top_block.'

None of the example code has been updated yet, so they are all broken
until that's done.



Modified: 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/Makefile.am
===================================================================
--- 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/Makefile.am
   2007-08-27 05:17:40 UTC (rev 6180)
+++ 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/Makefile.am
   2007-08-27 06:22:53 UTC (rev 6181)
@@ -48,8 +48,6 @@
        gr_pagesize.cc                          \
        gr_preferences.cc                       \
        gr_realtime.cc                          \
-       gr_runtime.cc                           \
-       gr_runtime_impl.cc                      \
        gr_scheduler_thread.cc                  \
        gr_single_threaded_scheduler.cc         \
        gr_sync_block.cc                        \
@@ -95,8 +93,6 @@
        gr_pagesize.h                           \
        gr_preferences.h                        \
        gr_realtime.h                           \
-       gr_runtime.h                            \
-       gr_runtime_impl.h                       \
        gr_runtime_types.h                      \
        gr_scheduler_thread.h                   \
        gr_select_handler.h                     \
@@ -137,12 +133,12 @@
        gr_msg_handler.i                \
        gr_msg_queue.i                  \
        gr_realtime.i                   \
-       gr_runtime.i                    \
        gr_single_threaded_scheduler.i  \
        gr_sync_block.i                 \
        gr_sync_decimator.i             \
        gr_sync_interpolator.i          \
        gr_swig_block_magic.i           \
+       gr_top_block.i                  \
        runtime.i
 
 MOSTLYCLEANFILES = *~ *.loT

Modified: 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_hier_block2.cc
===================================================================
--- 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_hier_block2.cc
     2007-08-27 05:17:40 UTC (rev 6180)
+++ 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_hier_block2.cc
     2007-08-27 06:22:53 UTC (rev 6181)
@@ -66,14 +66,6 @@
 }
 
 void
-gr_hier_block2::set_runtime(gr_runtime *runtime)
-{
-  if (GR_HIER_BLOCK2_DEBUG)
-    std::cout << "Setting runtime on " << this << " to " << runtime << 
std::endl;
-  d_detail->set_runtime(runtime);
-}
-
-void
 gr_hier_block2::lock()
 {
   d_detail->lock();

Modified: 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_hier_block2.h
===================================================================
--- 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_hier_block2.h
      2007-08-27 05:17:40 UTC (rev 6180)
+++ 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_hier_block2.h
      2007-08-27 06:22:53 UTC (rev 6181)
@@ -41,7 +41,6 @@
 {
 private:
   friend class gr_hier_block2_detail;
-  friend class gr_runtime_impl;
   friend gr_hier_block2_sptr gr_make_hier_block2(const std::string &name,
                                                 gr_io_signature_sptr 
input_signature,
                                                 gr_io_signature_sptr 
output_signature);
@@ -51,9 +50,6 @@
    */
   gr_hier_block2_detail *d_detail;
   
-  /* Internal use only */
-  void set_runtime(gr_runtime *runtime);
-  
 protected: 
   gr_hier_block2(const std::string &name,
                 gr_io_signature_sptr input_signature,
@@ -66,8 +62,8 @@
               gr_basic_block_sptr dst, int dst_port);
   void disconnect(gr_basic_block_sptr src, int src_port,
                  gr_basic_block_sptr dst, int dst_port);
-  void lock();
-  void unlock();
+  virtual void lock();
+  virtual void unlock();
 
   void flatten(gr_flat_flowgraph_sptr ffg);
 };

Modified: 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc
===================================================================
--- 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc
      2007-08-27 05:17:40 UTC (rev 6180)
+++ 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc
      2007-08-27 06:22:53 UTC (rev 6181)
@@ -25,7 +25,6 @@
 
 #include <gr_hier_block2_detail.h>
 #include <gr_io_signature.h>
-#include <gr_runtime.h>
 #include <stdexcept>
 #include <iostream>
 
@@ -36,8 +35,7 @@
   d_parent_detail(0),
   d_fg(gr_make_flowgraph()),
   d_inputs(owner->input_signature()->max_streams()),
-  d_outputs(owner->output_signature()->max_streams()),
-  d_runtime()
+  d_outputs(owner->output_signature()->max_streams())
 {
 }
 
@@ -263,8 +261,7 @@
   if (d_parent_detail)
     d_parent_detail->lock();
   else
-    if (d_runtime)
-      d_runtime->lock();
+    d_owner->lock();
 }
 
 void
@@ -276,6 +273,5 @@
   if (d_parent_detail)
     d_parent_detail->unlock();
   else
-    if (d_runtime)
-      d_runtime->unlock();
+    d_owner->unlock();
 }

Modified: 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h
===================================================================
--- 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h
       2007-08-27 05:17:40 UTC (rev 6180)
+++ 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.h
       2007-08-27 06:22:53 UTC (rev 6181)
@@ -40,7 +40,6 @@
     gr_flowgraph_sptr d_fg;
     gr_endpoint_vector_t d_inputs;
     gr_endpoint_vector_t d_outputs;
-    gr_runtime *d_runtime;
 
     // Private implementation methods
     void connect(gr_basic_block_sptr src, int src_port, 
@@ -54,7 +53,6 @@
     void flatten(gr_flat_flowgraph_sptr sfg);
     gr_endpoint resolve_port(int port, bool is_input);
     gr_endpoint resolve_endpoint(const gr_endpoint &endp, bool is_input);
-    void set_runtime(gr_runtime *runtime) { d_runtime = runtime; }
     void lock();
     void unlock();
 

Deleted: 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_runtime.cc

Deleted: 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_runtime.h

Deleted: 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_runtime.i

Deleted: 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc

Deleted: 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_runtime_impl.h

Modified: 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_runtime_types.h
===================================================================
--- 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_runtime_types.h
    2007-08-27 05:17:40 UTC (rev 6180)
+++ 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_runtime_types.h
    2007-08-27 06:22:53 UTC (rev 6181)
@@ -38,7 +38,6 @@
 class gr_buffer_reader;
 class gr_flowgraph;
 class gr_flat_flowgraph;
-class gr_runtime;
 class gr_top_block;
 class gr_top_block_detail;
 
@@ -49,7 +48,6 @@
 typedef boost::shared_ptr<gr_io_signature>      gr_io_signature_sptr;
 typedef boost::shared_ptr<gr_buffer>           gr_buffer_sptr;
 typedef boost::shared_ptr<gr_buffer_reader>    gr_buffer_reader_sptr;
-typedef boost::shared_ptr<gr_runtime>          gr_runtime_sptr;
 typedef boost::shared_ptr<gr_flowgraph>         gr_flowgraph_sptr;
 typedef boost::shared_ptr<gr_flat_flowgraph>    gr_flat_flowgraph_sptr;
 typedef boost::shared_ptr<gr_top_block>         gr_top_block_sptr;

Modified: 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_top_block.h
===================================================================
--- 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_top_block.h
        2007-08-27 05:17:40 UTC (rev 6180)
+++ 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_top_block.h
        2007-08-27 06:22:53 UTC (rev 6181)
@@ -77,7 +77,7 @@
    * N.B. lock() and unlock() cannot be called from a flowgraph thread or
    * deadlock will occur when reconfiguration happens.
    */
-  void lock();
+  virtual void lock();
 
   /*!
    * Lock a flowgraph in preparation for reconfiguration.  When an equal
@@ -87,7 +87,7 @@
    * N.B. lock() and unlock() cannot be called from a flowgraph thread or
    * deadlock will occur when reconfiguration happens.
    */
-  void unlock();
+  virtual void unlock();
 };
 
 #endif /* INCLUDED_GR_TOP_BLOCK_H */

Modified: 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/runtime.i
===================================================================
--- 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/runtime.i 
    2007-08-27 05:17:40 UTC (rev 6180)
+++ 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/runtime.i 
    2007-08-27 06:22:53 UTC (rev 6181)
@@ -27,7 +27,6 @@
 #include <gr_block.h>
 #include <gr_block_detail.h>
 #include <gr_hier_block2.h>
-#include <gr_runtime.h>
 #include <gr_single_threaded_scheduler.h>
 #include <gr_message.h>
 #include <gr_msg_handler.h>
@@ -38,6 +37,7 @@
 #include <gr_sync_block.h>
 #include <gr_sync_decimator.h>
 #include <gr_sync_interpolator.h>
+#include <gr_top_block.h>
 %}
 
 %include <gr_io_signature.i>
@@ -54,7 +54,7 @@
 %include <gr_dispatcher.i>
 %include <gr_error_handler.i>
 %include <gr_realtime.i>
-%include <gr_runtime.i>
 %include <gr_sync_block.i>
 %include <gr_sync_decimator.i>
 %include <gr_sync_interpolator.i>
+%include <gr_top_block.i>

Modified: 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/python/gnuradio/gr/Makefile.am
===================================================================
--- 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/python/gnuradio/gr/Makefile.am
    2007-08-27 05:17:40 UTC (rev 6180)
+++ 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/python/gnuradio/gr/Makefile.am
    2007-08-27 06:22:53 UTC (rev 6181)
@@ -41,7 +41,8 @@
        hier_block.py           \
        hier_block2.py          \
        prefs.py                \
-       scheduler.py            
+       scheduler.py            \
+       top_block.py
 
 noinst_PYTHON =                        \
        benchmark_filters.py            \

Modified: 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/python/gnuradio/gr/__init__.py
===================================================================
--- 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/python/gnuradio/gr/__init__.py
    2007-08-27 05:17:40 UTC (rev 6180)
+++ 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/python/gnuradio/gr/__init__.py
    2007-08-27 06:22:53 UTC (rev 6181)
@@ -30,6 +30,7 @@
 from exceptions import *
 from hier_block import *
 from hier_block2 import *
+from top_block import *
 
 # create a couple of aliases
 serial_to_parallel = stream_to_vector

Modified: 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/python/gnuradio/gr/hier_block2.py
===================================================================
--- 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/python/gnuradio/gr/hier_block2.py
 2007-08-27 05:17:40 UTC (rev 6180)
+++ 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/python/gnuradio/gr/hier_block2.py
 2007-08-27 06:22:53 UTC (rev 6181)
@@ -1,5 +1,5 @@
 #
-# Copyright 2006 Free Software Foundation, Inc.
+# Copyright 2006,2007 Free Software Foundation, Inc.
 # 
 # This file is part of GNU Radio
 # 
@@ -19,9 +19,7 @@
 # Boston, MA 02110-1301, USA.
 # 
 
-from gnuradio_swig_python import hier_block2_swig, gr_make_runtime, \
-    runtime_run_unlocked, runtime_start_unlocked, runtime_stop_unlocked, \
-    runtime_wait_unlocked, runtime_restart_unlocked, io_signature
+from gnuradio_swig_python import hier_block2_swig
 
 #
 # This hack forces a 'has-a' relationship to look like an 'is-a' one.
@@ -77,34 +75,3 @@
         self._hb.disconnect(src_block.basic_block(), src_port,
                             dst_block.basic_block(), dst_port)
 
-# Convenience class to create a no input, no output block for runtime top block
-class top_block(hier_block2):
-    def __init__(self, name):
-        hier_block2.__init__(self, name, io_signature(0,0,0), 
io_signature(0,0,0))
-
-# This allows the 'run_locked' methods, which are defined in gr_runtime.i,
-# to release the Python global interpreter lock before calling the actual
-# method in gr.runtime
-#
-# This probably should be elsewhere but it works here
-class runtime(object):
-    def __init__(self, top_block):
-        if (isinstance(top_block, hier_block2)):
-            self._r = gr_make_runtime(top_block._hb)            
-        else:
-            self._r = gr_make_runtime(top_block)
-
-    def run(self):
-        runtime_run_unlocked(self._r)
-
-    def start(self):
-        runtime_start_unlocked(self._r)
-
-    def stop(self):
-        runtime_stop_unlocked(self._r)
-
-    def wait(self):
-        runtime_wait_unlocked(self._r)
-
-    def restart(self):
-        runtime_restart_unlocked(self._r)

Modified: 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/python/gnuradio/gr/qa_hier_block2.py
===================================================================
--- 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/python/gnuradio/gr/qa_hier_block2.py
      2007-08-27 05:17:40 UTC (rev 6180)
+++ 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/python/gnuradio/gr/qa_hier_block2.py
      2007-08-27 06:22:53 UTC (rev 6181)
@@ -100,8 +100,7 @@
         sink2 = gr.vector_sink_f()
         hblock.connect(src, sink1)
         hblock.connect(src, sink2)
-        runtime = gr.runtime(hblock)
-        runtime.run()
+        hblock.run()
         actual1 = sink1.data()
         actual2 = sink2.data()
         self.assertEquals(expected, actual1)
@@ -185,8 +184,7 @@
        src = gr.vector_source_f(data, False)
        dst = gr.vector_sink_f()
        hblock.connect(src, dst)
-       r = gr.runtime(hblock)
-       r.run()
+       hblock.run()
        self.assertEquals(data, dst.data())
 
 if __name__ == "__main__":

Deleted: 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/python/gnuradio/gr/qa_runtime.py

Added: 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/python/gnuradio/gr/top_block.py
===================================================================
--- 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/python/gnuradio/gr/top_block.py
                           (rev 0)
+++ 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/python/gnuradio/gr/top_block.py
   2007-08-27 06:22:53 UTC (rev 6181)
@@ -0,0 +1,91 @@
+#
+# Copyright 2007 Free Software Foundation, Inc.
+# 
+# This file is part of GNU Radio
+# 
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+# 
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with GNU Radio; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+# 
+
+from gnuradio_swig_python import top_block_swig, \
+    top_block_wait_unlocked, top_block_run_unlocked
+
+#
+# This hack forces a 'has-a' relationship to look like an 'is-a' one.
+#
+# It allows Python classes to subclass this one, while passing through
+# method calls to the C++ class shared pointer from SWIG.
+#
+# It also allows us to intercept method calls if needed.
+#
+# This allows the 'run_locked' methods, which are defined in gr_top_block.i,
+# to release the Python global interpreter lock before calling the actual
+# method in gr_top_block
+#
+class top_block(object):
+    def __init__(self, name):
+       self._tb = top_block_swig(name)
+
+    def __getattr__(self, name):
+       return getattr(self._tb, name)
+
+    def run(self):
+        top_block_run_unlocked(self._tb)
+
+    def wait(self):
+        top_block_wait_unlocked(self._tb)
+
+    # FIXME: these are duplicated from hier_block2.py; they should really be 
implemented
+    # in the original C++ class (gr_hier_block2), then they would all be 
inherited here
+
+    def connect(self, *points):
+        '''connect requires two or more arguments that can be coerced to 
endpoints.
+        If more than two arguments are provided, they are connected together 
successively.
+        '''
+        if len (points) < 2:
+            raise ValueError, ("connect requires at least two endpoints; %d 
provided." % (len (points),))
+        for i in range (1, len (points)):
+            self._connect(points[i-1], points[i])
+
+    def _connect(self, src, dst):
+        (src_block, src_port) = self._coerce_endpoint(src)
+        (dst_block, dst_port) = self._coerce_endpoint(dst)
+        self._tb.connect(src_block.basic_block(), src_port,
+                         dst_block.basic_block(), dst_port)
+
+    def _coerce_endpoint(self, endp):
+        if hasattr(endp, 'basic_block'):
+            return (endp, 0)
+        else:
+            if hasattr(endp, "__getitem__") and len(endp) == 2:
+                return endp # Assume user put (block, port)
+            else:
+                raise ValueError("unable to coerce endpoint")
+
+    def disconnect(self, *points):
+        '''connect requires two or more arguments that can be coerced to 
endpoints.
+        If more than two arguments are provided, they are disconnected 
successively.
+        '''
+        if len (points) < 2:
+            raise ValueError, ("disconnect requires at least two endpoints; %d 
provided." % (len (points),))
+        for i in range (1, len (points)):
+            self._disconnect(points[i-1], points[i])
+
+    def _disconnect(self, src, dst):
+        (src_block, src_port) = self._coerce_endpoint(src)
+        (dst_block, dst_port) = self._coerce_endpoint(dst)
+        self._tb.disconnect(src_block.basic_block(), src_port,
+                            dst_block.basic_block(), dst_port)
+





reply via email to

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