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-01-30 17:10:17
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31386/include/pclasses/System Modified Files: Pipe.h Log Message: Added method to retrieve native OS handle. Index: Pipe.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/System/Pipe.h,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- Pipe.h 3 Jan 2005 13:50:44 -0000 1.8 +++ Pipe.h 30 Jan 2005 17:10:07 -0000 1.9 @@ -34,9 +34,7 @@ typedef std::pair<Pipe,Pipe> Pair; Pipe(const Pipe& f) throw(IO::IOError); - Pipe(unsigned long handle, bool readEnd) throw(); - ~Pipe() throw(); static Pair create() throw(IO::IOError); @@ -52,6 +50,8 @@ void _sync() const throw(IO::IOError); + unsigned long handle() const throw(); + private: unsigned long _handle; }; |
From: Christian P. <cp...@us...> - 2005-01-30 17:09:55
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31304/include/pclasses/System Modified Files: File.h Log Message: Moved inline docs to IODevice. Index: File.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/System/File.h,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- File.h 6 Jan 2005 17:23:06 -0000 1.10 +++ File.h 30 Jan 2005 17:09:46 -0000 1.11 @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2004 by Christian Prochnow * + * Copyright (C) 2004, 2005 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * @@ -73,54 +73,18 @@ static void unlink(const Unicode::String& path) throw(IO::IOError); protected: - /** - Frees any resources associated with this object, like filehandles. - */ void _close() throw(IO::IOError); - - /** - Reads up to count bytes and stores them in - buffer. Returns the number of bytes read. - */ size_t _read(char* buffer, size_t count) throw(IO::IOError); - - /** - Tries to extract up to count bytes from this object - without consuming them. The bytes are stored in - buffer, and the number of bytes read is returned. - - */ - size_t _peek(char* buffer, size_t count) throw(IO::IOError); - - /** - Writes count bytes from buffer to this object's - internal representation. - */ size_t _write(const char* buffer, size_t count) throw(IO::IOError); - - /** - Tries to move the current read position to the given offset. - SeekMode determines the relative starting point of offset. - - */ + size_t _peek(char* buffer, size_t count) throw(IO::IOError); offset_t _seek(offset_t offset, SeekMode mode) throw(IO::IOError); - - /** - Returns true if seek() is supported. - */ bool _isSeekable() const throw(); - - /** - @fixme: Same as conventional sync() functions??? - - */ void _sync() const throw(IO::IOError); - - /** - Returns the size of this File on disk. - */ offset_t _size() const throw(IO::IOError); + //! Returns the native O/S handle + unsigned long handle() const throw(); + private: unsigned long _handle; }; |
From: Christian P. <cp...@us...> - 2005-01-30 17:09:25
|
Update of /cvsroot/pclasses/pclasses2/src/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31217/src/IO Modified Files: IODevice.cpp Log Message: Removed IOListener. Index: IODevice.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/IO/IODevice.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- IODevice.cpp 7 Jan 2005 13:33:15 -0000 1.7 +++ IODevice.cpp 30 Jan 2005 17:09:13 -0000 1.8 @@ -251,18 +251,6 @@ _eof = eof; } -void IODevice::addListener(IOListener& l) -{ -} - -void IODevice::updateListener(IOListener& l) -{ -} - -void IODevice::removeListener(IOListener& l) -{ -} - IODevice& IODevice::operator=(const IODevice& dev) throw() { if(_filterOwner) @@ -288,42 +276,6 @@ } -IOListener::IOListener(IODevice& dev, int eventMask) throw() -: _dev(&dev), _eventMask(eventMask) -{ - dev.addListener(*this); -} - -IOListener::~IOListener() throw() -{ - if(_dev) - _dev->removeListener(*this); -} - -IODevice& IOListener::device() const throw() -{ - return *_dev; -} - -void IOListener::setDevice(IODevice& dev) throw() -{ - if(_dev) - _dev->removeListener(*this); - - _dev = &dev; - _dev->addListener(*this); -} - -int IOListener::eventMask() const throw() -{ - return _eventMask; -} - -void IOListener::setEventMask(int eventMask) throw() -{ - _eventMask = eventMask; -} - } // !namespace IO } // !namespace P |
From: Christian P. <cp...@us...> - 2005-01-30 17:09:00
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31053/include/pclasses/IO Modified Files: IODevice.h Log Message: added inline documentation for IODevice. removed IOListener. Index: IODevice.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/IO/IODevice.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- IODevice.h 17 Jan 2005 21:55:22 -0000 1.6 +++ IODevice.h 30 Jan 2005 17:08:48 -0000 1.7 @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2004 by Christian Prochnow * + * Copyright (C) 2004,2005 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * @@ -29,28 +29,49 @@ namespace IO { +// forward declaration class IOFilter; -class IOListener; //! I/O Device base class +/*! + This class serves as the base class for all kinds of I/O in P::Classes. + Since mostly everything in P::Classes that can do I/O is derived from + this class, client applications can be pretty generic about doing I/O. + IODevice's do support transparent I/O filters. When an IOFilter has been + associated with an IODevice all read/write method-calls will be proxied + through the IOFilter object. + \note Keep in mind that IOFilter's may change the seekability on the + IODevice. Relying on assumptions like "Files are always seekable" + when used with IOFilters are incorrect. +*/ class PIO_EXPORT IODevice { public: - friend class IOListener; friend class IOFilter; + //! Device open mode + /*! + Since the IODevice class does not support opening, the OpenMode + is only used by its childrens. + */ enum OpenMode { OpenCreate, CreateFail, OpenFail }; + //! Access mode flags + /*! + Device access flags. Tells open() how you want to access + device data. + */ enum AccessMode { - None = 0x00, - Read = 0x01, - Write = 0x02, - ReadWrite = 0x03 + None = 0x00, /*!< No reading/writing */ + Read = 0x01, /*!< Open for reading */ + Write = 0x02, /*!< Open for writing */ + ReadWrite = 0x03 /*!< Open for reading and writing */ }; + //! Sharing mode flags enum ShareMode { AllowNone = 0x00, AllowRead = 0x01, @@ -58,6 +79,11 @@ AllowReadWrite = 0x03 }; + //! Seeking modes + /*! + Seeking modes are used to describe how to + reposition the read position. See seek(). + */ enum SeekMode { SeekSet, SeekCurrent, @@ -67,31 +93,104 @@ IODevice() throw(); virtual ~IODevice() throw(); + //! Closes the I/O device + /*! + Frees any resources associated with this object, like I/O handles. + */ void close() throw(IOError); + //! Read data from I/O device + /*! + Reads up to count bytes and stores them in buffer. Returns the number + of bytes read, which may be less than requested. In case of EOF, zero + is returned. + \param buffer buffer where to place the data to be read. + \param count number of bytes to read + \return number of bytes read, which may be less than requested. + \throw IOError + */ size_t read(char* buffer, size_t count) throw(IOError); + //! Read one line from I/O device + /*! + Reads up to one line (terminated by ASCII NL) and returns it. + In case of EOF an empy string (string.size()==0) is returned. + When called for the first time the IODevice allocates and uses + a buffer for reading. + \return a string containing the line that has been read, + or an empty string in case of EOF. + \throw IOError + */ std::string readLine() throw(IOError); + //! Write data to I/O device + /*! + Writes count bytes from buffer to this I/O device. Returns the number + of bytes written, which may be less. + \param buffer buffer containing the data to be written. + \param count number of bytes that should be written. + \return number of bytes written, which may be less than requested. + \throw IOError + */ size_t write(const char* buffer, size_t count) throw(IOError); + //! Test for seekability + /*! + Tests if the device is seekable. Returns true if the device is + seekable, false if it is not. + \return true if the device is seekable, false otherwise. + */ bool isSeekable() const throw(); + //! Move the next read position to the given offset + /*! + Tries to move the current read position to the given offset. + SeekMode determines the relative starting point of offset. + \param offset the offset the pointer should be moved by. + \param mode determines the relative starting offset. + \return the new abosulte read positing. + \throw IOError + */ offset_t seek(offset_t offset, SeekMode mode) throw(IOError); + //! Read data from I/O device without consuming them + /*! + Tries to extract up to count bytes from this object + without consuming them. The bytes are stored in + buffer, and the number of bytes read is returned. + \param buffer buffer where to place the data to be read. + \param count number of bytes to read + \return number of bytes read. + \throw IOError + */ size_t peek(char* buffer, size_t count) throw(IOError); + //! Synchronize device + /*! + Commits written data to physical device. + \throw IOError + */ void sync() const throw(IOError); offset_t getPos() throw(IOError); + //! Returns the size of the I/O device offset_t size() const throw(IOError); + //! Test if the I/O device object is valid + /*! + Test if the I/O device object is valid. + The object is valid when it has been opened and was not + already closed. + \return true if the I/O device is usable, false otherwise. + */ bool valid() const throw(); + //! Returns the allowed access to the I/O device AccessMode access() const throw(); + //! Returns if the device has reached EOF bool eof() const throw(); void setFilter(IOFilter* filter) throw(LogicError); @@ -101,30 +200,42 @@ IODevice(const IODevice& dev) throw(); IODevice& operator=(const IODevice& dev) throw(); + //! Called when device should be closed + /*! + precondition: valid()==true + */ virtual void _close() throw(IOError) = 0; + //! Read bytes from device virtual size_t _read(char* buffer, size_t count) throw(IOError) = 0; + //! Write bytes to device virtual size_t _write(const char* buffer, size_t count) throw(IOError) = 0; + //! Test for seekability virtual bool _isSeekable() const throw(); + //! Seek on device virtual offset_t _seek(offset_t offset, SeekMode mode) throw(IOError); + //! Read bytes without consuming them virtual size_t _peek(char* buffer, size_t count) throw(IOError); + //! Sync device virtual void _sync() const throw(IOError); + //! Returns the size of the device virtual offset_t _size() const throw(IOError); + //! Set I/O device valid/invalid void setValid(bool v) throw(); + + //! Set AccessMode on device void setAccess(AccessMode mode) throw(); - void setEof(bool eof) throw(); - virtual void addListener(IOListener& l); - virtual void updateListener(IOListener& l); - virtual void removeListener(IOListener& l); + //! Set EOF on device + void setEof(bool eof) throw(); private: IOFilter* _filter; @@ -139,32 +250,6 @@ char* _readBuffNext; }; -class PIO_EXPORT IOListener { - public: - enum EventFlags { - None = 0x0, - Read = 0x1, - Write = 0x2, - ReadWrite = 0x03 - }; - - IOListener(IODevice& dev, int eventMask) throw(); - virtual ~IOListener() throw(); - - IODevice& device() const throw(); - void setDevice(IODevice& dev) throw(); - - int eventMask() const throw(); - void setEventMask(int eventMask) throw(); - - virtual void onRead() = 0; - virtual void onWrite() = 0; - - private: - IODevice* _dev; - int _eventMask; -}; - } // !namespace IO } // !namespace P |
From: Christian P. <cp...@us...> - 2005-01-30 17:07:20
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30544/src/System Modified Files: File.posix.cpp Pipe.posix.cpp Added Files: File.common.cpp File.win32.cpp IOHandle.h IOHandle.posix.cpp Pipe.common.cpp Log Message: IOHandle: Added internal I/O handle class. File, Pipe: ported to IOHandle. --- NEW FILE: File.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/File.h" #include "pclasses/System/FileInfo.h" #include "IOHandle.h" namespace P { namespace System { File::File() throw() : _handle(0) { } File::File(const File& f) throw(IO::IOError) : IODevice(f), _handle(0) { if(f.valid()) { IOHandle* h = new IOHandle(f.handle(), false); _handle = (unsigned long)h; } } File::File(const Unicode::String& name, AccessMode amode, OpenMode omode, ShareMode smode) throw(IO::IOError) : _handle(0) { open(name,amode,omode,smode); } File::~File() throw() { if(valid()) { try { close(); } catch(...) { } } } void File::open(const Unicode::String& name, AccessMode amode, OpenMode omode, ShareMode smode) throw(IO::IOError) { if(valid()) close(); IOHandle* h = new IOHandle(name, amode, omode, smode); _handle = (unsigned long)h; IODevice::setAccess(amode); IODevice::setValid(true); IODevice::setEof(false); } void File::_close() throw(IO::IOError) { IOHandle* h = (IOHandle*)_handle; h->close(); delete h; _handle = 0; IODevice::setAccess(None); IODevice::setValid(false); } size_t File::_read(char* buffer, size_t count) throw(IO::IOError) { IOHandle* h = (IOHandle*)_handle; size_t ret = h->read(buffer, count); if(ret == 0 && !eof()) setEof(true); return ret; } size_t File::_peek(char* buffer, size_t count) throw(IO::IOError) { IOHandle* h = (IOHandle*)_handle; return h->peek(buffer, count); } size_t File::_write(const char* buffer, size_t count) throw(IO::IOError) { IOHandle* h = (IOHandle*)_handle; return h->write(buffer, count); } offset_t File::_seek(offset_t offset, SeekMode mode) throw(IO::IOError) { IOHandle* h = (IOHandle*)_handle; return h->seek(offset, mode); } bool File::_isSeekable() const throw() { IOHandle* h = (IOHandle*)_handle; return h->isSeekable(); } void File::_sync() const throw(IO::IOError) { IOHandle* h = (IOHandle*)_handle; h->sync(); } offset_t File::_size() const throw(IO::IOError) { IOHandle* h = (IOHandle*)_handle; return h->size(); } void File::resize(size_t sz) throw(IO::IOError) { sync(); IOHandle* h = (IOHandle*)_handle; h->resize(sz); } File& File::operator=(const File& f) throw(IO::IOError) { // strong exception guarantee... if(f.valid()) { IOHandle* h = new IOHandle(f.handle(), false); if(valid()) { try { close(); } catch(...) { delete h; throw; } } IODevice::operator=(f); _handle = (unsigned long)h; } else { if(valid()) close(); setValid(false); setEof(true); setAccess(None); } return *this; } FileInfo File::stat(const Unicode::String& path) throw(IO::IOError) { return FileInfo(path); } unsigned long File::handle() const throw() { return ((IOHandle*)_handle)->handle(); } } // !namespace System } // !namespace P Index: File.posix.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/File.posix.cpp,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- File.posix.cpp 6 Jan 2005 17:23:07 -0000 1.12 +++ File.posix.cpp 30 Jan 2005 17:07:03 -0000 1.13 @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2004 by Christian Prochnow * + * Copyright (C) 2004,2005 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * @@ -19,288 +19,12 @@ ***************************************************************************/ #include "pclasses/System/File.h" -#include "pclasses/System/FileInfo.h" - -#include <sys/types.h> -#include <sys/stat.h> -#include <limits.h> -#include <fcntl.h> -#include <unistd.h> #include <errno.h> namespace P { namespace System { -int OpenMode2Flags(File::OpenMode omode) -{ - int flags = 0; - switch(omode) - { - case File::OpenCreate: - flags |= O_CREAT; - break; - - case File::CreateFail: - flags |= O_CREAT|O_EXCL; - break; - - case File::OpenFail: - break; - } - - return flags; -} - -int AccessMode2Flags(File::AccessMode amode) -{ - int flags = 0; - - switch(amode) - { - case File::None: - break; - - case File::Read: - flags |= O_RDONLY; - break; - - case File::Write: - flags |= O_WRONLY; - break; - - case File::ReadWrite: - flags |= O_RDWR; - break; - } - - return flags; -} - -File::File() throw() -: _handle((unsigned long)-1) -{ -} - -File::File(const File& f) throw(IO::IOError) -: IODevice(f), _handle((unsigned long)-1) -{ - if(f.valid()) - { - int handle = ::dup((int)f._handle); - if(handle == -1) - throw IO::IOError(errno, "Could not duplicate file handle", P_SOURCEINFO); - - _handle = (unsigned long)handle; - } -} - -File::File(const Unicode::String& name, AccessMode amode, OpenMode omode, - ShareMode smode) throw(IO::IOError) -: _handle((unsigned long)-1) -{ - open(name,amode,omode,smode); -} - -File::~File() throw() -{ - if(valid()) - { - try { close(); } catch(...) { } - } -} - -void File::open(const Unicode::String& name, AccessMode amode, OpenMode omode, - ShareMode smode) throw(IO::IOError) -{ - if(valid()) - close(); - - int flags = OpenMode2Flags(omode) | AccessMode2Flags(amode); - - int handle = ::open(name.utf8().c_str(), flags, 0644); - if(handle == -1) - throw IO::IOError(errno, "Could not open file", P_SOURCEINFO); - - _handle = (unsigned long)handle; - IODevice::setAccess(amode); - IODevice::setValid(true); - IODevice::setEof(false); -} - -void File::_close() throw(IO::IOError) -{ - if(::close((int)_handle) == -1) - throw IO::IOError(errno, "Could not close file", P_SOURCEINFO); - - _handle = (unsigned long)-1; - IODevice::setAccess(None); - IODevice::setValid(false); -} - -size_t File::_read(char* buffer, size_t count) throw(IO::IOError) -{ - if(count > SSIZE_MAX) - count = SSIZE_MAX; - - File_read: - ssize_t ret = ::read((int)_handle, (void*)buffer, count); - if(ret == -1) - { - if(errno == EINTR) - goto File_read; - - throw IO::IOError(errno, "Could not read from file", P_SOURCEINFO); - } - else if(ret == 0 && !eof()) - setEof(true); - - return ret; -} - -size_t File::_peek(char* buffer, size_t count) throw(IO::IOError) -{ - if(count > SSIZE_MAX) - count = SSIZE_MAX; - - File_peek: - ssize_t ret = ::read((int)_handle, (void*)buffer, count); - if(ret == -1) - { - if(errno == EINTR) - goto File_peek; - - throw IO::IOError(errno, "Could not read from file", P_SOURCEINFO); - } - - seek(-count, SeekCurrent); - return ret; -} - -size_t File::_write(const char* buffer, size_t count) throw(IO::IOError) -{ - if(count > SSIZE_MAX) - count = SSIZE_MAX; - - File_write: - ssize_t ret = ::write((int)_handle, (const void*)buffer, count); - if(ret == -1) - { - if(errno == EINTR) - goto File_write; - - throw IO::IOError(errno, "Could not read from file", P_SOURCEINFO); - } - - return ret; -} - -offset_t File::_seek(offset_t offset, SeekMode mode) throw(IO::IOError) -{ - int whence; - switch(mode) - { - case SeekSet: - whence = SEEK_SET; - break; - - case SeekCurrent: - whence = SEEK_CUR; - break; - - case SeekEnd: - whence = SEEK_END; - break; - } - - off_t ret = lseek((int)_handle, offset, whence); - if(ret == (off_t)-1) - throw IO::IOError(errno, "Could not seek on file", P_SOURCEINFO); - - return ret; -} - -bool File::_isSeekable() const throw() -{ - struct stat buff; - int ret = fstat((int)_handle, &buff); - if(ret == 0) - { - if(S_ISREG(buff.st_mode) || S_ISBLK(buff.st_mode)) - return true; - } - - return false; -} - -void File::_sync() const throw(IO::IOError) -{ - int ret = fsync((int)_handle); - if(ret == -1) - throw IO::IOError(errno, "Could not sync file to disk", P_SOURCEINFO); -} - -offset_t File::_size() const throw(IO::IOError) -{ - struct stat buff; - int ret = fstat((int)_handle, &buff); - if(ret == -1) - throw IO::IOError(errno, "Could not stat file", P_SOURCEINFO); - - return buff.st_size; -} - -void File::resize(size_t sz) throw(IO::IOError) -{ - sync(); - - int ret = ftruncate((int)_handle, sz); - if(ret == -1) - throw IO::IOError(errno, "Could not truncate file", P_SOURCEINFO); -} - -File& File::operator=(const File& f) throw(IO::IOError) -{ - if(f.valid()) - { - int handle = ::dup((int)f._handle); - if(handle == -1) - throw IO::IOError(errno, "Could not duplicate file handle", P_SOURCEINFO); - - if(valid()) - { - try - { - close(); - } - catch(...) - { - ::close(handle); - throw; - } - } - - IODevice::operator=(f); - _handle = (unsigned long)handle; - } - else - { - if(valid()) - close(); - - setValid(false); - setEof(true); - setAccess(None); - } - - return *this; -} - -FileInfo File::stat(const Unicode::String& path) throw(IO::IOError) -{ - return FileInfo(path); -} - void File::unlink(const Unicode::String& path) throw(IO::IOError) { if(::unlink(path.utf8().c_str()) == -1) --- NEW FILE: IOHandle.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_IOHandle_h #define P_System_IOHandle_h #include "pclasses/IO/IODevice.h" #include "pclasses/IO/IOError.h" #include "pclasses/Unicode/String.h" namespace P { namespace System { //! Internal System I/O handle class IOHandle { public: IOHandle(const IOHandle& h) throw(IO::IOError); IOHandle(unsigned long handle, bool takeOwnership) throw(IO::IOError); IOHandle(const Unicode::String& name, IO::IODevice::AccessMode amode, IO::IODevice::OpenMode omode = IO::IODevice::OpenCreate, IO::IODevice::ShareMode smode = IO::IODevice::AllowNone) throw(IO::IOError); ~IOHandle() throw(); void close() throw(IO::IOError); size_t read(char* buffer, size_t count) throw(IO::IOError); size_t write(const char* buffer, size_t count) throw(IO::IOError); bool isSeekable() const throw(); offset_t seek(offset_t offset, IO::IODevice::SeekMode mode) throw(IO::IOError); size_t peek(char* buffer, size_t count) throw(IO::IOError); void sync() const throw(IO::IOError); offset_t size() const throw(IO::IOError); void resize(size_t sz) throw(IO::IOError); //! Returns the native O/S handle unsigned long handle() const throw(); private: unsigned long _handle; }; } // !namespace System } // !namespace P #endif --- NEW FILE: File.win32.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/File.h" namespace P { namespace System { void File::unlink(const Unicode::String& path) throw(IO::IOError) { if(::DeleteFile(path.utf8().c_str()) == -1) throw IO::IOError(errno, "Could not unlink file", P_SOURCEINFO); } } // !namespace System } // !namespace P --- NEW FILE: Pipe.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/Pipe.h" #include "IOHandle.h" namespace P { namespace System { Pipe::Pipe(unsigned long handle, bool readEnd) throw() : IODevice(), _handle(0) { // takes ownership of the handle ... IOHandle* h = new IOHandle(handle, true); _handle = (unsigned long)h; IODevice::setAccess(readEnd ? Read : Write); IODevice::setValid(true); IODevice::setEof(false); } Pipe::Pipe(const Pipe& p) throw(IO::IOError) : IODevice(p), _handle(0) { if(p.valid()) { // duplicates the handle ... IOHandle* h = new IOHandle(p.handle(), false); _handle = (unsigned long)h; } } Pipe::~Pipe() throw() { if(valid()) { try { close(); } catch(...) { } } } void Pipe::_close() throw(IO::IOError) { IOHandle* h = (IOHandle*)_handle; h->close(); delete h; _handle = 0; IODevice::setAccess(None); IODevice::setValid(false); } size_t Pipe::_read(char* buffer, size_t count) throw(IO::IOError) { IOHandle* h = (IOHandle*)_handle; return h->read(buffer, count); } size_t Pipe::_write(const char* buffer, size_t count) throw(IO::IOError) { IOHandle* h = (IOHandle*)_handle; return h->write(buffer, count); } void Pipe::_sync() const throw(IO::IOError) { /* pipes cant be synced !! int ret = fsync((int)_handle); if(ret == -1) throw IO::IOError(errno, "Could not commit to pipe", P_SOURCEINFO); */ } Pipe& Pipe::operator=(const Pipe& p) throw(IO::IOError) { if(p.valid()) { IOHandle* h = new IOHandle(p.handle(), false); if(valid()) { try { close(); } catch(...) { delete h; throw; } } IODevice::operator=(p); _handle = (unsigned long)h; } else { if(valid()) close(); setValid(false); setEof(true); setAccess(None); } return *this; } unsigned long Pipe::handle() const throw() { return ((IOHandle*)_handle)->handle(); } } // !namespace System } // !namespace P --- NEW FILE: IOHandle.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 "IOHandle.h" #include <sys/types.h> #include <sys/stat.h> #include <limits.h> #include <fcntl.h> #include <unistd.h> #include <errno.h> namespace P { namespace System { int OpenMode2Flags(IO::IODevice::OpenMode omode) { int flags = 0; switch(omode) { case IO::IODevice::OpenCreate: flags |= O_CREAT; break; case IO::IODevice::CreateFail: flags |= O_CREAT|O_EXCL; break; case IO::IODevice::OpenFail: break; } return flags; } int AccessMode2Flags(IO::IODevice::AccessMode amode) { int flags = 0; switch(amode) { case IO::IODevice::None: break; case IO::IODevice::Read: flags |= O_RDONLY; break; case IO::IODevice::Write: flags |= O_WRONLY; break; case IO::IODevice::ReadWrite: flags |= O_RDWR; break; } return flags; } IOHandle::IOHandle(const IOHandle& h) throw(IO::IOError) { int handle = ::dup((int)h._handle); if(handle == -1) throw IO::IOError(errno, "Could not duplicate handle", P_SOURCEINFO); _handle = (unsigned long)handle; } IOHandle::IOHandle(unsigned long h, bool takeOwnership) throw(IO::IOError) { if(takeOwnership) { _handle = h; } else { int handle = ::dup((int)h); if(handle == -1) throw IO::IOError(errno, "Could not duplicate handle", P_SOURCEINFO); _handle = (unsigned long)handle; } } IOHandle::IOHandle(const Unicode::String& name, IO::IODevice::AccessMode amode, IO::IODevice::OpenMode omode, IO::IODevice::ShareMode smode) throw(IO::IOError) : _handle((unsigned long)-1) { int flags = OpenMode2Flags(omode) | AccessMode2Flags(amode); int handle; if(omode == IO::IODevice::OpenCreate || omode == IO::IODevice::CreateFail) handle = ::open(name.utf8().c_str(), flags, 0644); else handle = ::open(name.utf8().c_str(), flags); if(handle == -1) throw IO::IOError(errno, "Could not open handle", P_SOURCEINFO); _handle = (unsigned long)handle; } IOHandle::~IOHandle() throw() { if((int)_handle != -1) { try { close(); } catch(...) { } } } void IOHandle::close() throw(IO::IOError) { if(::close((int)_handle) == -1) throw IO::IOError(errno, "Could not close handle", P_SOURCEINFO); _handle = (unsigned long)-1; } size_t IOHandle::read(char* buffer, size_t count) throw(IO::IOError) { if(count > SSIZE_MAX) count = SSIZE_MAX; Handle_read: ssize_t ret = ::read((int)_handle, (void*)buffer, count); if(ret == -1) { if(errno == EINTR) goto Handle_read; throw IO::IOError(errno, "Could not read from handle", P_SOURCEINFO); } return ret; } size_t IOHandle::write(const char* buffer, size_t count) throw(IO::IOError) { if(count > SSIZE_MAX) count = SSIZE_MAX; Handle_write: ssize_t ret = ::write((int)_handle, (const void*)buffer, count); if(ret == -1) { if(errno == EINTR) goto Handle_write; throw IO::IOError(errno, "Could not read from handle", P_SOURCEINFO); } return ret; } bool IOHandle::isSeekable() const throw() { struct stat buff; int ret = fstat((int)_handle, &buff); if(ret == 0) { if(S_ISREG(buff.st_mode) || S_ISBLK(buff.st_mode)) return true; } return false; } offset_t IOHandle::seek(offset_t offset, IO::IODevice::SeekMode mode) throw(IO::IOError) { int whence; switch(mode) { case IO::IODevice::SeekSet: whence = SEEK_SET; break; case IO::IODevice::SeekCurrent: whence = SEEK_CUR; break; case IO::IODevice::SeekEnd: whence = SEEK_END; break; } off_t ret = lseek((int)_handle, offset, whence); if(ret == (off_t)-1) throw IO::IOError(errno, "Could not seek on handle", P_SOURCEINFO); return ret; } size_t IOHandle::peek(char* buffer, size_t count) throw(IO::IOError) { if(count > SSIZE_MAX) count = SSIZE_MAX; Handle_peek: ssize_t ret = ::read((int)_handle, (void*)buffer, count); if(ret == -1) { if(errno == EINTR) goto Handle_peek; throw IO::IOError(errno, "Could not read from handle", P_SOURCEINFO); } seek(-count, IO::IODevice::SeekCurrent); return ret; } void IOHandle::sync() const throw(IO::IOError) { int ret = fsync((int)_handle); if(ret == -1) throw IO::IOError(errno, "Could not sync handle", P_SOURCEINFO); } offset_t IOHandle::size() const throw(IO::IOError) { struct stat buff; int ret = fstat((int)_handle, &buff); if(ret == -1) throw IO::IOError(errno, "Could not stat file", P_SOURCEINFO); return buff.st_size; } void IOHandle::resize(size_t sz) throw(IO::IOError) { int ret = ftruncate((int)_handle, sz); if(ret == -1) throw IO::IOError(errno, "Could not truncate file", P_SOURCEINFO); } unsigned long IOHandle::handle() const throw() { return _handle; } } // !namespace System } // !namespace P Index: Pipe.posix.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/Pipe.posix.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- Pipe.posix.cpp 3 Jan 2005 13:50:45 -0000 1.8 +++ Pipe.posix.cpp 30 Jan 2005 17:07:03 -0000 1.9 @@ -19,10 +19,8 @@ ***************************************************************************/ #include "pclasses/System/Pipe.h" +#include "IOHandle.h" -#include <sys/types.h> -#include <sys/stat.h> -#include <limits.h> #include <unistd.h> #include <errno.h> @@ -30,40 +28,11 @@ namespace System { -Pipe::Pipe(unsigned long h, bool readEnd) throw() -: IODevice(), _handle(h) -{ - IODevice::setAccess(readEnd ? Read : Write); - IODevice::setValid(true); - IODevice::setEof(false); -} - -Pipe::Pipe(const Pipe& p) throw(IO::IOError) -: IODevice(p), _handle((unsigned long)-1) -{ - if(p.valid()) - { - int handle = ::dup((int)p._handle); - if(handle == -1) - throw IO::IOError(errno, "Could not duplicate pipe handle", P_SOURCEINFO); - - _handle = (unsigned long)handle; - } -} - -Pipe::~Pipe() throw() -{ - if(valid()) - { - try { close(); } catch(...) { } - } -} - Pipe::Pair Pipe::create() throw(IO::IOError) { int fds[2]; - if(pipe(fds) == -1) + if(::pipe(fds) == -1) throw IO::IOError(errno, "Could not create pipe", P_SOURCEINFO); Pipe readPipe((unsigned long)fds[0], true); @@ -72,100 +41,6 @@ return std::make_pair(readPipe, writePipe); } -void Pipe::_close() throw(IO::IOError) -{ - if(::close((int)_handle) == -1) - throw IO::IOError(errno, "Could not close pipe", P_SOURCEINFO); - - _handle = (unsigned long)-1; - IODevice::setAccess(None); - IODevice::setValid(false); -} - -size_t Pipe::_read(char* buffer, size_t count) throw(IO::IOError) -{ - if(count > SSIZE_MAX) - count = SSIZE_MAX; - - Pipe_read: - ssize_t ret = ::read((int)_handle, (void*)buffer, count); - if(ret == -1) - { - if(errno == EINTR) - goto Pipe_read; - - throw IO::IOError(errno, "Could not read from pipe", P_SOURCEINFO); - } - else if(ret == 0 && !eof()) - setEof(true); - - return ret; -} - -size_t Pipe::_write(const char* buffer, size_t count) throw(IO::IOError) -{ - if(count > SSIZE_MAX) - count = SSIZE_MAX; - - Pipe_write: - ssize_t ret = ::write((int)_handle, - (const void*)buffer, count); - - if(ret == -1) - { - if(errno == EINTR) - goto Pipe_write; - - throw IO::IOError(errno, "Could not read from pipe", P_SOURCEINFO); - } - - return ret; -} - -void Pipe::_sync() const throw(IO::IOError) -{ - /* pipes cant be synced !! - int ret = fsync((int)_handle); - if(ret == -1) - throw IO::IOError(errno, "Could not commit to pipe", P_SOURCEINFO); */ -} - -Pipe& Pipe::operator=(const Pipe& p) throw(IO::IOError) -{ - if(p.valid()) - { - int handle = ::dup((int)p._handle); - if(handle == -1) - throw IO::IOError(errno, "Could not duplicate pipe handle", P_SOURCEINFO); - - if(valid()) - { - try - { - close(); - } - catch(...) - { - ::close(handle); - throw; - } - } - - IODevice::operator=(p); - _handle = (unsigned long)handle; - } - else - { - if(valid()) - close(); - - setValid(false); - setEof(true); - setAccess(None); - } - - return *this; -} } // !namespace System |
From: Christian P. <cp...@us...> - 2005-01-30 11:56:59
|
Update of /cvsroot/pclasses/pclasses2/win32 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22665/win32 Modified Files: System.vcproj Log Message: Added Directory.win32.cpp Index: System.vcproj =================================================================== RCS file: /cvsroot/pclasses/pclasses2/win32/System.vcproj,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- System.vcproj 24 Jan 2005 01:33:28 -0000 1.1 +++ System.vcproj 30 Jan 2005 11:56:49 -0000 1.2 @@ -163,6 +163,9 @@ RelativePath="..\src\System\ThreadKey.win32.cpp"> </File> <File + RelativePath="..\src\System\Directory.win32.cpp"> + </File> + <File RelativePath="..\src\System\timeout.cpp"> </File> </Filter> |
From: Christian P. <cp...@us...> - 2005-01-28 20:37:36
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5569/include/pclasses Modified Files: Makefile.am Log Message: Added signal generation. Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Makefile.am,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- Makefile.am 24 Jan 2005 23:03:24 -0000 1.10 +++ Makefile.am 28 Jan 2005 17:37:02 -0000 1.11 @@ -3,10 +3,23 @@ SUBDIRS = Unicode IO System Plugin Net Util XML App INCLUDES = METASOURCES = AUTO + +all_callbacks: + if [ ! -e "$(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 + pkginclude_HEADERS = Exception.h IntTypes.h ScopedArrayPtr.h ScopedPtr.h \ SharedPtr.h Alloc.h SourceInfo.h Atomic.h AtomicTraits.h ValueType.h LockTraits.h \ ByteOrderTraits.h BasicTypes.h Vector.h Algorithm.h TypeTraits.h \ Stack.h LinkedItem.h Pair.h IntTypeLimits.h Queue.h IntrusivePtr.h \ CircularQueue.h List.h NonCopyable.h Phoenix.h Factory.h \ - SharingContext.h Time.h Date.h DateTime.h TimeSpan.h Callback.h Signal.h \ + SharingContext.h Time.h Date.h DateTime.h TimeSpan.h Callback.h Signal.h \ + CallbackN1.h CallbackN2.h CallbackN3.h CallbackN4.h \ Trace.h PropertyMap.h Export.h pclasses-config.h + +all: all_callbacks + +clean: all_callbacks_clean + |
From: Christian P. <cp...@us...> - 2005-01-28 20:23:49
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5411/src/System Modified Files: Thread.common.cpp Log Message: Add support for variable Callbacks in Thread::spawn() Index: Thread.common.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/Thread.common.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Thread.common.cpp 28 Jan 2005 11:36:38 -0000 1.1 +++ Thread.common.cpp 28 Jan 2005 17:36:12 -0000 1.2 @@ -27,8 +27,8 @@ class SpawnedThread: public Thread { public: - SpawnedThread(const Callback0<void>& cb, Semaphore* sem) - : Thread(true), _callback(cb.clone()), _sem(sem) + SpawnedThread(const Callback& cb, const CallbackArgs& args, Semaphore* sem) + : Thread(true), _callback(cb.clone()), _args(&args), _sem(sem) { } @@ -38,23 +38,31 @@ if(_sem) _sem->post(); - _callback->exec(); + _callback->exec(*_args); if(_sem) _sem->post(); + delete _callback; delete this; return 0; } private: - Callback0<void>* _callback; - Semaphore* _sem; + Callback* _callback; + const CallbackArgs* _args; + Semaphore* _sem; }; -void Thread::spawn(const Callback0<void>& cb, Semaphore* sem) throw(SystemError) +void Thread::spawn(const Callback& cb, Semaphore* sem) throw(SystemError) { - SpawnedThread* thr = new SpawnedThread(cb, sem); + Callback0<void>::Args args; + spawn(cb, args, sem); +} + +void Thread::spawn(const Callback& cb, const CallbackArgs& args, Semaphore* sem) throw(SystemError) +{ + SpawnedThread* thr = new SpawnedThread(cb, args, sem); thr->start(); // we don't leak the object ... it is self-deleted } |
From: Christian P. <cp...@us...> - 2005-01-28 20:21:44
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5411/include/pclasses/System Modified Files: Thread.h Log Message: Add support for variable Callbacks in Thread::spawn() Index: Thread.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/System/Thread.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- Thread.h 28 Jan 2005 11:36:37 -0000 1.4 +++ Thread.h 28 Jan 2005 17:36:13 -0000 1.5 @@ -55,8 +55,10 @@ static void yield() throw(); static void sleep(unsigned int ms) throw(); - static void spawn(const Callback0<void>& cb, Semaphore* sem = 0) - throw(SystemError); + static void spawn(const Callback& cb, Semaphore* sem = 0) throw(SystemError); + + static void spawn(const Callback& cb, const CallbackArgs& args, + Semaphore* sem = 0) throw(SystemError); protected: virtual int main() = 0; |
From: Christian P. <cp...@us...> - 2005-01-28 19:08:25
|
Update of /cvsroot/pclasses/pclasses2/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6988 Modified Files: ThreadTest.cpp SignalTest.cpp Log Message: Fixed ThredTest and SignalTest. Index: ThreadTest.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/test/ThreadTest.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- ThreadTest.cpp 28 Jan 2005 11:57:12 -0000 1.2 +++ ThreadTest.cpp 28 Jan 2005 17:41:36 -0000 1.3 @@ -67,7 +67,11 @@ sem.wait(); delete thread; - System::Thread::spawn(method(this, &ThreadTest::spawnedTest), &sem); + System::Thread::spawn(make_method(this, &ThreadTest::spawnedTest), &sem); + sem.wait(); sem.wait(); + + System::Thread::spawn(make_method(this, &ThreadTest::spawnedTest2), + make_args((int)12345), &sem); sem.wait(); sem.wait(); } @@ -75,7 +79,12 @@ { std::cout << "Hello from spawned callback!" << std::endl; } - + + void spawnedTest2(int arg) + { + std::cout << "Hello from spawned callback! arg=" << arg << std::endl; + } + static System::Semaphore sem; }; Index: SignalTest.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/test/SignalTest.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- SignalTest.cpp 6 Jan 2005 17:00:38 -0000 1.1 +++ SignalTest.cpp 28 Jan 2005 17:41:36 -0000 1.2 @@ -41,8 +41,8 @@ // bind signals and see if methods did run Signal0<void> sig; - sig.bind(function(&testFuncStatic)); - sig.bind(method(this, &Signal0Test::testFunc)); + sig.bind(make_function(&testFuncStatic)); + sig.bind(make_method(this, &Signal0Test::testFunc)); sig.fire(); P_TEST(_testFunc == true); @@ -52,8 +52,8 @@ _testFunc = false; _testFuncStatic = false; - sig.unbind(function(&testFuncStatic)); - sig.unbind(method(this, &Signal0Test::testFunc)); + sig.unbind(make_function(&testFuncStatic)); + sig.unbind(make_method(this, &Signal0Test::testFunc)); sig.fire(); P_TEST(_testFunc == false); @@ -61,9 +61,11 @@ // test signal with bool return-type Signal0<bool> sig2; - sig2.bind(function(&testFunc2Static)); - sig2.bind(method(this, &Signal0Test::testFunc2)); + sig2.bind(make_function(&testFunc2Static)); + sig2.bind(make_method(this, &Signal0Test::testFunc2)); P_TEST(sig2.fire() == true); + + make_args(1); } private: |
From: Christian P. <cp...@us...> - 2005-01-28 17:26:19
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30783/include/pclasses Added Files: CallbackN.sh Log Message: Added CallbackN generation shell-script --- NEW FILE: CallbackN.sh --- #/*************************************************************************** # * 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. * # ***************************************************************************/ # # this shell-script generates code for Signals with n arguments.... # generate_callbackN() { templateargs="typename _ArgT1" structmembers="_ArgT1 arg1;" argtypes="_ArgT1" argtypescp=", _ArgT1" argtypeswname="_ArgT1 arg1" args="arg1" argsassign="args.arg1 = arg1;" callargs="a->arg1" num=1 while [ "$num" -lt "$1" ] do num=`expr $num + 1` templateargs="$templateargs, typename _ArgT$num" structmembers="$structmembers _ArgT$num arg$num;" argtypes="$argtypes, _ArgT$num" argtypescp="$argtypescp, _ArgT$num" argtypeswname="$argtypeswname, _ArgT$num arg$num" args="$args, arg$num" argsassign="$argsassign args.arg$num = arg$num;" callargs="$callargs, a->arg$num" done cat <<- EOF > "CallbackN$1.h" namespace P { /* ----------------- Callback1 ------------------ */ template <$templateargs> struct CallbackArgs$num: CallbackArgs { $structmembers }; template <$templateargs> CallbackArgs$num<$argtypes> make_args($argtypeswname) { CallbackArgs$num<$argtypes> args; $argsassign return args; } //! Callback base class with $num argument template <typename _RetT, $templateargs> class Callback$num: public Callback { public: typedef CallbackArgs$num<$argtypes> Args; struct RetType: public Callback::RetType { _RetT retVal; }; Callback$num() { } virtual ~Callback$num() { } Callback::RetType exec(const CallbackArgs& args) const { RetType ret; const Args* a = static_cast<const Args*>(&args); if(!a) throw; ret.retVal = exec($callargs); return ret; } virtual _RetT exec($argtypes) const = 0; }; //! Callback base class with $num argument (void specialisation) template <$templateargs> class Callback$num<void $argtypescp>: public Callback { public: typedef CallbackArgs$num<$argtypes> Args; struct RetType: public Callback::RetType { }; Callback$num() { } virtual ~Callback$num() { } Callback::RetType exec(const CallbackArgs& args) const { const Args* a = static_cast<const Args*>(&args); if(!a) throw; exec($callargs); return RetType(); } virtual void exec($argtypes) const = 0; }; /* -------------- Function1 ------------- */ //! Function callback class with $num argument template <typename _RetT, $templateargs> class Function$num: public Callback$num<_RetT, $argtypes> { public: typedef _RetT (*FuncPtr)($argtypes); Function$num(FuncPtr ptr) : _funcPtr(ptr) { } _RetT exec($argtypeswname) const { return (*_funcPtr)($args); } Callback$num<_RetT, $argtypes>* clone() const { return new Function$num(*this); } bool operator==(const Function$num& f) const { return _funcPtr == f._funcPtr; } private: FuncPtr _funcPtr; }; //! Function callback class with $num argument (void specialisation) template <$templateargs> class Function$num<void, $argtypes>: public Callback$num<void, $argtypes> { public: typedef void (*FuncPtr)($argtypes); Function$num(FuncPtr ptr) : _funcPtr(ptr) { } void exec($argtypeswname) const { (*_funcPtr)($args); } Callback$num<void, $argtypes>* clone() const { return new Function$num(*this); } bool operator==(const Function$num& f) const { return _funcPtr == f._funcPtr; } private: FuncPtr _funcPtr; }; //! Returns a function-callback object template <typename _RetT, $templateargs> Function$num<_RetT, $argtypes> make_function(_RetT (*ptr)($argtypes)) { return Function$num<_RetT, $argtypes>(ptr); } /* ---------- Method1 ------------ */ //! Method callback class with $num arguments template <typename _RetT, class _ObjT, $templateargs> class Method$num: public Callback$num<_RetT, $argtypes> { public: typedef _RetT (_ObjT::*FuncPtr)($argtypes); Method$num(_ObjT* obj, FuncPtr ptr) : _obj(obj), _funcPtr(ptr) { } _RetT exec($argtypeswname) const { return (_obj->*_funcPtr)($args); } Callback$num<_RetT, $argtypes>* clone() const { return new Method$num(*this); } bool operator==(const Method$num& f) const { return _obj == f._obj && _funcPtr == f._funcPtr; } private: _ObjT* _obj; FuncPtr _funcPtr; }; //! Method callback class with $num arguments (void specialisation) template <class _ObjT, $templateargs> class Method$num<void, _ObjT, $argtypes>: public Callback$num<void, $argtypes> { public: typedef void (_ObjT::*FuncPtr)($argtypes); Method$num(_ObjT* obj, FuncPtr ptr) : _obj(obj), _funcPtr(ptr) { } void exec($argtypeswname) const { (_obj->*_funcPtr)($args); } Callback$num<void, $argtypes>* clone() const { return new Method$num(*this); } bool operator==(const Method$num& f) const { return _obj == f._obj && _funcPtr == f._funcPtr; } private: _ObjT* _obj; FuncPtr _funcPtr; }; //! Returns a method-callback object template <typename _RetT, class _ObjT, $templateargs> Method$num<_RetT, _ObjT, $argtypes> make_method(_ObjT* obj, _RetT (_ObjT::*ptr)($argtypes)) { return Method$num<_RetT, _ObjT, $argtypes>(obj, ptr); } } // !namespace P EOF } generate_callbackN 1 generate_callbackN 2 generate_callbackN 3 generate_callbackN 4 |
From: Christian P. <cp...@us...> - 2005-01-28 17:26:15
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30997/include/pclasses Modified Files: Callback.h Log Message: Added CallbackArgs. Added generic exec() method. Index: Callback.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Callback.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- Callback.h 28 Jan 2005 11:33:28 -0000 1.4 +++ Callback.h 28 Jan 2005 17:11:57 -0000 1.5 @@ -23,48 +23,79 @@ namespace P { +struct CallbackArgs { }; + +//! Callback base class +class Callback { + public: + struct RetType { }; + + Callback() { } + virtual ~Callback() { } + + virtual Callback* clone() const = 0; + virtual RetType exec(const CallbackArgs& args) const = 0; +}; + /* ----------------- Callback0 ------------------ */ +//! Callback arguments with no arguments +struct CallbackArgs0: CallbackArgs { }; + //! Callback base class with no arguments -template <typename RetType> -class Callback0 { +template <typename _RetT> +class Callback0: public Callback { public: - virtual ~Callback0() { } - virtual RetType exec() const = 0; - virtual Callback0* clone() const = 0; + typedef CallbackArgs0 Args; + struct RetType: public Callback::RetType { _RetT retVal; }; - protected: Callback0() { } + virtual ~Callback0() { } + + Callback::RetType exec(const CallbackArgs& args) const + { + RetType ret; + ret.retVal = exec(); + return ret; + } + + virtual _RetT exec() const = 0; }; //! Callback base class with no arguments (void specialisation) template <> -class Callback0<void> { +class Callback0<void>: public Callback { public: - virtual ~Callback0() { } - virtual void exec() const = 0; - virtual Callback0* clone() const = 0; + typedef CallbackArgs0 Args; + struct RetType: public Callback::RetType { }; - protected: Callback0() { } + virtual ~Callback0() { } + Callback::RetType exec(const CallbackArgs& args) const + { + exec(); + return RetType(); + } + + virtual void exec() const = 0; }; -/* -------------- Function0 ------------- */ +/* ----------------- Function0 ------------------ */ //! Function callback class with no arguments -template <typename RetType> -class Function0: public Callback0<RetType> { +template <typename _RetT> +class Function0: public Callback0<_RetT> { public: - typedef RetType (*FuncPtr)(); + typedef _RetT (*FuncPtr)(); Function0(FuncPtr ptr) : _funcPtr(ptr) { } - RetType exec() const + _RetT exec() const { return (*_funcPtr)(); } - Callback0<RetType>* clone() const + Callback0<_RetT>* clone() const { return new Function0(*this); } bool operator==(const Function0& f) const @@ -97,25 +128,25 @@ }; //! Returns a function-callback object -template <typename RetType> -Function0<RetType> function(RetType (*ptr)()) -{ return Function0<RetType>(ptr); } +template <typename _RetT> +Function0<_RetT> make_function(_RetT (*ptr)()) +{ return Function0<_RetT>(ptr); } -/* ---------- Method0 ------------ */ +/* ----------------- Method0 ------------------ */ //! Method callback class with no arguments -template <typename RetType, class ObjT> -class Method0: public Callback0<RetType> { +template <typename _RetT, class ObjT> +class Method0: public Callback0<_RetT> { public: - typedef RetType (ObjT::*FuncPtr)(); + typedef _RetT (ObjT::*FuncPtr)(); Method0(ObjT* obj, FuncPtr ptr) : _obj(obj), _funcPtr(ptr) { } - RetType exec() const + _RetT exec() const { return (_obj->*_funcPtr)(); } - Callback0<RetType>* clone() const + Callback0<_RetT>* clone() const { return new Method0(*this); } bool operator==(const Method0& f) const @@ -150,282 +181,15 @@ }; //! Returns a method-callback object -template <typename RetType, class ObjT> -Method0<RetType,ObjT> method(ObjT* obj, RetType (ObjT::*ptr)()) -{ return Method0<RetType,ObjT>(obj, ptr); } - - - - -/* ----------------- Callback1 ------------------ */ - -//! Callback base class with one argument -template <typename RetType, typename ArgType1> -class Callback1 { - public: - virtual ~Callback1() { } - virtual RetType exec(ArgType1) const = 0; - virtual Callback1* clone() const = 0; - - protected: - Callback1() { } -}; - -//! Callback base class with one argument (void specialisation) -template <typename ArgType1> -class Callback1<void, ArgType1> { - public: - virtual ~Callback1() { } - virtual void exec(ArgType1) const = 0; - virtual Callback1* clone() const = 0; - - protected: - Callback1() { } - -}; - -/* -------------- Function1 ------------- */ - -//! Function callback class with one argument -template <typename RetType, typename ArgType1> -class Function1: public Callback1<RetType, ArgType1> { - public: - typedef RetType (*FuncPtr)(ArgType1); - - Function1(FuncPtr ptr) - : _funcPtr(ptr) { } - - RetType exec(ArgType1 arg1) const - { return (*_funcPtr)(arg1); } - - Callback1<RetType, ArgType1>* clone() const - { return new Function1(*this); } - - bool operator==(const Function1& f) const - { return _funcPtr == f._funcPtr; } - - private: - FuncPtr _funcPtr; -}; - -//! Function callback class with one argument (void specialisation) -template <typename ArgType1> -class Function1<void, ArgType1>: public Callback1<void, ArgType1> { - public: - typedef void (*FuncPtr)(ArgType1); - - Function1(FuncPtr ptr) - : _funcPtr(ptr) { } - - void exec(ArgType1 arg1) const - { (*_funcPtr)(arg1); } - - Callback1<void, ArgType1>* clone() const - { return new Function1(*this); } - - bool operator==(const Function1& f) const - { return _funcPtr == f._funcPtr; } - - private: - FuncPtr _funcPtr; -}; - -//! Returns a function-callback object -template <typename RetType, typename ArgType1> -Function1<RetType, ArgType1> function(RetType (*ptr)(ArgType1)) -{ return Function1<RetType, ArgType1>(ptr); } - -/* ---------- Method1 ------------ */ - -//! Method callback class with one arguments -template <typename RetType, class ObjT, typename ArgType1> -class Method1: public Callback1<RetType, ArgType1> { - public: - typedef RetType (ObjT::*FuncPtr)(ArgType1); - - Method1(ObjT* obj, FuncPtr ptr) - : _obj(obj), _funcPtr(ptr) { } - - RetType exec(ArgType1 arg1) const - { return (_obj->*_funcPtr)(arg1); } - - Callback1<RetType, ArgType1>* clone() const - { return new Method1(*this); } - - bool operator==(const Method1& f) const - { return _obj == f._obj && _funcPtr == f._funcPtr; } - - private: - ObjT* _obj; - FuncPtr _funcPtr; -}; - -//! Method callback class with no arguments (void specialisation) -template <class ObjT, typename ArgType1> -class Method1<void, ObjT, ArgType1>: public Callback1<void, ArgType1> { - public: - typedef void (ObjT::*FuncPtr)(ArgType1); - - Method1(ObjT* obj, FuncPtr ptr) - : _obj(obj), _funcPtr(ptr) { } - - void exec(ArgType1 arg1) const - { (_obj->*_funcPtr)(arg1); } - - Callback1<void, ArgType1>* clone() const - { return new Method1(*this); } - - bool operator==(const Method1& f) const - { return _obj == f._obj && _funcPtr == f._funcPtr; } - - private: - ObjT* _obj; - FuncPtr _funcPtr; -}; - -//! Returns a method-callback object -template <typename RetType, class ObjT, typename ArgType1> -Method1<RetType, ObjT, ArgType1> method(ObjT* obj, RetType (ObjT::*ptr)(ArgType1)) -{ return Method1<RetType, ObjT, ArgType1>(obj, ptr); } - - - - -/* ----------------- Callback2 ------------------ */ - -//! Callback base class with two arguments -template <typename RetType, typename ArgType1, typename ArgType2> -class Callback2 { - public: - virtual ~Callback2() { } - virtual RetType exec(ArgType1, ArgType2) const = 0; - virtual Callback2* clone() const = 0; - - protected: - Callback2() { } -}; - -//! Callback base class with two arguments (void specialisation) -template <typename ArgType1, typename ArgType2> -class Callback2<void, ArgType1, ArgType2> { - public: - virtual ~Callback2() { } - virtual void exec(ArgType1, ArgType2) const = 0; - virtual Callback2* clone() const = 0; - - protected: - Callback2() { } - -}; - -/* -------------- Function2 ------------- */ - -//! Function callback class with two arguments -template <typename RetType, typename ArgType1, typename ArgType2> -class Function2: public Callback2<RetType, ArgType1, ArgType2> { - public: - typedef RetType (*FuncPtr)(ArgType1, ArgType2); - - Function2(FuncPtr ptr) - : _funcPtr(ptr) { } - - RetType exec(ArgType1 arg1, ArgType2 arg2) const - { return (*_funcPtr)(arg1, arg2); } - - Callback2<RetType, ArgType1, ArgType2>* clone() const - { return new Function2(*this); } - - bool operator==(const Function2& f) const - { return _funcPtr == f._funcPtr; } - - private: - FuncPtr _funcPtr; -}; - -//! Function callback class with two arguments (void specialisation) -template <typename ArgType1, typename ArgType2> -class Function2<void, ArgType1, ArgType2>: public Callback2<void, ArgType1, ArgType2> { - public: - typedef void (*FuncPtr)(ArgType1, ArgType2); - - Function2(FuncPtr ptr) - : _funcPtr(ptr) { } - - void exec(ArgType1 arg1, ArgType2 arg2) const - { (*_funcPtr)(arg1, arg2); } - - Callback2<void, ArgType1, ArgType2>* clone() const - { return new Function2(*this); } - - bool operator==(const Function2& f) const - { return _funcPtr == f._funcPtr; } - - private: - FuncPtr _funcPtr; -}; - -//! Returns a function-callback object -template <typename RetType, typename ArgType1, typename ArgType2> -Function2<RetType, ArgType1, ArgType2> function(RetType (*ptr)(ArgType1,ArgType2)) -{ return Function2<RetType, ArgType1, ArgType2>(ptr); } - -/* ---------- Method2 ------------ */ - -//! Method callback class with two arguments -template <typename RetType, class ObjT, typename ArgType1, typename ArgType2> -class Method2: public Callback2<RetType, ArgType1, ArgType2> { - public: - typedef RetType (ObjT::*FuncPtr)(ArgType1, ArgType2); - - Method2(ObjT* obj, FuncPtr ptr) - : _obj(obj), _funcPtr(ptr) { } - - RetType exec(ArgType1 arg1, ArgType2 arg2) const - { return (_obj->*_funcPtr)(arg1, arg2); } - - Callback2<RetType, ArgType1, ArgType2>* clone() const - { return new Method2(*this); } - - bool operator==(const Method2& f) const - { return _obj == f._obj && _funcPtr == f._funcPtr; } - - private: - ObjT* _obj; - FuncPtr _funcPtr; -}; - -//! Method callback class with two arguments (void specialisation) -template <class ObjT, typename ArgType1, typename ArgType2> -class Method2<void, ObjT, ArgType1, ArgType2>: - public Callback2<void, ArgType1, ArgType2> -{ - public: - typedef void (ObjT::*FuncPtr)(ArgType1, ArgType2); - - Method2(ObjT* obj, FuncPtr ptr) - : _obj(obj), _funcPtr(ptr) { } - - void exec(ArgType1 arg1, ArgType2 arg2) const - { (_obj->*_funcPtr)(arg1, arg2); } - - Callback2<void, ArgType1, ArgType2>* clone() const - { return new Method2(*this); } - - bool operator==(const Method2& f) const - { return _obj == f._obj && _funcPtr == f._funcPtr; } - - private: - ObjT* _obj; - FuncPtr _funcPtr; -}; - -//! Returns a method-callback object -template <typename RetType, class ObjT, typename ArgType1, typename ArgType2> -Method2<RetType, ObjT, ArgType1, ArgType2> -method(ObjT* obj, RetType (ObjT::*ptr)(ArgType1, ArgType2)) -{ return Method2<RetType, ObjT, ArgType1, ArgType2>(obj, ptr); } - +template <typename _RetT, class _ObjT> +Method0<_RetT,_ObjT> make_method(_ObjT* obj, _RetT (_ObjT::*ptr)()) +{ return Method0<_RetT,_ObjT>(obj, ptr); } } // !namespace P +#include <pclasses/CallbackN1.h> +#include <pclasses/CallbackN2.h> +#include <pclasses/CallbackN3.h> +#include <pclasses/CallbackN4.h> + #endif |
From: Christian P. <cp...@us...> - 2005-01-28 11:57:21
|
Update of /cvsroot/pclasses/pclasses2/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21151/test Modified Files: ThreadTest.cpp Log Message: Fixes for Thread changes. Index: ThreadTest.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/test/ThreadTest.cpp,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- ThreadTest.cpp 22 Dec 2004 17:54:37 -0000 1.1.1.1 +++ ThreadTest.cpp 28 Jan 2005 11:57:12 -0000 1.2 @@ -32,13 +32,13 @@ : Thread(detach) { } - int main(void *arg) + int main() { sleep(5000); if(detached()) ThreadTest::sem.post(); - return (int)arg; + return 0; } }; @@ -47,27 +47,35 @@ std::cout << "thread 1.. " << std::endl; TestThread* thread = new TestThread(false); - thread->start(0); - P_TEST_EXCEPTION(thread->start(0), LogicError); + thread->start(); + P_TEST_EXCEPTION(thread->start(), LogicError); P_TEST(thread->join() == 0); P_TEST_EXCEPTION(thread->join(), LogicError); std::cout << "thread 2.. " << std::endl; - thread->start((void*)1); + thread->start(); - P_TEST(thread->join() == 1); + P_TEST(thread->join() == 0); delete thread; std::cout << "thread 3.. " << std::endl; thread = new TestThread(true); - thread->start((void*)2); + thread->start(); P_TEST_EXCEPTION(thread->join(), System::SystemError); sem.wait(); delete thread; + + System::Thread::spawn(method(this, &ThreadTest::spawnedTest), &sem); + sem.wait(); sem.wait(); } + void spawnedTest() + { + std::cout << "Hello from spawned callback!" << std::endl; + } + static System::Semaphore sem; }; |
From: Christian P. <cp...@us...> - 2005-01-28 11:54:59
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18629/include/pclasses/IO Modified Files: URL.h Log Message: Changed ArgumentMap from map<string,string> to PropertyMap<string,string>. Index: URL.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/IO/URL.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- URL.h 17 Jan 2005 21:55:23 -0000 1.2 +++ URL.h 28 Jan 2005 11:54:50 -0000 1.3 @@ -22,6 +22,7 @@ #include <pclasses/Export.h> #include <pclasses/Exception.h> +#include <pclasses/PropertyMap.h> #include <iostream> #include <map> #include <string> @@ -51,7 +52,7 @@ */ class PIO_EXPORT URL { public: - typedef std::map<std::string, std::string> ArgumentMap; + typedef PropertyMap<std::string, std::string> ArgumentMap; //! Default constructor /*! @@ -140,6 +141,8 @@ static ArgumentMap fromString(const std::string& args); //! Returns the URL-encoded string representation of the given ArgumentMap + /*! + */ static std::string toString(const ArgumentMap& args); private: |
From: Christian P. <cp...@us...> - 2005-01-28 11:39:47
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17285/include/pclasses/Util Modified Files: ManagedThread.h WorkQueue.h Log Message: Added inline docs. Fixes for changes in Thread. Index: WorkQueue.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Util/WorkQueue.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- WorkQueue.h 23 Jan 2005 13:51:38 -0000 1.2 +++ WorkQueue.h 28 Jan 2005 11:39:36 -0000 1.3 @@ -80,7 +80,7 @@ ~WorkerThread() throw(); private: - virtual int main(); + virtual int mainLoop(); WorkQueue& _queue; }; Index: ManagedThread.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Util/ManagedThread.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- ManagedThread.h 26 Dec 2004 15:22:42 -0000 1.2 +++ ManagedThread.h 28 Jan 2005 11:39:36 -0000 1.3 @@ -29,15 +29,26 @@ namespace Util { -class ManagedThread: private System::Thread { +//! Managed thread +/*! + An advanced threading class that allows to suspend, resume + and exit the thread from the outside (that is other thread + contexts). +*/ +class ManagedThread: public System::Thread { public: + + //! Thread states enum State { - Stopped = 0x01, - Startup = 0x02, - Running = 0x04, - Suspended = 0x08, - Finished = 0x10, - Failed = 0x20 + Stopped = 0x01, /*<! Initial thread state + (or after joining the Thread) */ + Startup = 0x02, /*<! Thread is starting (in init(), + before mainLoop()) */ + Running = 0x04, /*<! Thread is running (in mainLoop()) */ + Suspended = 0x08, /*<! Thread is suspended */ + Finished = 0x10, /*<! Thread is finished */ + Failed = 0x20, /*<! Thread has failed (init() returned != 0) */ + AnyState = 0xff }; ManagedThread() throw(); @@ -46,31 +57,95 @@ //! Returns the current thread-state State state() const throw(System::SystemError); + //! Start the thread void start() throw(LogicError, System::SystemError); + + //! Signal the thread to exit void stop() throw(); + + //! Signal the thread to suspend void suspend() throw(); + + //! Signal the thread to resume void resume() throw(System::SystemError); + //! Wait for thread termination and cleanup + /*! + Wait for thread termination and cleanup all used + resources. You should signal the thread to stop before + waiting for it's termination. + */ int join() throw(System::SystemError); - + + //! Wait for state-change State wait(int stateMask); + + //! Wait for state-change with timeout State tryWait(int stateMask, unsigned int timeout = 0); protected: + + //! Test for exit/suspend + /*! + This method should be frequently called to allow suspend, + resume and exit notifies. If the thread should exit the + method returns false. If suspend was requested the method + calls suspended() and waits until the thread has been + resumed. Before returning control to the caller, resumed() + will be called. + \return true if the main-loop should continue, + false otherwise. + */ bool shouldRun() throw(System::SystemError); - + + //! Thread initialization + /*! + The method is called before the mainLoop() is executed. + When returning with an non-zero error-code the thread will + terminate and set the status to Failed. When successfull the + status will be set to Running. + \return zero if the initialization was the successfull, + non-zero exit-code otherwise. + */ virtual int init(); - virtual int main() = 0; + + //! Threads main-loop + /*! + The method should implement the threads main-loop and is + called after successfully returning from the init() method. + The implementation of this method should frequently call + shouldRun() to allow suspend, resume and exit notifies. + */ + virtual int mainLoop() = 0; + + //! Cleanup method + /*! + The method is called when the thread is about to exit, + after returning from the main() method. When returning + from this method the status of the thread will be set + to Finished. + */ virtual void cleanup(); - virtual void suspended() {}; - virtual void resumed() {}; - // ^^^^^ACHTUNG: no-op impls of suspended()/resumed() added by - // stephan to work around a link error. i have no clue what - // they SHOULD do. + + //! Called when the thread has been suspended + /*! + The method is called when the thread is about to suspend + its execution. + */ + virtual void suspended(); + + //! Called when the thread has been resumed + /*! + The method is called when the thread is about to resume + its execution. + */ + virtual void resumed(); private: - virtual int main(void* arg); + //! Implements the Threads main-method + virtual int main(); + //! Changes state and notifies the Condition void changeState(State newState); State _state; |
From: Christian P. <cp...@us...> - 2005-01-28 11:39:47
|
Update of /cvsroot/pclasses/pclasses2/src/Util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17285/src/Util Modified Files: ManagedThread.cpp WorkQueue.cpp Log Message: Added inline docs. Fixes for changes in Thread. Index: ManagedThread.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Util/ManagedThread.cpp,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- ManagedThread.cpp 22 Dec 2004 17:54:35 -0000 1.1.1.1 +++ ManagedThread.cpp 28 Jan 2005 11:39:37 -0000 1.2 @@ -47,7 +47,7 @@ Mutex::ScopedLock lck(_stateMtx); if(_state == Stopped) { - Thread::start(0); + Thread::start(); _state = Startup; _stateCond.broadcast(); @@ -109,7 +109,15 @@ { } -int ManagedThread::main(void* arg) +void ManagedThread::resumed() +{ +} + +void ManagedThread::suspended() +{ +} + +int ManagedThread::main() { int ret = init(); if(ret != 0) @@ -120,7 +128,7 @@ { changeState(Running); - ret = main(); + ret = mainLoop(); cleanup(); changeState(Finished); Index: WorkQueue.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Util/WorkQueue.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- WorkQueue.cpp 23 Jan 2005 13:51:39 -0000 1.2 +++ WorkQueue.cpp 28 Jan 2005 11:39:37 -0000 1.3 @@ -116,7 +116,7 @@ { } -int WorkerThread::main() +int WorkerThread::mainLoop() { WorkItem* item = 0; |
From: Christian P. <cp...@us...> - 2005-01-28 11:36:48
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16395/src/System Modified Files: Thread.posix.cpp Makefile.am Added Files: Thread.common.cpp Log Message: Added Thread::spawn() for spawning callback's in own threads. Added inline docs. Removed void* arg from Thread::main() and Thread::start(). Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/Makefile.am,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- Makefile.am 17 Jan 2005 22:50:39 -0000 1.9 +++ Makefile.am 28 Jan 2005 11:36:38 -0000 1.10 @@ -83,7 +83,7 @@ CPPFLAGS = -DPSYSTEM_BUILD libpclasses_system_la_SOURCES = timeout.cpp SystemError.cpp \ - CriticalSection.cpp Mutex.cpp $(Thread_Sources) \ + 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 --- NEW FILE: Thread.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/Thread.h" #include "pclasses/System/Semaphore.h" namespace P { namespace System { class SpawnedThread: public Thread { public: SpawnedThread(const Callback0<void>& cb, Semaphore* sem) : Thread(true), _callback(cb.clone()), _sem(sem) { } protected: int main() { if(_sem) _sem->post(); _callback->exec(); if(_sem) _sem->post(); delete this; return 0; } private: Callback0<void>* _callback; Semaphore* _sem; }; void Thread::spawn(const Callback0<void>& cb, Semaphore* sem) throw(SystemError) { SpawnedThread* thr = new SpawnedThread(cb, sem); thr->start(); // we don't leak the object ... it is self-deleted } } // !namespace System } // !namespace P Index: Thread.posix.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/Thread.posix.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- Thread.posix.cpp 24 Dec 2004 17:07:06 -0000 1.2 +++ Thread.posix.cpp 28 Jan 2005 11:36:38 -0000 1.3 @@ -22,6 +22,7 @@ #include "pclasses/Alloc.h" #include "pclasses/ScopedPtr.h" #include "pclasses/System/Thread.h" +#include "pclasses/System/Semaphore.h" #include "timeout.h" #include <pthread.h> @@ -33,20 +34,22 @@ namespace System { struct Thread::Handle { - Thread* obj; - void* arg; - bool detached; - pthread_t thread; - + Thread* obj; + bool detached; + pthread_t thread; + static void* entry(void* arg) { Handle* h = (Handle*)arg; - void* ret = (void*)h->obj->main(h->arg); - + + // do not access the Thread object after running main() + // it may be alreaedy deleted... (we want self-deleting threads) + void* ret = (void*)h->obj->main(); + // detached Thread's self-delete their handle if(h->detached) delete h; - + return ret; } }; @@ -60,14 +63,14 @@ { } -void Thread::start(void* arg) throw(LogicError, SystemError) +void Thread::start() throw(LogicError, SystemError) { if(_handle) throw LogicError("Thread is already running", P_SOURCEINFO); ScopedPtr<Handle> handle(new Handle); - handle->obj = this; - handle->arg = arg; + + handle->obj = this; handle->detached = _detached; pthread_attr_t attrs; @@ -123,6 +126,7 @@ return _detached; } + } // !namespace System } // !namespace P |
From: Christian P. <cp...@us...> - 2005-01-28 11:36:46
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16395/include/pclasses/System Modified Files: Thread.h Log Message: Added Thread::spawn() for spawning callback's in own threads. Added inline docs. Removed void* arg from Thread::main() and Thread::start(). Index: Thread.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/System/Thread.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Thread.h 24 Jan 2005 01:19:25 -0000 1.3 +++ Thread.h 28 Jan 2005 11:36:37 -0000 1.4 @@ -24,27 +24,42 @@ #include <pclasses/Export.h> #include <pclasses/Exception.h> #include <pclasses/NonCopyable.h> +#include <pclasses/Callback.h> #include <pclasses/System/SystemError.h> namespace P { namespace System { +class Semaphore; + +//! Simple threading class class PSYSTEM_EXPORT Thread: public NonCopyable { public: Thread(bool detached) throw(); virtual ~Thread() throw(); - void start(void* arg) throw(LogicError, SystemError); - int join() throw(LogicError, SystemError); + //! Start the thread + virtual void start() throw(LogicError, SystemError); + //! Wait for thread termination + /*! + Wait until the thread has exited. + \return the threads exit-code (returned by main()) + */ + virtual int join() throw(LogicError, SystemError); + + //! Test if thread is detached bool detached() const throw(); static void yield() throw(); static void sleep(unsigned int ms) throw(); + static void spawn(const Callback0<void>& cb, Semaphore* sem = 0) + throw(SystemError); + protected: - virtual int main(void* arg) = 0; + virtual int main() = 0; private: struct Handle; |
From: Christian P. <cp...@us...> - 2005-01-28 11:33:43
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16015/include/pclasses Modified Files: Callback.h Log Message: Added clone() to Callback classes. Index: Callback.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Callback.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Callback.h 11 Jan 2005 14:50:52 -0000 1.3 +++ Callback.h 28 Jan 2005 11:33:28 -0000 1.4 @@ -31,6 +31,7 @@ public: virtual ~Callback0() { } virtual RetType exec() const = 0; + virtual Callback0* clone() const = 0; protected: Callback0() { } @@ -42,6 +43,7 @@ public: virtual ~Callback0() { } virtual void exec() const = 0; + virtual Callback0* clone() const = 0; protected: Callback0() { } @@ -62,6 +64,9 @@ RetType exec() const { return (*_funcPtr)(); } + Callback0<RetType>* clone() const + { return new Function0(*this); } + bool operator==(const Function0& f) const { return _funcPtr == f._funcPtr; } @@ -80,7 +85,10 @@ void exec() const { (*_funcPtr)(); } - + + Callback0<void>* clone() const + { return new Function0(*this); } + bool operator==(const Function0& f) const { return _funcPtr == f._funcPtr; } @@ -107,6 +115,9 @@ RetType exec() const { return (_obj->*_funcPtr)(); } + Callback0<RetType>* clone() const + { return new Method0(*this); } + bool operator==(const Method0& f) const { return _obj == f._obj && _funcPtr == f._funcPtr; } @@ -127,6 +138,9 @@ void exec() const { (_obj->*_funcPtr)(); } + Callback0<void>* clone() const + { return new Method0(*this); } + bool operator==(const Method0& f) const { return _obj == f._obj && _funcPtr == f._funcPtr; } @@ -151,6 +165,7 @@ public: virtual ~Callback1() { } virtual RetType exec(ArgType1) const = 0; + virtual Callback1* clone() const = 0; protected: Callback1() { } @@ -162,6 +177,7 @@ public: virtual ~Callback1() { } virtual void exec(ArgType1) const = 0; + virtual Callback1* clone() const = 0; protected: Callback1() { } @@ -182,6 +198,9 @@ RetType exec(ArgType1 arg1) const { return (*_funcPtr)(arg1); } + Callback1<RetType, ArgType1>* clone() const + { return new Function1(*this); } + bool operator==(const Function1& f) const { return _funcPtr == f._funcPtr; } @@ -201,6 +220,9 @@ void exec(ArgType1 arg1) const { (*_funcPtr)(arg1); } + Callback1<void, ArgType1>* clone() const + { return new Function1(*this); } + bool operator==(const Function1& f) const { return _funcPtr == f._funcPtr; } @@ -227,6 +249,9 @@ RetType exec(ArgType1 arg1) const { return (_obj->*_funcPtr)(arg1); } + Callback1<RetType, ArgType1>* clone() const + { return new Method1(*this); } + bool operator==(const Method1& f) const { return _obj == f._obj && _funcPtr == f._funcPtr; } @@ -247,6 +272,9 @@ void exec(ArgType1 arg1) const { (_obj->*_funcPtr)(arg1); } + Callback1<void, ArgType1>* clone() const + { return new Method1(*this); } + bool operator==(const Method1& f) const { return _obj == f._obj && _funcPtr == f._funcPtr; } @@ -271,6 +299,7 @@ public: virtual ~Callback2() { } virtual RetType exec(ArgType1, ArgType2) const = 0; + virtual Callback2* clone() const = 0; protected: Callback2() { } @@ -282,6 +311,7 @@ public: virtual ~Callback2() { } virtual void exec(ArgType1, ArgType2) const = 0; + virtual Callback2* clone() const = 0; protected: Callback2() { } @@ -302,6 +332,9 @@ RetType exec(ArgType1 arg1, ArgType2 arg2) const { return (*_funcPtr)(arg1, arg2); } + Callback2<RetType, ArgType1, ArgType2>* clone() const + { return new Function2(*this); } + bool operator==(const Function2& f) const { return _funcPtr == f._funcPtr; } @@ -321,6 +354,9 @@ void exec(ArgType1 arg1, ArgType2 arg2) const { (*_funcPtr)(arg1, arg2); } + Callback2<void, ArgType1, ArgType2>* clone() const + { return new Function2(*this); } + bool operator==(const Function2& f) const { return _funcPtr == f._funcPtr; } @@ -347,6 +383,9 @@ RetType exec(ArgType1 arg1, ArgType2 arg2) const { return (_obj->*_funcPtr)(arg1, arg2); } + Callback2<RetType, ArgType1, ArgType2>* clone() const + { return new Method2(*this); } + bool operator==(const Method2& f) const { return _obj == f._obj && _funcPtr == f._funcPtr; } @@ -369,6 +408,9 @@ void exec(ArgType1 arg1, ArgType2 arg2) const { (_obj->*_funcPtr)(arg1, arg2); } + Callback2<void, ArgType1, ArgType2>* clone() const + { return new Method2(*this); } + bool operator==(const Method2& f) const { return _obj == f._obj && _funcPtr == f._funcPtr; } |
From: Christian P. <cp...@us...> - 2005-01-28 11:33:10
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15733/include/pclasses Modified Files: PropertyMap.h Log Message: Added clear() and compare operator. Index: PropertyMap.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/PropertyMap.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- PropertyMap.h 14 Jan 2005 14:52:57 -0000 1.1 +++ PropertyMap.h 28 Jan 2005 11:32:58 -0000 1.2 @@ -73,12 +73,18 @@ inline iterator end() { return _fields.end(); } + void clear() + { _fields.clear(); } + std::string& operator[](const KeyType& key) { return _fields[key]; } const std::string& operator[](const KeyType& key) const { return _fields[key]; } + bool operator==(const PropertyMap& p) const + { return _fields == p._fields; } + private: FieldMap _fields; }; |
From: Christian P. <cp...@us...> - 2005-01-27 10:41:53
|
Update of /cvsroot/pclasses/pclasses2/src/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1824/src/IO Modified Files: URL.cpp Log Message: Added URL-encoding/decoding. Re-implemented URL-parser (code was too complex and slow). Index: URL.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/IO/URL.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- URL.cpp 17 Jan 2005 21:58:36 -0000 1.2 +++ URL.cpp 27 Jan 2005 10:41:37 -0000 1.3 @@ -28,6 +28,7 @@ #endif #include <sstream> +#include <iomanip> namespace P { namespace IO { @@ -255,7 +256,123 @@ return *this; } -URL& URL::operator=(const std::string& url) throw(InvalidURL/*,NetDbError*/) +URL& URL::operator=(const std::string& url) throw(InvalidURL) +{ + using std::string; + + // file-URLs are handled specially ... + if(url.substr(0, 5) == "file:") + { + _proto = "file"; + _host = ""; + _user = ""; + _passwd = ""; + _port = 0; + _path = decode(url.substr(5, string::npos)); + std::cout << "path: '" << _path << "'" << std::endl; + _args.clear(); + _anchor = ""; + + return *this; + } + + // search for protocol delimiter ... + string::size_type protoEndPos = url.find("://"); + if(protoEndPos == string::npos) + throw InvalidURL("Invalid url", P_SOURCEINFO); + + string proto = url.substr(0, protoEndPos); + + // get the url-component starting positions ... + string::size_type hostStartPos = protoEndPos + 3; + string::size_type pathStartPos = url.find('/', hostStartPos); + string::size_type argsStartPos = url.find('?', pathStartPos == string::npos ? hostStartPos : pathStartPos); + string::size_type anchorStartPos = url.find('#', argsStartPos == string::npos ? hostStartPos : argsStartPos); + + // find the lenght of the hostname ... + string::size_type hostLen; + if(pathStartPos != string::npos) + hostLen = pathStartPos - hostStartPos; + else if(argsStartPos != string::npos) + hostLen = argsStartPos - hostStartPos; + else if(anchorStartPos != string::npos) + hostLen = anchorStartPos - hostStartPos; + else + hostLen = string::npos; + + // get the hostname (including username/passwd and port)... + string host = url.substr(hostStartPos, hostLen); + + // find the length of the path ... + string::size_type pathLen; + if(argsStartPos != string::npos) + pathLen = argsStartPos - pathStartPos; + else if(anchorStartPos != string::npos) + pathLen = anchorStartPos - pathStartPos; + else + pathLen = string::npos; + + // get the path ... + string path = "/"; + if(pathStartPos != string::npos) + path = url.substr(pathStartPos, pathLen); + + string::size_type argsLen; + if(anchorStartPos != string::npos) + argsLen = anchorStartPos - argsStartPos; + else + argsLen = string::npos; + + // get the arguments ... + string args; + if(argsStartPos != string::npos) + args = url.substr(argsStartPos, argsLen); + + // get the anchor ... + string anchor; + if(anchorStartPos != string::npos) + anchor = url.substr(anchorStartPos + 1, string::npos); + + // get username and password from hostname ... + string userPasswd, user, passwd; + hostStartPos = host.find("@"); + if(hostStartPos != string::npos) + { + userPasswd = host.substr(0, hostStartPos); + host = host.substr(hostStartPos + 1, string::npos); + + string::size_type passwdStartPos = userPasswd.find(":"); + if(passwdStartPos != string::npos) + { + user = userPasswd.substr(0, passwdStartPos); + passwd = userPasswd.substr(passwdStartPos + 1, string::npos); + } + } + + // get port from hostname ... + unsigned short port = 0; + string::size_type portStartPos = host.find(":"); + if(portStartPos != string::npos) + { + string portStr = host.substr(portStartPos + 1, string::npos); + host = host.substr(0, portStartPos); + port = atoi(portStr.c_str()); + } + + _proto = proto; + _host = host; + _user = user; + _passwd = passwd; + _port = port; + _path = path; + _args = fromString(args); + _anchor = anchor; + + return *this; +} + + +/*URL& URL::operator=(const std::string& url) throw(InvalidURL) { std::string proto, host, user, passwd, path, port; std::istringstream is(url); @@ -365,7 +482,13 @@ // parse path while((is >> ch)) + { + // argument delimiter ? + if(ch == '?') + break; + os << ch; + } //@@fixme ... parse args and anchor @@ -379,7 +502,7 @@ _anchor = ""; return *this; -} +}*/ bool URL::operator==(const URL& url) const throw() { @@ -424,7 +547,7 @@ // add URL arguments ... std::string args = URL::toString(url._args); if(!args.empty()) - os << '?' << args; + os << args; // add anchor if set ... if(!url._anchor.empty()) @@ -445,14 +568,68 @@ return is; } +bool charNeedEncode(unsigned char ch) +{ + bool ret = false; + + if((ch <= 0x1f) || (ch == 0x7f) || // ASCII control characters... + (ch >= 0x80 && ch <= 0xff) || // non-ASCII characters ... + (ch == 0x24) || (ch == 0x26) || // reserved characters... + (ch == 0x2b) || (ch == 0x2c) || + (ch == 0x2f) || (ch == 0x3a) || + (ch == 0x3b) || (ch == 0x3d) || + (ch == 0x3f) || (ch == 0x40) || + (ch == 0x20) || (ch == 0x22) || // unsafe characters ... + (ch == 0x3c) || (ch == 0x3e) || + (ch == 0x23) || (ch == 0x25) || + (ch == 0x7b) || (ch == 0x7d) || + (ch == 0x7c) || (ch == 0x5c) || + (ch == 0x5e) || (ch == 0x7e) || + (ch == 0x5b) || (ch == 0x5d) || + (ch == 0x60)) + ret = true; + + return ret; +} + std::string URL::encode(const std::string& str) { - return str; + std::ostringstream os; + os << std::setfill('0'); + + for(std::string::size_type i = 0; i < str.size(); ++i) + { + char ch = str[i]; + if(charNeedEncode(ch)) + os << '%' << std::setw(2) << std::hex << (((int)ch) & 0x000000ff); + else + os << ch; + } + + return os.str(); } std::string URL::decode(const std::string& str) { - return str; + std::ostringstream os; + std::istringstream is(str); + + char ch; + while((is >> ch)) + { + if(ch == '%') + { + int val; + is >> std::hex >> val; + os << (char) val; + } + else + { + os << ch; + } + } + + return os.str(); } } // !namespace IO |
From: Christian P. <cp...@us...> - 2005-01-26 10:27:10
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25831/src/System Modified Files: Directory.posix.cpp Log Message: Fixed a bug in posix impl. of Directory. Index: Directory.posix.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/Directory.posix.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- Directory.posix.cpp 27 Dec 2004 07:04:49 -0000 1.2 +++ Directory.posix.cpp 26 Jan 2005 10:27:00 -0000 1.3 @@ -38,6 +38,7 @@ throw IO::IOError(errno, "Could not open directory", P_SOURCEINFO); _handle = (unsigned long)d; + reload(); } Directory::~Directory() throw() |
From: Christian P. <cp...@us...> - 2005-01-26 10:25:52
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Net In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25401/include/pclasses/Net Modified Files: InetAddress.h InetSocket.h NetworkAddress.h RTSPHeader.h RTSPSession.h RTSPSocket.h Log Message: Added export-macros. Added StreamSocketServer ctor. Index: RTSPSession.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Net/RTSPSession.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- RTSPSession.h 16 Jan 2005 00:03:20 -0000 1.1 +++ RTSPSession.h 26 Jan 2005 10:25:40 -0000 1.2 @@ -18,6 +18,7 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include <pclasses/Export.h> #include <string> namespace P { @@ -25,7 +26,7 @@ namespace Net { //! RTSP Session -class RTSPSession { +class PNET_EXPORT RTSPSession { public: enum State { Setup, Index: RTSPHeader.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Net/RTSPHeader.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- RTSPHeader.h 14 Jan 2005 14:56:01 -0000 1.1 +++ RTSPHeader.h 26 Jan 2005 10:25:40 -0000 1.2 @@ -21,6 +21,7 @@ #ifndef P_Net_RTSPHeader_h #define P_Net_RTSPHeader_h +#include <pclasses/Export.h> #include <pclasses/PropertyMap.h> #include <string> @@ -29,7 +30,7 @@ namespace Net { //! RTSP Header base-class -class RTSPHeader: public PropertyMap<std::string, std::string> { +class PNET_EXPORT RTSPHeader: public PropertyMap<std::string, std::string> { public: RTSPHeader(); ~RTSPHeader(); @@ -73,7 +74,7 @@ }; //! RTSP Request header -class RTSPRequestHeader: public RTSPHeader { +class PNET_EXPORT RTSPRequestHeader: public RTSPHeader { public: RTSPRequestHeader(); ~RTSPRequestHeader(); @@ -115,7 +116,7 @@ }; //! RTSP Response header -class RTSPResponseHeader: public RTSPHeader { +class PNET_EXPORT RTSPResponseHeader: public RTSPHeader { public: RTSPResponseHeader(); ~RTSPResponseHeader(); Index: InetSocket.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Net/InetSocket.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- InetSocket.h 23 Dec 2004 04:32:16 -0000 1.2 +++ InetSocket.h 26 Jan 2005 10:25:40 -0000 1.3 @@ -21,6 +21,7 @@ #ifndef P_Net_InetSocket_h #define P_Net_InetSocket_h +#include <pclasses/Export.h> #include <pclasses/Net/Socket.h> #include <pclasses/Net/InetAddress.h> @@ -29,7 +30,7 @@ namespace Net { //! Internet IPv4 Socket -class InetSocket: public virtual Socket { +class PNET_EXPORT InetSocket: public virtual Socket { public: InetSocket() throw(); InetSocket(Type t, int proto) throw(IO::IOError); @@ -42,16 +43,16 @@ int timeToLive() const throw(IO::IOError); protected: - void open(Type type, int proto) throw(LogicError, IO::IOError); + void open(Type type, int proto) throw(IO::IOError); }; //! UDP Datagram Socket -class UDPSocket: public InetSocket, public DatagramSocket { +class PNET_EXPORT UDPSocket: public InetSocket, public DatagramSocket { public: UDPSocket() throw(IO::IOError); ~UDPSocket() throw(); - void open() throw(LogicError, IO::IOError); + void open() throw(IO::IOError); void setMulticastTTL(int ttl) throw(IO::IOError); int multicastTTL() const throw(IO::IOError); @@ -65,12 +66,14 @@ }; //! TCP Streaming Socket -class TCPSocket: public InetSocket, public StreamSocket { +class PNET_EXPORT TCPSocket: public InetSocket, public StreamSocket { public: TCPSocket() throw(IO::IOError); + TCPSocket(StreamSocketServer& srv) throw(IO::IOError); ~TCPSocket() throw(); - void open() throw(LogicError, IO::IOError); + void open() throw(IO::IOError); + void open(StreamSocketServer& srv) throw(IO::IOError); }; Index: NetworkAddress.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Net/NetworkAddress.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- NetworkAddress.h 7 Jan 2005 13:38:22 -0000 1.3 +++ NetworkAddress.h 26 Jan 2005 10:25:40 -0000 1.4 @@ -21,6 +21,7 @@ #ifndef P_Net_NetworkAddress_h #define P_Net_NetworkAddress_h +#include <pclasses/Export.h> #include <pclasses/BasicTypes.h> #include <string> @@ -28,7 +29,7 @@ namespace Net { -class NetworkAddress { +class PNET_EXPORT NetworkAddress { public: NetworkAddress(const NetworkAddress& addr); NetworkAddress(int family, const void* addr, size_t addrLen); Index: RTSPSocket.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Net/RTSPSocket.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- RTSPSocket.h 16 Jan 2005 00:05:00 -0000 1.2 +++ RTSPSocket.h 26 Jan 2005 10:25:40 -0000 1.3 @@ -18,6 +18,10 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#ifndef P_Net_RTSPSocket_h +#define P_Net_RTSPSocket_h + +#include <pclasses/Export.h> #include <pclasses/IO/URL.h> #include <pclasses/IO/IODevice.h> #include <pclasses/Net/Socket.h> @@ -76,7 +80,7 @@ class RTSPSocket; //! RTSP response class -class RTSPResponse: public IO::IODevice { +class PNET_EXPORT RTSPResponse: public IO::IODevice { public: RTSPResponse(const std::string& protoVer, int code, const std::string& reason); @@ -111,10 +115,11 @@ //! RTSP coomunication socket -class RTSPSocket: public StreamSocket { +class PNET_EXPORT RTSPSocket: public StreamSocket { public: RTSPSocket(); RTSPSocket(Socket::Domain d); + RTSPSocket(StreamSocketServer& srv); RTSPSocket(const NetworkAddress& addr, port_t port); ~RTSPSocket() throw(); @@ -138,3 +143,5 @@ } // !namespace Net } // !namespace P + +#endif Index: InetAddress.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Net/InetAddress.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- InetAddress.h 7 Jan 2005 13:40:30 -0000 1.3 +++ InetAddress.h 26 Jan 2005 10:25:40 -0000 1.4 @@ -21,6 +21,7 @@ #ifndef P_Net_InetAddress_h #define P_Net_InetAddress_h +#include <pclasses/Export.h> #include <pclasses/Net/NetworkAddress.h> struct in_addr; @@ -29,7 +30,7 @@ namespace Net { -class InetAddress: public NetworkAddress { +class PNET_EXPORT InetAddress: public NetworkAddress { public: enum Special { Any = 0x00000000, |
From: Christian P. <cp...@us...> - 2005-01-26 10:25:52
|
Update of /cvsroot/pclasses/pclasses2/src/Net In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25401/src/Net Modified Files: HTTPClient.cpp InetSocket.cpp RTSPSocket.cpp Log Message: Added export-macros. Added StreamSocketServer ctor. Index: RTSPSocket.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Net/RTSPSocket.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- RTSPSocket.cpp 16 Jan 2005 00:05:00 -0000 1.2 +++ RTSPSocket.cpp 26 Jan 2005 10:25:40 -0000 1.3 @@ -26,8 +26,6 @@ namespace Net { -extern Socket::Domain AddrFamily2Domain(int family); - RTSPRequest::RTSPRequest() : _method(UNKNOWN), _url(), _urlValid(false), _protoVer("RTSP/1.0") { @@ -214,10 +212,15 @@ open(d); } +RTSPSocket::RTSPSocket(StreamSocketServer& srv) +: StreamSocket(srv) +{ +} + RTSPSocket::RTSPSocket(const NetworkAddress& addr, port_t port) : StreamSocket() { - open(AddrFamily2Domain(addr.family())); + open(addrFamily2Domain(addr.family())); connect(addr, port); } Index: HTTPClient.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Net/HTTPClient.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- HTTPClient.cpp 14 Jan 2005 14:58:05 -0000 1.2 +++ HTTPClient.cpp 26 Jan 2005 10:25:40 -0000 1.3 @@ -221,32 +221,6 @@ return ret; } -Socket::Domain AddrFamily2Domain(int family) -{ - Socket::Domain d; - switch(family) - { - case AF_INET: - d = Socket::Inet; - break; - case AF_INET6: - d = Socket::Inet6; - break; - case AF_IPX: - d = Socket::IPX; - break; - case AF_APPLETALK: - d = Socket::AppleTalk; - break; - default: - throw; - } - - return d; -} - - - HTTPClient::HTTPClient() : StreamSocket() { @@ -261,7 +235,7 @@ HTTPClient::HTTPClient(const NetworkAddress& addr, port_t port) : StreamSocket() { - open(AddrFamily2Domain(addr.family())); + open(addrFamily2Domain(addr.family())); connect(addr, port); } Index: InetSocket.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Net/InetSocket.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- InetSocket.cpp 23 Dec 2004 04:32:18 -0000 1.2 +++ InetSocket.cpp 26 Jan 2005 10:25:40 -0000 1.3 @@ -44,7 +44,7 @@ { } -void InetSocket::open(Type type, int proto) throw(LogicError, IO::IOError) +void InetSocket::open(Type type, int proto) throw(IO::IOError) { Socket::open(Socket::Inet, type, proto); } @@ -84,7 +84,7 @@ { } -void UDPSocket::open() throw(LogicError, IO::IOError) +void UDPSocket::open() throw(IO::IOError) { InetSocket::open(Socket::Datagram, IPPROTO_UDP); } @@ -164,11 +164,22 @@ InetSocket::open(Socket::Stream, IPPROTO_TCP); } +TCPSocket::TCPSocket(StreamSocketServer& srv) throw(IO::IOError) +: InetSocket(), StreamSocket() +{ + open(srv); +} + TCPSocket::~TCPSocket() throw() { } -void TCPSocket::open() throw(LogicError, IO::IOError) +void TCPSocket::open(StreamSocketServer& srv) throw(IO::IOError) +{ + StreamSocket::open(srv); +} + +void TCPSocket::open() throw(IO::IOError) { InetSocket::open(Socket::Stream, IPPROTO_TCP); } |
From: Christian P. <cp...@us...> - 2005-01-26 10:23:26
|
Update of /cvsroot/pclasses/pclasses2/src/Net In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24824/src/Net Modified Files: Socket.cpp Log Message: Added export-macros. Added "static int Socket::wait()" for waiting on a number of sockets. Index: Socket.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Net/Socket.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- Socket.cpp 24 Jan 2005 23:00:39 -0000 1.6 +++ Socket.cpp 26 Jan 2005 10:23:17 -0000 1.7 @@ -304,26 +304,37 @@ return ret; } -int Socket::wait(int wait, unsigned int timeout) throw(IO::IOError) +int Socket::wait(int wf, unsigned int timeout) throw(IO::IOError) +{ + Socket* s[] = { this }; + int w[] = { wf }; + int ret = wait(s, w, 1, timeout); + if(ret != 1) + return 0; + + return w[0]; +} + +int Socket::wait(Socket* s[], int wait[], int num, unsigned int timeout) + throw(IO::IOError) { fd_set readFds, writeFds; + FD_ZERO(&readFds); + FD_ZERO(&writeFds); - if(wait & WaitInput) + for(int i = 0; i < num; ++i) { - FD_ZERO(&readFds); - FD_SET(_handle, &readFds); - } + if(wait[i] & WaitInput) + FD_SET(s[i]->handle(), &readFds); - if(wait & WaitOutput) - { - FD_ZERO(&writeFds); - FD_SET(_handle, &writeFds); + if(wait[i] & WaitOutput) + FD_SET(s[i]->handle(), &writeFds); } struct timeval timeVal; select_loop: - int ret = ::select(_handle + 1, &readFds, &writeFds, 0, + int ret = ::select(num + 1, &readFds, &writeFds, 0, get_timeout(&timeVal, timeout, TIMEOUT_RELATIVE)); if(ret == -1) @@ -334,15 +345,29 @@ throw IO::IOError(errno, "Could not write to socket", P_SOURCEINFO); } - ret = 0; - - if(wait & WaitInput && FD_ISSET(_handle, &readFds)) - ret |= WaitInput; + int numReady = 0; + for(int i = 0; i < num; ++i) + { + wait[i] = 0; + int r = 0; + + if(FD_ISSET(s[i]->handle(), &readFds)) + { + wait[i] |= WaitInput; + ++r; + } + + if(FD_ISSET(s[i]->handle(), &writeFds)) + { + wait[i] |= WaitOutput; + ++r; + } - if(wait & WaitOutput && FD_ISSET(_handle, &writeFds)) - ret |= WaitOutput; + if(r > 0) + ++numReady; + } - return ret; + return numReady; } void Socket::bind(const NetworkAddress& addr, port_t port) throw(IO::IOError) @@ -369,24 +394,6 @@ throw IO::IOError(errno, "Could not connect socket", P_SOURCEINFO); } -void Socket::listen() throw(IO::IOError) -{ - int ret = ::listen(_handle, 128); - if(ret == -1) - throw IO::IOError(errno, "Could not listen on socket", P_SOURCEINFO); -} - -Socket Socket::accept() throw(IO::IOError) -{ - int ret = ::accept(_handle, 0, 0); - if(ret == -1) - throw IO::IOError(errno, "Could not accept connection on socket", P_SOURCEINFO); - - Socket s; - s.open(ret, _domain, _type, _proto); - return s; -} - void Socket::setSendTimeout(unsigned int timeout) throw(IO::IOError) { SocketOption<SOL_SOCKET, SO_SNDTIMEO, int> opt(_handle); @@ -456,18 +463,6 @@ return _handle; } -void Socket::addListener(IO::IOListener& l) -{ -} - -void Socket::updateListener(IO::IOListener& l) -{ -} - -void Socket::removeListener(IO::IOListener& l) -{ -} - DatagramSocket::DatagramSocket() throw() : Socket() @@ -495,10 +490,88 @@ { } +StreamSocket::StreamSocket(StreamSocketServer& srv) throw(IO::IOError) +: Socket() +{ + open(srv); +} + StreamSocket::~StreamSocket() throw() { } +void StreamSocket::open(StreamSocketServer& srv) throw(IO::IOError) +{ + Socket::open(srv.accept(), srv.domain(), srv.type(), srv.protocol()); +} + +StreamSocketServer::StreamSocketServer(Domain domain, int proto) throw(IO::IOError) +: Socket(domain, Socket::Stream, proto) +{ +} + +StreamSocketServer::StreamSocketServer(const NetworkAddress& addr, port_t port) + throw(IO::IOError) +: Socket(addrFamily2Domain(addr.family()), Socket::Stream, 0) +{ + bind(addr, port); +} + +StreamSocketServer::~StreamSocketServer() throw() +{ +} + +void StreamSocketServer::bind(const NetworkAddress& addr, port_t port) + throw(IO::IOError) +{ + Socket::bind(addr, port); +} + +bool StreamSocketServer::wait(unsigned int timeout) throw(IO::IOError) +{ + bool ret = Socket::wait(WaitOutput, timeout) & WaitOutput ? true : false; + return ret; +} + +void StreamSocketServer::listen() throw(IO::IOError) +{ + int ret = ::listen(handle(), 128); + if(ret == -1) + throw IO::IOError(errno, "Could not listen on socket", P_SOURCEINFO); +} + +int StreamSocketServer::accept() throw(IO::IOError) +{ + int ret = ::accept(handle(), 0, 0); + if(ret == -1) + throw IO::IOError(errno, "Could not accept connection on socket", P_SOURCEINFO); + + return ret; +} + +Socket::Domain Socket::addrFamily2Domain(int family) +{ + Socket::Domain d; + switch(family) + { + case AF_INET: + d = Socket::Inet; + break; + case AF_INET6: + d = Socket::Inet6; + break; + case AF_IPX: + d = Socket::IPX; + break; + case AF_APPLETALK: + d = Socket::AppleTalk; + break; + default: + throw; + } + + return d; +} } // !namespace Net |