mirror of
https://github.com/debauchee/barrier.git
synced 2026-07-05 19:36:16 +08:00
Refactored event queue. The event queue is now separated from the
buffer that holds the events and generates system events. This allows us to switch in/out a platform specific event handler as necessary without losing our timers and handlers.
This commit is contained in:
@@ -34,6 +34,7 @@ public:
|
||||
virtual ~CEventQueue();
|
||||
|
||||
// IEventQueue overrides
|
||||
virtual void adoptBuffer(IEventQueueBuffer*);
|
||||
virtual bool getEvent(CEvent& event, double timeout = -1.0);
|
||||
virtual bool dispatchEvent(const CEvent& event);
|
||||
virtual void addEvent(const CEvent& event);
|
||||
@@ -52,80 +53,13 @@ public:
|
||||
virtual bool isEmpty() const;
|
||||
virtual IEventJob* getHandler(CEvent::Type type, void* target) const;
|
||||
|
||||
protected:
|
||||
//! @name manipulators
|
||||
//@{
|
||||
|
||||
//! Get the data for a given id
|
||||
/*!
|
||||
Takes a saved event id, \p eventID, and returns a \c CEvent. The
|
||||
event id becomes invalid after this call. The \p eventID must have
|
||||
been passed to a successful call to \c doAddEvent() and not removed
|
||||
since.
|
||||
*/
|
||||
CEvent removeEvent(UInt32 eventID);
|
||||
|
||||
//! Block waiting for an event
|
||||
/*!
|
||||
Wait for an event in the system event queue for up to \p timeout
|
||||
seconds.
|
||||
*/
|
||||
virtual void waitForEvent(double timeout) = 0;
|
||||
|
||||
//! Get the next event
|
||||
/*!
|
||||
Remove the next system event (one should be pending) and convert it
|
||||
to a \c CEvent. The event type should be either \c CEvent::kSystem
|
||||
if the event was not added by \c doAddEvent() or a type returned by
|
||||
\c CEvent::registerType() if it was (and not \c CEvent::kTimer). A
|
||||
non-system event will normally be retrieved by \c removeEvent(), but
|
||||
the implementation must be able to tell the difference between a
|
||||
system event and one added by \c doAddEvent().
|
||||
*/
|
||||
virtual bool doGetEvent(CEvent& event) = 0;
|
||||
|
||||
//! Post an event
|
||||
/*!
|
||||
Add the given event to the end of the system queue. This is a user
|
||||
event and \c doGetEvent() must be able to identify it as such.
|
||||
This method must cause \c waitForEvent() to return at some future
|
||||
time if it's blocked waiting on an event.
|
||||
*/
|
||||
virtual bool doAddEvent(UInt32 dataID) = 0;
|
||||
|
||||
//@}
|
||||
//! @name accessors
|
||||
//@{
|
||||
|
||||
//! Check if system queue is empty
|
||||
/*!
|
||||
Return true iff the system queue is empty.
|
||||
*/
|
||||
virtual bool doIsEmpty() const = 0;
|
||||
|
||||
//! Create a timer object
|
||||
/*!
|
||||
Create and return a timer object. The object is opaque and is
|
||||
used only by the subclass but it must be a valid object (i.e.
|
||||
not NULL).
|
||||
*/
|
||||
virtual CEventQueueTimer*
|
||||
doNewTimer(double duration, bool oneShot) const = 0;
|
||||
|
||||
//! Destroy a timer object
|
||||
/*!
|
||||
Destroy a timer object previously returned by \c doNewTimer().
|
||||
*/
|
||||
virtual void doDeleteTimer(CEventQueueTimer*) const = 0;
|
||||
|
||||
//@}
|
||||
|
||||
private:
|
||||
void doAdoptHandler(CEvent::Type type,
|
||||
void* target, IEventJob* handler);
|
||||
IEventJob* doOrphanHandler(CEvent::Type type, void* target);
|
||||
|
||||
UInt32 saveEvent(const CEvent& event);
|
||||
CEvent removeEvent(UInt32 eventID);
|
||||
bool hasTimerExpired(CEvent& event);
|
||||
double getNextTimerTimeout() const;
|
||||
|
||||
@@ -175,6 +109,8 @@ private:
|
||||
|
||||
CArchMutex m_mutex;
|
||||
|
||||
IEventQueueBuffer* m_buffer;
|
||||
|
||||
CEventTable m_events;
|
||||
CEventIDList m_oldEventIDs;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user