Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages
cseventq.h
Go to the documentation of this file.00001 /* 00002 Crystal Space 3D engine: Event Queue interface 00003 Copyright (C) 1998 by Andrew Zabolotny <bit@freya.etu.ru> 00004 Copyright (C) 2001 by Eric Sunshine <sunshine@sunshineco.com> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public 00017 License along with this library; if not, write to the Free 00018 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00019 */ 00020 00021 #ifndef __CS_CSEVENTQ_H__ 00022 #define __CS_CSEVENTQ_H__ 00023 00028 #include "csextern.h" 00029 00030 #include "csutil/array.h" 00031 #include "csutil/ref.h" 00032 #include "csutil/refarr.h" 00033 #include "csutil/thread.h" 00034 #include "iutil/eventq.h" 00035 00036 struct iObjectRegistry; 00037 00038 class csEventCord; 00039 class csEventOutlet; 00040 class csPoolEvent; 00041 00046 #define DEF_EVENT_QUEUE_LENGTH 256 00047 00053 class CS_CRYSTALSPACE_EXPORT csEventQueue : public iEventQueue 00054 { 00055 friend class csEventOutlet; 00056 friend class csPoolEvent; 00057 00058 private: 00059 struct CS_CRYSTALSPACE_EXPORT Listener 00060 { 00061 iEventHandler* object; 00062 unsigned int trigger; 00063 }; 00064 typedef csArray<Listener> ListenerVector; 00065 00066 size_t EventCordsFind (int cat, int subcat); 00067 00068 // Shared-object registry 00069 iObjectRegistry* Registry; 00070 // The queue itself 00071 volatile iEvent** EventQueue; 00072 // Queue head and tail pointers 00073 volatile size_t evqHead, evqTail; 00074 // The maximum queue length 00075 volatile size_t Length; 00076 // Protection against multiple threads accessing same event queue 00077 csRef<csMutex> Mutex; 00078 // Protection against delete while looping through the listeners. 00079 int busy_looping; 00080 /* 00081 * If a delete happened while busy_looping is true we set the 00082 * following to true. 00083 */ 00084 bool delete_occured; 00085 // Registered listeners. 00086 ListenerVector Listeners; 00087 // Array of allocated event outlets. 00088 csArray<csEventOutlet*> EventOutlets; 00089 // Array of allocated event cords. 00090 csRefArray<csEventCord> EventCords; 00091 // Pool of event objects 00092 csPoolEvent* EventPool; 00093 00094 // Enlarge the queue size. 00095 void Resize (size_t iLength); 00096 // Lock the queue for modifications: NESTED CALLS TO LOCK/UNLOCK NOT ALLOWED! 00097 inline void Lock () { Mutex->LockWait(); } 00098 // Unlock the queue 00099 inline void Unlock () { Mutex->Release(); } 00100 // Find a particular listener index; return -1 if listener is not registered. 00101 size_t FindListener (iEventHandler*) const; 00102 // Send listeners of CSMASK_FrameProcess one of the frame processing 00103 // pseudo-events. 00104 void Notify (unsigned int pseudo_event); 00105 00106 /* 00107 * Start a loop. The purpose of this function is to protect 00108 * against modifications to the Listeners array while this array 00109 * is being processed. 00110 */ 00111 void StartLoop (); 00112 // End a loop. 00113 void EndLoop (); 00114 00115 public: 00116 SCF_DECLARE_IBASE; 00117 00119 csEventQueue (iObjectRegistry*, size_t iLength = DEF_EVENT_QUEUE_LENGTH); 00121 virtual ~csEventQueue (); 00122 00124 virtual void Process (); 00126 virtual void Dispatch (iEvent&); 00127 00129 virtual void RegisterListener (iEventHandler*, unsigned int trigger); 00131 virtual void RemoveListener (iEventHandler*); 00136 virtual void RemoveAllListeners (); 00138 virtual void ChangeListenerTrigger (iEventHandler*, unsigned int trigger); 00139 00141 virtual csPtr<iEventOutlet> CreateEventOutlet (iEventPlug*); 00143 virtual iEventOutlet* GetEventOutlet (); 00145 virtual iEventCord* GetEventCord (int Category, int Subcategory); 00146 00148 uint32 CountPool (); 00150 virtual csPtr<iEvent> CreateEvent (uint8 type); 00152 virtual void Post (iEvent*); 00154 virtual csPtr<iEvent> Get (); 00156 virtual void Clear (); 00158 virtual bool IsEmpty () { return evqHead == evqTail; } 00159 }; 00160 00161 #endif // __CS_CSEVENTQ_H__
Generated for Crystal Space by doxygen 1.4.4