CrystalSpace

Public API Reference

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

csutil/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 #include "csevent.h"
00030 #include "csevcord.h"
00031 #include "evoutlet.h"
00032 #include "array.h"
00033 #include "ref.h"
00034 #include "refarr.h"
00035 #include "thread.h"
00036 #include "iutil/eventq.h"
00037 
00038 struct iObjectRegistry;
00039 
00044 #define DEF_EVENT_QUEUE_LENGTH  256
00045 
00051 class CS_CSUTIL_EXPORT csEventQueue : public iEventQueue
00052 {
00053   friend class csEventOutlet;
00054   friend class csPoolEvent;
00055 
00056 private:
00057   struct CS_CSUTIL_EXPORT Listener
00058   {
00059     iEventHandler* object;
00060     unsigned int trigger;
00061   };
00062   typedef csArray<Listener> ListenerVector;
00063 
00064   int EventCordsFind (int cat, int subcat);
00065 
00066   // Shared-object registry
00067   iObjectRegistry* Registry;
00068   // The queue itself
00069   volatile iEvent** EventQueue;
00070   // Queue head and tail pointers
00071   volatile size_t evqHead, evqTail;
00072   // The maximum queue length
00073   volatile size_t Length;
00074   // Protection against multiple threads accessing same event queue
00075   csRef<csMutex> Mutex;
00076   // Protection against delete while looping through the listeners.
00077   int busy_looping;
00078   /*  
00079    * If a delete happened while busy_looping is true we set the
00080    * following to true.
00081    */
00082   bool delete_occured;
00083   // Registered listeners.
00084   ListenerVector Listeners;
00085   // Array of allocated event outlets.
00086   csArray<csEventOutlet*> EventOutlets;
00087   // Array of allocated event cords.
00088   csRefArray<csEventCord> EventCords;
00089   // Pool of event objects
00090   csPoolEvent* EventPool;
00091 
00092   // Enlarge the queue size.
00093   void Resize (size_t iLength);
00094   // Lock the queue for modifications: NESTED CALLS TO LOCK/UNLOCK NOT ALLOWED!
00095   inline void Lock () { Mutex->LockWait(); }
00096   // Unlock the queue
00097   inline void Unlock () { Mutex->Release(); }
00098   // Find a particular listener index; return -1 if listener is not registered.
00099   int FindListener (iEventHandler*) const;
00100   // Send listeners of CSMASK_FrameProcess one of the frame processing
00101   // pseudo-events.
00102   void Notify (unsigned int pseudo_event);
00103 
00104   /*
00105    * Start a loop. The purpose of this function is to protect
00106    * against modifications to the Listeners array while this array
00107    * is being processed.
00108    */
00109   void StartLoop ();
00110   // End a loop.
00111   void EndLoop ();
00112 
00113 public:
00114   SCF_DECLARE_IBASE;
00115 
00117   csEventQueue (iObjectRegistry*, size_t iLength = DEF_EVENT_QUEUE_LENGTH);
00119   virtual ~csEventQueue ();
00120 
00122   virtual void Process ();
00124   virtual void Dispatch (iEvent&);
00125 
00127   virtual void RegisterListener (iEventHandler*, unsigned int trigger);
00129   virtual void RemoveListener (iEventHandler*);
00134   virtual void RemoveAllListeners ();
00136   virtual void ChangeListenerTrigger (iEventHandler*, unsigned int trigger);
00137 
00139   virtual csPtr<iEventOutlet> CreateEventOutlet (iEventPlug*);
00141   virtual iEventOutlet* GetEventOutlet ();
00143   virtual iEventCord* GetEventCord (int Category, int Subcategory);
00144 
00146   uint32 CountPool ();
00148   virtual csPtr<iEvent> CreateEvent (uint8 type);
00150   virtual void Post (iEvent*);
00152   virtual csPtr<iEvent> Get ();
00154   virtual void Clear ();
00156   virtual bool IsEmpty () { return evqHead == evqTail; }
00157 };
00158 
00159 #endif // __CS_CSEVENTQ_H__

Generated for Crystal Space by doxygen 1.2.18