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;
64 typedef std::map<pmt::pmt_t , msg_handler_t, pmt::comparator> d_msg_handlers_t;
65 d_msg_handlers_t d_msg_handlers;
67 typedef std::deque<pmt::pmt_t> msg_queue_t;
68 typedef std::map<pmt::pmt_t, msg_queue_t, pmt::comparator> msg_queue_map_t;
69 typedef std::map<pmt::pmt_t, msg_queue_t, pmt::comparator>::iterator msg_queue_map_itr;
70 std::map<pmt::pmt_t, boost::shared_ptr<boost::condition_variable>,
pmt::comparator> msg_queue_ready;
76 friend class flat_flowgraph;
77 friend class tpb_thread_body;
103 d_input_signature = iosig;
108 d_output_signature = iosig;
121 return (d_msg_handlers.find(which_port) != d_msg_handlers.end());
133 if(has_msg_handler(which_port)) {
134 d_msg_handlers[which_port](msg);
148 std::string
name()
const {
return d_name; }
159 basic_block_sptr to_basic_block();
169 std::string
alias(){
return alias_set()?d_symbol_alias:symbol_name(); }
181 void set_block_alias(std::string name);
184 void message_port_register_in(
pmt::pmt_t port_id);
185 void message_port_register_out(
pmt::pmt_t port_id);
217 if(msg_queue.find(which_port) == msg_queue.end())
218 throw std::runtime_error(
"port does not exist!");
219 return msg_queue[which_port].empty();
223 BOOST_FOREACH(msg_queue_map_t::value_type &i, msg_queue) {
224 rv &= msg_queue[i.first].empty();
231 return (empty_p(which_port) || !has_msg_handler(which_port));
235 BOOST_FOREACH(msg_queue_map_t::value_type &i, msg_queue) {
236 rv &= empty_handled_p(i.first);
243 if(msg_queue.find(which_port) == msg_queue.end())
244 throw std::runtime_error(
"port does not exist!");
245 return msg_queue[which_port].size();
263 return msg_queue[which_port].begin();
267 msg_queue[which_port].erase(it);
271 if(msg_queue.find(which_port) != msg_queue.end()) {
297 void add_rpc_variable(rpcbasic_sptr s)
299 d_rpc_vars.push_back(s);
373 if(msg_queue.find(which_port) == msg_queue.end()) {
374 throw std::runtime_error(
"attempt to set_msg_handler() on bad input message port!");
376 d_msg_handlers[which_port] = msg_handler_t(msg_handler);
380 {
throw std::runtime_error(
"set_processor_affinity not overloaded in child class."); }
383 {
throw std::runtime_error(
"unset_processor_affinity not overloaded in child class."); }
386 {
throw std::runtime_error(
"processor_affinity not overloaded in child class."); }
389 inline bool operator<(basic_block_sptr lhs, basic_block_sptr rhs)
391 return lhs->unique_id() < rhs->unique_id();
401 os << basic_block->name() <<
"(" << basic_block->unique_id() <<
")";
boost::shared_ptr< io_signature > sptr
Definition: io_signature.h:45
Provide a comparator function object to allow pmt use in stl types.
Definition: pmt.h:904
std::string d_symbol_alias
Definition: basic_block.h:87
void set_input_signature(gr::io_signature::sptr iosig)
may only be called during constructor
Definition: basic_block.h:102
size_t nmsgs(pmt::pmt_t which_port)
How many messages in the queue?
Definition: basic_block.h:242
virtual void setup_rpc()
Set up the RPC registered variables.
Definition: basic_block.h:311
std::string alias()
Definition: basic_block.h:169
virtual void set_processor_affinity(const std::vector< int > &mask)
Definition: basic_block.h:379
bool empty_p()
Definition: basic_block.h:221
std::string d_symbol_name
Definition: basic_block.h:86
bool is_rpc_set()
Ask if this block has been registered to the RPC.
Definition: basic_block.h:319
void set_color(vcolor color)
Allow the flowgraph to set for sorting and partitioning.
Definition: basic_block.h:114
virtual bool message_port_is_hier(pmt::pmt_t port_id)
Definition: basic_block.h:190
msg_queue_map_t msg_queue
Definition: basic_block.h:91
void erase_msg(pmt::pmt_t which_port, msg_queue_t::iterator it)
Definition: basic_block.h:266
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:120
bool empty_handled_p(pmt::pmt_t which_port)
are all msg ports with handlers empty?
Definition: basic_block.h:230
virtual std::vector< int > processor_affinity()
Definition: basic_block.h:385
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:324
std::string name() const
Definition: basic_block.h:148
virtual bool has_msg_port(pmt::pmt_t which_port)
Definition: basic_block.h:270
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:144
gr::io_signature::sptr d_input_signature
Definition: basic_block.h:82
gr::io_signature::sptr output_signature() const
Definition: basic_block.h:158
Include this header to use the message passing features.
Definition: logger.h:695
vcolor
Definition: basic_block.h:79
const msg_queue_map_t & get_msg_map(void) const
Definition: basic_block.h:280
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:157
std::string d_name
Definition: basic_block.h:81
vcolor color() const
Definition: basic_block.h:115
basic_block(void)
Definition: basic_block.h:94
virtual bool message_port_is_hier_in(pmt::pmt_t port_id)
Definition: basic_block.h:191
virtual bool message_port_is_hier_out(pmt::pmt_t port_id)
Definition: basic_block.h:192
bool empty_p(pmt::pmt_t which_port)
is the queue empty?
Definition: basic_block.h:216
bool empty_handled_p()
Definition: basic_block.h:233
virtual bool check_topology(int ninputs, int noutputs)
Confirm that ninputs and noutputs is an acceptable combination.
Definition: basic_block.h:339
virtual void unset_processor_affinity()
Definition: basic_block.h:382
std::vector< boost::any > d_rpc_vars
Definition: basic_block.h:92
std::vector< basic_block_sptr > basic_block_vector_t
Definition: basic_block.h:394
msg_queue_t::iterator get_iterator(pmt::pmt_t which_port)
Definition: basic_block.h:262
long d_symbolic_id
Definition: basic_block.h:85
pmt::pmt_t alias_pmt()
Definition: basic_block.h:174
std::vector< basic_block_sptr >::iterator basic_block_viter_t
Definition: basic_block.h:395
gr::io_signature::sptr d_output_signature
Definition: basic_block.h:83
std::ostream & operator<<(std::ostream &os, basic_block_sptr basic_block)
Definition: basic_block.h:399
GR_RUNTIME_API long basic_block_ncurrently_allocated()
boost::mutex mutex
Definition: thread.h:48
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:145
bool d_rpc_set
Definition: basic_block.h:89
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:130
vcolor d_color
Definition: basic_block.h:88
Definition: basic_block.h:79
pmt::pmt_t d_message_subscribers
Definition: basic_block.h:139
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:372
bool alias_set()
Definition: basic_block.h:164
long d_unique_id
Definition: basic_block.h:84
bool operator<(basic_block_sptr lhs, basic_block_sptr rhs)
Definition: basic_block.h:389
void set_output_signature(gr::io_signature::sptr iosig)
may only be called during constructor
Definition: basic_block.h:107
std::string symbol_name() const
Definition: basic_block.h:155
abstract class of message handlers
Definition: msg_handler.h:38