11 #ifndef INCLUDED_GR_BASIC_BLOCK_H 12 #define INCLUDED_GR_BASIC_BLOCK_H 21 #include <boost/thread/condition_variable.hpp> 43 public std::enable_shared_from_this<basic_block>
45 typedef std::function<void(pmt::pmt_t)> msg_handler_t;
48 typedef std::map<pmt::pmt_t, msg_handler_t, pmt::comparator> d_msg_handlers_t;
49 d_msg_handlers_t d_msg_handlers;
51 typedef std::deque<pmt::pmt_t> msg_queue_t;
52 typedef std::map<pmt::pmt_t, msg_queue_t, pmt::comparator> msg_queue_map_t;
53 typedef std::map<pmt::pmt_t, msg_queue_t, pmt::comparator>::iterator
60 friend class flat_flowgraph;
61 friend class tpb_thread_body;
96 d_output_signature = iosig;
110 return (d_msg_handlers.find(which_port) != d_msg_handlers.end());
122 if (has_msg_handler(which_port)) {
123 d_msg_handlers[which_port](msg);
137 std::string
name()
const {
return d_name; }
147 return this->name() +
"(" + std::to_string(this->unique_id()) +
")";
152 basic_block_sptr to_basic_block();
157 bool alias_set()
const {
return !d_symbol_alias.empty(); }
162 std::string
alias()
const {
return alias_set() ? d_symbol_alias : symbol_name(); }
174 void set_block_alias(std::string name);
177 void message_port_register_in(
pmt::pmt_t port_id);
178 void message_port_register_out(
pmt::pmt_t port_id);
224 throw std::runtime_error(
"port does not exist!");
239 return (empty_p(which_port) || !has_msg_handler(which_port));
245 rv &= empty_handled_p(i.first);
254 throw std::runtime_error(
"port does not exist!");
301 void add_rpc_variable(rpcbasic_sptr s) { d_rpc_vars.push_back(s); }
374 template <
typename T>
378 throw std::runtime_error(
379 "attempt to set_msg_handler() on bad input message port!");
381 d_msg_handlers[which_port] = msg_handler_t(
msg_handler);
384 virtual void set_processor_affinity(
const std::vector<int>& mask) = 0;
386 virtual void unset_processor_affinity() = 0;
388 virtual std::vector<int> processor_affinity() = 0;
390 virtual void set_log_level(std::string level) = 0;
392 virtual std::string log_level() = 0;
395 inline bool operator<(basic_block_sptr lhs, basic_block_sptr rhs)
397 return lhs->unique_id() < rhs->unique_id();
std::string identifier() const
Definition: basic_block.h:145
std::string d_symbol_alias
Definition: basic_block.h:71
std::shared_ptr< io_signature > sptr
Definition: io_signature.h:34
void set_input_signature(gr::io_signature::sptr iosig)
may only be called during constructor
Definition: basic_block.h:91
size_t nmsgs(pmt::pmt_t which_port)
How many messages in the queue?
Definition: basic_block.h:251
virtual void setup_rpc()
Set up the RPC registered variables.
Definition: basic_block.h:312
long symbolic_id() const
Definition: basic_block.h:134
bool empty_p()
Definition: basic_block.h:227
gr::io_signature::sptr input_signature() const
Definition: basic_block.h:150
std::string d_symbol_name
Definition: basic_block.h:70
bool is_rpc_set()
Ask if this block has been registered to the RPC.
Definition: basic_block.h:320
void set_color(vcolor color)
Allow the flowgraph to set for sorting and partitioning.
Definition: basic_block.h:102
virtual bool message_port_is_hier(pmt::pmt_t port_id)
Definition: basic_block.h:183
std::string alias() const
Definition: basic_block.h:162
msg_queue_map_t msg_queue
Verbose logger.
Definition: basic_block.h:80
void erase_msg(pmt::pmt_t which_port, msg_queue_t::iterator it)
Definition: basic_block.h:270
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:108
bool empty_handled_p(pmt::pmt_t which_port)
are all msg ports with handlers empty?
Definition: basic_block.h:237
Class representing a directed, acyclic graph of basic blocks.
Definition: flowgraph.h:150
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:325
virtual bool has_msg_port(pmt::pmt_t which_port)
Definition: basic_block.h:275
Accepts messages and inserts them into a message queue, then notifies subclass gr::basic_block there ...
Definition: msg_accepter.h:24
#define GR_RUNTIME_API
Definition: gnuradio-runtime/include/gnuradio/api.h:18
const msg_queue_map_t & get_msg_map(void) const
Definition: basic_block.h:286
thread-safe message queue
Definition: msg_queue.h:24
gr::io_signature::sptr d_input_signature
Definition: basic_block.h:66
GNU Radio logging wrapper for log4cpp library (C++ port of log4j)
Definition: basic_block.h:29
vcolor
Definition: basic_block.h:63
The abstract base class for all signal processing blocks.Basic blocks are the bare abstraction of an ...
Definition: basic_block.h:42
std::string d_name
Definition: basic_block.h:65
basic_block(void)
Definition: basic_block.h:83
virtual bool message_port_is_hier_in(pmt::pmt_t port_id)
Definition: basic_block.h:188
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:221
bool empty_handled_p()
Definition: basic_block.h:241
std::string symbol_name() const
Definition: basic_block.h:144
pmt::pmt_t alias_pmt() const
Definition: basic_block.h:167
virtual bool check_topology(int ninputs, int noutputs)
Confirm that ninputs and noutputs is an acceptable combination.
Definition: basic_block.h:340
bool alias_set() const
Definition: basic_block.h:157
std::vector< basic_block_sptr > basic_block_vector_t
Definition: basic_block.h:400
msg_queue_t::iterator get_iterator(pmt::pmt_t which_port)
Definition: basic_block.h:265
long d_symbolic_id
Definition: basic_block.h:69
log4cpp::Category * logger_ptr
GR_LOG macrosThese macros wrap the standard LOG4CPP_LEVEL macros. The availablie macros are: LOG_DEBU...
Definition: logger.h:60
std::vector< basic_block_sptr >::iterator basic_block_viter_t
Definition: basic_block.h:401
gr::io_signature::sptr d_output_signature
Definition: basic_block.h:67
gr::logger_ptr d_debug_logger
Default logger.
Definition: basic_block.h:78
std::ostream & operator<<(std::ostream &os, basic_block_sptr basic_block)
Definition: basic_block.h:405
long unique_id() const
Definition: basic_block.h:133
GR_RUNTIME_API long basic_block_ncurrently_allocated()
boost::mutex mutex
Definition: thread.h:37
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:73
gr::io_signature::sptr output_signature() const
Definition: basic_block.h:151
virtual void dispatch_msg(pmt::pmt_t which_port, pmt::pmt_t msg)
Definition: basic_block.h:119
vcolor d_color
Definition: basic_block.h:72
Definition: basic_block.h:63
std::vector< rpcbasic_sptr > d_rpc_vars
Definition: basic_block.h:81
vcolor color() const
Definition: basic_block.h:103
std::string name() const
Definition: basic_block.h:137
pmt::pmt_t d_message_subscribers
Definition: basic_block.h:128
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:375
long d_unique_id
Definition: basic_block.h:68
bool operator<(basic_block_sptr lhs, basic_block_sptr rhs)
Definition: basic_block.h:395
std::shared_ptr< pmt_base > pmt_t
typedef for shared pointer (transparent reference counting).
Definition: pmt.h:84
void set_output_signature(gr::io_signature::sptr iosig)
may only be called during constructor
Definition: basic_block.h:94
gr::logger_ptr d_logger
Definition: basic_block.h:77
abstract class of message handlers
Definition: msg_handler.h:26