NCBI C++ ToolKit
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Attributes | Static Private Attributes | List of all members
CEventHandler Class Reference

Search Toolkit Book for CEventHandler

CEventHandler. More...

#include <gui/utils/event_handler.hpp>

+ Inheritance diagram for CEventHandler:
+ Collaboration diagram for CEventHandler:


class  CPostQueue
 CPostQueue - singleton queue for asynchronous events all methods are synchronized. More...
struct  SPostRequest

Public Types

enum  EDispatch { eDispatch_SelfOnly , eDispatch_AllHandlers , eDispatch_FirstHandler , eDispatch_Default = eDispatch_AllHandlers }
 enum controlling dispatching strategies More...
enum  EPoolName {
  ePool_Default = 0 , ePool_Parent , ePool_Child , ePool_Sibling ,
 Identifiers for standard pools. More...
typedef vector< CEventHandler * > TListeners
typedef map< int, TListenersTPools
typedef list< AutoPtr< SPostRequest > > TPostRequests
typedef std::map< CEventHandler *, intTHandlerToCount
typedef void(* FOnPostCallback) ()

Public Member Functions

 CEventHandler ()
 CEventHandler. More...
virtual ~CEventHandler ()
Event Dispatching Interface
virtual void AddListener (CEventHandler *listener, int pool_name=ePool_Default)
 Add a listener. More...
virtual void RemoveListener (CEventHandler *listener)
 Remove a listener. More...
virtual void RemoveAllListeners (void)
virtual bool HasListener (CEventHandler *listener, int pool_name=ePool_Default) const
 returns "true" if the given listener belongs to the specified pool More...
virtual const TListenersGetListeners (int pool_name=ePool_Default) const
 returns a set of listeners fro the specified pool More...
virtual bool OnEvent (CEvent *evt)
 Processes en event. Returns "true" if event has been processed. More...
virtual bool Dispatch (CEvent *evt, EDispatch disp_how=eDispatch_Default, int pool_name=ePool_Default)
 Dispatches an event to the listeners (but does not handle it). More...
virtual bool Send (CEvent *evt, EDispatch disp_how=eDispatch_Default, int pool_name=ePool_Default)
 Sends an event synchronously. More...
virtual bool Send (CEvent *evt, int pool_name)
void Post (CRef< CEvent > evt, EDispatch disp_how=eDispatch_Default, int pool_name=ePool_Default)
 Handles an event asynchronously (process and/or dispatch). More...

Static Public Member Functions

Static API

extracts the next request from the Post Queue and sends it to the target returns true if the Queue is empty

static bool HandlePostRequest ()
static void ClearPostQueue ()
 erases all events from the queue More...
static void DestroyPostQueue ()

Protected Member Functions

virtual const SEvtMapGetEventMap () const
void x_DeclareDead ()
 Removes itself unavailable for async event delivery. More...
void x_AddListenerToPool (CEventHandler *listener, int pool_name)

Protected Attributes

TPools m_Pools

Static Protected Attributes

static const SEvtMap sm_EvtMap

Private Attributes

CRef< CPostQueuem_Queue

Static Private Attributes

static const SEvtMapEntry sm_EvtMapEntries []

Detailed Description


CEventHandler provides basic support for event handling. Event handling includes processing events and dispatching events. Processing involves recognizing an event of the particular type and invoking a corresponding callback. CEventHandler provide support for mapping events to callback by means of Event Maps (see macros in this file). A class can define its own Event Map that can be inherited from the Event map of the base class. Dispatching is a process of forwarding an event to other CEventHandler-s subscribed as listeners to the current handler. Dispatching algorithm can be controlled by specifying a strategy (EDispatch enumeration). All events are dispatched within pools. Pools are isolated networks of listeners subscribed to each other. An event sent to a pool will reach only listeners added to this particular pool, all other listeners will be ignored. CEventHandler has several entry points: OnEvent() processes an event, locates a callback corresponding to it and executes the callback. Dispatch() dispatches an event to listeners. Send() synchronously handles events by calling OnEvent() and Dispatch(). Post() posts an event to the event queue. Events are retrieved from the queue by HandlePostRequest() and then sent to the handler.

Definition at line 135 of file event_handler.hpp.

The documentation for this class was generated from the following files:
Modified on Sun Jul 21 04:16:15 2024 by rev. 669887