commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r8844 - in gnuradio/trunk/gnuradio-core/src/lib: gener


From: eb
Subject: [Commit-gnuradio] r8844 - in gnuradio/trunk/gnuradio-core/src/lib: general runtime
Date: Wed, 9 Jul 2008 12:59:39 -0600 (MDT)

Author: eb
Date: 2008-07-09 12:59:37 -0600 (Wed, 09 Jul 2008)
New Revision: 8844

Added:
   gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_sptr_magic.cc
   gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_sptr_magic.h
   gnuradio/trunk/gnuradio-core/src/lib/runtime/qa_gr_hier_block2_derived.cc
   gnuradio/trunk/gnuradio-core/src/lib/runtime/qa_gr_hier_block2_derived.h
Modified:
   gnuradio/trunk/gnuradio-core/src/lib/general/gr_kludge_copy.cc
   gnuradio/trunk/gnuradio-core/src/lib/runtime/Makefile.am
   gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_basic_block.h
   gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_hier_block2.cc
   gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_hier_block2.h
   gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc
   gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_top_block.cc
   gnuradio/trunk/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.cc
   gnuradio/trunk/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.h
   gnuradio/trunk/gnuradio-core/src/lib/runtime/qa_runtime.cc
Log:
Merged jcorgan/ptrfix -r8827:8843 into the trunk.

Fix that allows C++ classes derived from gr_hier_block2 to
use the new self() method to get a magic object that can be passed
to connect or disconnect to refer to their own inputs and outputs.

Note that the constructor wrapper of all classes derived from
gr_hier_block2 (and thus gr_top_block too) MUST USE the new
gnuradio::get_initial_sptr function to get the initial shared pointer.
gnuradio::get_initial_sptr works on all block types, and should be
used in all new code. See qa_gr_hier_block2_derived.{h,cc} for an
example. 



Modified: gnuradio/trunk/gnuradio-core/src/lib/general/gr_kludge_copy.cc
===================================================================
--- gnuradio/trunk/gnuradio-core/src/lib/general/gr_kludge_copy.cc      
2008-07-09 18:39:15 UTC (rev 8843)
+++ gnuradio/trunk/gnuradio-core/src/lib/general/gr_kludge_copy.cc      
2008-07-09 18:59:37 UTC (rev 8844)
@@ -31,7 +31,7 @@
 gr_kludge_copy_sptr
 gr_make_kludge_copy(size_t itemsize)
 {
-  return gr_kludge_copy_sptr(new gr_kludge_copy(itemsize));
+  return gnuradio::get_initial_sptr(new gr_kludge_copy(itemsize));
 }
 
 gr_kludge_copy::gr_kludge_copy(size_t itemsize)

Modified: gnuradio/trunk/gnuradio-core/src/lib/runtime/Makefile.am
===================================================================
--- gnuradio/trunk/gnuradio-core/src/lib/runtime/Makefile.am    2008-07-09 
18:39:15 UTC (rev 8843)
+++ gnuradio/trunk/gnuradio-core/src/lib/runtime/Makefile.am    2008-07-09 
18:59:37 UTC (rev 8844)
@@ -50,6 +50,7 @@
        gr_realtime.cc                          \
        gr_scheduler_thread.cc                  \
        gr_single_threaded_scheduler.cc         \
+       gr_sptr_magic.cc                        \
        gr_sync_block.cc                        \
        gr_sync_decimator.cc                    \
        gr_sync_interpolator.cc                 \
@@ -67,6 +68,7 @@
 libruntime_qa_la_SOURCES =                     \
        qa_gr_block.cc                          \
        qa_gr_hier_block2.cc                    \
+       qa_gr_hier_block2_derived.cc            \
        qa_gr_buffer.cc                         \
        qa_gr_flowgraph.cc                      \
        qa_gr_top_block.cc                      \
@@ -98,6 +100,7 @@
        gr_scheduler_thread.h                   \
        gr_select_handler.h                     \
        gr_single_threaded_scheduler.h          \
+       gr_sptr_magic.h                         \
        gr_sync_block.h                         \
        gr_sync_decimator.h                     \
        gr_sync_interpolator.h                  \
@@ -117,6 +120,7 @@
        qa_gr_block.h                           \
        qa_gr_flowgraph.h                       \
        qa_gr_hier_block2.h                     \
+       qa_gr_hier_block2_derived.h             \
        qa_gr_buffer.h                          \
        qa_gr_io_signature.h                    \
        qa_gr_top_block.h                       \

Modified: gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_basic_block.h
===================================================================
--- gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_basic_block.h       
2008-07-09 18:39:15 UTC (rev 8843)
+++ gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_basic_block.h       
2008-07-09 18:59:37 UTC (rev 8844)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2006 Free Software Foundation, Inc.
+ * Copyright 2006,2008 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
@@ -24,6 +24,7 @@
 #define INCLUDED_GR_BASIC_BLOCK_H
 
 #include <gr_runtime_types.h>
+#include <gr_sptr_magic.h>
 #include <boost/enable_shared_from_this.hpp>
 #include <string>
 

Modified: gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_hier_block2.cc
===================================================================
--- gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_hier_block2.cc      
2008-07-09 18:39:15 UTC (rev 8843)
+++ gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_hier_block2.cc      
2008-07-09 18:59:37 UTC (rev 8844)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2006,2007 Free Software Foundation, Inc.
+ * Copyright 2006,2007,2008 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
@@ -31,11 +31,13 @@
 
 #define GR_HIER_BLOCK2_DEBUG 0
 
-gr_hier_block2_sptr gr_make_hier_block2(const std::string &name, 
-                                        gr_io_signature_sptr input_signature,
-                                        gr_io_signature_sptr output_signature)
+
+gr_hier_block2_sptr
+gr_make_hier_block2(const std::string &name, 
+                    gr_io_signature_sptr input_signature,
+                    gr_io_signature_sptr output_signature)
 {
-  return gr_hier_block2_sptr(new gr_hier_block2(name, input_signature, 
output_signature));
+  return gnuradio::get_initial_sptr(new gr_hier_block2(name, input_signature, 
output_signature));
 }
 
 gr_hier_block2::gr_hier_block2(const std::string &name,
@@ -44,6 +46,8 @@
   : gr_basic_block(name, input_signature, output_signature),
     d_detail(new gr_hier_block2_detail(this))
 {
+  // This bit of magic ensures that self() works in the constructors of 
derived classes.
+  gnuradio::detail::sptr_magic::create_and_stash_initial_sptr(this);
 }
 
 gr_hier_block2::~gr_hier_block2()
@@ -51,6 +55,13 @@
   delete d_detail;
 }
 
