23 #ifndef INCLUDED_GR_BASIC_BLOCK_H
24 #define INCLUDED_GR_BASIC_BLOCK_H
32 #include <boost/enable_shared_from_this.hpp>
33 #include <boost/function.hpp>
34 #include <boost/foreach.hpp>
35 #include <boost/thread/condition_variable.hpp>
59 public boost::enable_shared_from_this<basic_block>
61 typedef boost::function<void(pmt::pmt_t)> msg_handler_t;
65 typedef std::map<pmt::pmt_t , msg_handler_t, pmt::comparator> d_msg_handlers_t;
66 d_msg_handlers_t d_msg_handlers;
68 typedef std::deque<pmt::pmt_t> msg_queue_t;
69 typedef std::map<pmt::pmt_t, msg_queue_t, pmt::comparator> msg_queue_map_t;
70 typedef std::map<pmt::pmt_t, msg_queue_t, pmt::comparator>::iterator msg_queue_map_itr;
71 std::map<pmt::pmt_t, boost::shared_ptr<boost::condition_variable>,
pmt::comparator> msg_queue_ready;
77 friend class flat_flowgraph;
78 friend class tpb_thread_body;
104 d_input_signature = iosig;
109 d_output_signature = iosig;
122 return (d_msg_handlers.find(which_port) != d_msg_handlers.end());
134 if(has_msg_handler(which_port)) {
135 d_msg_handlers[which_port](msg);
149 std::string
name()
const {
return d_name; }
170 std::string
alias(){
return alias_set()?d_symbol_alias:symbol_name(); }
182 void set_block_alias(std::string
name);
185 void message_port_register_in(
pmt::pmt_t port_id);
186 void message_port_register_out(
pmt::pmt_t port_id);
219 throw std::runtime_error(
"port does not exist!");
224 BOOST_FOREACH(msg_queue_map_t::value_type &i,
msg_queue) {
232 return (empty_p(which_port) || !has_msg_handler(which_port));
236 BOOST_FOREACH(msg_queue_map_t::value_type &i,
msg_queue) {
237 rv &= empty_handled_p(i.first);
245 throw std::runtime_error(
"port does not exist!");
298 d_rpc_vars.push_back(s);
373 throw std::runtime_error(
"attempt to set_msg_handler() on bad input message port!");
375 d_msg_handlers[which_port] = msg_handler_t(msg_handler);
379 {
throw std::runtime_error(
"set_processor_affinity not overloaded in child class."); }
382 {
throw std::runtime_error(
"unset_processor_affinity not overloaded in child class."); }
385 {
throw std::runtime_error(
"processor_affinity not overloaded in child class."); }
390 return lhs->unique_id() < rhs->unique_id();
400 os << basic_block->name() <<
"(" << basic_block->unique_id() <<
")";
Provide a comparator function object to allow pmt use in stl types.
Definition: pmt.h:881
std::string d_symbol_alias
Definition: basic_block.h:88
void set_input_signature(gr::io_signature::sptr iosig)
may only be called during constructor
Definition: basic_block.h:103
size_t nmsgs(pmt::pmt_t which_port)
How many messages in the queue?
Definition: basic_block.h:243
virtual void setup_rpc()
Set up the RPC registered variables.
Definition: basic_block.h:310
std::string alias()
Definition: basic_block.h:170
virtual void set_processor_affinity(const std::vector< int > &mask)
Definition: basic_block.h:378
bool empty_p()
Definition: basic_block.h:222
std::string d_symbol_name
Definition: basic_block.h:87
bool is_rpc_set()
Ask if this block has been registered to the RPC.
Definition: basic_block.h:318
void set_color(vcolor color)
Allow the flowgraph to set for sorting and partitioning.
Definition: basic_block.h:115
virtual bool message_port_is_hier(pmt::pmt_t port_id)
Definition: basic_block.h:191
msg_queue_map_t msg_queue
Definition: basic_block.h:92
void erase_msg(pmt::pmt_t which_port, msg_queue_t::iterator it)
Definition: basic_block.h:265
virtual bool has_msg_handler(pmt::pmt_t which_port)
Tests if there is a handler attached to port which_port.
Definition: basic_block.h:121
bool empty_handled_p(pmt::pmt_t which_port)
are all msg ports with handlers empty?
Definition: basic_block.h:231
virtual std::vector< int > processor_affinity()
Definition: basic_block.h:384
Class representing a directed, acyclic graph of basic blocks.
Definition: flowgraph.h:144
PMT_API pmt_t intern(const std::string &s)
Alias for pmt_string_to_symbol.
void rpc_set()
When the block is registered with the RPC, set this.
Definition: basic_block.h:323
std::string name() const
Definition: basic_block.h:149
virtual bool has_msg_port(pmt::pmt_t which_port)
Definition: basic_block.h:269
Accepts messages and inserts them into a message queue, then notifies subclass gr::basic_block there ...
Definition: msg_accepter.h:35
#define GR_RUNTIME_API
Definition: gnuradio-runtime/include/gnuradio/api.h:30
long unique_id() const
Definition: basic_block.h:145
thread-safe message queue
Definition: msg_queue.h:36
gr::io_signature::sptr d_input_signature
Definition: basic_block.h:83
gr::io_signature::sptr output_signature() const
Definition: basic_block.h:159
vcolor
Definition: basic_block.h:80
const msg_queue_map_t & get_msg_map(void) const
Definition: basic_block.h:279
The abstract base class for all signal processing blocks.Basic blocks are the bare abstraction of an ...
Definition: basic_block.h:58
gr::io_signature::sptr input_signature() const
Definition: basic_block.h:158
std::string d_name
Definition: basic_block.h:82
vcolor color() const
Definition: basic_block.h:116
basic_block(void)
Definition: basic_block.h:95
virtual bool message_port_is_hier_in(pmt::pmt_t port_id)
Definition: basic_block.h:192
virtual bool message_port_is_hier_out(pmt::pmt_t port_id)
Definition: basic_block.h:193
bool empty_p(pmt::pmt_t which_port)
is the queue empty?
Definition: basic_block.h:217
bool empty_handled_p()
Definition: basic_block.h:234
virtual bool check_topology(int ninputs, int noutputs)
Confirm that ninputs and noutputs is an acceptable combination.
Definition: basic_block.h:338
VOLK_API void(kern.name) _manual($kern.arglist_full
Call into a specific implementation given by name.
virtual void unset_processor_affinity()
Definition: basic_block.h:381
std::vector< boost::any > d_rpc_vars
Definition: basic_block.h:93
std::vector< basic_block_sptr > basic_block_vector_t
Definition: basic_block.h:393
msg_queue_t::iterator get_iterator(pmt::pmt_t which_port)
Definition: basic_block.h:261
long d_symbolic_id
Definition: basic_block.h:86
pmt::pmt_t alias_pmt()
Definition: basic_block.h:175
std::vector< basic_block_sptr >::iterator basic_block_viter_t
Definition: basic_block.h:394
gr::io_signature::sptr d_output_signature
Definition: basic_block.h:84
std::ostream & operator<<(std::ostream &os, basic_block_sptr basic_block)
Definition: basic_block.h:398
VOLK_API $kern pname $kern name
A function pointer to the dispatcher implementation.
GR_RUNTIME_API long basic_block_ncurrently_allocated()
boost::mutex mutex
Definition: thread.h:46
PMT_API bool dict_has_key(const pmt_t &dict, const pmt_t &key)
Return true if key exists in dict.
long symbolic_id() const
Definition: basic_block.h:146
bool d_rpc_set
Definition: basic_block.h:90
boost::intrusive_ptr< pmt_base > pmt_t
typedef for shared pointer (transparent reference counting). See http://www.boost.org/libs/smart_ptr/smart_ptr.htm
Definition: pmt.h:56
virtual void dispatch_msg(pmt::pmt_t which_port, pmt::pmt_t msg)
Definition: basic_block.h:131
vcolor d_color
Definition: basic_block.h:89
Definition: basic_block.h:80
pmt::pmt_t d_message_subscribers
Definition: basic_block.h:140
void set_msg_handler(pmt::pmt_t which_port, T msg_handler)
Set the callback that is fired when messages are available.
Definition: basic_block.h:371
bool alias_set()
Definition: basic_block.h:165
long d_unique_id
Definition: basic_block.h:85
bool operator<(basic_block_sptr lhs, basic_block_sptr rhs)
Definition: basic_block.h:388
void set_output_signature(gr::io_signature::sptr iosig)
may only be called during constructor
Definition: basic_block.h:108
std::string symbol_name() const
Definition: basic_block.h:156
abstract class of message handlers
Definition: msg_handler.h:38