|
sdi_toolBox
|
#include <node.h>


Concrete subscriber node in the event bus system.
Node is the concrete implementation of INode. It represents a participant in the event bus that can subscribe to specific message types or to broadcast mode, emit and post messages through the bus, and consume received messages from its internal FIFO queue.
Each Node holds a reference to the Bus it belongs to. Subscriptions and message transmissions are delegated to the bus. Incoming messages are stored in an internal thread-safe queue and can be retrieved via popMessage().
The Node also supports synchronous waiting: a thread can block on syncWaitForMessage() until at least one message is available in the queue.
On destruction, the Node automatically unsubscribes from all event types and broadcast mode, preventing dangling pointers in the bus routing table.
Public Member Functions | |
Construction & Destruction | |
| Node ()=delete | |
| Default constructor - deleted. A Bus reference must be provided. | |
| virtual | ~Node () |
| Destructor. | |
| Node (const Node &obj)=delete | |
| Copy constructor - deleted. | |
| Node (Node &&obj) noexcept=delete | |
| Move constructor - deleted. | |
| Node & | operator= (const Node &obj)=delete |
| Copy assignment operator - deleted. | |
| Node & | operator= (Node &&obj) noexcept=delete |
| Move assignment operator - deleted. | |
| Node (Bus &bus) | |
| Construct a Node attached to the given Bus. | |
Synchronization | |
| void | syncWaitForMessage () |
| Block the calling thread until a message is received. | |
Subscription Management | |
| void | subscribe (MessageTypeID eventType) |
| Subscribe this node to a specific message type. | |
| void | unsubscribe (MessageTypeID eventType) |
| Unsubscribe this node from a specific message type. | |
| void | unsubscribeFromAll () |
| Unsubscribe this node from all message types and broadcast mode. | |
Message Transmission | |
| template<class T , class... Args> | |
| bool | emit (Args &&...args) |
Construct and emit a message of type T through the bus. | |
| bool | post (const std::shared_ptr< Message > &message) const |
| Post an already constructed message through the bus. | |
Message queue management | |
| size_t | getMessageCount () const |
| Get the number of messages currently in the node's queue. | |
| std::shared_ptr< Message > | popMessage () |
| Remove and return the front message from the node's queue (FIFO). | |
Public Member Functions inherited from INode | |
| INode ()=default | |
| Default constructor. | |
| virtual | ~INode ()=default |
| Default destructor. | |
| INode (const INode &obj)=delete | |
| Copy constructor - deleted. | |
| INode (INode &&obj) noexcept=delete | |
| Move constructor - deleted. | |
| INode & | operator= (const INode &obj)=delete |
| Copy assignment operator - deleted. | |
| INode & | operator= (INode &&obj) noexcept=delete |
| Move assignment operator - deleted. | |
Private Member Functions | |
| void | append (const std::shared_ptr< Message > &message) override |
| Append a message to the node's internal queue. | |
|
inlinevirtual |
Destructor.
Automatically unsubscribes the node from all specific event types and broadcast mode via unsubscribeFromAll(), preventing dangling pointers in the bus routing table. Also notifies any thread blocked in syncWaitForMessage() to unblock it gracefully.
Copy assignment operator - deleted.
Node is non-copyable.
Move assignment operator - deleted.
Node is non-movable.
|
inline |
Block the calling thread until a message is received.
Suspends the calling thread using an atomic wait until at least one message has been appended to the node's internal queue by the Bus. This method is intended for synchronous event-driven patterns where a thread should idle until work is available.
|
inline |
Subscribe this node to a specific message type.
Delegates to Bus::subscribe(). The node will receive all messages of the given type posted to the bus. Duplicate subscriptions are ignored.
| eventType | The message type identifier to subscribe to. |
|
inline |
Unsubscribe this node from a specific message type.
Delegates to Bus::unsubscribe(). If the node was not subscribed to the given type, this call has no effect.
| eventType | The message type identifier to unsubscribe from. |
|
inline |
Unsubscribe this node from all message types and broadcast mode.
Delegates to Bus::unsubscribeFromAll(). After this call, the node will no longer receive any messages until it re-subscribes.
| bool emit | ( | Args &&... | args | ) |
Construct and emit a message of type T through the bus.
Forwards the call to Bus::emit(). Creates a new message of type T using the provided arguments and posts it to the bus.
| T | The message type to emit. Must be derived from Message. |
| Args | Constructor argument types for T. |
| args | Arguments forwarded to the constructor of T. |
true if at least one subscriber received the message, false otherwise.
|
inline |
Post an already constructed message through the bus.
Forwards the call to Bus::post().
| message | Shared pointer to the message to post. Must not be nullptr. |
true if at least one subscriber received the message, false otherwise.
|
inline |
|
inline |
Remove and return the front message from the node's queue (FIFO).
Retrieves the oldest message in the queue and removes it. If the queue is empty, returns nullptr.
nullptr if the queue is empty.
|
inlineoverrideprivatevirtual |
Append a message to the node's internal queue.
Called exclusively by Bus when dispatching a message to this node. Pushes the message onto the queue and notifies any thread waiting in syncWaitForMessage().
| message | Shared pointer to the message being delivered. |
Implements INode.
|
mutable |