+gr_hier_block2::opaque_self
+gr_hier_block2::self()
+{
+  return shared_from_this();
+}
+
+
 void 
 gr_hier_block2::connect(gr_basic_block_sptr block)
 {

Modified: gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_hier_block2.h
===================================================================
--- gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_hier_block2.h       
2008-07-09 18:39:15 UTC (rev 8843)
+++ gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_hier_block2.h       
2008-07-09 18:59:37 UTC (rev 8844)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2006,2007 Free Software Foundation, Inc.
+ * Copyright 2006,2007,2008 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
@@ -51,7 +51,7 @@
    * \brief Private implementation details of gr_hier_block2
    */
   gr_hier_block2_detail *d_detail;
-  
+    
 protected: 
   gr_hier_block2(const std::string &name,
                 gr_io_signature_sptr input_signature,
@@ -61,6 +61,22 @@
   virtual ~gr_hier_block2();
   
   /*!
+   * \brief typedef for object returned from self().
+   *
+   * This type is only guaranteed to be passable to connect and disconnect.
+   * No other assumptions should be made about it.
+   */
+  typedef gr_basic_block_sptr  opaque_self;
+
+  /*!
+   * \brief Return an object, representing the current block, which can be 
passed to connect.
+   *
+   * The returned object may only be used as an argument to connect or 
disconnect.
+   * Any other use of self() results in unspecified (erroneous) behavior.
+   */
+  opaque_self self();
+
+  /*!
    * \brief Add a stand-alone (possibly hierarchical) block to internal graph
    *
    * This adds a gr-block or hierarchical block to the internal graph
@@ -132,7 +148,7 @@
   gr_flat_flowgraph_sptr flatten() const;
 };
 
-inline gr_hier_block2_sptr make_hier_block2_sptr(gr_basic_block_sptr block) {
+inline gr_hier_block2_sptr cast_to_hier_block2_sptr(gr_basic_block_sptr block) 
{
   return boost::dynamic_pointer_cast<gr_hier_block2, gr_basic_block>(block);
 }
 

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       
2008-07-09 18:39:15 UTC (rev 8843)
+++ gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_hier_block2_detail.cc       
2008-07-09 18:59:37 UTC (rev 8844)
@@ -78,8 +78,8 @@
   if (src.get() == dst.get())
     throw std::invalid_argument("connect: src and destination blocks cannot be 
the same");
 
-  gr_hier_block2_sptr src_block(make_hier_block2_sptr(src));
-  gr_hier_block2_sptr dst_block(make_hier_block2_sptr(dst));
+  gr_hier_block2_sptr src_block(cast_to_hier_block2_sptr(src));
+  gr_hier_block2_sptr dst_block(cast_to_hier_block2_sptr(dst));
 
   if (src_block && src.get() != d_owner) {
     if (GR_HIER_BLOCK2_DETAIL_DEBUG)
@@ -147,8 +147,8 @@
   if (src.get() == dst.get())
     throw std::invalid_argument("disconnect: source and destination blocks 
cannot be the same");
 
-  gr_hier_block2_sptr src_block(make_hier_block2_sptr(src));
-  gr_hier_block2_sptr dst_block(make_hier_block2_sptr(dst));
+  gr_hier_block2_sptr src_block(cast_to_hier_block2_sptr(src));
+  gr_hier_block2_sptr dst_block(cast_to_hier_block2_sptr(dst));
 
   if (src_block && src.get() != d_owner) {
     if (GR_HIER_BLOCK2_DETAIL_DEBUG)
@@ -307,7 +307,7 @@
     return endp;
   
   // Check if endpoint is a hierarchical block
-  gr_hier_block2_sptr hier_block2(make_hier_block2_sptr(endp.block()));
+  gr_hier_block2_sptr hier_block2(cast_to_hier_block2_sptr(endp.block()));
   if (hier_block2) {
     if (GR_HIER_BLOCK2_DETAIL_DEBUG)
       std::cout << "Resolving endpoint " << endp << " as an " 
@@ -351,7 +351,7 @@
 
   // Recurse hierarchical children
   for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) {
-    gr_hier_block2_sptr hier_block2(make_hier_block2_sptr(*p));
+    gr_hier_block2_sptr hier_block2(cast_to_hier_block2_sptr(*p));
     if (hier_block2)
       hier_block2->d_detail->flatten_aux(sfg);
   }

Copied: gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_sptr_magic.cc (from rev 
8843, 
gnuradio/branches/developers/jcorgan/ptrfix/gnuradio-core/src/lib/runtime/gr_sptr_magic.cc)
===================================================================
--- gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_sptr_magic.cc               
                (rev 0)
+++ gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_sptr_magic.cc       
2008-07-09 18:59:37 UTC (rev 8844)
@@ -0,0 +1,81 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 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 this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <gr_sptr_magic.h>
+#include <gr_hier_block2.h>
+#include <map>
+#include <stdexcept>
+
+
+#if 0
+  #include <boost/thread.hpp>
+  typedef boost::mutex                 mutex;
+  typedef boost::mutex::scoped_lock    scoped_lock;
+#else
+  #include <omnithread.h>
+  typedef omni_mutex                   mutex;
+  typedef omni_mutex_lock              scoped_lock;
+#endif
+
+namespace gnuradio {
+
+  static mutex         s_mutex;
+  typedef std::map<gr_basic_block*, gr_basic_block_sptr> sptr_map;
+  static sptr_map      s_map;
+
+  void
+  detail::sptr_magic::create_and_stash_initial_sptr(gr_hier_block2 *p)
+  {
+    gr_basic_block_sptr sptr(p);
+    scoped_lock        l();
+    s_map.insert(sptr_map::value_type(static_cast<gr_basic_block *>(p), sptr));
+  }
+
+
+  gr_basic_block_sptr 
+  detail::sptr_magic::fetch_initial_sptr(gr_basic_block *p)
+  {
+    /*
+     * If p isn't a subclass of gr_hier_block2, just create the
+     * shared ptr and return it.
+     */
+    gr_hier_block2 *hb2 = dynamic_cast<gr_hier_block2 *>(p);
+    if (!hb2){
+      return gr_basic_block_sptr(p);
+    }
+
+    /*
+     * p is a subclass of gr_hier_block2, thus we've already created the 
shared pointer
+     * and stashed it away.  Fish it out and return it.
+     */
+    scoped_lock        l();
+    sptr_map::iterator pos = s_map.find(static_cast<gr_basic_block *>(p));
+    if (pos == s_map.end())
+      throw std::invalid_argument("gr_sptr_magic: invalid pointer!");
+
+    gr_basic_block_sptr sptr = pos->second;
+    s_map.erase(pos);
+    return sptr;
+  }
+};
+

