00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __CSEVENTQ_H__
00022 #define __CSEVENTQ_H__
00023
00024 #include "csutil/csevent.h"
00025 #include "csutil/csevcord.h"
00026 #include "csutil/csvector.h"
00027 #include "csutil/evoutlet.h"
00028 #include "csutil/garray.h"
00029 #include "iutil/eventq.h"
00030 struct iObjectRegistry;
00031
00032
00033
00034 #define DEF_EVENT_QUEUE_LENGTH 256
00035
00044 class csEventQueue : public iEventQueue
00045 {
00046 friend class csEventOutlet;
00047 private:
00048 struct Listener
00049 {
00050 iEventHandler* object;
00051 unsigned int trigger;
00052 };
00053 CS_TYPEDEF_GROWING_ARRAY(ListenerVector, Listener);
00054
00055
00056
00057
00058
00059
00060
00061
00062 class EventOutletsVector : public csVector
00063 {
00064 public:
00065 EventOutletsVector() : csVector (16, 16) {}
00066 virtual ~EventOutletsVector () { DeleteAll(); }
00067 csEventOutlet* Get(int i)
00068 { return (csEventOutlet*)csVector::Get(i); }
00069 };
00070
00071
00072 class EventCordsVector : public csVector
00073 {
00074 public:
00075 EventCordsVector() : csVector (16, 16) {}
00076 virtual ~EventCordsVector() { DeleteAll(); }
00077 virtual bool FreeItem(csSome p)
00078 { ((csEventCord*)p)->DecRef(); return true; }
00079 csEventCord* Get(int i)
00080 { return (csEventCord*)csVector::Get(i); }
00081 int Find(int Category, int SubCategory);
00082 };
00083
00084
00085 iObjectRegistry* Registry;
00086
00087 volatile iEvent** EventQueue;
00088
00089 volatile size_t evqHead, evqTail;
00090
00091 volatile size_t Length;
00092
00093 volatile int SpinLock;
00094
00095 int busy_looping;
00096
00097
00098 bool delete_occured;
00099
00100 ListenerVector Listeners;
00101
00102 EventOutletsVector EventOutlets;
00103
00104 EventCordsVector EventCords;
00105
00106
00107 void Resize(size_t iLength);
00108
00109 inline void Lock() { while (SpinLock) {} SpinLock++; }
00110
00111 inline void Unlock() { SpinLock--; }
00112
00113 int FindListener(iEventHandler*) const;
00114
00115 void Notify(iEvent&);
00116
00117
00118
00119
00120 void StartLoop ();
00121 void EndLoop ();
00122
00123 public:
00124 SCF_DECLARE_IBASE;
00125
00127 csEventQueue(iObjectRegistry*, size_t iLength = DEF_EVENT_QUEUE_LENGTH);
00129 virtual ~csEventQueue();
00130
00132 virtual void Process();
00134 virtual void Dispatch(iEvent&);
00135
00137 virtual void RegisterListener(iEventHandler*, unsigned int trigger);
00139 virtual void RemoveListener(iEventHandler*);
00141 virtual void ChangeListenerTrigger(iEventHandler*, unsigned int trigger);
00142
00144 virtual iEventOutlet* CreateEventOutlet(iEventPlug*);
00146 virtual iEventOutlet* GetEventOutlet();
00148 virtual iEventCord* GetEventCord (int Category, int Subcategory);
00149
00151 virtual void Post(iEvent*);
00153 virtual iEvent* Get();
00155 virtual void Clear();
00157 virtual bool IsEmpty() { return evqHead == evqTail; }
00158 };
00159
00160 #endif // __CSEVENTQ_H__