Update of /cvsroot/pclasses/pclasses2/include/pclasses/System
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18685/include/pclasses/System
Modified Files:
Makefile.am
Added Files:
EventQueue.h
Log Message:
Added EventQueue, Event.
Added FdListener and FdListenerThread.
Index: Makefile.am
===================================================================
RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/System/Makefile.am,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- Makefile.am 30 Jan 2005 17:16:05 -0000 1.7
+++ Makefile.am 7 Feb 2005 18:41:06 -0000 1.8
@@ -4,4 +4,5 @@
METASOURCES = AUTO
pclasses_system_include_HEADERS = SystemError.h SharedMemory.h CriticalSection.h Mutex.h \
Condition.h Semaphore.h Thread.h SharedLib.h File.h FileInfo.h \
- Directory.h SystemClock.h ProcessIO.h Process.h ThreadKey.h StorageDevice.h
+ Directory.h SystemClock.h ProcessIO.h Process.h ThreadKey.h StorageDevice.h \
+ EventQueue.h
--- NEW FILE: EventQueue.h ---
/***************************************************************************
* Copyright (C) 2005 by Christian Prochnow *
* cp...@se... *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Library General Public License as *
* published by the Free Software Foundation; either version 2 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef P_System_EventLoop_h
#define P_System_EventLoop_h
#include <pclasses/NonCopyable.h>
#include <pclasses/System/ThreadKey.h>
#include <pclasses/System/Mutex.h>
#include <pclasses/System/Condition.h>
#include <map>
#include <queue>
namespace P {
namespace System {
class Event {
public:
Event(void* sender = 0, unsigned int id = 0);
~Event();
void* sender() const throw();
unsigned int id() const throw();
private:
void* _sender;
unsigned int _id;
};
class EventQueue;
//! Event listener base-class
class EventListener {
public:
friend class EventQueue;
EventListener(void* sender);
EventListener(EventQueue& q, void* sender);
virtual ~EventListener();
EventQueue& eventQueue() const throw();
void* sender() const throw();
protected:
virtual void signaled(const Event& ev) = 0;
private:
EventQueue& _eventQueue;
void* _sender;
};
//! Event queue
/*!
The EventQueue is used to deliver and dispatch asynchronous
Events. Each thread has it's own EventQueue that is created
on the first call to EventQueue::instance().
*/
class EventQueue: public NonCopyable {
public:
friend class EventListener;
//! Wait for event
void wait(Event& ev);
//! Try waiting for event
bool tryWait(Event& ev, unsigned int timeout);
//! Dispatch event
void dispatch(const Event& ev);
//! Post event to queue
void post(const Event& ev);
//! Returns the EventQueue for the calling thread
static EventQueue& instance();
protected:
void addListener(EventListener* l);
void removeListener(EventListener* l);
private:
EventQueue();
~EventQueue();
std::queue<
Event
> _eventQueue;
Mutex _eventQMutex;
Condition _eventQCond;
typedef std::multimap<
void*, EventListener*
> ListenerMap;
ListenerMap _listeners;
Mutex _listenersMutex;
static ThreadKey<EventQueue> _theQueues;
};
} // !namespace System
} // !namespace P
#endif
|