Copied: gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_sptr_magic.h (from rev 
8843, 
gnuradio/branches/developers/jcorgan/ptrfix/gnuradio-core/src/lib/runtime/gr_sptr_magic.h)
===================================================================
--- gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_sptr_magic.h                
                (rev 0)
+++ gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_sptr_magic.h        
2008-07-09 18:59:37 UTC (rev 8844)
@@ -0,0 +1,51 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 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 this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifndef INCLUDED_GR_SPTR_MAGIC_H
+#define INCLUDED_GR_SPTR_MAGIC_H
+
+#include <boost/shared_ptr.hpp>
+
+class gr_basic_block;
+class gr_hier_block2;
+
+namespace gnuradio {
+
+  namespace detail {
+    
+    class sptr_magic {
+    public:
+      static boost::shared_ptr<gr_basic_block> 
fetch_initial_sptr(gr_basic_block *p);
+      static void create_and_stash_initial_sptr(gr_hier_block2 *p);
+    };
+  };
+
+  /* 
+   * \brief New!  Improved!  Standard method to get/create the 
boost::shared_ptr for a block.
+   */
+  template<class T>
+  boost::shared_ptr<T>
+  get_initial_sptr(T *p)
+  {
+    return boost::dynamic_pointer_cast<T, 
gr_basic_block>(detail::sptr_magic::fetch_initial_sptr(p));
+  }
+};
+
+#endif /* INCLUDED_GR_SPTR_MAGIC_H */

Modified: gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_top_block.cc
===================================================================
--- gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_top_block.cc        
2008-07-09 18:39:15 UTC (rev 8843)
+++ gnuradio/trunk/gnuradio-core/src/lib/runtime/gr_top_block.cc        
2008-07-09 18:59:37 UTC (rev 8844)
@@ -34,7 +34,7 @@
 gr_top_block_sptr 
 gr_make_top_block(const std::string &name)
 {
-  return gr_top_block_sptr(new gr_top_block(name));
+  return gnuradio::get_initial_sptr(new gr_top_block(name));
 }
 
 gr_top_block::gr_top_block(const std::string &name)

