You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(622) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(303) |
Feb
(64) |
Mar
(5) |
Apr
(63) |
May
(82) |
Jun
(53) |
Jul
(50) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Christian P. <cp...@us...> - 2005-02-10 19:10:49
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Net In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1512/include/pclasses/Net Added Files: ServerSocketManager.h Log Message: Added ServerSocketManager --- NEW FILE: ServerSocketManager.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_Net_ServerSocketManager_h #define P_Net_ServerSocketManager_h #include <pclasses/Export.h> #include <pclasses/Signal.h> #include <pclasses/Net/Socket.h> #include <list> #include <map> namespace P { namespace Net { //! A StreamSocket server manager class PNET_EXPORT ServerSocketManager { public: ServerSocketManager(); virtual ~ServerSocketManager(); void addServer(const NetworkAddress& addr, port_t port); void removeServer(const NetworkAddress& addr, port_t port); Signal1<void, StreamSocketServer&> sigConnect; protected: virtual void onConnect(StreamSocketServer& s); private: void slotConnected(SocketListener&); std::list< StreamSocketServer* > _servers; std::map< StreamSocketServer*, SocketListener* > _listeners; }; } // !namespace Net } // !namespace P #endif |
From: Christian P. <cp...@us...> - 2005-02-10 19:10:49
|
Update of /cvsroot/pclasses/pclasses2/src/Net In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1512/src/Net Added Files: ServerSocketManager.cpp Log Message: Added ServerSocketManager --- NEW FILE: ServerSocketManager.cpp --- /*************************************************************************** * 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. * ***************************************************************************/ #include "pclasses/Net/ServerSocketManager.h" namespace P { namespace Net { typedef std::list< StreamSocketServer* > ServerList; typedef std::map< StreamSocketServer*, SocketListener* > ListenersMap; ServerSocketManager::ServerSocketManager() { } ServerSocketManager::~ServerSocketManager() { // delete all listeners ... ListenersMap::const_iterator li = _listeners.begin(); while(li != _listeners.end()) { delete li->second; ++li; } // delete the server sockets ... ServerList::const_iterator si = _servers.begin(); while(si != _servers.end()) { delete *si; ++si; } } void ServerSocketManager::addServer(const NetworkAddress& addr, port_t port) { // create the server socket and listen for incomming connections ... StreamSocketServer* srv = new StreamSocketServer(addr, port); srv->listen(); // create the socket listener and connect the write-signal for // accepting incomming connections ... SocketListener* listener = new SocketListener(*srv); listener->sigWrite.bind(make_method(this, &ServerSocketManager::slotConnected)); _servers.push_back(srv); _listeners.insert(std::make_pair(srv, listener)); } void ServerSocketManager::removeServer(const NetworkAddress& addr, port_t port) { //@fixme .. we need Socket::socketAddr() to implement this method } void ServerSocketManager::onConnect(StreamSocketServer& srv) { // left empty... } void ServerSocketManager::slotConnected(SocketListener& l) { StreamSocketServer& srv = (StreamSocketServer&)l.socket(); onConnect(srv); sigConnect.fire(srv); } } // !namespace Net } // !namespace P |
From: Christian P. <cp...@us...> - 2005-02-07 18:47:24
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Net In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20255/include/pclasses/Net Modified Files: Socket.h Log Message: Added SocketListener. Index: Socket.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Net/Socket.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- Socket.h 26 Jan 2005 10:23:17 -0000 1.6 +++ Socket.h 7 Feb 2005 18:47:13 -0000 1.7 @@ -23,7 +23,9 @@ #include <pclasses/Export.h> #include <pclasses/BasicTypes.h> +#include <pclasses/Signal.h> #include <pclasses/IO/IODevice.h> +#include <pclasses/System/EventQueue.h> #include <pclasses/Net/NetworkAddress.h> namespace P { @@ -32,9 +34,13 @@ typedef uint16_t port_t; +class SocketListener; + //! Socket class PNET_EXPORT Socket: public IO::IODevice { public: + friend class SocketListener; + enum Domain { Inet, Inet6, @@ -54,7 +60,6 @@ }; Socket() throw(); - Socket(Domain domain, Type type, int proto = 0) throw(IO::IOError); ~Socket() throw(); Domain domain() const throw(); @@ -92,6 +97,8 @@ static Domain addrFamily2Domain(int family); protected: + Socket(Domain domain, Type type, int proto = 0) throw(IO::IOError); + void open(Domain domain, Type type, int proto) throw(IO::IOError); @@ -113,6 +120,41 @@ int _handle; }; + +//! Socket Event-listener +class PNET_EXPORT SocketListener: public System::EventListener { + public: + enum EventMask { + Read = 0x01, + Write = 0x02, + Error = 0x04 + }; + + SocketListener(Socket& s); + SocketListener(System::EventQueue& evq, Socket& s); + ~SocketListener(); + + Socket& socket() const throw(); + + void setEventMask(int mask); + int eventMask() const throw(); + + Signal1<void, SocketListener&> sigRead; + Signal1<void, SocketListener&> sigWrite; + Signal1<void, SocketListener&> sigError; + + protected: + virtual void onRead(); + virtual void onWrite(); + virtual void onError(); + + private: + void signaled(const System::Event& ev); + unsigned long _handle; +}; + + + //! Datagram Socket class PNET_EXPORT DatagramSocket: public virtual Socket { public: @@ -151,9 +193,11 @@ class PNET_EXPORT StreamSocket: public virtual Socket { public: StreamSocket() throw(); + StreamSocket(Domain d, int proto) throw(IO::IOError); StreamSocket(StreamSocketServer& srv) throw(IO::IOError); ~StreamSocket() throw(); + void open(Domain d, int proto) throw(IO::IOError); void open(StreamSocketServer& srv) throw(IO::IOError); }; |
From: Christian P. <cp...@us...> - 2005-02-07 18:47:24
|
Update of /cvsroot/pclasses/pclasses2/src/Net In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20255/src/Net Modified Files: Socket.cpp Log Message: Added SocketListener. Index: Socket.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Net/Socket.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- Socket.cpp 26 Jan 2005 10:23:17 -0000 1.7 +++ Socket.cpp 7 Feb 2005 18:47:13 -0000 1.8 @@ -39,6 +39,10 @@ # include <netipx/ipx.h> #endif +#ifndef WIN32 +# include "../System/FdListener.h" +#endif + namespace P { using namespace Private; @@ -490,6 +494,11 @@ { } +StreamSocket::StreamSocket(Domain d, int proto) throw(IO::IOError) +: Socket(d, Socket::Stream, proto) +{ +} + StreamSocket::StreamSocket(StreamSocketServer& srv) throw(IO::IOError) : Socket() { @@ -500,6 +509,11 @@ { } +void StreamSocket::open(Domain d, int proto) throw(IO::IOError) +{ + Socket::open(d, Socket::Stream, proto); +} + void StreamSocket::open(StreamSocketServer& srv) throw(IO::IOError) { Socket::open(srv.accept(), srv.domain(), srv.type(), srv.protocol()); @@ -573,6 +587,127 @@ return d; } +enum SocketEvent { + SocketEventRead = 0, + SocketEventWrite = 1, + SocketEventError = 2 +}; + +// The SocketFdListener posts Event's occuring on the file-descriptor +// to the EventQueue that has been given to SocketListener. +class SocketFdListener: public System::FdListener { + public: + SocketFdListener(SocketListener* listener, int fd, int flags) + : System::FdListener(fd, flags), _listener(listener) + { + System::FdListenerThread& thr = System::FdListenerThread::instance(); + thr.addListener(this); + } + + ~SocketFdListener() + { + System::FdListenerThread& thr = System::FdListenerThread::instance(); + thr.removeListener(this); + } + + void onRead() + { + _listener->eventQueue().post( + System::Event(_listener->sender(), SocketEventRead)); + } + + void onWrite() + { + _listener->eventQueue().post( + System::Event(_listener->sender(), SocketEventWrite)); + } + + void onError() + { + _listener->eventQueue().post( + System::Event(_listener->sender(), SocketEventError)); + } + + private: + SocketListener* _listener; +}; + + + +SocketListener::SocketListener(Socket& s) +: EventListener(&s) +{ + using System::FdListener; + + _handle = (unsigned long)new SocketFdListener(this, s.handle(), + FdListener::Read|FdListener::Write|FdListener::Error); +} + +SocketListener::SocketListener(System::EventQueue& evq, Socket& s) +: EventListener(evq, &s) +{ + using System::FdListener; + + _handle = (unsigned long)new SocketFdListener(this, s.handle(), + FdListener::Read|FdListener::Write|FdListener::Error); +} + +SocketListener::~SocketListener() +{ + delete (SocketFdListener*)_handle; +} + +Socket& SocketListener::socket() const throw() +{ + return *((Socket*)sender()); +} + +void SocketListener::setEventMask(int mask) +{ + ((SocketFdListener*)_handle)->setFlags(mask); + + // Wakeup the thread so it can get the new event flags ... + System::FdListenerThread& thr = System::FdListenerThread::instance(); + thr.wakeup(); +} + +int SocketListener::eventMask() const throw() +{ + return ((SocketFdListener*)_handle)->flags(); +} + +void SocketListener::signaled(const System::Event& ev) +{ + switch(ev.id()) + { + case SocketEventRead: + onRead(); + sigRead.fire(*this); + break; + case SocketEventWrite: + onWrite(); + sigWrite.fire(*this); + break; + case SocketEventError: + onError(); + sigError.fire(*this); + break; + } +} + +void SocketListener::onRead() +{ +} + +void SocketListener::onWrite() +{ +} + +void SocketListener::onError() +{ +} + + } // !namespace Net } // !namespace P |
From: Christian P. <cp...@us...> - 2005-02-07 18:46:41
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20090/include/pclasses Modified Files: Makefile.am Log Message: Generate CallbackN.h if CallbackN.sh is newer. Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Makefile.am,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- Makefile.am 28 Jan 2005 17:37:02 -0000 1.11 +++ Makefile.am 7 Feb 2005 18:46:30 -0000 1.12 @@ -5,7 +5,7 @@ METASOURCES = AUTO all_callbacks: - if [ ! -e "$(top_builddir)/include/pclasses/CallbackN1.h" ]; then bash $(top_srcdir)/include/pclasses/CallbackN.sh; fi + if [ "$(top_builddir)/include/pclasses/CallbackN.sh" -nt "$(top_builddir)/include/pclasses/CallbackN1.h" ]; then bash $(top_srcdir)/include/pclasses/CallbackN.sh; fi all_callbacks_clean: rm -f CallbackN1.h CallbackN2.h CallbackN3.h CallbackN4.h |
From: Christian P. <cp...@us...> - 2005-02-07 18:45:26
|
Update of /cvsroot/pclasses/pclasses2/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19838/src Modified Files: Makefile.am Log Message: Added Callback.cpp Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Makefile.am,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- Makefile.am 17 Jan 2005 22:50:23 -0000 1.6 +++ Makefile.am 7 Feb 2005 18:45:15 -0000 1.7 @@ -11,6 +11,6 @@ libpclasses_la_SOURCES = Alloc.cpp Exception.cpp AtomicInt.gcc-x86.cpp \ ByteOrderTraits.cpp LinkedItem.cpp Time.cpp Date.cpp DateTime.cpp \ - TimeSpan.cpp Trace.cpp + TimeSpan.cpp Trace.cpp Callback.cpp SUBDIRS = . Unicode IO System Net Util XML App |
From: Christian P. <cp...@us...> - 2005-02-07 18:41:17
|
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 |
From: Christian P. <cp...@us...> - 2005-02-07 18:41:17
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18685/src/System Modified Files: Makefile.am Added Files: EventQueue.cpp FdListener.h FdListener.posix.cpp Log Message: Added EventQueue, Event. Added FdListener and FdListenerThread. --- NEW FILE: FdListener.posix.cpp --- /*************************************************************************** * 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. * ***************************************************************************/ #include "FdListener.h" #include "timeout.h" #include <sys/select.h> #include <unistd.h> #include <fcntl.h> #include <errno.h> namespace P { namespace System { FdListener::FdListener(int fd, int flags) : _fd(fd), _flags(flags) { } FdListener::~FdListener() { } int FdListener::fd() const throw() { return _fd; } int FdListener::flags() const throw() { return _flags; } void FdListener::setFlags(int flags) throw() { _flags = flags; } void FdListener::onRead() { } void FdListener::onWrite() { } void FdListener::onError() { } // our internal wakeup listener class class WakeupListener: public FdListener { public: WakeupListener(int handle) : FdListener(handle, FdListener::Read) { } protected: void onRead() { // read data from pipe .. we dont want to get signaled forever ... char tmp[256]; ::read(fd(), tmp, sizeof(tmp)); } }; FdListenerThread* FdListenerThread::_theThread = 0; FdListenerThread::FdListenerThread() throw(SystemError) : Thread(true), _shouldExit(false) { // we use a pipe for wakeup signaling ... int ret = ::pipe(_wakeupPipe); if(ret == -1) throw SystemError(errno, "Could not create wakeup pipe", P_SOURCEINFO); ::fcntl(_wakeupPipe[0], F_SETFL, O_NONBLOCK); _wakeupListener = new WakeupListener(_wakeupPipe[0]); _listeners.insert(_wakeupListener); } FdListenerThread::~FdListenerThread() throw() { delete _wakeupListener; ::close(_wakeupPipe[0]); ::close(_wakeupPipe[1]); } void FdListenerThread::addListener(FdListener* l) { CriticalSection::ScopedLock lck(_listenersCs); _listeners.insert(l); wakeup(); } void FdListenerThread::removeListener(FdListener* l) { CriticalSection::ScopedLock lck(_listenersCs); _listeners.erase(l); wakeup(); } void FdListenerThread::stop() { _shouldExit = true; wakeup(); } void FdListenerThread::wakeup() { ::write(_wakeupPipe[1], "W", 1); } FdListenerThread& FdListenerThread::instance() { static CriticalSection cs; CriticalSection::ScopedLock lck(cs); if(!_theThread) { _theThread = new FdListenerThread(); _theThread->start(); } return *_theThread; } int populate_fd_sets(fd_set* read_fds, fd_set* write_fds, fd_set* error_fds, FdListenerThread::ListenerSet& l) { int highest_fd = 0; int num_read_fds = 0, num_write_fds = 0, num_error_fds = 0; FD_ZERO(read_fds); FD_ZERO(write_fds); FD_ZERO(error_fds); for(FdListenerThread::ListenerSet::const_iterator i = l.begin(); i != l.end(); ++i) { FdListener* listener = *i; int fd = listener->fd(); int lflags = listener->flags(); if(lflags & FdListener::Read) { FD_SET(fd, read_fds); ++num_read_fds; if(fd > highest_fd) highest_fd = fd; } if(lflags & FdListener::Write) { FD_SET(fd, write_fds); ++num_write_fds; if(fd > highest_fd) highest_fd = fd; } if(lflags & FdListener::Error) { FD_SET(fd, error_fds); ++num_error_fds; if(fd > highest_fd) highest_fd = fd; } } return highest_fd; } int FdListenerThread::main() { fd_set read_fds, write_fds, error_fds; struct timeval timeout; unsigned int timeout_ms = 0; while(!_shouldExit) { int highest_fd; { CriticalSection::ScopedLock lck(_listenersCs); highest_fd = populate_fd_sets(&read_fds, &write_fds, &error_fds, _listeners); } Private::get_timeout(&timeout, timeout_ms, Private::TIMEOUT_RELATIVE); int ret = ::select(highest_fd + 1, &read_fds, &write_fds, &error_fds, &timeout); if(ret == -1) { //@@fixme ... we don't want to throw from Thread::main() !!! throw SystemError(errno, "Could not select() for events", P_SOURCEINFO); } else if(ret) { // i think we can hold the lock when dispatching the events ... CriticalSection::ScopedLock lck(_listenersCs); for(ListenerSet::const_iterator i = _listeners.begin(); i != _listeners.end(); ++i) { FdListener* l = *i; int fd = l->fd(); int flags = l->flags(); if(flags & FdListener::Read && FD_ISSET(fd, &read_fds)) { flags &= ~FdListener::Read; l->onRead(); } if(flags & FdListener::Write && FD_ISSET(fd, &write_fds)) { flags &= ~FdListener::Write; l->onWrite(); } if(flags & FdListener::Error && FD_ISSET(fd, &error_fds)) { flags &= ~FdListener::Error; l->onError(); } if(flags != l->flags()) l->setFlags(flags); } } } delete this; return 0; } } // !namespace System } // !namespace P Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/Makefile.am,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- Makefile.am 31 Jan 2005 11:19:38 -0000 1.12 +++ Makefile.am 7 Feb 2005 18:41:07 -0000 1.13 @@ -55,12 +55,14 @@ if WITH_POSIX_IO IO_Sources = IOHandle.posix.cpp Pipe.posix.cpp File.posix.cpp \ - FileInfo.posix.cpp Directory.posix.cpp Process.posix.cpp + FileInfo.posix.cpp Directory.posix.cpp Process.posix.cpp \ + FdListener.posix.cpp endif if WITH_WIN32_IO IO_Sources = IOHandle.win32.cpp Pipe.win32.cpp File.win32.cpp \ - FileInfo.win32.cpp Directory.win32.cpp Process.win32.cpp + FileInfo.win32.cpp Directory.win32.cpp Process.win32.cpp \ + FdListener.win32.cpp endif if WITH_POSIX_TIME @@ -73,8 +75,6 @@ System_Sources = CdRomDevice.linux.cpp -#EventLoop_Sources = EventLoop.select.cpp - EXTRA_DIST = CriticalSection.generic.cpp CriticalSection.win32.cpp \ Mutex.solaris.cpp Mutex.posix.cpp Mutex.win32.cpp SharedMemory.sysv.cpp \ SharedMemory.posix.cpp SharedMemory.win32.cpp @@ -91,8 +91,7 @@ $(Semaphore_Sources) $(SharedMem_Sources) $(SharedLib_Sources) \ SharedLib.common.cpp FileInfo.common.cpp ProcessIO.cpp Process.common.cpp \ $(IO_Sources) File.common.cpp Pipe.common.cpp StorageDevice.common.cpp \ - $(Time_Sources) PathFinder.cpp $(System_Sources) -# EventLoop.common.cpp $(EventLoop_Sources) + $(Time_Sources) PathFinder.cpp $(System_Sources) EventQueue.cpp libpclasses_system_la_LDFLAGS = -no-undefined --- NEW FILE: FdListener.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_FdListener_h #define P_System_FdListener_h #include "pclasses/System/Thread.h" #include "pclasses/System/CriticalSection.h" #include "pclasses/System/SystemError.h" #include <set> namespace P { namespace System { class PSYSTEM_EXPORT FdListener { public: friend class FdListenerThread; enum Flags { Read = 0x01, Write = 0x02, Error = 0x04 }; FdListener(int fd, int flags); virtual ~FdListener(); int fd() const throw(); int flags() const throw(); void setFlags(int flags) throw(); protected: virtual void onRead(); virtual void onWrite(); virtual void onError(); private: int _fd; int _flags; }; class PSYSTEM_EXPORT FdListenerThread: private Thread { public: typedef std::set<FdListener*> ListenerSet; void addListener(FdListener* l); void removeListener(FdListener* l); void wakeup(); void stop(); static FdListenerThread& instance(); private: FdListenerThread() throw(SystemError); ~FdListenerThread() throw(); int main(); volatile bool _shouldExit; int _wakeupPipe[2]; FdListener* _wakeupListener; ListenerSet _listeners; CriticalSection _listenersCs; static FdListenerThread* _theThread; }; } // !namespace System } // !namespace P #endif --- NEW FILE: EventQueue.cpp --- /*************************************************************************** * 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. * ***************************************************************************/ #include "pclasses/System/EventQueue.h" #include <set> namespace P { namespace System { Event::Event(void* sender, unsigned int id) : _sender(sender), _id(id) { } Event::~Event() { } void* Event::sender() const throw() { return _sender; } unsigned int Event::id() const throw() { return _id; } EventListener::EventListener(void* sender) : _eventQueue(EventQueue::instance()), _sender(sender) { _eventQueue.addListener(this); } EventListener::EventListener(EventQueue& evq, void* sender) : _eventQueue(evq), _sender(sender) { _eventQueue.addListener(this); } EventListener::~EventListener() { _eventQueue.removeListener(this); } EventQueue& EventListener::eventQueue() const throw() { return _eventQueue; } void* EventListener::sender() const throw() { return _sender; } ThreadKey<EventQueue> EventQueue::_theQueues; EventQueue::EventQueue() : _eventQMutex(), _eventQCond(_eventQMutex) { } EventQueue::~EventQueue() { } void EventQueue::post(const Event& ev) { Mutex::ScopedLock lck(_eventQMutex); _eventQueue.push(ev); _eventQCond.signal(); } void EventQueue::wait(Event& ev) { Mutex::ScopedLock lck(_eventQMutex); while(_eventQueue.empty()) _eventQCond.wait(lck); ev = _eventQueue.front(); _eventQueue.pop(); } bool EventQueue::tryWait(Event& ev, unsigned int timeout) { Mutex::ScopedLock lck(_eventQMutex); if(_eventQueue.empty()) { if(!_eventQCond.tryWait(lck, timeout) || _eventQueue.empty()) return false; } ev = _eventQueue.front(); _eventQueue.pop(); return true; } void EventQueue::dispatch(const Event& ev) { // we should call the EventListener's without held mutex lock, since a // signaled EventListener may modify our list of listeners. std::set<EventListener*> _dispatchers; // we need exclusive access to the multimap ... _listenersMutex.lock(); std::pair<ListenerMap::iterator, ListenerMap::iterator> p = _listeners.equal_range(ev.sender()); // copy the EventListeners that should be notified. while(p.first != p.second) { EventListener* l = (*p.first).second; _dispatchers.insert(l); ++p.first; } // unlock the mutex _listenersMutex.unlock(); // now notify all EventListener's without held lock std::set<EventListener*>::iterator i = _dispatchers.begin(); while(i != _dispatchers.end()) { (*i)->signaled(ev); ++i; } } void EventQueue::addListener(EventListener* l) { Mutex::ScopedLock lck(_listenersMutex); _listeners.insert(std::make_pair(l->sender(), l)); } void EventQueue::removeListener(EventListener* l) { Mutex::ScopedLock lck(_listenersMutex); std::pair<ListenerMap::iterator, ListenerMap::iterator> p = _listeners.equal_range(l->sender()); // the EventListener may have been added multiple times. // only remove the first one ... while(p.first != p.second) { if((*p.first).second == l) { _listeners.erase(p.first); break; } ++p.first; } } EventQueue& EventQueue::instance() { // we have one EventQueue per thread ... EventQueue* q = _theQueues; if(!q) { q = new EventQueue(); _theQueues = q; } return *q; } } // !namespace System } // !namespace P |
From: Christian P. <cp...@us...> - 2005-02-07 18:29:28
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16689/src/System Modified Files: Condition.posix.cpp Mutex.posix.cpp Log Message: Fixed SIGSEGV in POSIX Conditon implementation. Added note in POSIX Mutex implementation. Index: Mutex.posix.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/Mutex.posix.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- Mutex.posix.cpp 23 Jan 2005 13:28:55 -0000 1.2 +++ Mutex.posix.cpp 7 Feb 2005 18:29:14 -0000 1.3 @@ -37,6 +37,9 @@ pthread_mutex_t mutex; }; +// There is a ugly HACK in Condition.posix.cpp that relies on the layout +// of this structure. When changing this struct don't forget to change it +// in Condition.posix.cpp! struct Mutex::Handle { SharedMemory* shmem; RealHandle* realHandle; Index: Condition.posix.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/Condition.posix.cpp,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- Condition.posix.cpp 22 Dec 2004 17:54:35 -0000 1.1.1.1 +++ Condition.posix.cpp 7 Feb 2005 18:29:14 -0000 1.2 @@ -72,9 +72,20 @@ } /* UGLY HACK STARTS HERE */ +struct RealMutexHandle { + pthread_mutex_t mutex; +}; + +class SharedMemory; + class _MyMutex { public: - struct Handle { pthread_mutex_t mutex; }; + struct Handle { + SharedMemory* shmem; + RealMutexHandle* realHandle; + RealMutexHandle _realHandle; + }; + Handle* _handle; }; @@ -85,7 +96,7 @@ pthread_mutex_t* mutex_get_handle(Mutex::ScopedLock& lck) { - return &(((_MyLock&)lck)._mutex->_handle->mutex); + return &(((_MyLock&)lck)._mutex->_handle->realHandle->mutex); } /* END OF UGLY HACK */ |
From: Christian P. <cp...@us...> - 2005-02-03 00:05:28
|
Update of /cvsroot/pclasses/pclasses2/win32 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11856 Modified Files: System.vcproj Log Message: Added missing files. Index: System.vcproj =================================================================== RCS file: /cvsroot/pclasses/pclasses2/win32/System.vcproj,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- System.vcproj 30 Jan 2005 11:56:49 -0000 1.2 +++ System.vcproj 3 Feb 2005 00:05:17 -0000 1.3 @@ -130,9 +130,18 @@ RelativePath="..\src\System\CriticalSection.win32.cpp"> </File> <File + RelativePath="..\src\System\IOHandle.win32.cpp"> + </File> + <File RelativePath="..\src\System\FileInfo.common.cpp"> </File> <File + RelativePath="..\src\System\File.common.cpp"> + </File> + <File + RelativePath="..\src\System\File.win32.cpp"> + </File> + <File RelativePath="..\src\System\Mutex.win32.cpp"> </File> <File @@ -216,6 +225,9 @@ RelativePath="..\src\System\SharedLibCache.h"> </File> <File + RelativePath="..\src\System\IOHandle.h"> + </File> + <File RelativePath="..\include\pclasses\System\SharedMemory.h"> </File> <File |
From: Christian P. <cp...@us...> - 2005-02-02 15:54:53
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28007/include/pclasses Modified Files: Callback.h CallbackN.sh Log Message: Moved implementation of non-templates to Callback.cpp. Added throw() specifiers to Callback classes. Index: CallbackN.sh =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/CallbackN.sh,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- CallbackN.sh 1 Feb 2005 16:45:17 -0000 1.2 +++ CallbackN.sh 2 Feb 2005 15:54:42 -0000 1.3 @@ -56,7 +56,8 @@ template <$templateargs> class CallbackArgs$num: public CallbackArgs { public: - CallbackArgs$num() : CallbackArgs($num) { } + CallbackArgs$num() throw() + : CallbackArgs($num) { } CallbackArgs* clone() const { return new CallbackArgs$num(*this); } @@ -79,8 +80,8 @@ typedef CallbackArgs$num<$argtypes> Args; struct RetType: public Callback::RetType { _RetT retVal; }; - Callback$num() { } - virtual ~Callback$num() { } + Callback$num() throw() { } + virtual ~Callback$num() throw() { } Callback::RetType exec(const CallbackArgs& args) const { @@ -101,8 +102,8 @@ typedef CallbackArgs$num<$argtypes> Args; struct RetType: public Callback::RetType { }; - Callback$num() { } - virtual ~Callback$num() { } + Callback$num() throw() { } + virtual ~Callback$num() throw() { } Callback::RetType exec(const CallbackArgs& args) const { @@ -123,7 +124,7 @@ public: typedef _RetT (*FuncPtr)($argtypes); - Function$num(FuncPtr ptr) + Function$num(FuncPtr ptr) throw() : _funcPtr(ptr) { } _RetT exec($argtypeswname) const @@ -132,7 +133,7 @@ Callback$num<_RetT, $argtypes>* clone() const { return new Function$num(*this); } - bool operator==(const Function$num& f) const + bool operator==(const Function$num& f) const throw() { return _funcPtr == f._funcPtr; } private: @@ -145,7 +146,7 @@ public: typedef void (*FuncPtr)($argtypes); - Function$num(FuncPtr ptr) + Function$num(FuncPtr ptr) throw() : _funcPtr(ptr) { } void exec($argtypeswname) const @@ -154,7 +155,7 @@ Callback$num<void, $argtypes>* clone() const { return new Function$num(*this); } - bool operator==(const Function$num& f) const + bool operator==(const Function$num& f) const throw() { return _funcPtr == f._funcPtr; } private: @@ -163,7 +164,7 @@ //! Returns a function-callback object template <typename _RetT, $templateargs> -Function$num<_RetT, $argtypes> make_function(_RetT (*ptr)($argtypes)) +Function$num<_RetT, $argtypes> make_function(_RetT (*ptr)($argtypes)) throw() { return Function$num<_RetT, $argtypes>(ptr); } /* ---------- Method1 ------------ */ @@ -174,7 +175,7 @@ public: typedef _RetT (_ObjT::*FuncPtr)($argtypes); - Method$num(_ObjT* obj, FuncPtr ptr) + Method$num(_ObjT* obj, FuncPtr ptr) throw() : _obj(obj), _funcPtr(ptr) { } _RetT exec($argtypeswname) const @@ -183,7 +184,7 @@ Callback$num<_RetT, $argtypes>* clone() const { return new Method$num(*this); } - bool operator==(const Method$num& f) const + bool operator==(const Method$num& f) const throw() { return _obj == f._obj && _funcPtr == f._funcPtr; } private: @@ -197,7 +198,7 @@ public: typedef void (_ObjT::*FuncPtr)($argtypes); - Method$num(_ObjT* obj, FuncPtr ptr) + Method$num(_ObjT* obj, FuncPtr ptr) throw() : _obj(obj), _funcPtr(ptr) { } void exec($argtypeswname) const @@ -206,7 +207,7 @@ Callback$num<void, $argtypes>* clone() const { return new Method$num(*this); } - bool operator==(const Method$num& f) const + bool operator==(const Method$num& f) const throw() { return _obj == f._obj && _funcPtr == f._funcPtr; } private: @@ -216,7 +217,8 @@ //! Returns a method-callback object template <typename _RetT, class _ObjT, $templateargs> -Method$num<_RetT, _ObjT, $argtypes> make_method(_ObjT* obj, _RetT (_ObjT::*ptr)($argtypes)) +Method$num<_RetT, _ObjT, $argtypes> +make_method(_ObjT* obj, _RetT (_ObjT::*ptr)($argtypes)) throw() { return Method$num<_RetT, _ObjT, $argtypes>(obj, ptr); } } // !namespace P Index: Callback.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Callback.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- Callback.h 1 Feb 2005 16:45:17 -0000 1.6 +++ Callback.h 2 Feb 2005 15:54:42 -0000 1.7 @@ -27,11 +27,10 @@ class CallbackArgs { public: - CallbackArgs(int numArgs) : _numArgs(numArgs) { } - virtual ~CallbackArgs() { } + CallbackArgs(int numArgs) throw(); + virtual ~CallbackArgs() throw(); - int numArgs() const throw() - { return _numArgs; } + int numArgs() const throw(); virtual CallbackArgs* clone() const = 0; @@ -44,8 +43,8 @@ public: struct RetType { }; - Callback() { } - virtual ~Callback() { } + Callback() throw(); + virtual ~Callback() throw(); virtual Callback* clone() const = 0; virtual RetType exec(const CallbackArgs& args) const = 0; @@ -56,12 +55,12 @@ //! Callback arguments with no arguments class CallbackArgs0: public CallbackArgs { public: - CallbackArgs0() : CallbackArgs(0) { } - - CallbackArgs* clone() const - { return new CallbackArgs0(*this); } + CallbackArgs0() throw(); + CallbackArgs* clone() const; }; +CallbackArgs0 make_args(); + //! Callback base class with no arguments template <typename _RetT> class Callback0: public Callback { @@ -69,8 +68,8 @@ typedef CallbackArgs0 Args; struct RetType: public Callback::RetType { _RetT retVal; }; - Callback0() { } - virtual ~Callback0() { } + Callback0() throw() { } + virtual ~Callback0() throw() { } Callback::RetType exec(const CallbackArgs& args) const { @@ -92,8 +91,8 @@ typedef CallbackArgs0 Args; struct RetType: public Callback::RetType { }; - Callback0() { } - virtual ~Callback0() { } + Callback0() throw() { } + virtual ~Callback0() throw() { } Callback::RetType exec(const CallbackArgs& args) const { @@ -115,7 +114,7 @@ public: typedef _RetT (*FuncPtr)(); - Function0(FuncPtr ptr) + Function0(FuncPtr ptr) throw() : _funcPtr(ptr) { } _RetT exec() const @@ -124,7 +123,7 @@ Callback0<_RetT>* clone() const { return new Function0(*this); } - bool operator==(const Function0& f) const + bool operator==(const Function0& f) const throw() { return _funcPtr == f._funcPtr; } private: @@ -137,7 +136,7 @@ public: typedef void (*FuncPtr)(); - Function0(FuncPtr ptr) + Function0(FuncPtr ptr) throw() : _funcPtr(ptr) { } void exec() const @@ -146,7 +145,7 @@ Callback0<void>* clone() const { return new Function0(*this); } - bool operator==(const Function0& f) const + bool operator==(const Function0& f) const throw() { return _funcPtr == f._funcPtr; } private: @@ -155,7 +154,7 @@ //! Returns a function-callback object template <typename _RetT> -Function0<_RetT> make_function(_RetT (*ptr)()) +Function0<_RetT> make_function(_RetT (*ptr)()) throw() { return Function0<_RetT>(ptr); } /* ----------------- Method0 ------------------ */ @@ -166,7 +165,7 @@ public: typedef _RetT (ObjT::*FuncPtr)(); - Method0(ObjT* obj, FuncPtr ptr) + Method0(ObjT* obj, FuncPtr ptr) throw() : _obj(obj), _funcPtr(ptr) { } _RetT exec() const @@ -175,7 +174,7 @@ Callback0<_RetT>* clone() const { return new Method0(*this); } - bool operator==(const Method0& f) const + bool operator==(const Method0& f) const throw() { return _obj == f._obj && _funcPtr == f._funcPtr; } private: @@ -189,7 +188,7 @@ public: typedef void (ObjT::*FuncPtr)(); - Method0(ObjT* obj, FuncPtr ptr) + Method0(ObjT* obj, FuncPtr ptr) throw() : _obj(obj), _funcPtr(ptr) { } void exec() const @@ -198,7 +197,7 @@ Callback0<void>* clone() const { return new Method0(*this); } - bool operator==(const Method0& f) const + bool operator==(const Method0& f) const throw() { return _obj == f._obj && _funcPtr == f._funcPtr; } private: @@ -208,7 +207,7 @@ //! Returns a method-callback object template <typename _RetT, class _ObjT> -Method0<_RetT,_ObjT> make_method(_ObjT* obj, _RetT (_ObjT::*ptr)()) +Method0<_RetT,_ObjT> make_method(_ObjT* obj, _RetT (_ObjT::*ptr)()) throw() { return Method0<_RetT,_ObjT>(obj, ptr); } } // !namespace P |
From: Christian P. <cp...@us...> - 2005-02-02 15:54:52
|
Update of /cvsroot/pclasses/pclasses2/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28007/src Added Files: Callback.cpp Log Message: Moved implementation of non-templates to Callback.cpp. Added throw() specifiers to Callback classes. --- NEW FILE: Callback.cpp --- /*************************************************************************** * 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. * ***************************************************************************/ #include "pclasses/Callback.h" namespace P { CallbackArgs::CallbackArgs(int numArgs) throw() : _numArgs(numArgs) { } CallbackArgs::~CallbackArgs() throw() { } int CallbackArgs::numArgs() const throw() { return _numArgs; } Callback::Callback() throw() { } Callback::~Callback() throw() { } CallbackArgs0::CallbackArgs0() throw() : CallbackArgs(0) { } CallbackArgs* CallbackArgs0::clone() const { return new CallbackArgs0(*this); } CallbackArgs0 make_args() { return CallbackArgs0(); } } // !namespace P |
From: Christian P. <cp...@us...> - 2005-02-01 16:55:58
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18125/src/System Modified Files: Thread.common.cpp Log Message: Catch exceptions in SpawnedThread and ignore them. Index: Thread.common.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/Thread.common.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- Thread.common.cpp 28 Jan 2005 17:36:12 -0000 1.2 +++ Thread.common.cpp 1 Feb 2005 16:55:44 -0000 1.3 @@ -28,23 +28,32 @@ class SpawnedThread: public Thread { public: SpawnedThread(const Callback& cb, const CallbackArgs& args, Semaphore* sem) - : Thread(true), _callback(cb.clone()), _args(&args), _sem(sem) + : Thread(true), _callback(cb.clone()), _args(args.clone()), _sem(sem) { } protected: int main() { - if(_sem) - _sem->post(); - - _callback->exec(*_args); + Semaphore* sem = _sem; + if(sem) + sem->post(); - if(_sem) - _sem->post(); + try + { + _callback->exec(*_args); + } + catch(...) + { + } delete _callback; + delete _args; delete this; + + if(sem) + sem->post(); + return 0; } |
From: Christian P. <cp...@us...> - 2005-02-01 16:46:44
|
Update of /cvsroot/pclasses/pclasses2/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15530/test Modified Files: Makefile.am Log Message: Added -lpclasses to SignalTest. Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/test/Makefile.am,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- Makefile.am 23 Jan 2005 13:31:54 -0000 1.6 +++ Makefile.am 1 Feb 2005 16:46:35 -0000 1.7 @@ -36,3 +36,4 @@ $(top_builddir)/src/IO/libpclasses_io.la\ $(top_builddir)/src/App/libpclasses_app.la\ $(top_builddir)/src/libpclasses.la +SignalTest_LDADD = $(top_builddir)/src/libpclasses.la |
From: Christian P. <cp...@us...> - 2005-02-01 16:45:30
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15254/include/pclasses Modified Files: Callback.h CallbackN.sh Log Message: Added numArgs() and virtual ctor to CallbackArgs. Index: CallbackN.sh =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/CallbackN.sh,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- CallbackN.sh 28 Jan 2005 17:11:00 -0000 1.1 +++ CallbackN.sh 1 Feb 2005 16:45:17 -0000 1.2 @@ -1,3 +1,4 @@ +#! /bin/bash #/*************************************************************************** # * Copyright (C) 2005 by Christian Prochnow * # * cp...@se... * @@ -19,7 +20,7 @@ # ***************************************************************************/ # -# this shell-script generates code for Signals with n arguments.... +# this shell-script generates code for Callbacks with n arguments.... # generate_callbackN() @@ -47,13 +48,21 @@ callargs="$callargs, a->arg$num" done -cat <<- EOF > "CallbackN$1.h" +cat << EOF > "CallbackN$1.h" namespace P { /* ----------------- Callback1 ------------------ */ template <$templateargs> -struct CallbackArgs$num: CallbackArgs { $structmembers }; +class CallbackArgs$num: public CallbackArgs { + public: + CallbackArgs$num() : CallbackArgs($num) { } + + CallbackArgs* clone() const + { return new CallbackArgs$num(*this); } + + $structmembers +}; template <$templateargs> CallbackArgs$num<$argtypes> make_args($argtypeswname) @@ -76,8 +85,8 @@ Callback::RetType exec(const CallbackArgs& args) const { RetType ret; - const Args* a = static_cast<const Args*>(&args); - if(!a) throw; + const Args* a = dynamic_cast<const Args*>(&args); + if(!a) throw LogicError("Invalid argument", P_SOURCEINFO); ret.retVal = exec($callargs); return ret; } @@ -97,8 +106,8 @@ Callback::RetType exec(const CallbackArgs& args) const { - const Args* a = static_cast<const Args*>(&args); - if(!a) throw; + const Args* a = dynamic_cast<const Args*>(&args); + if(!a) throw LogicError("Invalid arguments", P_SOURCEINFO); exec($callargs); return RetType(); } Index: Callback.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Callback.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- Callback.h 28 Jan 2005 17:11:57 -0000 1.5 +++ Callback.h 1 Feb 2005 16:45:17 -0000 1.6 @@ -21,9 +21,23 @@ #ifndef P_Callback_h #define P_Callback_h +#include <pclasses/Exception.h> + namespace P { -struct CallbackArgs { }; +class CallbackArgs { + public: + CallbackArgs(int numArgs) : _numArgs(numArgs) { } + virtual ~CallbackArgs() { } + + int numArgs() const throw() + { return _numArgs; } + + virtual CallbackArgs* clone() const = 0; + + private: + int _numArgs; +}; //! Callback base class class Callback { @@ -40,7 +54,13 @@ /* ----------------- Callback0 ------------------ */ //! Callback arguments with no arguments -struct CallbackArgs0: CallbackArgs { }; +class CallbackArgs0: public CallbackArgs { + public: + CallbackArgs0() : CallbackArgs(0) { } + + CallbackArgs* clone() const + { return new CallbackArgs0(*this); } +}; //! Callback base class with no arguments template <typename _RetT> @@ -54,6 +74,9 @@ Callback::RetType exec(const CallbackArgs& args) const { + if(dynamic_cast<const Args*>(&args) == 0) + throw LogicError("Invalid arguments", P_SOURCEINFO); + RetType ret; ret.retVal = exec(); return ret; @@ -74,6 +97,9 @@ Callback::RetType exec(const CallbackArgs& args) const { + if(dynamic_cast<const Args*>(&args) == 0) + throw LogicError("Invalid arguments", P_SOURCEINFO); + exec(); return RetType(); } |
From: Christian P. <cp...@us...> - 2005-02-01 00:14:43
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12015/src/System Modified Files: CdRomDevice.linux.cpp Log Message: Added size and startMSF/endMSF to CdRomDevice::Track. Added play(const Track& from, const Track& to). Index: CdRomDevice.linux.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/CdRomDevice.linux.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- CdRomDevice.linux.cpp 31 Jan 2005 11:08:47 -0000 1.1 +++ CdRomDevice.linux.cpp 1 Feb 2005 00:14:34 -0000 1.2 @@ -121,9 +121,10 @@ throw IO::IOError(errno, "ioctl error on device", P_SOURCEINFO); } -void CdRomDevice::play(const Track& trk) throw(IO::IOError) +void CdRomDevice::play(const Track& from, const Track& to) throw(IO::IOError) { - + play(from.startMinute(), from.startSecond(), from.startFrame(), + to.endMinute(), to.endSecond(), to.endFrame()); } void CdRomDevice::stop() throw(IO::IOError) @@ -188,9 +189,10 @@ unsigned int i = 0; for(i = 1; i < ti; ++i); { + int length = toc_entries[i].cdte_addr.lba - toc_entries[i-1].cdte_addr.lba; toc.push_back(Track(i, toc_entries[i-1].cdte_ctrl & CDROM_DATA_TRACK ? Track::Data : Track::Audio, - toc_entries[i-1].cdte_addr.lba)); + toc_entries[i-1].cdte_addr.lba, length)); } return toc; @@ -198,6 +200,10 @@ void lba2msf(size_t lba, uint8_t *msf) { +#ifndef CD_MSF_OFFSET +# define CD_MSF_OFFSET 150 +#endif + lba += CD_MSF_OFFSET; // msf addressing starts a lba=150 lba &= 0xffffff; // only 24bit ... msf[0] = lba / (CD_SECS*CD_FRAMES); @@ -206,10 +212,11 @@ msf[2] = lba % CD_FRAMES; } -CdRomDevice::Track::Track(unsigned int num, Type type, size_t lba) -: _num(num), _type(type), _lba(lba) +CdRomDevice::Track::Track(unsigned int num, Type type, size_t lba, size_t size) +: _num(num), _type(type), _lba(lba), _size(size) { - lba2msf(lba, _msf); + lba2msf(lba, _startMsf); + lba2msf(lba + size, _endMsf); } CdRomDevice::Track::~Track() @@ -232,19 +239,39 @@ return _lba; } -uint8_t CdRomDevice::Track::minute() const throw() +size_t CdRomDevice::Track::size() const throw() { - return _msf[0]; + return _size; } -uint8_t CdRomDevice::Track::second() const throw() +uint8_t CdRomDevice::Track::startMinute() const throw() { - return _msf[1]; + return _startMsf[0]; } -uint8_t CdRomDevice::Track::frame() const throw() +uint8_t CdRomDevice::Track::startSecond() const throw() { - return _msf[2]; + return _startMsf[1]; +} + +uint8_t CdRomDevice::Track::startFrame() const throw() +{ + return _startMsf[2]; +} + +uint8_t CdRomDevice::Track::endMinute() const throw() +{ + return _endMsf[0]; +} + +uint8_t CdRomDevice::Track::endSecond() const throw() +{ + return _endMsf[1]; +} + +uint8_t CdRomDevice::Track::endFrame() const throw() +{ + return _endMsf[2]; } } // !namespace System |
From: Christian P. <cp...@us...> - 2005-02-01 00:14:43
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12015/include/pclasses/System Modified Files: CdRomDevice.h Log Message: Added size and startMSF/endMSF to CdRomDevice::Track. Added play(const Track& from, const Track& to). Index: CdRomDevice.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/System/CdRomDevice.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- CdRomDevice.h 31 Jan 2005 11:08:43 -0000 1.1 +++ CdRomDevice.h 1 Feb 2005 00:14:34 -0000 1.2 @@ -53,7 +53,7 @@ //! TOC-Entry class Track; - //! List of TOC-Entries + //! Track-list (the TOC) typedef std::list<Track> TrackList; CdRomDevice(const std::string& path, AccessMode access, @@ -65,47 +65,69 @@ DiscStatus discStatus() throw(IO::IOError); + //! Eject media void eject() throw(IO::IOError); + //! Read TOC (track-list) TrackList readTOC() throw(IO::IOError); + //! Start audio playback void play(uint8_t startMin, uint8_t startSec, uint8_t startFrame, uint8_t endMin, uint8_t endSec, uint8_t endFrame) throw(IO::IOError); - void play(const Track& trk) throw(IO::IOError); + //! Play audio tracks + void play(const Track& from, const Track& to) throw(IO::IOError); + //! Stop audio playback void stop() throw(IO::IOError); + + //! Pause audio playback void pause() throw(IO::IOError); + + //! Resume audio playback void resume() throw(IO::IOError); }; +//! CD-ROM Trackinfo class PSYSTEM_EXPORT CdRomDevice::Track { public: + //! Type of Track enum Type { Data, Audio }; Track(unsigned int num, Type type, - size_t lba); + size_t lba, size_t size); ~Track(); + //! Returns the track-number unsigned int num() const throw(); + + //! Returns the track-type Type type() const throw(); + //! Returns the LBA of this track size_t lba() const throw(); + size_t size() const throw(); + + uint8_t startMinute() const throw(); + uint8_t startSecond() const throw(); + uint8_t startFrame() const throw(); - uint8_t minute() const throw(); - uint8_t second() const throw(); - uint8_t frame() const throw(); + uint8_t endMinute() const throw(); + uint8_t endSecond() const throw(); + uint8_t endFrame() const throw(); private: unsigned int _num; Type _type; size_t _lba; - uint8_t _msf[3]; + size_t _size; + uint8_t _startMsf[3]; + uint8_t _endMsf[3]; }; } // !namespace System |
From: Christian P. <cp...@us...> - 2005-01-31 11:21:26
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Plugin In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8078/include/pclasses/Plugin Modified Files: Plugin.h Log Message: Added /usr/local/lib/pclasses to PluginManager. Index: Plugin.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Plugin/Plugin.h,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- Plugin.h 17 Jan 2005 22:01:54 -0000 1.14 +++ Plugin.h 31 Jan 2005 11:21:11 -0000 1.15 @@ -250,6 +250,8 @@ #endif #ifdef PCLASSES_LIB_DIR this->m_path.addPath( PCLASSES_LIB_DIR ); +#else + this->m_path.addPath("/usr/local/lib/pclasses"); #endif this->m_path.addExtension(std::string(".")+System::SharedLib::extension()); } |
From: Christian P. <cp...@us...> - 2005-01-31 11:19:48
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7790/src/System Modified Files: Makefile.am Log Message: Added CdRomDevice.linux.cpp Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/Makefile.am,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- Makefile.am 30 Jan 2005 17:12:55 -0000 1.11 +++ Makefile.am 31 Jan 2005 11:19:38 -0000 1.12 @@ -71,6 +71,8 @@ Time_Sources = SystemClock.win32.cpp endif +System_Sources = CdRomDevice.linux.cpp + #EventLoop_Sources = EventLoop.select.cpp EXTRA_DIST = CriticalSection.generic.cpp CriticalSection.win32.cpp \ @@ -89,7 +91,7 @@ $(Semaphore_Sources) $(SharedMem_Sources) $(SharedLib_Sources) \ SharedLib.common.cpp FileInfo.common.cpp ProcessIO.cpp Process.common.cpp \ $(IO_Sources) File.common.cpp Pipe.common.cpp StorageDevice.common.cpp \ - $(Time_Sources) PathFinder.cpp + $(Time_Sources) PathFinder.cpp $(System_Sources) # EventLoop.common.cpp $(EventLoop_Sources) libpclasses_system_la_LDFLAGS = -no-undefined |
From: Christian P. <cp...@us...> - 2005-01-31 11:19:21
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7731/include/pclasses/System Modified Files: StorageDevice.h Log Message: Added eject() to StorageDevice. Index: StorageDevice.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/System/StorageDevice.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- StorageDevice.h 30 Jan 2005 17:16:05 -0000 1.1 +++ StorageDevice.h 31 Jan 2005 11:19:11 -0000 1.2 @@ -41,6 +41,9 @@ void open(const std::string& path, AccessMode access, ShareMode share) throw(IO::IOError); + //! Eject media + virtual void eject() throw(IO::IOError) = 0; + protected: void _close() throw(IO::IOError); size_t _read(char* buffer, size_t count) throw(IO::IOError); |
From: Christian P. <cp...@us...> - 2005-01-31 11:09:07
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5290/src/System Added Files: CdRomDevice.linux.cpp Log Message: Added CdRomDevice. --- NEW FILE: CdRomDevice.linux.cpp --- /*************************************************************************** * 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. * ***************************************************************************/ #include "pclasses/System/CdRomDevice.h" #include <sys/ioctl.h> #include <linux/cdrom.h> #include <errno.h> namespace P { namespace System { CdRomDevice::CdRomDevice(const std::string& path, AccessMode access, ShareMode share) throw(IO::IOError) : StorageDevice(path, access, share) { } CdRomDevice::~CdRomDevice() throw() { } CdRomDevice::DriveStatus CdRomDevice::driveStatus() throw(IO::IOError) { int ret = ::ioctl((int)handle(), CDROM_DRIVE_STATUS, CDSL_CURRENT); if(ret == -1) throw IO::IOError(errno, "ioctl error on device", P_SOURCEINFO); DriveStatus status; switch(ret) { case CDS_NO_DISC: status = NoDisc; break; case CDS_TRAY_OPEN: status = TrayOpen; break; case CDS_DRIVE_NOT_READY: status = DriveNotReady; break; case CDS_DISC_OK: status = DiscOk; break; case CDS_NO_INFO: /* fall through */ default: status = NoInfo; } return status; } CdRomDevice::DiscStatus CdRomDevice::discStatus() throw(IO::IOError) { int ret = ::ioctl((int)handle(), CDROM_DISC_STATUS, CDSL_CURRENT); if(ret == -1) throw IO::IOError(errno, "ioctl error on device", P_SOURCEINFO); DiscStatus status; switch(ret) { case CDS_AUDIO: status = DiscAudio; break; case CDS_DATA_1: status = DiscData1; break; case CDS_DATA_2: status = DiscData2; break; case CDS_XA_2_1: status = DiscXA21; break; case CDS_XA_2_2: status = DiscXA22; break; case CDS_MIXED: status = DiscMixed; break; case CDS_NO_DISC: case CDS_NO_INFO: /* fall through */ default: status = DiscUnknown; } return status; } void CdRomDevice::play(uint8_t startMin, uint8_t startSec, uint8_t startFrame, uint8_t endMin, uint8_t endSec, uint8_t endFrame) throw(IO::IOError) { struct cdrom_msf msf; msf.cdmsf_min0 = startMin; msf.cdmsf_sec0 = startSec; msf.cdmsf_frame0 = startFrame; msf.cdmsf_min1 = endMin; msf.cdmsf_sec1 = endSec; msf.cdmsf_frame1 = endFrame; int ret = ::ioctl((int)handle(), CDROMPLAYMSF, (void*)&msf); if(ret == -1) throw IO::IOError(errno, "ioctl error on device", P_SOURCEINFO); } void CdRomDevice::play(const Track& trk) throw(IO::IOError) { } void CdRomDevice::stop() throw(IO::IOError) { int ret = ::ioctl((int)handle(), CDROMSTOP); if(ret == -1) throw IO::IOError(errno, "ioctl error on device", P_SOURCEINFO); } void CdRomDevice::eject() throw(IO::IOError) { int ret = ::ioctl((int)handle(), CDROMEJECT); if(ret == -1) throw IO::IOError(errno, "ioctl error on device", P_SOURCEINFO); } void CdRomDevice::pause() throw(IO::IOError) { int ret = ::ioctl((int)handle(), CDROMPAUSE); if(ret == -1) throw IO::IOError(errno, "ioctl error on device", P_SOURCEINFO); } void CdRomDevice::resume() throw(IO::IOError) { int ret = ::ioctl((int)handle(), CDROMRESUME); if(ret == -1) throw IO::IOError(errno, "ioctl error on device", P_SOURCEINFO); } CdRomDevice::TrackList CdRomDevice::readTOC() throw(IO::IOError) { struct cdrom_tochdr hdr; int ret = ::ioctl((int)handle(), CDROMREADTOCHDR, (void*)&hdr); if(ret == -1) throw IO::IOError(errno, "ioctl error on device", P_SOURCEINFO); unsigned int num_tracks = hdr.cdth_trk1; struct cdrom_tocentry* toc_entries = new cdrom_tocentry[num_tracks + 1]; unsigned int ti = 0; TrackList toc; for(int track=hdr.cdth_trk0; track <= hdr.cdth_trk1; ++track) { toc_entries[ti].cdte_track = track; toc_entries[ti].cdte_format = CDROM_LBA; ret = ::ioctl((int)handle(), CDROMREADTOCENTRY, &toc_entries[ti++]); if(ret == -1) throw IO::IOError(errno, "ioctl error on device", P_SOURCEINFO); } // read lead-out ... toc_entries[ti].cdte_track = CDROM_LEADOUT; toc_entries[ti].cdte_format = CDROM_LBA; ret = ::ioctl((int)handle(), CDROMREADTOCENTRY, &toc_entries[ti++]); if(ret == -1) throw IO::IOError(errno, "ioctl error on device", P_SOURCEINFO); unsigned int i = 0; for(i = 1; i < ti; ++i); { toc.push_back(Track(i, toc_entries[i-1].cdte_ctrl & CDROM_DATA_TRACK ? Track::Data : Track::Audio, toc_entries[i-1].cdte_addr.lba)); } return toc; } void lba2msf(size_t lba, uint8_t *msf) { lba += CD_MSF_OFFSET; // msf addressing starts a lba=150 lba &= 0xffffff; // only 24bit ... msf[0] = lba / (CD_SECS*CD_FRAMES); lba %= CD_SECS*CD_FRAMES; msf[1] = lba / CD_FRAMES; msf[2] = lba % CD_FRAMES; } CdRomDevice::Track::Track(unsigned int num, Type type, size_t lba) : _num(num), _type(type), _lba(lba) { lba2msf(lba, _msf); } CdRomDevice::Track::~Track() { } unsigned int CdRomDevice::Track::num() const throw() { return _num; } CdRomDevice::Track::Type CdRomDevice::Track::type() const throw() { return _type; } size_t CdRomDevice::Track::lba() const throw() { return _lba; } uint8_t CdRomDevice::Track::minute() const throw() { return _msf[0]; } uint8_t CdRomDevice::Track::second() const throw() { return _msf[1]; } uint8_t CdRomDevice::Track::frame() const throw() { return _msf[2]; } } // !namespace System } // !namespace P |
From: Christian P. <cp...@us...> - 2005-01-31 11:09:06
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5290/include/pclasses/System Added Files: CdRomDevice.h Log Message: Added CdRomDevice. --- NEW FILE: CdRomDevice.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_CdRomDevice_h #define P_System_CdRomDevice_h #include <pclasses/Export.h> #include <pclasses/System/StorageDevice.h> #include <list> namespace P { namespace System { //! CD-ROM device class PSYSTEM_EXPORT CdRomDevice: public StorageDevice { public: enum DriveStatus { NoInfo, NoDisc, TrayOpen, DriveNotReady, DiscOk }; enum DiscStatus { DiscUnknown, DiscAudio, DiscData1, DiscData2, DiscXA21, DiscXA22, DiscMixed }; //! TOC-Entry class Track; //! List of TOC-Entries typedef std::list<Track> TrackList; CdRomDevice(const std::string& path, AccessMode access, ShareMode share) throw(IO::IOError); ~CdRomDevice() throw(); DriveStatus driveStatus() throw(IO::IOError); DiscStatus discStatus() throw(IO::IOError); void eject() throw(IO::IOError); TrackList readTOC() throw(IO::IOError); void play(uint8_t startMin, uint8_t startSec, uint8_t startFrame, uint8_t endMin, uint8_t endSec, uint8_t endFrame) throw(IO::IOError); void play(const Track& trk) throw(IO::IOError); void stop() throw(IO::IOError); void pause() throw(IO::IOError); void resume() throw(IO::IOError); }; class PSYSTEM_EXPORT CdRomDevice::Track { public: enum Type { Data, Audio }; Track(unsigned int num, Type type, size_t lba); ~Track(); unsigned int num() const throw(); Type type() const throw(); size_t lba() const throw(); uint8_t minute() const throw(); uint8_t second() const throw(); uint8_t frame() const throw(); private: unsigned int _num; Type _type; size_t _lba; uint8_t _msf[3]; }; } // !namespace System } // !namespace P #endif |
From: Christian P. <cp...@us...> - 2005-01-30 17:17:09
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv513/src/System Added Files: StorageDevice.common.cpp Log Message: Added StorageDevice. --- NEW FILE: StorageDevice.common.cpp --- /*************************************************************************** * 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. * ***************************************************************************/ #include "pclasses/System/StorageDevice.h" #include "IOHandle.h" namespace P { namespace System { StorageDevice::StorageDevice() throw() : _handle(0) { } StorageDevice::StorageDevice(const std::string& path, AccessMode access, ShareMode share) throw(IO::IOError) : _handle(0) { open(path,access,share); } StorageDevice::~StorageDevice() throw() { if(valid()) { try { close(); } catch(...) { } } } void StorageDevice::open(const std::string& str, AccessMode access, ShareMode share) throw(IO::IOError) { if(valid()) close(); _handle = (unsigned long)new IOHandle(str, access, IO::IODevice::OpenFail, share); } void StorageDevice::_close() throw(IO::IOError) { delete (IOHandle*)_handle; _handle = 0; } size_t StorageDevice::_read(char* buffer, size_t count) throw(IO::IOError) { return ((IOHandle*)_handle)->read(buffer, count); } size_t StorageDevice::_peek(char* buffer, size_t count) throw(IO::IOError) { return ((IOHandle*)_handle)->peek(buffer, count); } size_t StorageDevice::_write(const char* buffer, size_t count) throw(IO::IOError) { return ((IOHandle*)_handle)->write(buffer, count); } offset_t StorageDevice::_seek(offset_t offset, SeekMode mode) throw(IO::IOError) { return ((IOHandle*)_handle)->seek(offset, mode); } bool StorageDevice::_isSeekable() const throw() { return ((IOHandle*)_handle)->isSeekable(); } void StorageDevice::_sync() const throw(IO::IOError) { ((IOHandle*)_handle)->sync(); } offset_t StorageDevice::_size() const throw(IO::IOError) { return ((IOHandle*)_handle)->size(); } unsigned long StorageDevice::handle() const throw() { return ((IOHandle*)_handle)->handle(); } } // !namespace System } // !namespace P |
From: Christian P. <cp...@us...> - 2005-01-30 17:16:14
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32751/include/pclasses/System Modified Files: Makefile.am Added Files: StorageDevice.h Log Message: Added StorageDevice. Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/System/Makefile.am,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- Makefile.am 16 Jan 2005 01:59:18 -0000 1.6 +++ Makefile.am 30 Jan 2005 17:16:05 -0000 1.7 @@ -4,4 +4,4 @@ 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 + Directory.h SystemClock.h ProcessIO.h Process.h ThreadKey.h StorageDevice.h --- NEW FILE: StorageDevice.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_StorageDevice_h #define P_System_StorageDevice_h #include <pclasses/Export.h> #include <pclasses/IO/IODevice.h> namespace P { namespace System { //! System Storage device (block device) class PSYSTEM_EXPORT StorageDevice: public IO::IODevice { public: StorageDevice() throw(); StorageDevice(const std::string& path, AccessMode access, ShareMode share) throw(IO::IOError); ~StorageDevice() throw(); void open(const std::string& path, AccessMode access, ShareMode share) throw(IO::IOError); protected: void _close() throw(IO::IOError); size_t _read(char* buffer, size_t count) throw(IO::IOError); size_t _peek(char* buffer, size_t count) throw(IO::IOError); size_t _write(const char* buffer, size_t count) throw(IO::IOError); offset_t _seek(offset_t offset, SeekMode mode) throw(IO::IOError); bool _isSeekable() const throw(); void _sync() const throw(IO::IOError); offset_t _size() const throw(IO::IOError); //! Returns the native O/S handle unsigned long handle() const throw(); private: unsigned long _handle; }; } // !namespace System } // !namespace P #endif |
From: Christian P. <cp...@us...> - 2005-01-30 17:13:04
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31982/src/System Modified Files: Makefile.am Log Message: Added IOHandle.[h|cpp]. Added File.common.cpp, Pipe.common.cpp. Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/Makefile.am,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- Makefile.am 28 Jan 2005 11:36:38 -0000 1.10 +++ Makefile.am 30 Jan 2005 17:12:55 -0000 1.11 @@ -54,11 +54,13 @@ endif if WITH_POSIX_IO -IO_Sources = Pipe.posix.cpp File.posix.cpp FileInfo.posix.cpp Directory.posix.cpp Process.posix.cpp +IO_Sources = IOHandle.posix.cpp Pipe.posix.cpp File.posix.cpp \ + FileInfo.posix.cpp Directory.posix.cpp Process.posix.cpp endif if WITH_WIN32_IO -IO_Sources = Pipe.win32.cpp File.win32.cpp FileInfo.win32.cpp Directory.win32.cpp Process.win32.cpp +IO_Sources = IOHandle.win32.cpp Pipe.win32.cpp File.win32.cpp \ + FileInfo.win32.cpp Directory.win32.cpp Process.win32.cpp endif if WITH_POSIX_TIME @@ -86,7 +88,8 @@ CriticalSection.cpp Mutex.cpp $(Thread_Sources) Thread.common.cpp \ $(Semaphore_Sources) $(SharedMem_Sources) $(SharedLib_Sources) \ SharedLib.common.cpp FileInfo.common.cpp ProcessIO.cpp Process.common.cpp \ - $(IO_Sources) $(Time_Sources) PathFinder.cpp + $(IO_Sources) File.common.cpp Pipe.common.cpp StorageDevice.common.cpp \ + $(Time_Sources) PathFinder.cpp # EventLoop.common.cpp $(EventLoop_Sources) libpclasses_system_la_LDFLAGS = -no-undefined @@ -96,4 +99,4 @@ $(top_builddir)/src/IO/libpclasses_io.la \ $(DL_LIBS) -noinst_HEADERS = timeout.h SharedLibCache.h +noinst_HEADERS = timeout.h SharedLibCache.h IOHandle.h |