Loading...
Searching...
No Matches
gr::basic_block Class Referenceabstract
Implementation Details

The abstract base class for all signal processing blocks. More...

`#include <gnuradio/basic_block.h>`

## Public Member Functions

pmt::pmt_t | message_subscribers (pmt::pmt_t port)
| ~basic_block () override
long | unique_id () const
long | symbolic_id () const
std::string | name () const
std::string | symbol_name () const
std::string | identifier () const
gr::io_signature::sptr | input_signature () const
gr::io_signature::sptr | output_signature () const
basic_block_sptr | to_basic_block ()
bool | alias_set () const
std::string | alias () const
pmt::pmt_t | alias_pmt () const
void | set_block_alias (std::string name)
void | message_port_register_in (pmt::pmt_t port_id)
void | message_port_register_out (pmt::pmt_t port_id)
void | message_port_pub (pmt::pmt_t port_id, pmt::pmt_t msg)
void | message_port_sub (pmt::pmt_t port_id, pmt::pmt_t target)
void | message_port_unsub (pmt::pmt_t port_id, pmt::pmt_t target)
virtual bool | message_port_is_hier (pmt::pmt_t port_id)
virtual bool | message_port_is_hier_in (pmt::pmt_t port_id)
virtual bool | message_port_is_hier_out (pmt::pmt_t port_id)
pmt::pmt_t | message_ports_in ()
| Get input message port names.
pmt::pmt_t | message_ports_out ()
| Get output message port names.
void | _post (pmt::pmt_t which_port, pmt::pmt_t msg)
bool | empty_p (pmt::pmt_t which_port)
| is the queue empty?
bool | empty_p ()
bool | empty_handled_p (pmt::pmt_t which_port)
| are all msg ports with handlers empty?
bool | empty_handled_p ()
size_t | nmsgs (pmt::pmt_t which_port)
| How many messages in the queue?
void | insert_tail (pmt::pmt_t which_port, pmt::pmt_t msg)
pmt::pmt_t | delete_head_nowait (pmt::pmt_t which_port)
msg_queue_t::iterator | get_iterator (pmt::pmt_t which_port)
void | erase_msg (pmt::pmt_t which_port, msg_queue_t::iterator it)
virtual bool | has_msg_port (pmt::pmt_t which_port)
const msg_queue_map_t & | get_msg_map (void) const
void | add_rpc_variable (rpcbasic_sptr s)
| Add an RPC variable (get or set).
virtual void | setup_rpc ()
| Set up the RPC registered variables.
bool | is_rpc_set ()
| Ask if this block has been registered to the RPC.
void | rpc_set ()
| When the block is registered with the RPC, set this.
virtual bool | check_topology (int ninputs, int noutputs)
| Confirm that ninputs and noutputs is an acceptable combination.
template<typename T>
void | set_msg_handler (pmt::pmt_t which_port, T msg_handler)
| Set the callback that is fired when messages are available.
virtual void | set_processor_affinity (const std::vector< int > &mask)=0
virtual void | unset_processor_affinity ()=0
virtual std::vector< int > | processor_affinity ()=0
virtual void | set_log_level (const std::string &level)=0
virtual std::string | log_level ()=0
Public Member Functions inherited from gr::msg_accepter
| msg_accepter ()
| ~msg_accepter () override
void | post (pmt::pmt_t which_port, pmt::pmt_t msg) override
| send `msg` to `msg_accepter` on port `which_port`
Public Member Functions inherited from gr::messages::msg_accepter
| msg_accepter ()

## Protected Types

enum | vcolor { WHITE , GREY , BLACK }

## Protected Member Functions

| basic_block (void)
| 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 | set_input_signature (gr::io_signature::sptr iosig)
| may only be called during constructor
void | set_output_signature (gr::io_signature::sptr iosig)
| may only be called during constructor
void | set_color (vcolor color)
| Allow the flowgraph to set for sorting and partitioning.
vcolor | color () const
virtual bool | has_msg_handler (pmt::pmt_t which_port)
| Tests if there is a handler attached to port `which_port`.
virtual void | dispatch_msg (pmt::pmt_t which_port, pmt::pmt_t msg)
template<typename Derived>
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. This is needed because std::enable_shared_from_this doesn't seem to work with derived classes in an inheritance hierarchy.

## Protected Attributes

std::string | d_name
gr::io_signature::sptr | d_input_signature
gr::io_signature::sptr | d_output_signature
long | d_unique_id
long | d_symbolic_id
std::string | d_symbol_name
std::string | d_symbol_alias
vcolor | d_color
bool | d_rpc_set
gr::logger_ptr | d_logger
gr::logger_ptr | d_debug_logger
| Default logger.
msg_queue_map_t | msg_queue
| Verbose logger.
std::vector< rpcbasic_sptr > | d_rpc_vars
pmt::pmt_t | d_message_subscribers

## Friends

class | flowgraph
class | flat_flowgraph
class | tpb_thread_body

## Detailed Description

The abstract base class for all signal processing blocks.

Basic blocks are the bare abstraction of an entity that has a name, a set of inputs and outputs, and a message queue. These are never instantiated directly; rather, this is the abstract parent class of both gr_hier_block, which is a recursive container, and block, which implements actual signal processing functions.

## Member Enumeration Documentation

## vcolor

enum gr::basic_block::vcolor

protected

Enumerator
WHITE |
GREY |
BLACK |

## Constructor & Destructor Documentation

## basic_block() [1/2]

gr::basic_block::basic_block | ( | void |  | ) |

inline protected

## basic_block() [2/2]

gr::basic_block::basic_block | ( | const std::string & | name,
|  | gr::io_signature::sptr | input_signature,
|  | gr::io_signature::sptr | output_signature )

protected

Protected constructor prevents instantiation by non-derived classes.

References input_signature(), name(), and output_signature().

## ~basic_block()

gr::basic_block::~basic_block | ( |  | ) |

override

## Member Function Documentation

## _post()

void gr::basic_block::_post | ( | pmt::pmt_t | which_port,
|  | pmt::pmt_t | msg )

Accept msg, place in queue, arrange for thread to be awakened if it's not already.

## add_rpc_variable()

void gr::basic_block::add_rpc_variable | ( | rpcbasic_sptr | s | ) |

inline

Add an RPC variable (get or set).

Using controlport, we create new getters/setters and need to store them. Each block has a vector to do this, and these never need to be accessed again once they are registered with the RPC backend. This function takes a std::shared_sptr<rpcbasic_base> so that when the block is deleted, all RPC registered variables are cleaned up.

Parameters

  s | an rpcbasic_sptr of the new RPC variable register to store.

References d_rpc_vars.

## alias()

std::string gr::basic_block::alias | ( |  | ) | const

inline

Returns the block's alias as a string.

References alias_set(), d_symbol_alias, and symbol_name().

Referenced by alias_pmt().

## alias_pmt()

pmt::pmt_t gr::basic_block::alias_pmt | ( |  | ) | const

inline

Returns the block's alias as PMT.

References alias(), and pmt::intern().

## alias_set()

bool gr::basic_block::alias_set | ( |  | ) | const

inline

True if the block has an alias (see set_block_alias).

References d_symbol_alias.

Referenced by alias().

## check_topology()

virtual bool gr::basic_block::check_topology | ( | int | ninputs,
|  | int | noutputs )

inline virtual

Confirm that ninputs and noutputs is an acceptable combination.

Parameters

  ninputs | number of input streams connected
  noutputs | number of output streams connected

Returns
  true if this is a valid configuration for this block.

This function is called by the runtime system whenever the topology changes. Most classes do not need to override this. This check is in addition to the constraints specified by the input and output gr::io_signatures.

Reimplemented in gr::tagged_stream_block.

## color()

vcolor gr::basic_block::color | ( |  | ) | const

inline protected

References d_color.