Modified: gnuradio/trunk/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.cc
===================================================================
--- gnuradio/trunk/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.cc   
2008-07-09 18:39:15 UTC (rev 8843)
+++ gnuradio/trunk/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.cc   
2008-07-09 18:59:37 UTC (rev 8844)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2006 Free Software Foundation, Inc.
+ * Copyright 2006,2008 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
@@ -33,14 +33,25 @@
 void qa_gr_hier_block2::test_make()
 {
     gr_hier_block2_sptr src1(gr_make_hier_block2("test",
-                                                gr_make_io_signature(1, 1, 
sizeof(int)),
-                                                gr_make_io_signature(1, 1, 
sizeof(int))));
+                                                gr_make_io_signature(1, 2, 1 * 
sizeof(int)),
+                                                gr_make_io_signature(3, 4, 2 * 
sizeof(int))));
 
     CPPUNIT_ASSERT(src1);
     CPPUNIT_ASSERT_EQUAL(std::string("test"), src1->name());
-    CPPUNIT_ASSERT_EQUAL(1, src1->input_signature()->max_streams());
-    CPPUNIT_ASSERT_EQUAL(1, src1->output_signature()->min_streams());
-    CPPUNIT_ASSERT_EQUAL(1, src1->output_signature()->max_streams());
-    CPPUNIT_ASSERT_EQUAL((int) sizeof(int), 
+
+    CPPUNIT_ASSERT_EQUAL(1 * (int) sizeof(int), 
+                        src1->input_signature()->sizeof_stream_item(0));
+
+    CPPUNIT_ASSERT_EQUAL(1, src1->input_signature()->min_streams());
+    CPPUNIT_ASSERT_EQUAL(2, src1->input_signature()->max_streams());
+
+
+    CPPUNIT_ASSERT_EQUAL(2 * (int) sizeof(int), 
                         src1->output_signature()->sizeof_stream_item(0));
+
+    CPPUNIT_ASSERT_EQUAL(3, src1->output_signature()->min_streams());
+    CPPUNIT_ASSERT_EQUAL(4, src1->output_signature()->max_streams());
+
 }
+
+

Modified: gnuradio/trunk/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.h
===================================================================
--- gnuradio/trunk/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.h    
2008-07-09 18:39:15 UTC (rev 8843)
+++ gnuradio/trunk/gnuradio-core/src/lib/runtime/qa_gr_hier_block2.h    
2008-07-09 18:59:37 UTC (rev 8844)
@@ -32,12 +32,11 @@
     CPPUNIT_TEST_SUITE(qa_gr_hier_block2);
 
     CPPUNIT_TEST(test_make);
-    
+        
     CPPUNIT_TEST_SUITE_END();
 
 private:
     void test_make();
-    void test_derived();
 };
 
 #endif /* INCLUDED_QA_GR_HIER_BLOCK2_H */

Copied: 
gnuradio/trunk/gnuradio-core/src/lib/runtime/qa_gr_hier_block2_derived.cc (from 
rev 8843, 
gnuradio/branches/developers/jcorgan/ptrfix/gnuradio-core/src/lib/runtime/qa_gr_hier_block2_derived.cc)
===================================================================
--- gnuradio/trunk/gnuradio-core/src/lib/runtime/qa_gr_hier_block2_derived.cc   
                        (rev 0)
