Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

EventHandler Class Reference

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

#include <eventHandler.h>

Inheritance diagram for EventHandler:

TypedObject List of all members.

Public Types

typedef void EventFunction (CPT_Event)
typedef void EventCallbackFunction (ConstPointerTo< Event >, void *)

Public Member Functions

 EventHandler (EventQueue *queue)
void process_events ()
 The main processing loop of the EventHandler.

virtual void dispatch_event (const CPT_Event &event)
 Calls the hooks assigned to the indicated single event.

void write (ostream &out) const
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 *)
 Adds the indicated function to the list of those that will be called when the named event is thrown.

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 *)
 Removes the indicated function from the named event hook.

void remove_all_hooks ()
 Removes all hooks assigned to all events.

virtual TypeHandle get_type () const
virtual TypeHandle force_init_type ()
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_of_type (TypeHandle handle) const
 Returns true if the current object is or derives from the indicated type.

bool is_exact_type (TypeHandle handle) const
 Returns true if the current object is the indicated type exactly.


Static Public Member Functions

TypeHandle get_class_type ()
void init_type ()
 This function is declared non-inline to work around a compiler bug in g++ 2.96.


Protected Types

typedef pset< EventFunction * > Functions
typedef pmap< string, FunctionsHooks
typedef pair< EventCallbackFunction *,
void * > 
CallbackFunction
typedef pset< CallbackFunctionCallbackFunctions
typedef pmap< string, CallbackFunctionsCallbackHooks

Protected Attributes

Hooks _hooks
CallbackHooks _cbhooks
EventQueue_queue

Private Member Functions

void write_hook (ostream &out, const Hooks::value_type &hook) const
void write_cbhook (ostream &out, const CallbackHooks::value_type &hook) const

Static Private Attributes

TypeHandle _type_handle

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.

Definition at line 58 of file eventHandler.h.


Member Typedef Documentation

typedef pair<EventCallbackFunction*, void*> EventHandler::CallbackFunction [protected]
 

Definition at line 87 of file eventHandler.h.

typedef pset<CallbackFunction> EventHandler::CallbackFunctions [protected]
 

Definition at line 88 of file eventHandler.h.

typedef pmap<string, CallbackFunctions> EventHandler::CallbackHooks [protected]
 

Definition at line 89 of file eventHandler.h.

typedef void EventHandler::EventCallbackFunction(ConstPointerTo< Event >, void*)
 

Definition at line 62 of file eventHandler.h.

typedef void EventHandler::EventFunction(CPT_Event)
 

Definition at line 61 of file eventHandler.h.

typedef pset<EventFunction *> EventHandler::Functions [protected]
 

Definition at line 85 of file eventHandler.h.

typedef pmap<string, Functions> EventHandler::Hooks [protected]
 

Definition at line 86 of file eventHandler.h.


Constructor & Destructor Documentation

EventHandler::EventHandler EventQueue queue  ) 
 

Definition at line 36 of file eventHandler.cxx.

References _queue, EventQueue::dequeue_event(), dispatch_event(), and EventQueue::is_queue_empty().


Member Function Documentation

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

References _cbhooks, and _hooks.

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

References _hooks.

Referenced by event_la(), and AutonomousLerp::stop().

void EventHandler::dispatch_event const CPT_Event event  )  [virtual]
 

Calls the hooks assigned to the indicated single event.

Definition at line 71 of file eventHandler.cxx.

Referenced by EventHandler(), and throw_event_directly().

virtual TypeHandle EventHandler::force_init_type void   )  [inline, virtual]
 

Implements TypedObject.

Definition at line 112 of file eventHandler.h.

TypeHandle EventHandler::get_class_type void   )  [inline, static]
 

Reimplemented from TypedObject.

Definition at line 101 of file eventHandler.h.

virtual TypeHandle EventHandler::get_type void   )  const [inline, virtual]
 

Implements TypedObject.

Definition at line 109 of file eventHandler.h.

int TypedObject::get_type_index  )  const [inline, inherited]
 

Returns the internal index number associated with this object's TypeHandle, a unique number for each different type.

This is equivalent to get_type().get_index().

Definition at line 71 of file typedObject.I.

References TypeHandle::get_name(), TypedObject::get_type(), and INLINE.

void EventHandler::init_type void   )  [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 104 of file eventHandler.h.

bool TypedObject::is_exact_type TypeHandle  handle  )  const [inline, inherited]
 

Returns true if the current object is the indicated type exactly.

Definition at line 101 of file typedObject.I.

Referenced by PT(), and CollisionNode::xform().

bool TypedObject::is_of_type TypeHandle  handle  )  const [inline, inherited]
 

Returns true if the current object is or derives from the indicated type.

Definition at line 86 of file typedObject.I.

Referenced by EggMaterialCollection::collapse_equivalent_materials(), EggTextureCollection::collapse_equivalent_textures(), DeferredNodeProperty::compose(), AnimBundleMaker::create_s_channel(), CharacterMaker::create_slider(), ProjectionScreen::cull_callback(), DataNode::define_output(), EggNode::determine_draw_order(), CharacterMaker::egg_to_index(), EggGroupUniquifier::EggGroupUniquifier(), EggPoolUniquifier::EggPoolUniquifier(), EggGroupNode::find_textures(), StaticTextFont::get_glyph(), EggMaterialCollection::insert_materials(), EggTextureCollection::insert_textures(), CharacterJoint::make_copy(), PT(), EggGroupNode::r_flatten_transforms(), EggGroupNode::r_transform_vertices(), EggGroupNode::recompute_polygon_normals(), CollisionLevelState::reserve(), PandaFramework::reset_frame_rate(), PandaFramework::set_texture(), EggGroupNode::steal_children(), and DataGraphTraverser::traverse().

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

References _hooks.

void EventHandler::remove_all_hooks  ) 
 

Removes all hooks assigned to all events.

Definition at line 251 of file eventHandler.cxx.

Referenced by PandaFramework::open_framework().

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

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

void EventHandler::write ostream &  out  )  const
 

Definition at line 116 of file eventHandler.cxx.

void EventHandler::write_cbhook ostream &  out,
const CallbackHooks::value_type &  hook
const [private]
 

Definition at line 279 of file eventHandler.cxx.

void EventHandler::write_hook ostream &  out,
const Hooks::value_type &  hook
const [private]
 

Definition at line 265 of file eventHandler.cxx.


Member Data Documentation

CallbackHooks EventHandler::_cbhooks [protected]
 

Definition at line 92 of file eventHandler.h.

Referenced by add_hook().

Hooks EventHandler::_hooks [protected]
 

Definition at line 91 of file eventHandler.h.

Referenced by add_hook(), and process_events().

EventQueue& EventHandler::_queue [protected]
 

Definition at line 93 of file eventHandler.h.

Referenced by EventHandler().

TypeHandle EventHandler::_type_handle [static, private]
 

Reimplemented from TypedObject.

Definition at line 26 of file eventHandler.cxx.


The documentation for this class was generated from the following files:
Generated on Fri May 2 00:50:34 2003 for Panda by doxygen1.3