Referenced by set_color(), gr::qtgui::time_raster_sink_b::set_color_map(), gr::qtgui::time_raster_sink_f::set_color_map(), gr::qtgui::waterfall_sink_c::set_color_map(), gr::qtgui::waterfall_sink_f::set_color_map(), gr::qtgui::ber_sink_b::set_line_color(), gr::qtgui::const_sink_c::set_line_color(), gr::qtgui::eye_sink_c::set_line_color(), gr::qtgui::eye_sink_f::set_line_color(), gr::qtgui::freq_sink_c::set_line_color(), gr::qtgui::freq_sink_f::set_line_color(), gr::qtgui::histogram_sink_f::set_line_color(), gr::qtgui::time_raster_sink_b::set_line_color(), gr::qtgui::time_raster_sink_f::set_line_color(), gr::qtgui::time_sink_c::set_line_color(), gr::qtgui::time_sink_f::set_line_color(), and gr::qtgui::vector_sink_f::set_line_color().

## delete_head_nowait()

pmt::pmt_t gr::basic_block::delete_head_nowait | ( | pmt::pmt_t | which_port | ) |

Returns
  returns pmt at head of queue or pmt::pmt_t() if empty.

## dispatch_msg()

virtual void gr::basic_block::dispatch_msg | ( | pmt::pmt_t | which_port,
|  | pmt::pmt_t | msg )

inline protected virtual

References has_msg_handler().

## empty_handled_p() [1/2]

bool gr::basic_block::empty_handled_p | ( |  | ) |

inline

References empty_handled_p(), and msg_queue.

## empty_handled_p() [2/2]

bool gr::basic_block::empty_handled_p | ( | pmt::pmt_t | which_port | ) |

inline

are all msg ports with handlers empty?

References empty_p(), and has_msg_handler().

Referenced by empty_handled_p().

## empty_p() [1/2]

bool gr::basic_block::empty_p | ( |  | ) |

inline

References msg_queue.

## empty_p() [2/2]

bool gr::basic_block::empty_p | ( | pmt::pmt_t | which_port | ) |

inline

is the queue empty?

References msg_queue.

Referenced by empty_handled_p().

## erase_msg()

void gr::basic_block::erase_msg | ( | pmt::pmt_t | which_port,
|  | msg_queue_t::iterator | it )

inline

References msg_queue.

## get_iterator()

msg_queue_t::iterator gr::basic_block::get_iterator | ( | pmt::pmt_t | which_port | ) |

inline

References msg_queue.

## get_msg_map()

const msg_queue_map_t & gr::basic_block::get_msg_map | ( | void |  | ) | const

inline

References msg_queue.

## has_msg_handler()

virtual bool gr::basic_block::has_msg_handler | ( | pmt::pmt_t | which_port | ) |

inline protected virtual

Tests if there is a handler attached to port `which_port`.

Referenced by dispatch_msg(), and empty_handled_p().

## has_msg_port()

virtual bool gr::basic_block::has_msg_port | ( | pmt::pmt_t | which_port | ) |

inline virtual

Reimplemented in gr::hier_block2.

References d_message_subscribers, pmt::dict_has_key(), and msg_queue.

Referenced by gr::hier_block2::has_msg_port().

## identifier()

std::string gr::basic_block::identifier | ( |  | ) | const

inline

References name(), and unique_id().

Referenced by gr::operator<<().

## input_signature()

gr::io_signature::sptr gr::basic_block::input_signature | ( |  | ) | const

inline

References d_input_signature.

Referenced by basic_block(), gr::block::block(), gr::hier_block2::hier_block2(), gr::sync_block::sync_block(), gr::sync_decimator::sync_decimator(), gr::sync_interpolator::sync_interpolator(), gr::tagged_stream_block::tagged_stream_block(), and gr::uhd::usrp_block::usrp_block().

## insert_tail()

void gr::basic_block::insert_tail | ( | pmt::pmt_t | which_port,
|  | pmt::pmt_t | msg )

## is_rpc_set()

bool gr::basic_block::is_rpc_set | ( |  | ) |

inline

Ask if this block has been registered to the RPC.

We can only register a block once, so we use this to protect us from calling it multiple times.

References d_rpc_set.

## log_level()

virtual std::string gr::basic_block::log_level | ( |  | ) |

pure virtual

Implemented in gr::block, and gr::hier_block2.

## message_port_is_hier()

virtual bool gr::basic_block::message_port_is_hier | ( | pmt::pmt_t | port_id | ) |

inline virtual

