Public Member Functions | |
EventChannel (EventManager *manager, const std::string &name) | |
Create a new instance of the communication channel. | |
virtual | ~EventChannel () |
Releas eused memory and destroy hte instance. | |
Result | add (EventActor *actor, bool notice=true) |
Result | del (EventActor *actor, bool notice=true) |
NR_FORCEINLINE const std::string & | getName () const |
void | emit (SharedPtr< Event > event) |
void | push (SharedPtr< Event > event) |
void | deliver () |
Protected Types | |
typedef std::map< std::string, EventActor * > | ActorDatabase |
Store here the mapping between actor names and their connections. | |
typedef std::priority_queue< SharedPtr< Event >, std::vector< SharedPtr< Event > >, GreatEvent< SharedPtr< Event > > > | EventQueue |
We store our event messages in a priority queue. | |
Protected Member Functions | |
bool | isConnected (const std::string &name) |
Check whenever a given actor is already connected. | |
void | _disconnectAll () |
Disconnect all actors from the channel. | |
Protected Attributes | |
std::string | mName |
Unique name of the communication channel. | |
EventManager * | mParentManager |
We always does store a pointer to the event manager where this channel belongs to. | |
ActorDatabase | mActorDb |
Connected actor database. | |
EventQueue | mEventQueue |
Store the event messages in this variable. | |
Friends | |
class | EventManager |
The event manager system is a friend to this class. | |
Data Structures | |
struct | GreatEvent |
Definition at line 52 of file EventChannel.h.
Result nrEngine::EventChannel::add | ( | EventActor * | actor, | |
bool | notice = true | |||
) |
Connect a new actor to the channel. The actor will be connected so it get noticed about any communication on the channel.
The actor has to implement default event reactions needed for our channel communication system. Compilation error will occur if the reactions to the default events are not implemented.
actor | An actor to connect to the channel | |
notice | Should channel let notice the actor that he is connected now (default YES) |
Definition at line 34 of file EventChannel.cpp.
References nrEngine::EventActor::_noticeConnected(), nrEngine::EVENT_ALREADY_CONNECTED, nrEngine::EVENT_NO_VALID_ACTOR, getName(), nrEngine::EventActor::getName(), isConnected(), nrEngine::Log::LL_DEBUG, nrEngine::Log::LL_ERROR, nrEngine::Log::LOG_ENGINE, mActorDb, and nrEngine::OK.
Result nrEngine::EventChannel::del | ( | EventActor * | actor, | |
bool | notice = true | |||
) |
Disconnect an actor from the channel. It is a good coding style if you call this function, when you do not need the connection anymore. However our engine does provide you the possibility to forget about disconnecting the actors from the channel, because the lifetime of an actor will be tracked. If the object does not exists anymore, so it will be automaticaly disconnected.
If you want to be performant, so remove actors from the channels, if they do not need the connection anymore.
actor | An actor already connected to the channel | |
notice | Should channel notice the actor, about disconnection (default YES) |
Definition at line 60 of file EventChannel.cpp.
References nrEngine::EventActor::_noticeDisconnected(), nrEngine::EVENT_NOT_CONNECTED, getName(), nrEngine::EventActor::getName(), isConnected(), nrEngine::Log::LL_DEBUG, nrEngine::Log::LOG_ENGINE, mActorDb, and nrEngine::OK.
NR_FORCEINLINE const std::string& nrEngine::EventChannel::getName | ( | ) | const |
Get the name of the channel
Definition at line 93 of file EventChannel.h.
Referenced by _disconnectAll(), nrEngine::EventActor::_noticeConnected(), nrEngine::EventActor::_noticeDisconnected(), add(), and del().
void nrEngine::EventChannel::emit | ( | SharedPtr< Event > | event | ) |
Emit a certain event to a channel. This will send this event to all connected actors, so they get noticed about new event.
event | Smart pointer to an event object |
Definition at line 105 of file EventChannel.cpp.
References mActorDb.
void nrEngine::EventChannel::push | ( | SharedPtr< Event > | event | ) |
Instead of emit() this will not send the message directly to the channel listeners, but it store the message first in a queue based on priority numbers of the events. When you call deliver(), then all messages are getting delivered to the channel listeners
event | Smart pointer to the event message |
Definition at line 115 of file EventChannel.cpp.
References emit(), nrEngine::CPriority::IMMEDIATE, and mEventQueue.
void nrEngine::EventChannel::deliver | ( | ) |
Deliver all stored event messages from the queue to the actors connected to the channel.
Definition at line 127 of file EventChannel.cpp.
References emit(), and mEventQueue.