|
TinyRobotics
|
Base class for message sources in the TinyRobotics communication framework. More...
#include <MessageSource.h>

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< MessageHandlerEntry > | messageHandlers_ |
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:
Extend this class to implement custom message-producing components (e.g., sensors, controllers) that need to broadcast messages to other system parts.
|
inline |
Publish a message to all registered handlers.
Forwards the given message to each handler in the messageHandlers_ list.
| msg | The message to publish. |
|
inline |
Publish a message to all registered handlers.
Forwards the given message to each handler in the messageHandlers_ list.
| msg | The message to publish. |
|
inline |
Publish a message to all registered handlers.
Forwards the given message to each handler in the messageHandlers_ list.
| msg | The message to publish. |
|
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.
| handler | Reference 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: