Panda3D
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | List of all members
EventHandler Class Reference

A class to monitor events from the C++ side of things. More...

#include "eventHandler.h"

Inheritance diagram for EventHandler:
TypedObject MemoryBase

Public Types

typedef void EventCallbackFunction(const Event *, void *)
 
typedef void EventFunction(const Event *)
 

Public Member Functions

 EventHandler (EventQueue *ev_queue)
 
bool add_hook (const std::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.
 
bool add_hook (const std::string &event_name, EventFunction *function)
 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 *event)
 Calls the hooks assigned to the indicated single event.
 
virtual TypeHandle force_init_type ()
 
AsyncFutureget_future (const std::string &event_name)
 Returns a pending future that will be marked as done when the event is next fired.
 
virtual TypeHandle get_type () const
 
bool has_hook (const std::string &event_name) const
 Returns true if there is any hook added on the indicated event name, false otherwise.
 
bool has_hook (const std::string &event_name, EventCallbackFunction *function, void *data) const
 Returns true if there is the hook added on the indicated event name, function pointer and callback data, false otherwise.
 
bool has_hook (const std::string &event_name, EventFunction *function) const
 Returns true if there is the hook added on the indicated event name and function pointer, 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 std::string &event_name, EventCallbackFunction *function, void *data)
 Removes the indicated function from the named event hook.
 
bool remove_hook (const std::string &event_name, EventFunction *function)
 Removes the indicated function from the named event hook.
 
bool remove_hooks (const std::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 (std::ostream &out) const
 
- Public Member Functions inherited from TypedObject
 TypedObject (const TypedObject &copy)=default
 
TypedObjectas_typed_object ()
 Returns the object, upcast (if necessary) to a TypedObject pointer.
 
const TypedObjectas_typed_object () const
 Returns the object, upcast (if necessary) to a TypedObject pointer.
 
int get_best_parent_from_Set (const std::set< int > &) const
 
int get_type_index () const
 Returns the internal index number associated with this object's TypeHandle, a unique number for each different type.
 
bool is_exact_type (TypeHandle handle) const
 Returns true if the current object is the indicated type exactly.
 
bool is_of_type (TypeHandle handle) const
 Returns true if the current object is or derives from the indicated type.
 
TypedObjectoperator= (const TypedObject &copy)=default
 
- Public Member Functions inherited from MemoryBase
void operator delete (void *, void *)
 
void operator delete (void *ptr)
 
void operator delete[] (void *, void *)
 
void operator delete[] (void *ptr)
 
void * operator new (size_t size)
 
void * operator new (size_t size, void *ptr)
 
void * operator new[] (size_t size)
 
void * operator new[] (size_t size, void *ptr)
 

Static Public Member Functions

static TypeHandle get_class_type ()
 
static EventHandlerget_global_event_handler (EventQueue *queue=nullptr)
 Returns a pointer to the one global EventHandler object.
 
static void init_type ()
 
- Static Public Member Functions inherited from TypedObject
static TypeHandle get_class_type ()
 
static void init_type ()
 This function is declared non-inline to work around a compiler bug in g++ 2.96.
 

Additional Inherited Members

- Public Attributes inherited from TypedObject
 get_type
 

Detailed Description

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 37 of file eventHandler.h.

Member Typedef Documentation

◆ EventCallbackFunction

typedef void EventHandler::EventCallbackFunction(const Event *, void *)

Definition at line 41 of file eventHandler.h.

◆ EventFunction

typedef void EventHandler::EventFunction(const Event *)

Definition at line 40 of file eventHandler.h.

Constructor & Destructor Documentation

◆ EventHandler()

EventHandler::EventHandler ( EventQueue * ev_queue)
explicit

Definition at line 28 of file eventHandler.cxx.

◆ ~EventHandler()

EventHandler::~EventHandler ( )
inline

Definition at line 45 of file eventHandler.h.

Member Function Documentation

◆ add_hook() [1/2]

bool EventHandler::add_hook ( const std::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 184 of file eventHandler.cxx.

◆ add_hook() [2/2]

bool EventHandler::add_hook ( const std::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 165 of file eventHandler.cxx.

Referenced by PandaFramework::define_key(), and PandaFramework::open_framework().

◆ dispatch_event()

void EventHandler::dispatch_event ( const Event * event)
virtual

Calls the hooks assigned to the indicated single event.

Definition at line 67 of file eventHandler.cxx.

References AsyncFuture::done(), and AsyncFuture::set_result().

Referenced by process_events().

◆ force_init_type()

virtual TypeHandle EventHandler::force_init_type ( )
inlinevirtual

Implements TypedObject.

Definition at line 108 of file eventHandler.h.

◆ get_class_type()

static TypeHandle EventHandler::get_class_type ( )
inlinestatic

Definition at line 97 of file eventHandler.h.

◆ get_future()

AsyncFuture * EventHandler::get_future ( const std::string & event_name)

Returns a pending future that will be marked as done when the event is next fired.

Definition at line 36 of file eventHandler.cxx.

◆ get_global_event_handler()

EventHandler * EventHandler::get_global_event_handler ( EventQueue * queue = nullptr)
inlinestatic

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 18 of file eventHandler.I.

◆ get_type()

virtual TypeHandle EventHandler::get_type ( ) const
inlinevirtual

Implements TypedObject.

Definition at line 105 of file eventHandler.h.

◆ has_hook() [1/3]

bool EventHandler::has_hook ( const std::string & event_name) const

Returns true if there is any hook added on the indicated event name, false otherwise.

Definition at line 196 of file eventHandler.cxx.

Referenced by PandaFramework::define_key().

◆ has_hook() [2/3]

bool EventHandler::has_hook ( const std::string & event_name,
EventCallbackFunction * function,
void * data ) const

Returns true if there is the hook added on the indicated event name, function pointer and callback data, false otherwise.

Definition at line 243 of file eventHandler.cxx.

◆ has_hook() [3/3]

bool EventHandler::has_hook ( const std::string & event_name,
EventFunction * function ) const

Returns true if there is the hook added on the indicated event name and function pointer, false otherwise.

Definition at line 223 of file eventHandler.cxx.

◆ init_type()

static void EventHandler::init_type ( )
inlinestatic

Definition at line 100 of file eventHandler.h.

◆ process_events()

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 57 of file eventHandler.cxx.

References dispatch_event().

Referenced by PandaFramework::task_event().

◆ remove_all_hooks()

void EventHandler::remove_all_hooks ( )

Removes all hooks assigned to all events.

Definition at line 343 of file eventHandler.cxx.

Referenced by PandaFramework::close_framework().

◆ remove_hook() [1/2]

bool EventHandler::remove_hook ( const std::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 276 of file eventHandler.cxx.

◆ remove_hook() [2/2]

bool EventHandler::remove_hook ( const std::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 263 of file eventHandler.cxx.

◆ remove_hooks()

bool EventHandler::remove_hooks ( const std::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 288 of file eventHandler.cxx.

◆ remove_hooks_with()

bool EventHandler::remove_hooks_with ( void * data)

Removes all CallbackFunction hooks that have the indicated pointer as the associated data pointer.

Definition at line 316 of file eventHandler.cxx.

◆ write()

void EventHandler::write ( std::ostream & out) const

Definition at line 124 of file eventHandler.cxx.


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