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 &&obj) | |
Move Constructor. More... | |
virtual | ~EventDispatcher () |
Default Destructor. More... | |
void | addEventListener (int type, Listener listener, void *addiction=nullptr) |
Register an event listener. More... | |
void | removeEventListener (int type, Listener listener, void *addiction=nullptr) |
Remove a registered event listener. More... | |
void | dispatch (std::shared_ptr< Event > event) |
Dispatches an event to all listeners. More... | |
Static Public Member Functions | |
static size_t & | THREAD_SIZE () |
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 50 of file EventDispatcher.hpp.
|
inline |
Default Constructor.
Definition at line 74 of file EventDispatcher.hpp.
|
inline |
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 87 of file EventDispatcher.hpp.
|
inline |
Move Constructor.
eventDispatcher | The object to move |
Definition at line 97 of file EventDispatcher.hpp.
References samchon::library::UniqueWriteLock::unlock().
|
inlinevirtual |
Default Destructor.
Definition at line 120 of file EventDispatcher.hpp.
|
inline |
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 154 of file EventDispatcher.hpp.
|
inline |
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 172 of file EventDispatcher.hpp.
|
inline |
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 205 of file EventDispatcher.hpp.
References THREAD_SIZE(), and samchon::library::UniqueReadLock::unlock().
|
inlinestatic |
Numer of threads for background.
Definition at line 317 of file EventDispatcher.hpp.
Referenced by dispatch().
|
private |
A container storing listeners.
Definition at line 60 of file EventDispatcher.hpp.
|
private |
A rw_mutex for concurrency.
Definition at line 65 of file EventDispatcher.hpp.