commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r3885 - in gnuradio/branches/developers/jcorgan/hier/g


From: jcorgan
Subject: [Commit-gnuradio] r3885 - in gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src: lib/runtime python/gnuradio/gr
Date: Fri, 27 Oct 2006 18:53:28 -0600 (MDT)

Author: jcorgan
Date: 2006-10-27 18:53:27 -0600 (Fri, 27 Oct 2006)
New Revision: 3885

Added:
   
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/python/gnuradio/gr/hier_block2.py
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_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.i
   
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/python/gnuradio/gr/Makefile.am
   
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/python/gnuradio/gr/__init__.py
   
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/python/gnuradio/gr/qa_hier_block2.py
Log:
Work in progress.

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-10-27 23:00:47 UTC (rev 3884)
+++ 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_basic_block.h
    2006-10-28 00:53:27 UTC (rev 3885)
@@ -39,13 +39,12 @@
 
 class gr_basic_block
 {
-private:
+protected:
     std::string                 d_name;
     gr_io_signature_sptr d_input_signature;
     gr_io_signature_sptr d_output_signature;
     long                d_unique_id;
         
-protected:
     gr_basic_block(const std::string name,
                    gr_io_signature_sptr input_signature,
                    gr_io_signature_sptr output_signature);

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-10-27 23:00:47 UTC (rev 3884)
+++ 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_hier_block2.cc
   2006-10-28 00:53:27 UTC (rev 3885)
@@ -50,8 +50,11 @@
     delete d_impl;
 }
 
-void gr_hier_block2::define_component(const std::string name, gr_block_sptr 
comp)
+void gr_hier_block2::define_component(const std::string name, 
gr_basic_block_sptr comp)
 {
     if (GR_HIER_BLOCK2_DEBUG)
-       std::cout << "Adding block '" << name << "' to container." << std::endl;
+       std::cout << "Adding block '" << name << "' to container '" << d_name 
<< "'" << std::endl;
+
+    if (d_impl->lookup_component(name))
+       throw std::invalid_argument("Component already defined");
 }

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-10-27 23:00:47 UTC (rev 3884)
+++ 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_hier_block2.h
    2006-10-28 00:53:27 UTC (rev 3885)
@@ -62,10 +62,10 @@
     ~gr_hier_block2();
 
     /*!
-     * \brief Add a named terminal block to container
+     * \brief Add a named block to container
      * \ingroup block
      */
-    void define_component(const std::string name, gr_block_sptr comp);
+    void define_component(const std::string name, gr_basic_block_sptr comp);
 };
 
 #endif /* INCLUDED_GR_HIER_BLOCK2_H */

Modified: 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_hier_block2.i
===================================================================
--- 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_hier_block2.i
    2006-10-27 23:00:47 UTC (rev 3884)
+++ 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_hier_block2.i
    2006-10-28 00:53:27 UTC (rev 3885)
@@ -24,7 +24,9 @@
 typedef boost::shared_ptr<gr_hier_block2> gr_hier_block2_sptr;
 %template(gr_hier_block2_sptr) boost::shared_ptr<gr_hier_block2>;
 
-%rename(hier_block2) gr_make_hier_block2;
+// Hack to have a Python shim implementation of gr.hier_block2
+// that instantiates one of these and passes through calls
+%rename(hier_block2_swig) gr_make_hier_block2;
 gr_hier_block2_sptr gr_make_hier_block2(const std::string name,
                                        gr_io_signature_sptr input_signature,
                                        gr_io_signature_sptr output_signature);
@@ -42,6 +44,6 @@
 public:
     ~gr_hier_block2 ();
 
-    // Add a named terminal block to the container
-    void define_component(const std::string name, gr_block_sptr comp);
+    // Add a named block to the container
+    void define_component(const std::string name, gr_basic_block_sptr comp);
 };

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-10-27 23:00:47 UTC (rev 3884)
+++ 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_hier_block2_impl.cc
      2006-10-28 00:53:27 UTC (rev 3885)
@@ -36,3 +36,12 @@
 gr_hier_block2_impl::~gr_hier_block2_impl()
 {
 }
