Panda3D
|
A class to monitor events from the C++ side of things. More...
#include "eventHandler.h"
Public Types | |
typedef void | EventCallbackFunction (const Event *, void *) |
typedef void | EventFunction (const Event *) |
Public Member Functions | |
EventHandler (EventQueue *ev_queue) | |
bool | add_hook (const string &event_name, EventFunction *function) |
Adds the indicated function to the list of those that will be called when the named event is thrown. | |
bool | add_hook (const string &event_name, EventCallbackFunction *function, void *data) |
Adds the indicated function to the list of those that will be called when the named event is thrown. | |
virtual void | dispatch_event (const Event *) |
Calls the hooks assigned to the indicated single event. | |
virtual TypeHandle | force_init_type () |
virtual TypeHandle | get_type () const |
bool | has_hook (const string &event_name) const |
Returns true if there is any hook added on the indicated event name, false otherwise. | |
void | process_events () |
The main processing loop of the EventHandler. | |
void | remove_all_hooks () |
Removes all hooks assigned to all events. | |
bool | remove_hook (const string &event_name, EventFunction *function) |
Removes the indicated function from the named event hook. | |
bool | remove_hook (const string &event_name, EventCallbackFunction *function, void *data) |
Removes the indicated function from the named event hook. | |
bool | remove_hooks (const string &event_name) |
Removes all functions from the named event hook. | |
bool | remove_hooks_with (void *data) |
Removes all CallbackFunction hooks that have the indicated pointer as the associated data pointer. | |
void | write (ostream &out) const |
Static Public Member Functions | |
static TypeHandle | get_class_type () |
static EventHandler * | get_global_event_handler (EventQueue *queue=NULL) |
Returns a pointer to the one global EventHandler object. | |
static void | init_type () |
This function is declared non-inline to work around a compiler bug in g++ 2.96. | |
Protected Types | |
typedef pair < EventCallbackFunction *, void * > | CallbackFunction |
typedef pset< CallbackFunction > | CallbackFunctions |
typedef pmap< string, CallbackFunctions > | CallbackHooks |
typedef pset< EventFunction * > | Functions |
typedef pmap< string, Functions > | Hooks |
Static Protected Member Functions | |
static void | make_global_event_handler () |
Protected Attributes | |
CallbackHooks | _cbhooks |
Hooks | _hooks |
EventQueue & | _queue |
Static Protected Attributes | |
static EventHandler * | _global_event_handler = 0 |
A class to monitor events from the C++ side of things.
It maintains a set of "hooks", function pointers assigned to event names, and calls the appropriate hooks when the matching event is detected.
This class is not necessary when the hooks are detected and processed entirely by the scripting language, e.g. via Scheme hooks or the messenger in Python.
Definition at line 41 of file eventHandler.h.
bool EventHandler::add_hook | ( | const string & | event_name, |
EventFunction * | function | ||
) |
Adds the indicated function to the list of those that will be called when the named event is thrown.
Returns true if the function was successfully added, false if it was already defined on the indicated event name.
Definition at line 147 of file eventHandler.cxx.
Referenced by PandaFramework::define_key(), and PandaFramework::open_framework().
bool EventHandler::add_hook | ( | const string & | event_name, |
EventCallbackFunction * | function, | ||
void * | data | ||
) |
Adds the indicated function to the list of those that will be called when the named event is thrown.
Returns true if the function was successfully added, false if it was already defined on the indicated event name. This version records an untyped pointer to user callback data.
Definition at line 170 of file eventHandler.cxx.
void EventHandler::dispatch_event | ( | const Event * | event | ) | [virtual] |
Calls the hooks assigned to the indicated single event.
Definition at line 55 of file eventHandler.cxx.
Referenced by process_events().
EventHandler * EventHandler::get_global_event_handler | ( | EventQueue * | queue = NULL | ) | [inline, static] |
Returns a pointer to the one global EventHandler object.
If the global object has not yet been created, this will create it.
Definition at line 24 of file eventHandler.I.
bool EventHandler::has_hook | ( | const string & | event_name | ) | const |
Returns true if there is any hook added on the indicated event name, false otherwise.
Definition at line 184 of file eventHandler.cxx.
Referenced by PandaFramework::define_key().
static void EventHandler::init_type | ( | ) | [inline, static] |
This function is declared non-inline to work around a compiler bug in g++ 2.96.
Making it inline seems to cause problems in the optimizer.
Reimplemented from TypedObject.
Definition at line 96 of file eventHandler.h.
References TypedObject::init_type().
void EventHandler::process_events | ( | ) |
The main processing loop of the EventHandler.
This function must be called periodically to service events. Walks through each pending event and calls its assigned hooks.
Definition at line 42 of file eventHandler.cxx.
References dispatch_event().
void EventHandler::remove_all_hooks | ( | ) |
Removes all hooks assigned to all events.
Definition at line 304 of file eventHandler.cxx.
Referenced by PandaFramework::close_framework().
bool EventHandler::remove_hook | ( | const string & | event_name, |
EventFunction * | function | ||
) |
Removes the indicated function from the named event hook.
Returns true if the hook was removed, false if it wasn't there in the first place.
Definition at line 214 of file eventHandler.cxx.
bool EventHandler::remove_hook | ( | const string & | event_name, |
EventCallbackFunction * | function, | ||
void * | data | ||
) |
Removes the indicated function from the named event hook.
Returns true if the hook was removed, false if it wasn't there in the first place. This version takes an untyped pointer to user callback data.
Definition at line 230 of file eventHandler.cxx.
bool EventHandler::remove_hooks | ( | const string & | event_name | ) |
Removes all functions from the named event hook.
Returns true if any functions were removed, false if there were no functions added to the hook.
Definition at line 245 of file eventHandler.cxx.
bool EventHandler::remove_hooks_with | ( | void * | data | ) |
Removes all CallbackFunction hooks that have the indicated pointer as the associated data pointer.
Definition at line 275 of file eventHandler.cxx.