CORESENSE4home_Architecture
Loading...
Searching...
No Matches
Afferent Class Referenceabstract

Manages afferent processing in robotic nodes, including message handling, subscriptions, and modes for processing serialized data. More...

#include <Afferent.hpp>

Inheritance diagram for Afferent:
Collaboration diagram for Afferent:

Public Types

enum  EfferentProcessMode { CALLBACK , ONDEMAND }
 Defines processing modes for serialized message handling. More...
 

Public Member Functions

 Afferent (rclcpp_lifecycle::LifecycleNode::SharedPtr parent)
 Constructor for the Afferent class.
 
virtual bool configure ()=0
 Configures the afferent component; intended for subclass implementation.
 
size_t get_max_queue_size ()
 Gets the maximum queue size.
 
EfferentProcessMode get_mode ()
 Gets the current processing mode.
 
template<class MessageT>
std::unique_ptr< MessageT > get_msg ()
 Retrieves the next message from the queue, if available.
 
template<class MessageT>
std::unique_ptr< MessageT > get_msg (std::unique_ptr< rclcpp::SerializedMessage > msg)
 Converts a serialized message to a typed message.
 
void set_max_queue_size (size_t size)
 Sets the maximum queue size for storing messages.
 
void set_mode (EfferentProcessMode mode, std::function< void(std::unique_ptr< rclcpp::SerializedMessage >)> cb=nullptr)
 Sets the processing mode and an optional callback function.
 

Protected Member Functions

bool create_subscriber (const std::string &topic, const std::string &type)
 Creates a subscriber for a specific topic and message type.
 

Protected Attributes

std::function< void(std::unique_ptr< rclcpp::SerializedMessage >)> callback_
 Callback for serialized messages.
 
const size_t MAX_DEFAULT_QUEUE_SIZE = 100
 Default maximum queue size.
 
size_t max_queue_size_ {MAX_DEFAULT_QUEUE_SIZE}
 Maximum queue size.
 
EfferentProcessMode mode_ {ONDEMAND}
 Current processing mode.
 
std::queue< std::unique_ptr< rclcpp::SerializedMessage > > msg_queue_
 Queue for serialized messages.
 
rclcpp_lifecycle::LifecycleNode::SharedPtr parent_
 Shared pointer to the parent node.
 
std::vector< std::shared_ptr< rclcpp::GenericSubscription > > subs_
 List of subscriptions.
 

Detailed Description

Manages afferent processing in robotic nodes, including message handling, subscriptions, and modes for processing serialized data.

Member Enumeration Documentation

◆ EfferentProcessMode

Defines processing modes for serialized message handling.

Enumerator
CALLBACK 
ONDEMAND 

Constructor & Destructor Documentation

◆ Afferent()

Afferent ( rclcpp_lifecycle::LifecycleNode::SharedPtr parent)
explicit

Constructor for the Afferent class.

Parameters
parentShared pointer to the lifecycle node managing this instance.
parentShared pointer to the lifecycle node that owns this Afferent instance.

Member Function Documentation

◆ configure()

virtual bool configure ( )
pure virtual

Configures the afferent component; intended for subclass implementation.

Returns
True if configuration is successful.

Implemented in SimpleImageInput.

◆ create_subscriber()

bool create_subscriber ( const std::string & topic,
const std::string & type )
protected

Creates a subscriber for a specific topic and message type.

Creates a subscription to a specified topic and type.

Parameters
topicTopic to subscribe to.
typeType of message for the subscription.
Returns
True if the subscriber was created successfully.

This method sets up a subscription to receive messages on a given topic with a specified message type. The received messages are either processed through a callback (if set) or stored in an internal message queue.

Parameters
topicThe topic name to subscribe to.
typeThe type of messages expected on the topic.
Returns
True if the subscription was created successfully.

◆ get_max_queue_size()

size_t get_max_queue_size ( )

Gets the maximum queue size.

Returns
The maximum queue size.

◆ get_mode()

EfferentProcessMode get_mode ( )

Gets the current processing mode.

Returns
The current EfferentProcessMode.

◆ get_msg() [1/2]

template<class MessageT>
std::unique_ptr< MessageT > get_msg ( )

Retrieves the next message from the queue, if available.

Template Parameters
MessageTType of message to retrieve.
Returns
A unique pointer to the next message, or nullptr if the queue is empty.

◆ get_msg() [2/2]

template<class MessageT>
std::unique_ptr< MessageT > get_msg ( std::unique_ptr< rclcpp::SerializedMessage > msg)

Converts a serialized message to a typed message.

Template Parameters
MessageTType of the message to deserialize.
Parameters
msgSerialized message to convert.
Returns
A unique pointer to the deserialized message.

◆ set_max_queue_size()

void set_max_queue_size ( size_t size)

Sets the maximum queue size for storing messages.

Parameters
sizeMaximum number of messages the queue can hold.

◆ set_mode()

void set_mode ( EfferentProcessMode mode,
std::function< void(std::unique_ptr< rclcpp::SerializedMessage >)> cb = nullptr )

Sets the processing mode and an optional callback function.

Sets the operation mode and an optional callback function.

Parameters
modeProcessing mode for handling messages.
cbOptional callback function for handling serialized messages in CALLBACK mode.

This function allows configuring the Afferent object with a specific processing mode and an optional callback to handle serialized messages.

Parameters
modeThe processing mode for the Afferent object.
cbA callback function to process serialized messages, used if the mode is CALLBACK.

Member Data Documentation

◆ callback_

std::function<void(std::unique_ptr<rclcpp::SerializedMessage>)> callback_
protected

Callback for serialized messages.

◆ MAX_DEFAULT_QUEUE_SIZE

const size_t MAX_DEFAULT_QUEUE_SIZE = 100
protected

Default maximum queue size.

◆ max_queue_size_

size_t max_queue_size_ {MAX_DEFAULT_QUEUE_SIZE}
protected

Maximum queue size.

◆ mode_

EfferentProcessMode mode_ {ONDEMAND}
protected

Current processing mode.

◆ msg_queue_

std::queue<std::unique_ptr<rclcpp::SerializedMessage> > msg_queue_
protected

Queue for serialized messages.

◆ parent_

rclcpp_lifecycle::LifecycleNode::SharedPtr parent_
protected

Shared pointer to the parent node.

◆ subs_

std::vector<std::shared_ptr<rclcpp::GenericSubscription> > subs_
protected

List of subscriptions.


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