+
+gr_basic_block_sptr gr_hier_block2_impl::lookup_component(std::string name)
+{
+    gr_basic_block_sptr result;
+
+    // NOP
+
+    return result;
+}
\ No newline at end of file

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-10-27 23:00:47 UTC (rev 3884)
+++ 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/lib/runtime/gr_hier_block2_impl.h
       2006-10-28 00:53:27 UTC (rev 3885)
@@ -25,11 +25,20 @@
 // Define to 0 to eliminate debugging
 #define GR_HIER_BLOCK2_IMPL_DEBUG 1
 
+#include <gr_basic_block.h>
+#include <stdexcept>
+
 class gr_hier_block2_impl
 {
 private:
     friend class gr_hier_block2;
     gr_hier_block2_impl();
+
+    // Not implemented, making private makes class noncopyable
+    gr_hier_block2_impl(const gr_hier_block2_impl &rhs);
+    gr_hier_block2_impl &operator=(const gr_hier_block2_impl &rhs);
+
+    gr_basic_block_sptr lookup_component(const std::string name);
         
 public:
     ~gr_hier_block2_impl();

Modified: 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/python/gnuradio/gr/Makefile.am
===================================================================
--- 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/python/gnuradio/gr/Makefile.am
  2006-10-27 23:00:47 UTC (rev 3884)
+++ 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/python/gnuradio/gr/Makefile.am
  2006-10-28 00:53:27 UTC (rev 3885)
@@ -39,6 +39,7 @@
        gr_threading_23.py      \
        gr_threading_24.py      \
        hier_block.py           \
+       hier_block2.py          \
        prefs.py                \
        scheduler.py            
 
@@ -62,6 +63,7 @@
        qa_fsk_stuff.py                 \
        qa_goertzel.py                  \
        qa_head.py                      \
+       qa_hier_block2.py               \
        qa_hilbert.py                   \
        qa_iir.py                       \
        qa_interleave.py                \

Modified: 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/python/gnuradio/gr/__init__.py
===================================================================
--- 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/python/gnuradio/gr/__init__.py
  2006-10-27 23:00:47 UTC (rev 3884)
+++ 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/python/gnuradio/gr/__init__.py
  2006-10-28 00:53:27 UTC (rev 3885)
@@ -29,8 +29,8 @@
 from flow_graph import *
 from exceptions import *
 from hier_block import *
+from hier_block2 import *
 
-
 # create a couple of aliases
 serial_to_parallel = stream_to_vector
 parallel_to_serial = vector_to_stream

Added: 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/python/gnuradio/gr/hier_block2.py
===================================================================
--- 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/python/gnuradio/gr/hier_block2.py
                               (rev 0)
+++ 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/python/gnuradio/gr/hier_block2.py
       2006-10-28 00:53:27 UTC (rev 3885)
@@ -0,0 +1,38 @@
+#
+# Copyright 2006 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 2, 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 hier_block2_swig
+
+#
+# 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.
+#
+# It also allows us to intercept method calls if needed
+#
+class hier_block2(object):
+    def __init__(self, name, input_signature, output_signature):
+       print "hier_block2.__init__: called for ", name
+       self._hb = hier_block2_swig(name, input_signature, output_signature)
+
+    def __getattr__(self, name):
+       return getattr(self._hb, name)

Modified: 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/python/gnuradio/gr/qa_hier_block2.py
===================================================================
--- 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/python/gnuradio/gr/qa_hier_block2.py
    2006-10-27 23:00:47 UTC (rev 3884)
+++ 
gnuradio/branches/developers/jcorgan/hier/gnuradio-core/src/python/gnuradio/gr/qa_hier_block2.py
    2006-10-28 00:53:27 UTC (rev 3885)
@@ -20,5 +20,16 @@
        self.assertEqual(1, hblock.output_signature().max_streams())
        self.assertEqual(gr.sizeof_int, 
hblock.output_signature().sizeof_stream_item(0))
 
+    def test_002_define_component(self):
+       hblock = gr.hier_block2("test_block", 
+                               gr.io_signature(1,1,gr.sizeof_int), 
+                               gr.io_signature(1,1,gr.sizeof_int))
+
+       src1 = gr.null_source(gr.sizeof_int)
+       sink1 = gr.null_sink(gr.sizeof_int)
+           
+       hblock.define_component("source", src1)
+       hblock.define_component("sink", sink1)
+
 if __name__ == "__main__":
     gr_unittest.main()
\ No newline at end of file





reply via email to

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