Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

CEventQueue.h

00001 /*
00002  * synergy -- mouse and keyboard sharing utility
00003  * Copyright (C) 2004 Chris Schoeneman
00004  * 
00005  * This package is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * found in the file COPYING that should have accompanied this file.
00008  * 
00009  * This package is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  */
00014 
00015 #ifndef CEVENTQUEUE_H
00016 #define CEVENTQUEUE_H
00017 
00018 #include "IEventQueue.h"
00019 #include "CEvent.h"
00020 #include "CPriorityQueue.h"
00021 #include "CStopwatch.h"
00022 #include "IArchMultithread.h"
00023 #include "stdmap.h"
00024 #include "stdset.h"
00025 
00027 
00031 class CEventQueue : public IEventQueue {
00032 public:
00033     CEventQueue();
00034     virtual ~CEventQueue();
00035 
00036     // IEventQueue overrides
00037     virtual void        adoptBuffer(IEventQueueBuffer*);
00038     virtual bool        getEvent(CEvent& event, double timeout = -1.0);
00039     virtual bool        dispatchEvent(const CEvent& event);
00040     virtual void        addEvent(const CEvent& event);
00041     virtual CEventQueueTimer*
00042                         newTimer(double duration, void* target);
00043     virtual CEventQueueTimer*
00044                         newOneShotTimer(double duration, void* target);
00045     virtual void        deleteTimer(CEventQueueTimer*);
00046     virtual void        adoptHandler(CEvent::Type type,
00047                             void* target, IEventJob* handler);
00048     virtual void        removeHandler(CEvent::Type type, void* target);
00049     virtual void        removeHandlers(void* target);
00050     virtual CEvent::Type
00051                         registerType(const char* name);
00052     virtual CEvent::Type
00053                         registerTypeOnce(CEvent::Type& type, const char* name);
00054     virtual bool        isEmpty() const;
00055     virtual IEventJob*  getHandler(CEvent::Type type, void* target) const;
00056     virtual const char* getTypeName(CEvent::Type type);
00057 
00058 private:
00059     UInt32              saveEvent(const CEvent& event);
00060     CEvent              removeEvent(UInt32 eventID);
00061     bool                hasTimerExpired(CEvent& event);
00062     double              getNextTimerTimeout() const;
00063 
00064 private:
00065     class CTimer {
00066     public:
00067         CTimer(CEventQueueTimer*, double timeout, double initialTime,
00068                             void* target, bool oneShot);
00069         ~CTimer();
00070 
00071         void            reset();
00072 
00073         CTimer&         operator-=(double);
00074 
00075                         operator double() const;
00076 
00077         bool            isOneShot() const;
00078         CEventQueueTimer*
00079                         getTimer() const;
00080         void*           getTarget() const;
00081         void            fillEvent(CTimerEvent&) const;
00082 
00083         bool            operator<(const CTimer&) const;
00084 
00085     private:
00086         CEventQueueTimer*   m_timer;
00087         double              m_timeout;
00088         void*               m_target;
00089         bool                m_oneShot;
00090         double              m_time;
00091     };
00092     typedef std::set<CEventQueueTimer*> CTimers;
00093     typedef CPriorityQueue<CTimer> CTimerQueue;
00094     typedef std::map<UInt32, CEvent> CEventTable;
00095     typedef std::vector<UInt32> CEventIDList;
00096     typedef std::map<CEvent::Type, const char*> CTypeMap;
00097     typedef std::map<CEvent::Type, IEventJob*> CTypeHandlerTable;
00098     typedef std::map<void*, CTypeHandlerTable> CHandlerTable;
00099 
00100     CArchMutex          m_mutex;
00101 
00102     // registered events
00103     CEvent::Type        m_nextType;
00104     CTypeMap            m_typeMap;
00105 
00106     // buffer of events
00107     IEventQueueBuffer*  m_buffer;
00108 
00109     // saved events
00110     CEventTable         m_events;
00111     CEventIDList        m_oldEventIDs;
00112 
00113     // timers
00114     CStopwatch          m_time;
00115     CTimers             m_timers;
00116     CTimerQueue         m_timerQueue;
00117     CTimerEvent         m_timerEvent;
00118 
00119     // event handlers
00120     CHandlerTable       m_handlers;
00121 };
00122 
00123 #endif

Generated on Fri Nov 6 00:21:13 2009 for synergy-plus by  doxygen 1.3.9.1