Merge branch 'dfsg-orig'
[debian/gnuradio] / gnuradio-core / src / lib / runtime / gr_basic_block.h
index 8dc965da737594efa892333e634c71b87bf101d7..b8797fdc678038d49075b0faf94cce8176ca5267 100644 (file)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2006 Free Software Foundation, Inc.
+ * Copyright 2006,2008,2009 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
 #define INCLUDED_GR_BASIC_BLOCK_H
 
 #include <gr_runtime_types.h>
+#include <gr_sptr_magic.h>
 #include <boost/enable_shared_from_this.hpp>
+#include <gr_msg_accepter.h>
 #include <string>
 
 /*!
  * \brief The abstract base class for all signal processing blocks.
- * \ingroup base
+ * \ingroup internal
  *
- * Basic blocks are the bare abstraction of an entity that has a name
- * and a set of inputs and outputs.  These are never instantiated
+ * Basic blocks are the bare abstraction of an entity that has a name,
+ * a set of inputs and outputs, and a message queue.  These are never instantiated
  * directly; rather, this is the abstract parent class of both gr_hier_block,
  * which is a recursive container, and gr_block, which implements actual
  * signal processing functions.
  */
 
-class gr_basic_block : public boost::enable_shared_from_this<gr_basic_block>
+class gr_basic_block : public gr_msg_accepter, public boost::enable_shared_from_this<gr_basic_block>
 {
 protected:
     friend class gr_flowgraph;
@@ -95,8 +97,24 @@ public:
      * and output gr_io_signatures.
      */
     virtual bool check_topology(int ninputs, int noutputs) { return true; }
+
+    /*!
+     * \brief Block message handler.
+     * 
+     * \param msg  Arbitrary message encapsulated as pmt::pmt_t
+     *
+     * This function is called by the runtime system whenever there are
+     * messages in its queue.  Blocks should override this to receive
+     * messages; the default behavior is to drop them on the floor.
+     */
+    virtual void handle_msg(pmt::pmt_t msg) { };
 };
 
+inline bool operator<(gr_basic_block_sptr lhs, gr_basic_block_sptr rhs)
+{
+  return lhs->unique_id() < rhs->unique_id();
+}
+
 typedef std::vector<gr_basic_block_sptr> gr_basic_block_vector_t;
 typedef std::vector<gr_basic_block_sptr>::iterator gr_basic_block_viter_t;