 |
GNU Radio Manual and C++ API Reference
3.9.1.0
The Free & Open Software Radio Ecosystem
|
|
Go to the documentation of this file.
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
55 std::map<pmt::pmt_t, std::shared_ptr<boost::condition_variable>,
pmt::comparator>
62 friend class flat_flowgraph;
63 friend class tpb_thread_body;
98 d_output_signature = iosig;
112 return (d_msg_handlers.find(which_port) != d_msg_handlers.end());
124 if (has_msg_handler(which_port)) {
125 d_msg_handlers[which_port](msg);
139 std::string
name()
const {
return d_name; }
149 return this->name() +
"(" + std::to_string(this->unique_id()) +
")";
154 basic_block_sptr to_basic_block();
159 bool alias_set()
const {
return !d_symbol_alias.empty(); }
164 std::string
alias()
const {
return alias_set() ? d_symbol_alias : symbol_name(); }
176 void set_block_alias(std::string name);
179 void message_port_register_in(
pmt::pmt_t port_id);
180 void message_port_register_out(
pmt::pmt_t port_id);
226 throw std::runtime_error(
"port does not exist!");
241 return (empty_p(which_port) || !has_msg_handler(which_port));
247 rv &= empty_handled_p(i.first);
256 throw std::runtime_error(
"port does not exist!");
303 void add_rpc_variable(rpcbasic_sptr s) { d_rpc_vars.push_back(s); }
376 template <
typename T>
380 throw std::runtime_error(
381 "attempt to set_msg_handler() on bad input message port!");
383 d_msg_handlers[which_port] = msg_handler_t(
msg_handler);
386 virtual void set_processor_affinity(
const std::vector<int>& mask) = 0;
388 virtual void unset_processor_affinity() = 0;
390 virtual std::vector<int> processor_affinity() = 0;
392 virtual void set_log_level(std::string level) = 0;
394 virtual std::string log_level() = 0;
397 inline bool operator<(basic_block_sptr lhs, basic_block_sptr rhs)
399 return lhs->unique_id() < rhs->unique_id();
bool empty_p()
Definition: basic_block.h:229
abstract class of message handlers
Definition: msg_handler.h:26
virtual void dispatch_msg(pmt::pmt_t which_port, pmt::pmt_t msg)
Definition: basic_block.h:121
bool is_rpc_set()
Ask if this block has been registered to the RPC.
Definition: basic_block.h:322
Accepts messages and inserts them into a message queue, then notifies subclass gr::basic_block there ...
Definition: msg_accepter.h:24
virtual bool message_port_is_hier(pmt::pmt_t port_id)
Definition: basic_block.h:185
bool d_rpc_set
Definition: basic_block.h:75
std::string name() const
Definition: basic_block.h:139
msg_queue_map_t msg_queue
Verbose logger.
Definition: basic_block.h:82
void set_color(vcolor color)
Allow the flowgraph to set for sorting and partitioning.
Definition: basic_block.h:104
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:110
std::string alias() const
Definition: basic_block.h:164
void set_output_signature(gr::io_signature::sptr iosig)
may only be called during constructor
Definition: basic_block.h:96
void erase_msg(pmt::pmt_t which_port, msg_queue_t::iterator it)
Definition: basic_block.h:272
long d_unique_id
Definition: basic_block.h:70
gr::logger_ptr d_logger
Definition: basic_block.h:79
void set_input_signature(gr::io_signature::sptr iosig)
may only be called during constructor
Definition: basic_block.h:93
virtual void setup_rpc()
Set up the RPC registered variables.
Definition: basic_block.h:314
std::string d_symbol_alias
Definition: basic_block.h:73
const msg_queue_map_t & get_msg_map(void) const
Definition: basic_block.h:288
Class representing a directed, acyclic graph of basic blocks.
Definition: flowgraph.h:150
Provide a comparator function object to allow pmt use in stl types.
Definition: pmt.h:986
long symbolic_id() const
Definition: basic_block.h:136
vcolor
Definition: basic_block.h:65
virtual bool message_port_is_hier_out(pmt::pmt_t port_id)
Definition: basic_block.h:195
std::string d_symbol_name
Definition: basic_block.h:72
std::string d_name
Definition: basic_block.h:67
bool empty_p(pmt::pmt_t which_port)
is the queue empty?
Definition: basic_block.h:223
PMT_API bool dict_has_key(const pmt_t &dict, const pmt_t &key)
Return true if key exists in dict.
std::string symbol_name() const
Definition: basic_block.h:146
pmt::pmt_t alias_pmt() const
Definition: basic_block.h:169
void rpc_set()
When the block is registered with the RPC, set this.
Definition: basic_block.h:327
#define GR_RUNTIME_API
Definition: gnuradio-runtime/include/gnuradio/api.h:18
bool empty_handled_p(pmt::pmt_t which_port)
are all msg ports with handlers empty?
Definition: basic_block.h:239
virtual bool has_msg_port(pmt::pmt_t which_port)
Definition: basic_block.h:277
boost::mutex mutex
Definition: thread.h:37
long d_symbolic_id
Definition: basic_block.h:71
GR_RUNTIME_API long basic_block_ncurrently_allocated()
@ WHITE
Definition: basic_block.h:65
gr::io_signature::sptr d_input_signature
Definition: basic_block.h:68
The abstract base class for all signal processing blocks.
Definition: basic_block.h:42
gr::io_signature::sptr output_signature() const
Definition: basic_block.h:153
vcolor d_color
Definition: basic_block.h:74
log4cpp::Category * logger_ptr
GR_LOG macros.
Definition: logger.h:60
std::shared_ptr< pmt_base > pmt_t
typedef for shared pointer (transparent reference counting).
Definition: pmt.h:84
std::vector< rpcbasic_sptr > d_rpc_vars
Definition: basic_block.h:83
bool operator<(basic_block_sptr lhs, basic_block_sptr rhs)
Definition: basic_block.h:397
basic_block(void)
Definition: basic_block.h:85
vcolor color() const
Definition: basic_block.h:105
pmt::pmt_t d_message_subscribers
Definition: basic_block.h:130
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:377
virtual bool message_port_is_hier_in(pmt::pmt_t port_id)
Definition: basic_block.h:190
GNU Radio logging wrapper for log4cpp library (C++ port of log4j)
Definition: basic_block.h:29
virtual bool check_topology(int ninputs, int noutputs)
Confirm that ninputs and noutputs is an acceptable combination.
Definition: basic_block.h:342
std::vector< basic_block_sptr >::iterator basic_block_viter_t
Definition: basic_block.h:403
bool empty_handled_p()
Definition: basic_block.h:243
std::shared_ptr< io_signature > sptr
Definition: io_signature.h:34
size_t nmsgs(pmt::pmt_t which_port)
How many messages in the queue?
Definition: basic_block.h:253
std::string identifier() const
Definition: basic_block.h:147
PMT_API pmt_t intern(const std::string &s)
Alias for pmt_string_to_symbol.
bool alias_set() const
Definition: basic_block.h:159
std::ostream & operator<<(std::ostream &os, basic_block_sptr basic_block)
Definition: basic_block.h:407
thread-safe message queue
Definition: msg_queue.h:24
std::vector< basic_block_sptr > basic_block_vector_t
Definition: basic_block.h:402
msg_queue_t::iterator get_iterator(pmt::pmt_t which_port)
Definition: basic_block.h:267
gr::io_signature::sptr d_output_signature
Definition: basic_block.h:69
gr::logger_ptr d_debug_logger
Default logger.
Definition: basic_block.h:80
gr::io_signature::sptr input_signature() const
Definition: basic_block.h:152
long unique_id() const
Definition: basic_block.h:135