+++ gnuradio/trunk/gnuradio-core/src/lib/runtime/qa_gr_hier_block2_derived.cc   
2008-07-09 18:59:37 UTC (rev 8844)
@@ -0,0 +1,87 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2006,2008 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <qa_gr_hier_block2_derived.h>
+#include <gr_top_block.h>
+#include <gr_io_signature.h>
+#include <gr_null_source.h>
+#include <gr_null_sink.h>
+#include <gr_head.h>
+#include <gr_kludge_copy.h>
+
+// Declare a test C++ hierarchical block
+
+class gr_derived_block;
+typedef boost::shared_ptr<gr_derived_block> gr_derived_block_sptr;
+gr_derived_block_sptr gr_make_derived_block();
+
+class gr_derived_block : public gr_hier_block2
+{
+private:
+  friend gr_derived_block_sptr gr_make_derived_block();
+  gr_derived_block();
+
+public:
+  ~gr_derived_block();
+};
+
+
+gr_derived_block_sptr
+gr_make_derived_block()
+{
+  return gnuradio::get_initial_sptr(new gr_derived_block());
+}
+
+gr_derived_block::gr_derived_block()
+  : gr_hier_block2("gr_derived_block",
+                  gr_make_io_signature(1, 1, sizeof(int)), // Input signature
+                  gr_make_io_signature(1, 1, sizeof(int))) // Output signature
+{
+  gr_block_sptr copy(gr_make_kludge_copy(sizeof(int)));
+
+  connect(self(), 0, copy, 0);
+  connect(copy, 0, self(), 0);
+}
+
+gr_derived_block::~gr_derived_block()
+{
+}
+
+void qa_gr_hier_block2_derived::test_1()
+{
+  gr_top_block_sptr     tb(gr_make_top_block("test"));
+
+  gr_block_sptr         src(gr_make_null_source(sizeof(int)));
+  gr_block_sptr         head(gr_make_head(sizeof(int), 1000));
+  gr_derived_block_sptr blk(gr_make_derived_block());
+  gr_block_sptr         dst(gr_make_null_sink(sizeof(int)));
+  
+  tb->connect(src,  0, head, 0);
+  tb->connect(head, 0, blk,  0);
+  tb->connect(blk,  0, dst,  0);
+
+  tb->run();
+}

Copied: 
gnuradio/trunk/gnuradio-core/src/lib/runtime/qa_gr_hier_block2_derived.h (from 
rev 8843, 
gnuradio/branches/developers/jcorgan/ptrfix/gnuradio-core/src/lib/runtime/qa_gr_hier_block2_derived.h)
===================================================================
--- gnuradio/trunk/gnuradio-core/src/lib/runtime/qa_gr_hier_block2_derived.h    
                        (rev 0)
+++ gnuradio/trunk/gnuradio-core/src/lib/runtime/qa_gr_hier_block2_derived.h    
2008-07-09 18:59:37 UTC (rev 8844)
@@ -0,0 +1,41 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2006,2008 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.
+ */
+
+#ifndef INCLUDED_QA_GR_HIER_BLOCK2_DERIVED_H
+#define INCLUDED_QA_GR_HIER_BLOCK2_DERIVED_H
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/TestCase.h>
+#include <stdexcept>
+
+// Declare a QA test case
+class qa_gr_hier_block2_derived : public CppUnit::TestCase 
+{
+  CPPUNIT_TEST_SUITE(qa_gr_hier_block2_derived);
+  CPPUNIT_TEST(test_1);
+  CPPUNIT_TEST_SUITE_END();
+
+private:
+  void test_1();
+};
+
+#endif /* INCLUDED_QA_GR_HIER_BLOCK2_DERIVED_H */

Modified: gnuradio/trunk/gnuradio-core/src/lib/runtime/qa_runtime.cc
===================================================================
--- gnuradio/trunk/gnuradio-core/src/lib/runtime/qa_runtime.cc  2008-07-09 
18:39:15 UTC (rev 8843)
+++ gnuradio/trunk/gnuradio-core/src/lib/runtime/qa_runtime.cc  2008-07-09 
18:59:37 UTC (rev 8844)
@@ -36,6 +36,7 @@
 #include <qa_gr_flowgraph.h>
 #include <qa_gr_top_block.h>
 #include <qa_gr_hier_block2.h>
+#include <qa_gr_hier_block2_derived.h>
 #include <qa_gr_buffer.h>
 
 CppUnit::TestSuite *
@@ -49,6 +50,7 @@
   s->addTest (qa_gr_flowgraph::suite ());
   s->addTest (qa_gr_top_block::suite ());
   s->addTest (qa_gr_hier_block2::suite ());
+  s->addTest (qa_gr_hier_block2_derived::suite ());
   s->addTest (qa_gr_buffer::suite ());
   
   return s;





reply via email to

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