Reimplemented in gr::hier_block2.

## message_port_is_hier_in()

virtual bool gr::basic_block::message_port_is_hier_in | ( | pmt::pmt_t | port_id | ) |

inline virtual

Reimplemented in gr::hier_block2.

## message_port_is_hier_out()

virtual bool gr::basic_block::message_port_is_hier_out | ( | pmt::pmt_t | port_id | ) |

inline virtual

Reimplemented in gr::hier_block2.

## message_port_pub()

void gr::basic_block::message_port_pub | ( | pmt::pmt_t | port_id,
|  | pmt::pmt_t | msg )

## message_port_register_in()

void gr::basic_block::message_port_register_in | ( | pmt::pmt_t | port_id | ) |

## message_port_register_out()

void gr::basic_block::message_port_register_out | ( | pmt::pmt_t | port_id | ) |

## message_port_sub()

void gr::basic_block::message_port_sub | ( | pmt::pmt_t | port_id,
|  | pmt::pmt_t | target )

## message_port_unsub()

void gr::basic_block::message_port_unsub | ( | pmt::pmt_t | port_id,
|  | pmt::pmt_t | target )

## message_ports_in()

pmt::pmt_t gr::basic_block::message_ports_in | ( |  | ) |

Get input message port names.

Returns the available input message ports for a block. The return object is a PMT vector that is filled with PMT symbols.

## message_ports_out()

pmt::pmt_t gr::basic_block::message_ports_out | ( |  | ) |

Get output message port names.

Returns the available output message ports for a block. The return object is a PMT vector that is filled with PMT symbols.

## message_subscribers()

pmt::pmt_t gr::basic_block::message_subscribers | ( | pmt::pmt_t | port | ) |

## name()

std::string gr::basic_block::name | ( |  | ) | const

inline

The name of the block

References d_name.

Referenced by basic_block(), gr::block::block(), block_gateway::block_gateway(), gr::uhd::usrp_block::get_dboard_sensor(), gr::soapy::block::get_frequency(), gr::soapy::block::get_frequency_range(), gr::soapy::block::get_gain(), gr::uhd::usrp_block::get_gain(), gr::soapy::block::get_gain_range(), gr::uhd::usrp_block::get_gain_range(), gr::uhd::usrp_sink::get_lo_export_enabled(), gr::uhd::usrp_source::get_lo_export_enabled(), gr::uhd::usrp_sink::get_lo_freq(), gr::uhd::usrp_source::get_lo_freq(), gr::uhd::usrp_sink::get_lo_freq_range(), gr::uhd::usrp_source::get_lo_freq_range(), gr::uhd::usrp_sink::get_lo_source(), gr::uhd::usrp_source::get_lo_source(), gr::uhd::usrp_sink::get_lo_sources(), gr::uhd::usrp_source::get_lo_sources(), gr::uhd::usrp_block::get_mboard_sensor(), gr::uhd::rfnoc_block::get_property(), gr::uhd::usrp_block::get_sensor(), gr::hier_block2::hier_block2(), identifier(), block_gateway::make(), gr::blocks::probe_rate::make(), gr::blocks::tag_debug::make(), gr::blocks::transcendental::make(), gr::qtgui::const_sink_c::make(), gr::qtgui::freq_sink_c::make(), gr::qtgui::freq_sink_f::make(), gr::qtgui::histogram_sink_f::make(), gr::qtgui::matrix_sink::make(), gr::qtgui::sink_c::make(), gr::qtgui::sink_f::make(), gr::qtgui::time_raster_sink_b::make(), gr::qtgui::time_raster_sink_f::make(), gr::qtgui::time_sink_c::make(), gr::qtgui::time_sink_f::make(), gr::qtgui::vector_sink_f::make(), gr::qtgui::waterfall_sink_c::make(), gr::qtgui::waterfall_sink_f::make(), gr::soapy::block::read_register(), gr::soapy::block::read_registers(), gr::soapy::block::set_antenna(), set_block_alias(), gr::soapy::block::set_frequency(), gr::soapy::block::set_gain(), gr::uhd::rfnoc_rx_radio::set_gain(), gr::uhd::rfnoc_tx_radio::set_gain(), gr::uhd::usrp_block::set_gain(), gr::uhd::rfnoc_rx_radio::set_lo_export_enabled(), gr::uhd::rfnoc_tx_radio::set_lo_export_enabled(), gr::uhd::usrp_sink::set_lo_export_enabled(), gr::uhd::usrp_source::set_lo_export_enabled(), gr::uhd::rfnoc_rx_radio::set_lo_freq(), gr::uhd::rfnoc_tx_radio::set_lo_freq(), gr::uhd::usrp_sink::set_lo_freq(), gr::uhd::usrp_source::set_lo_freq(), gr::uhd::rfnoc_rx_radio::set_lo_source(), gr::uhd::rfnoc_tx_radio::set_lo_source(), gr::uhd::usrp_sink::set_lo_source(), gr::uhd::usrp_source::set_lo_source(), gr::blocks::probe_rate::set_name(), gr::uhd::rfnoc_block::set_property(), gr::sync_block::sync_block(), gr::sync_decimator::sync_decimator(), gr::sync_interpolator::sync_interpolator(), gr::tagged_stream_block::tagged_stream_block(), gr::top_block::top_block(), gr::uhd::usrp_block::usrp_block(), gr::soapy::block::write_register(), and gr::soapy::block::write_registers().

## nmsgs()

size_t gr::basic_block::nmsgs | ( | pmt::pmt_t | which_port | ) |

inline

How many messages in the queue?

References msg_queue.

## output_signature()

gr::io_signature::sptr gr::basic_block::output_signature | ( |  | ) | const

inline

References d_output_signature.

Referenced by basic_block(), gr::block::block(), gr::hier_block2::hier_block2(), gr::sync_block::sync_block(), gr::sync_decimator::sync_decimator(), gr::sync_interpolator::sync_interpolator(), gr::tagged_stream_block::tagged_stream_block(), and gr::uhd::usrp_block::usrp_block().

## processor_affinity()

virtual std::vector< int > gr::basic_block::processor_affinity | ( |  | ) |

pure virtual

Implemented in gr::block, and gr::hier_block2.

## rpc_set()

void gr::basic_block::rpc_set | ( |  | ) |

inline

When the block is registered with the RPC, set this.

References d_rpc_set.

## set_block_alias()

void gr::basic_block::set_block_alias | ( | std::string | name | ) |

Set's a new alias for the block; also adds an entry into the block_registry to get the block using either the alias or the original symbol name.

References name().

## set_color()

void gr::basic_block::set_color | ( | vcolor | color | ) |

inline protected

Allow the flowgraph to set for sorting and partitioning.

References color(), and d_color.

## set_input_signature()

void gr::basic_block::set_input_signature | ( | gr::io_signature::sptr | iosig | ) |

inline protected

may only be called during constructor

References d_input_signature.

## set_log_level()

virtual void gr::basic_block::set_log_level | ( | const std::string & | level | ) |

pure virtual

Implemented in gr::block, and gr::hier_block2.

## set_msg_handler()

template<typename T>

void gr::basic_block::set_msg_handler | ( | pmt::pmt_t | which_port,
|  | T | msg_handler )

inline

Set the callback that is fired when messages are available.

`msg_handler` can be any kind of function pointer or function object that has the signature:

       void msg_handler(pmt::pmt msg);

(You may want to use boost::bind to massage your callable into the correct form. See gr::blocks::nop for an example that sets up a class method as the callback.)

Blocks that desire to handle messages must call this method in their constructors to register the handler that will be invoked when messages are available.

If the block inherits from block, the runtime system will ensure that msg_handler is called in a thread-safe manner, such that work and msg_handler will never be called concurrently. This allows msg_handler to update state variables without having to worry about thread-safety issues with work, general_work or another invocation of msg_handler.

If the block inherits from hier_block2, the runtime system will ensure that no reentrant calls are made to msg_handler.

References msg_queue.

## set_output_signature()

void gr::basic_block::set_output_signature | ( | gr::io_signature::sptr | iosig | ) |

inline protected

may only be called during constructor

References d_output_signature.

## set_processor_affinity()

