Uniot Core
0.8.1
Loading...
Searching...
No Matches
uniot::EventEntity< T_topic, T_msg, T_data > Class Template Reference

Entity that can connect to and interact with EventBus instances. More...

#include <EventEntity.h>

Inheritance diagram for uniot::EventEntity< T_topic, T_msg, T_data >:
[legend]

Public Types

using DataChannelCallback = std::function<void(unsigned int, bool, T_data)>
 Callback type for handling data received from channels.
 

Public Member Functions

virtual ~EventEntity ()
 Destructor - disconnects from all connected EventBus instances.
 
virtual type_id getTypeId () const override
 Returns the type ID of this class.
 
bool sendDataToChannel (T_topic channel, T_data data)
 Sends data to a specific channel on all connected EventBus instances.
 
void receiveDataFromChannel (T_topic channel, DataChannelCallback callback)
 Receives data from a specific channel on all connected EventBus instances.
 

Protected Member Functions

bool connectUnique (EventBus< T_topic, T_msg, T_data > *eventBus)
 Connects to an EventBus instance if not already connected.
 

Protected Attributes

IterableQueue< EventBus< T_topic, T_msg, T_data > * > mEventBusQueue
 Queue of EventBus instances this entity is connected to.
 

Friends

class EventBus< T_topic, T_msg, T_data >
 

Detailed Description

template<class T_topic, class T_msg, class T_data>
class uniot::EventEntity< T_topic, T_msg, T_data >

Entity that can connect to and interact with EventBus instances.

EventEntity serves as a base class for components that need to communicate through the event system. It can connect to multiple EventBus instances and provides methods for sending and receiving data through channels.

Template Parameters
T_topicType used for channel identification (typically unsigned int)
T_msgType used for message identification (typically int)
T_dataType of data being transmitted through channels (typically Bytes)

Member Typedef Documentation

◆ DataChannelCallback

template<class T_topic, class T_msg, class T_data>
using uniot::EventEntity< T_topic, T_msg, T_data >::DataChannelCallback = std::function<void(unsigned int, bool, T_data)>

Callback type for handling data received from channels.

Parameters
unsignedint EventBus ID
boolWhether the channel was empty before receiving
T_dataThe data received from the channel

Constructor & Destructor Documentation

◆ ~EventEntity()

template<class T_topic, class T_msg, class T_data>
uniot::EventEntity< T_topic, T_msg, T_data >::~EventEntity ( )
virtual

Destructor - disconnects from all connected EventBus instances.

Removes this entity from all connected EventBus instances to prevent dangling references and ensure proper cleanup.

Member Function Documentation

◆ connectUnique()

template<class T_topic, class T_msg, class T_data>
bool uniot::EventEntity< T_topic, T_msg, T_data >::connectUnique ( EventBus< T_topic, T_msg, T_data > * eventBus)
inlineprotected

Connects to an EventBus instance if not already connected.

Checks if the EventBus with the same ID is already connected. If not, adds it to the queue of connected EventBus instances.

Parameters
eventBusPointer to the EventBus to connect to
Return values
trueConnection was successful
falseConnection failed (e.g., EventBus already connected)

◆ getTypeId()

template<class T_topic, class T_msg, class T_data>
virtual type_id uniot::EventEntity< T_topic, T_msg, T_data >::getTypeId ( ) const
inlineoverridevirtual

◆ receiveDataFromChannel()

template<class T_topic, class T_msg, class T_data>
void uniot::EventEntity< T_topic, T_msg, T_data >::receiveDataFromChannel ( T_topic channel,
DataChannelCallback callback )
inline

Receives data from a specific channel on all connected EventBus instances.

Iterates through all connected EventBus instances and retrieves data from the specified channel on each, invoking the callback for each data item.

Parameters
channelThe channel to receive data from
callbackFunction to be called for each data item received

◆ sendDataToChannel()

template<class T_topic, class T_msg, class T_data>
bool uniot::EventEntity< T_topic, T_msg, T_data >::sendDataToChannel ( T_topic channel,
T_data data )
inline

Sends data to a specific channel on all connected EventBus instances.

Iterates through all connected EventBus instances and attempts to send the provided data to the specified channel on each.

Parameters
channelThe channel to send data to
dataThe data to be sent
Return values
trueData was successfully sent to at least one EventBus
falseNo EventBus was able to send the data (e.g., all channels were full)

Friends And Related Symbol Documentation

◆ EventBus< T_topic, T_msg, T_data >

template<class T_topic, class T_msg, class T_data>
friend class EventBus< T_topic, T_msg, T_data >
friend

Member Data Documentation

◆ mEventBusQueue

template<class T_topic, class T_msg, class T_data>
IterableQueue<EventBus<T_topic, T_msg, T_data> *> uniot::EventEntity< T_topic, T_msg, T_data >::mEventBusQueue
protected

Queue of EventBus instances this entity is connected to.

This instantiation creates a concrete class for the most commonly used template parameters: unsigned int for topics, int for messages, and Bytes for data.


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