Merge branch 'dfsg-orig'
[debian/gnuradio] / gnuradio-core / src / lib / runtime / gr_basic_block.h
index 583c3241d5d75633b87278d9ef0dba6403aaee60..b8797fdc678038d49075b0faf94cce8176ca5267 100644 (file)
@@ -1,12 +1,12 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2006 Free Software Foundation, Inc.
+ * Copyright 2006,2008,2009 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)
+ * 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,
 #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 block
+ * \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;
+    friend class gr_flat_flowgraph; // TODO: will be redundant
+
+    enum vcolor { WHITE, GREY, BLACK };
+
     std::string          d_name;
     gr_io_signature_sptr d_input_signature;
     gr_io_signature_sptr d_output_signature;
     long                 d_unique_id;
+    vcolor               d_color;
 
     //! Protected constructor prevents instantiation by non-derived classes
     gr_basic_block(const std::string &name,
@@ -61,6 +69,12 @@ protected:
         d_output_signature = iosig;
     }
 
+    /*!
+     * \brief Allow the flowgraph to set for sorting and partitioning
+     */
+    void set_color(vcolor color) { d_color = color; }
+    vcolor color() const { return d_color; }
+
 public:
     virtual ~gr_basic_block();
     long unique_id() const { return d_unique_id; }
@@ -83,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;