virtual void gr::basic_block::set_processor_affinity | ( | const std::vector< int > & | mask | ) |

pure virtual

Implemented in gr::block, and gr::hier_block2.

## setup_rpc()

virtual void gr::basic_block::setup_rpc | ( |  | ) |

inline virtual

Set up the RPC registered variables.

This must be overloaded by a block that wants to use controlport. This is where rpcbasic_register_{get,set} pointers are created, which then get wrapped as shared pointers (rpcbasic_sptr(...)) and stored using add_rpc_variable.

Reimplemented in gr::top_block.

## shared_from_base()

template<typename Derived>

std::shared_ptr< Derived > gr::basic_block::shared_from_base | ( |  | ) |

inline protected

This is meant to be called by derived classes (e.g. block) to get a shared pointer internally. This is needed because std::enable_shared_from_this doesn't seem to work with derived classes in an inheritance hierarchy.

## symbol_name()

std::string gr::basic_block::symbol_name | ( |  | ) | const

inline

The symbolic name of the block, which is used in the block_registry. The name is assigned by the block's constructor and never changes during the life of the block.

References d_symbol_name.

Referenced by alias().

## symbolic_id()

long gr::basic_block::symbolic_id | ( |  | ) | const

inline

References d_symbolic_id.

## to_basic_block()

basic_block_sptr gr::basic_block::to_basic_block | ( |  | ) |

## unique_id()

long gr::basic_block::unique_id | ( |  | ) | const

inline

References d_unique_id.

Referenced by identifier(), and gr::operator<().

## unset_processor_affinity()

virtual void gr::basic_block::unset_processor_affinity | ( |  | ) |

pure virtual

Implemented in gr::block, and gr::hier_block2.

## Friends And Related Symbol Documentation

## flat_flowgraph

friend class flat_flowgraph

friend

References flat_flowgraph.

Referenced by flat_flowgraph.

## flowgraph

friend class flowgraph

friend

References flowgraph.

Referenced by flowgraph.

## tpb_thread_body

friend class tpb_thread_body

friend

References tpb_thread_body.

Referenced by tpb_thread_body.

## Member Data Documentation

## d_color

vcolor gr::basic_block::d_color

protected

Referenced by color(), and set_color().

## d_debug_logger

gr::logger_ptr gr::basic_block::d_debug_logger

protected

Default logger.

## d_input_signature

gr::io_signature::sptr gr::basic_block::d_input_signature

protected

Referenced by input_signature(), and set_input_signature().

## d_logger

gr::logger_ptr gr::basic_block::d_logger

protected

Used by blocks to access the logger system.

Referenced by block_gateway::_get_logger().

## d_message_subscribers

pmt::pmt_t gr::basic_block::d_message_subscribers

protected

Referenced by has_msg_port(), and gr::hier_block2::message_port_register_hier_out().

## d_name

std::string gr::basic_block::d_name

protected

Referenced by name().

## d_output_signature

gr::io_signature::sptr gr::basic_block::d_output_signature

protected

Referenced by output_signature(), and set_output_signature().

## d_rpc_set

bool gr::basic_block::d_rpc_set

protected

Referenced by is_rpc_set(), and rpc_set().

## d_rpc_vars

std::vector<rpcbasic_sptr> gr::basic_block::d_rpc_vars

protected

Referenced by add_rpc_variable().

## d_symbol_alias

std::string gr::basic_block::d_symbol_alias

protected

Referenced by alias(), and alias_set().

## d_symbol_name

std::string gr::basic_block::d_symbol_name

protected

Referenced by symbol_name().

## d_symbolic_id

long gr::basic_block::d_symbolic_id

protected

Referenced by symbolic_id().

## d_unique_id

long gr::basic_block::d_unique_id

protected

Referenced by unique_id().

## msg_queue

msg_queue_map_t gr::basic_block::msg_queue

protected

Verbose logger.

Referenced by empty_handled_p(), empty_p(), empty_p(), erase_msg(), get_iterator(), get_msg_map(), has_msg_port(), gr::hier_block2::message_port_register_hier_in(), nmsgs(), and set_msg_handler().

The documentation for this class was generated from the following file:

- basic_block.h