11#ifndef INCLUDED_GR_BASIC_BLOCK_H
12#define INCLUDED_GR_BASIC_BLOCK_H
21#include <boost/thread/condition_variable.hpp>
39 if (
pmt::eqv(queue_key2, d_system_port))
41 else if (
pmt::eqv(queue_key1, d_system_port))
45 return cmp(queue_key1, queue_key2);
62 public std::enable_shared_from_this<basic_block>
64 typedef std::function<void(
pmt::pmt_t)> msg_handler_t;
67 typedef std::map<pmt::pmt_t, msg_handler_t, pmt::comparator> d_msg_handlers_t;
68 d_msg_handlers_t d_msg_handlers;
70 typedef std::deque<pmt::pmt_t> msg_queue_t;
71 typedef std::map<pmt::pmt_t, msg_queue_t, msg_queue_comparator> msg_queue_map_t;
72 typedef std::map<pmt::pmt_t, msg_queue_t, msg_queue_comparator>::iterator
79 friend class flat_flowgraph;
80 friend class tpb_thread_body;
115 d_output_signature = iosig;
129 return (d_msg_handlers.find(which_port) != d_msg_handlers.end());
141 if (has_msg_handler(which_port)) {
142 d_msg_handlers[which_port](
msg);
155 template <
typename Derived>
158 return std::static_pointer_cast<Derived>(shared_from_this());
168 std::string
name()
const {
return d_name; }
178 return this->name() +
"(" + std::to_string(this->unique_id()) +
")";
188 bool alias_set()
const {
return !d_symbol_alias.empty(); }
193 std::string
alias()
const {
return alias_set() ? d_symbol_alias : symbol_name(); }
255 throw std::runtime_error(
"port does not exist!");
270 return (empty_p(which_port) || !has_msg_handler(which_port));
276 rv &= empty_handled_p(i.first);
285 throw std::runtime_error(
"port does not exist!");
332 void add_rpc_variable(rpcbasic_sptr s) { d_rpc_vars.push_back(s); }
405 template <
typename T>
409 throw std::runtime_error(
410 "attempt to set_msg_handler() on bad input message port!");
412 d_msg_handlers[which_port] = msg_handler_t(
msg_handler);
426inline bool operator<(basic_block_sptr lhs, basic_block_sptr rhs)
428 return lhs->unique_id() < rhs->unique_id();
The abstract base class for all signal processing blocks.
Definition: basic_block.h:63
gr::io_signature::sptr input_signature() const
Definition: basic_block.h:181
virtual void set_log_level(const std::string &level)=0
bool empty_handled_p(pmt::pmt_t which_port)
are all msg ports with handlers empty?
Definition: basic_block.h:268
bool is_rpc_set()
Ask if this block has been registered to the RPC.
Definition: basic_block.h:351
gr::logger_ptr d_debug_logger
Default logger.
Definition: basic_block.h:97
pmt::pmt_t message_subscribers(pmt::pmt_t port)
virtual bool message_port_is_hier_out(pmt::pmt_t port_id)
Definition: basic_block.h:224
void set_color(vcolor color)
Allow the flowgraph to set for sorting and partitioning.
Definition: basic_block.h:121
std::string d_symbol_alias
Definition: basic_block.h:90
long unique_id() const
Definition: basic_block.h:164
const msg_queue_map_t & get_msg_map(void) const
Definition: basic_block.h:317
msg_queue_t::iterator get_iterator(pmt::pmt_t which_port)
Definition: basic_block.h:296
void message_port_register_in(pmt::pmt_t port_id)
void set_input_signature(gr::io_signature::sptr iosig)
may only be called during constructor
Definition: basic_block.h:110
basic_block(const std::string &name, gr::io_signature::sptr input_signature, gr::io_signature::sptr output_signature)
Protected constructor prevents instantiation by non-derived classes.
void message_port_pub(pmt::pmt_t port_id, pmt::pmt_t msg)
size_t nmsgs(pmt::pmt_t which_port)
How many messages in the queue?
Definition: basic_block.h:282
virtual void set_processor_affinity(const std::vector< int > &mask)=0
std::shared_ptr< Derived > shared_from_base()
This is meant to be called by derived classes (e.g. block) to get a shared pointer internally....
Definition: basic_block.h:156
virtual bool message_port_is_hier_in(pmt::pmt_t port_id)
Definition: basic_block.h:219
gr::logger_ptr d_logger
Definition: basic_block.h:96
msg_queue_map_t msg_queue
Verbose logger.
Definition: basic_block.h:99
basic_block(void)
Definition: basic_block.h:102
long d_symbolic_id
Definition: basic_block.h:88
virtual std::vector< int > processor_affinity()=0
bool empty_handled_p()
Definition: basic_block.h:272
virtual std::string log_level()=0
void set_output_signature(gr::io_signature::sptr iosig)
may only be called during constructor
Definition: basic_block.h:113
std::string identifier() const
Definition: basic_block.h:176
long symbolic_id() const
Definition: basic_block.h:165
pmt::pmt_t alias_pmt() const
Definition: basic_block.h:198
virtual void setup_rpc()
Set up the RPC registered variables.
Definition: basic_block.h:343
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:406
basic_block_sptr to_basic_block()
gr::io_signature::sptr d_output_signature
Definition: basic_block.h:86
gr::io_signature::sptr d_input_signature
Definition: basic_block.h:85
virtual bool message_port_is_hier(pmt::pmt_t port_id)
Definition: basic_block.h:214
long d_unique_id
Definition: basic_block.h:87
virtual bool has_msg_port(pmt::pmt_t which_port)
Definition: basic_block.h:306
bool d_rpc_set
Definition: basic_block.h:92
virtual void dispatch_msg(pmt::pmt_t which_port, pmt::pmt_t msg)
Definition: basic_block.h:138
std::string symbol_name() const
Definition: basic_block.h:175
std::string alias() const
Definition: basic_block.h:193
void _post(pmt::pmt_t which_port, pmt::pmt_t msg)
bool alias_set() const
Definition: basic_block.h:188
void message_port_register_out(pmt::pmt_t port_id)
void rpc_set()
When the block is registered with the RPC, set this.
Definition: basic_block.h:356
virtual void unset_processor_affinity()=0
vcolor
Definition: basic_block.h:82
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:127
virtual bool check_topology(int ninputs, int noutputs)
Confirm that ninputs and noutputs is an acceptable combination.
Definition: basic_block.h:371
void insert_tail(pmt::pmt_t which_port, pmt::pmt_t msg)
void erase_msg(pmt::pmt_t which_port, msg_queue_t::iterator it)
Definition: basic_block.h:301
void set_block_alias(std::string name)
void message_port_unsub(pmt::pmt_t port_id, pmt::pmt_t target)
pmt::pmt_t message_ports_out()
Get output message port names.
std::string d_name
Definition: basic_block.h:84
void message_port_sub(pmt::pmt_t port_id, pmt::pmt_t target)
gr::io_signature::sptr output_signature() const
Definition: basic_block.h:182
std::vector< rpcbasic_sptr > d_rpc_vars
Definition: basic_block.h:100
vcolor color() const
Definition: basic_block.h:122
pmt::pmt_t message_ports_in()
Get input message port names.
bool empty_p(pmt::pmt_t which_port)
is the queue empty?
Definition: basic_block.h:252
bool empty_p()
Definition: basic_block.h:258
pmt::pmt_t d_message_subscribers
Definition: basic_block.h:147
std::string name() const
Definition: basic_block.h:168
std::string d_symbol_name
Definition: basic_block.h:89
pmt::pmt_t delete_head_nowait(pmt::pmt_t which_port)
vcolor d_color
Definition: basic_block.h:91
Class representing a directed, acyclic graph of basic blocks.
Definition: flowgraph.h:150
std::shared_ptr< io_signature > sptr
Definition: io_signature.h:47
Accepts messages and inserts them into a message queue, then notifies subclass gr::basic_block there ...
Definition: msg_accepter.h:25
abstract class of message handlers
Definition: msg_handler.h:27
Definition: basic_block.h:32
bool operator()(pmt::pmt_t const &queue_key1, pmt::pmt_t const &queue_key2) const
Definition: basic_block.h:37
thread-safe message queue
Definition: msg_queue.h:25
Provide a comparator function object to allow pmt use in stl types.
Definition: pmt.h:972
#define GR_RUNTIME_API
Definition: gnuradio-runtime/include/gnuradio/api.h:18
GR_RUNTIME_API const pmt::pmt_t msg()
boost::mutex mutex
Definition: thread.h:37
GNU Radio logging wrapper.
Definition: basic_block.h:29
std::shared_ptr< logger > logger_ptr
Definition: logger.h:225
std::vector< basic_block_sptr > basic_block_vector_t
Definition: basic_block.h:431
std::ostream & operator<<(std::ostream &os, basic_block_sptr basic_block)
Definition: basic_block.h:436
bool operator<(basic_block_sptr lhs, basic_block_sptr rhs)
Definition: basic_block.h:426
std::vector< basic_block_sptr >::iterator basic_block_viter_t
Definition: basic_block.h:432
GR_RUNTIME_API long basic_block_ncurrently_allocated()
PMT_API bool dict_has_key(const pmt_t &dict, const pmt_t &key)
Return true if key exists in dict.
PMT_API bool eqv(const pmt_t &x, const pmt_t &y)
Return true if x and y should normally be regarded as the same object, else false.
PMT_API pmt_t intern(const std::string &s)
Alias for pmt_string_to_symbol.
std::shared_ptr< pmt_base > pmt_t
typedef for shared pointer (transparent reference counting).
Definition: pmt.h:83