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/foreach.hpp> 34 #include <boost/function.hpp> 35 #include <boost/thread/condition_variable.hpp> 57 public boost::enable_shared_from_this<basic_block>
59 typedef boost::function<void(pmt::pmt_t)> msg_handler_t;
62 typedef std::map<pmt::pmt_t, msg_handler_t, pmt::comparator> d_msg_handlers_t;
63 d_msg_handlers_t d_msg_handlers;
65 typedef std::deque<pmt::pmt_t> msg_queue_t;
66 typedef std::map<pmt::pmt_t, msg_queue_t, pmt::comparator> msg_queue_map_t;
67 typedef std::map<pmt::pmt_t, msg_queue_t, pmt::comparator>::iterator
69 std::map<pmt::pmt_t, boost::shared_ptr<boost::condition_variable>,
pmt::comparator>
76 friend class flat_flowgraph;
77 friend class tpb_thread_body;
107 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; }
158 return this->name() +
"(" + std::to_string(this->unique_id()) +
")";
163 basic_block_sptr to_basic_block();
168 bool alias_set()
const {
return !d_symbol_alias.empty(); }
173 std::string
alias()
const {
return alias_set() ? d_symbol_alias : symbol_name(); }
185 void set_block_alias(std::string name);
188 void message_port_register_in(
pmt::pmt_t port_id);
189 void message_port_register_out(
pmt::pmt_t port_id);
234 if (msg_queue.find(which_port) == msg_queue.end())
235 throw std::runtime_error(
"port does not exist!");
236 return msg_queue[which_port].empty();
241 BOOST_FOREACH (msg_queue_map_t::value_type& i, msg_queue) {
242 rv &= msg_queue[i.first].empty();
250 return (empty_p(which_port) || !has_msg_handler(which_port));
255 BOOST_FOREACH (msg_queue_map_t::value_type& i, msg_queue) {
256 rv &= empty_handled_p(i.first);
264 if (msg_queue.find(which_port) == msg_queue.end())
265 throw std::runtime_error(
"port does not exist!");
266 return msg_queue[which_port].size();
278 return msg_queue[which_port].begin();
283 msg_queue[which_port].erase(it);
288 if (msg_queue.find(which_port) != msg_queue.end()) {
297 const msg_queue_map_t&
get_msg_map(
void)
const {
return msg_queue; }
312 void add_rpc_variable(rpcbasic_sptr s) { d_rpc_vars.push_back(s); }
385 template <
typename T>
388 if (msg_queue.find(which_port) == msg_queue.end()) {
389 throw std::runtime_error(
390 "attempt to set_msg_handler() on bad input message port!");
392 d_msg_handlers[which_port] = msg_handler_t(msg_handler);
395 virtual void set_processor_affinity(
const std::vector<int>& mask) = 0;
397 virtual void unset_processor_affinity() = 0;
399 virtual std::vector<int> processor_affinity() = 0;
401 virtual void set_log_level(std::string level) = 0;
403 virtual std::string log_level() = 0;
406 inline bool operator<(basic_block_sptr lhs, basic_block_sptr rhs)
408 return lhs->unique_id() < rhs->unique_id();
418 os << basic_block->identifier();
std::string identifier() const
Definition: basic_block.h:156
boost::shared_ptr< io_signature > sptr
Definition: io_signature.h:46
Provide a comparator function object to allow pmt use in stl types.
Definition: pmt.h:986
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:262
virtual void setup_rpc()
Set up the RPC registered variables.
Definition: basic_block.h:323
boost::shared_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:96
long symbolic_id() const
Definition: basic_block.h:145
bool empty_p()
Definition: basic_block.h:238
gr::io_signature::sptr input_signature() const
Definition: basic_block.h:161
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:331
void set_color(vcolor color)
Allow the flowgraph to set for sorting and partitioning.
Definition: basic_block.h:113
virtual bool message_port_is_hier(pmt::pmt_t port_id)
Definition: basic_block.h:194
std::string alias() const
Definition: basic_block.h:173
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:281
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:119
bool empty_handled_p(pmt::pmt_t which_port)
are all msg ports with handlers empty?
Definition: basic_block.h:248
Class representing a directed, acyclic graph of basic blocks.
Definition: flowgraph.h:162
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:336
virtual bool has_msg_port(pmt::pmt_t which_port)
Definition: basic_block.h:286
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
const msg_queue_map_t & get_msg_map(void) const
Definition: basic_block.h:297
gr::io_signature::sptr d_input_signature
Definition: basic_block.h:82
GNU Radio logging wrapper for log4cpp library (C++ port of log4j)
Definition: basic_block.h:43
vcolor
Definition: basic_block.h:79
The abstract base class for all signal processing blocks.Basic blocks are the bare abstraction of an ...
Definition: basic_block.h:56
std::string d_name
Definition: basic_block.h:81
basic_block(void)
Definition: basic_block.h:94
virtual bool message_port_is_hier_in(pmt::pmt_t port_id)
Definition: basic_block.h:199
virtual bool message_port_is_hier_out(pmt::pmt_t port_id)
Definition: basic_block.h:204
bool empty_p(pmt::pmt_t which_port)
is the queue empty?
Definition: basic_block.h:232
bool empty_handled_p()
Definition: basic_block.h:252
std::string symbol_name() const
Definition: basic_block.h:155
pmt::pmt_t alias_pmt() const
Definition: basic_block.h:178
virtual bool check_topology(int ninputs, int noutputs)
Confirm that ninputs and noutputs is an acceptable combination.
Definition: basic_block.h:351
bool alias_set() const
Definition: basic_block.h:168
std::vector< basic_block_sptr > basic_block_vector_t
Definition: basic_block.h:411
msg_queue_t::iterator get_iterator(pmt::pmt_t which_port)
Definition: basic_block.h:276
long d_symbolic_id
Definition: basic_block.h:85
std::vector< basic_block_sptr >::iterator basic_block_viter_t
Definition: basic_block.h:412
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:416
long unique_id() const
Definition: basic_block.h:144
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.
bool d_rpc_set
Definition: basic_block.h:89
gr::io_signature::sptr output_signature() const
Definition: basic_block.h:162
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
std::vector< rpcbasic_sptr > d_rpc_vars
Definition: basic_block.h:92
vcolor color() const
Definition: basic_block.h:114
std::string name() const
Definition: basic_block.h:148
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:386
long d_unique_id
Definition: basic_block.h:84
bool operator<(basic_block_sptr lhs, basic_block_sptr rhs)
Definition: basic_block.h:406
void set_output_signature(gr::io_signature::sptr iosig)
may only be called during constructor
Definition: basic_block.h:105
abstract class of message handlers
Definition: msg_handler.h:38