Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __CS_CSEVENTQ_H__
00023 #define __CS_CSEVENTQ_H__
00024
00025 #ifdef ADB_DEBUG
00026 #include <iostream>
00027 #endif
00028
00033 #include "csextern.h"
00034
00035 #include "csutil/array.h"
00036 #include "csutil/hash.h"
00037 #include "csutil/ref.h"
00038 #include "csutil/refarr.h"
00039 #include "csutil/scf_implementation.h"
00040 #include "csutil/threading/rwmutex.h"
00041 #include "csutil/weakref.h"
00042 #include "csutil/eventhandlers.h"
00043 #include "iutil/eventh.h"
00044 #include "iutil/eventq.h"
00045 #include "cssubscription.h"
00046
00047 struct iObjectRegistry;
00048
00049 class csEventCord;
00050 class csEventOutlet;
00051 class csPoolEvent;
00052
00057 #define DEF_EVENT_QUEUE_LENGTH 256
00058
00059 template<>
00060 class csHashComputer<iEventHandler *> : public csHashComputerIntegral<iEventHandler *> {};
00061
00067 class CS_CRYSTALSPACE_EXPORT csEventQueue :
00068 public scfImplementation1<csEventQueue, iEventQueue>
00069 {
00070 friend class csEventOutlet;
00071 friend class csPoolEvent;
00072 friend class csEventTree;
00073 friend class csEventQueueTest;
00074
00075 private:
00076
00077 iObjectRegistry* Registry;
00078
00079 csRef<iEventNameRegistry> NameRegistry;
00080
00081 csRef<iEventHandlerRegistry> HandlerRegistry;
00082
00083 volatile iEvent** EventQueue;
00084
00085 volatile size_t evqHead, evqTail;
00086
00087 volatile size_t Length;
00088
00089
00090 csEventTree *EventTree;
00091
00092 csHash<csEventTree *,csEventID> EventHash;
00093
00094 csArray<csEventOutlet*> EventOutlets;
00095
00096 csHash<csEventCord *, csEventID> EventCords;
00097
00098 csPoolEvent* EventPool;
00100 csRefArray<iEventHandler> handlers;
00102 CS::Threading::ReadWriteMutex mutex;
00103 CS::Threading::ReadWriteMutex etreeMutex;
00104
00105
00106 void Resize (size_t iLength);
00107
00108 void Notify (const csEventID &name);
00109
00110
00111
00112
00113
00114
00115 void StartLoop ();
00116
00117 void EndLoop ();
00118
00119
00120
00121 void RemoveAllListeners (bool recreateEventTree);
00122 public:
00123
00125 csEventQueue (iObjectRegistry*, size_t iLength = DEF_EVENT_QUEUE_LENGTH);
00127 virtual ~csEventQueue ();
00128
00130 virtual void Process ();
00132 virtual void Dispatch (iEvent&);
00133
00135 virtual csHandlerID RegisterListener (iEventHandler*);
00137 virtual csHandlerID RegisterListener (iEventHandler *handler,
00138 const csEventID &event)
00139 {
00140 csHandlerID id = RegisterListener(handler);
00141 if (id!=CS_HANDLER_INVALID)
00142 {
00143 if (Subscribe(handler, event))
00144 return id;
00145 else
00146 RemoveListener(handler);
00147 }
00148 return CS_HANDLER_INVALID;
00149 }
00151 virtual csHandlerID RegisterListener (iEventHandler *handler,
00152 const csEventID events[])
00153 {
00154 csHandlerID id = RegisterListener(handler);
00155 if (id!=CS_HANDLER_INVALID)
00156 {
00157 if (Subscribe(handler, events))
00158 return id;
00159 else
00160 RemoveListener(handler);
00161 }
00162 return CS_HANDLER_INVALID;
00163 }
00169 virtual bool Subscribe (iEventHandler*, const csEventID &);
00176 virtual bool Subscribe (iEventHandler*, const csEventID[]);
00182 virtual void Unsubscribe (iEventHandler*, const csEventID &);
00187 virtual void Unsubscribe (iEventHandler*, const csEventID[]);
00194 virtual void RemoveListener (iEventHandler*);
00199 virtual void RemoveAllListeners ();
00200
00202 virtual csPtr<iEventOutlet> CreateEventOutlet (iEventPlug*);
00204 virtual iEventOutlet* GetEventOutlet ();
00206 virtual iEventCord* GetEventCord (const csEventID &);
00207
00209 uint32 CountPool ();
00210 protected:
00211 virtual iEvent *CreateRawEvent ();
00212 public:
00214 virtual csPtr<iEvent> CreateEvent ();
00215 virtual csPtr<iEvent> CreateEvent (const csEventID &name, bool broadcast);
00216 virtual csPtr<iEvent> CreateEvent (const csEventID &name);
00217 virtual csPtr<iEvent> CreateEvent (const char *name);
00218 virtual csPtr<iEvent> CreateBroadcastEvent (const csEventID &name);
00219 virtual csPtr<iEvent> CreateBroadcastEvent (const char *name);
00221 virtual void Post (iEvent*);
00223 virtual csPtr<iEvent> Get ();
00225 virtual void Clear ();
00227 virtual bool IsEmpty () { return evqHead == evqTail; }
00228
00229 csEventID Frame;
00230 };
00231
00232 #endif // __CS_CSEVENTQ_H__