Samchon Framework for CPP
1.0.0
|
Abstract class for dispatching Event. More...
#include <EventDispatcher.hpp>
Public Member Functions | |
EventDispatcher () | |
Default Constructor. More... | |
EventDispatcher (const EventDispatcher &) | |
Copy Constructor. More... | |
EventDispatcher (EventDispatcher &&) | |
Move Constructor. More... | |
virtual | ~EventDispatcher () |
Default Destructor. More... | |
void | addEventListener (int, Listener, void *=nullptr) |
Register an event listener. More... | |
void | removeEventListener (int, Listener, void *=nullptr) |
Remove a registered event listener. More... | |
void | dispatch (std::shared_ptr< Event >) |
Dispatches an event to all listeners. More... | |
Static Public Attributes | |
static size_t | THREAD_SIZE = 2 |
Numer of threads for background. More... | |
Private Attributes | |
std::unordered_map< int, std::unordered_map< Listener, std::unordered_set< void * > > > | listeners |
A container storing listeners. More... | |
RWMutex | mtx |
A rw_mutex for concurrency. More... | |
Abstract class for dispatching Event.
EventDispatcher is the base class for all classes that dispatch events.
All the events are sent asynchronously. To avoid from creating tooo enourmouse threads dispatching events, all event sending processes will acuiqre a semaphore. The default permitted size of the semaphore is 2.
EventDispatcher is a candidate to be deprecated.
Since C++11, calling member method of a class by a new thread passing by static method and using void pointer are recommeded to avoid. As the reason, using std::thread and std::bind will be better.
Definition at line 51 of file EventDispatcher.hpp.
EventDispatcher::EventDispatcher | ( | ) |
Default Constructor.
Definition at line 12 of file EventDispatcher.cpp.
EventDispatcher::EventDispatcher | ( | const EventDispatcher & | obj | ) |
Copy Constructor.
Copying an EventDispatcher instance does not copy the event listeners attached to it. (If your newly created node needs an event listener, you must attach the listener after creating the node.)
eventDispatcher | The object to copy |
Definition at line 15 of file EventDispatcher.cpp.
EventDispatcher::EventDispatcher | ( | EventDispatcher && | obj | ) |
Move Constructor.
eventDispatcher | The object to move |
Definition at line 19 of file EventDispatcher.cpp.
References samchon::library::UniqueWriteLock::unlock().
|
virtual |
Default Destructor.
Definition at line 39 of file EventDispatcher.cpp.
void EventDispatcher::addEventListener | ( | int | type, |
Listener | listener, | ||
void * | addiction = nullptr |
||
) |
Register an event listener.
Registers an event listener object with an EventDispatcher object so that the listener receives notification of an event.
type | The type of event. |
listener | The listener function processes the event. |
addiction | Something to be addicted following the listener. |
Definition at line 54 of file EventDispatcher.cpp.
void EventDispatcher::removeEventListener | ( | int | type, |
Listener | listener, | ||
void * | addiction = nullptr |
||
) |
Remove a registered event listener.
Removes a listener from the EventDispatcher object. If there is no matching listener registered with the EventDispatcher object, a call to this method has no effect
type | The type of event. |
listener | The listener function to remove. |
addiction | Somethhing to be addicted following the listener. |
Definition at line 60 of file EventDispatcher.cpp.
void EventDispatcher::dispatch | ( | std::shared_ptr< Event > | event | ) |
Dispatches an event to all listeners.
Dispatches an event into the event flow in the background. The Event::source is the EventDispatcher object upon which the dispatchEvent.
event | The Event object that is dispatched into the event flow. |
Definition at line 83 of file EventDispatcher.cpp.
References samchon::library::UniqueReadLock::unlock().
|
private |
A container storing listeners.
Definition at line 61 of file EventDispatcher.hpp.
|
private |
A rw_mutex for concurrency.
Definition at line 66 of file EventDispatcher.hpp.
|
static |
Numer of threads for background.
Definition at line 168 of file EventDispatcher.hpp.