TinyRobotics
Loading...
Searching...
No Matches
Classes | Public Member Functions | Protected Attributes | List of all members
MessageSource Class Reference

Base class for message sources in the TinyRobotics communication framework. More...

#include <MessageSource.h>

Inheritance diagram for MessageSource:
Inheritance graph
[legend]

Classes

struct  MessageHandlerEntry
 

Public Member Functions

void subscribe (MessageHandler &handler, MessageOrigin origin=MessageOrigin::Undefined, MessageContent content=MessageContent::Undefined)
 Subscribe a message handler to this source, with optional filtering.
 
void unsubscribeAll ()
 Remove all registered message handlers.
 
void sendMessage (Message< float > &msg)
 Publish a message to all registered handlers.
 
void sendMessage (const Message< Coordinate< float > > &msg)
 Publish a message to all registered handlers.
 
void sendMessage (const Message< GPSCoordinate > &msg)
 Publish a message to all registered handlers.
 
void sendMessage (const Message< MotionState3D > &msg)
 Overload for MotionState3D messages.
 

Protected Attributes

std::vector< MessageHandlerEntrymessageHandlers_
 

Detailed Description

Base class for message sources in the TinyRobotics communication framework.

MessageSource manages a list of MessageHandler objects and provides methods to add, clear, and forward messages to all registered handlers. This enables a flexible publish/subscribe or observer pattern for distributing messages (such as sensor data, commands, or events) to multiple consumers in a robotics system.

Typical usage:

source.subscribe(handler1);
source.subscribe(handler2);
source.sendMessage(msg); // Forwards to all handlers
Base class for message sources in the TinyRobotics communication framework.
Definition: MessageSource.h:35
void sendMessage(Message< float > &msg)
Publish a message to all registered handlers.
Definition: MessageSource.h:77
void subscribe(MessageHandler &handler, MessageOrigin origin=MessageOrigin::Undefined, MessageContent content=MessageContent::Undefined)
Subscribe a message handler to this source, with optional filtering.
Definition: MessageSource.h:59

Extend this class to implement custom message-producing components (e.g., sensors, controllers) that need to broadcast messages to other system parts.

Member Function Documentation

◆ sendMessage() [1/3]

void sendMessage ( const Message< Coordinate< float > > &  msg)
inline

Publish a message to all registered handlers.

Forwards the given message to each handler in the messageHandlers_ list.

Parameters
msgThe message to publish.

◆ sendMessage() [2/3]

void sendMessage ( const Message< GPSCoordinate > &  msg)
inline

Publish a message to all registered handlers.

Forwards the given message to each handler in the messageHandlers_ list.

Parameters
msgThe message to publish.

◆ sendMessage() [3/3]

void sendMessage ( Message< float > &  msg)
inline

Publish a message to all registered handlers.

Forwards the given message to each handler in the messageHandlers_ list.

Parameters
msgThe message to publish.

◆ subscribe()

void subscribe ( MessageHandler handler,
MessageOrigin  origin = MessageOrigin::Undefined,
MessageContent  content = MessageContent::Undefined 
)
inline

Subscribe a message handler to this source, with optional filtering.

Registers a MessageHandler to receive messages published by this source. Optionally, you can specify a filter for message origin and content. Only messages matching the filter (or with filter set to Undefined) will be delivered to the handler.

Parameters
handlerReference to a MessageHandler to add.
origin(Optional) Only deliver messages with this origin. Use MessageOrigin::Undefined to accept all origins.
content(Optional) Only deliver messages with this content type. Use MessageContent::Undefined to accept all content types.

Example:

source.subscribe(handler); // Receives all messages
source.subscribe(handler, MessageOrigin::RemoteControl); // Only messages
from remote control source.subscribe(handler, MessageOrigin::Undefined,
MessageContent::Throttle); // Only throttle messages

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