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-06-16 13:08:47
|
Update of /cvsroot/pclasses/pclasses2/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27098/src Modified Files: Factory.cpp Log Message: - Use Phoenix<> for FactoryInstanceMap::instance() - Added cleanup code Index: Factory.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Factory.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- Factory.cpp 7 May 2005 11:55:47 -0000 1.2 +++ Factory.cpp 16 Jun 2005 13:08:21 -0000 1.3 @@ -19,10 +19,13 @@ ***************************************************************************/ #include "pclasses/Trace.h" +#include "pclasses/Phoenix.h" #include "pclasses/Factory.h" namespace P { +struct factory_instancemap_context_t { }; + /* The FactoryInstanceMap holds the instances of our Factory objects. */ @@ -31,10 +34,28 @@ typedef std::pair<std::string, std::string> InstanceKey; typedef std::map<InstanceKey, FactoryBase*> FactoryMap; + FactoryInstanceMap() + { + P_TRACE(FactoryInstanceMap) << "FactoryInstanceMap()"; + } + + ~FactoryInstanceMap() + { + P_TRACE(FactoryInstanceMap) << "~FactoryInstanceMap()"; + + FactoryMap::iterator i = _factories.begin(); + while(i != _factories.end()) + { + delete i->second; + FactoryMap::iterator del = i++; + _factories.erase(del); + } + } + static FactoryInstanceMap& instance() { - static FactoryInstanceMap inst; - return inst; + typedef Phoenix<FactoryInstanceMap, factory_instancemap_context_t> PHX; + return PHX::instance(); } void addFactory(const std::string& ifaceType, @@ -60,9 +81,6 @@ } private: - FactoryInstanceMap() {} - ~FactoryInstanceMap() {} - FactoryMap _factories; CoreMutex _mutex; }; |
From: Christian P. <cp...@us...> - 2005-06-16 13:08:47
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27098/include/pclasses Modified Files: Factory.h Log Message: - Use Phoenix<> for FactoryInstanceMap::instance() - Added cleanup code Index: Factory.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Factory.h,v retrieving revision 1.24 retrieving revision 1.25 diff -u -d -r1.24 -r1.25 --- Factory.h 29 May 2005 17:42:09 -0000 1.24 +++ Factory.h 16 Jun 2005 13:08:21 -0000 1.25 @@ -51,6 +51,8 @@ //! Type for factory creation hook function typedef FactoryBase* (*FactoryCreateFunc)(); + ~FactoryBase(); + //! Type for type loader hook functions typedef void (*LoaderFunc)(const std::string&, const std::string&, const std::string&); @@ -100,7 +102,6 @@ const std::string& contextType, const std::string& key); FactoryBase(); - ~FactoryBase(); }; //! Type factory |
From: Christian P. <cp...@us...> - 2005-06-16 13:07:24
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26832/src/System Modified Files: Path.posix.cpp Log Message: - Added some trace messages Index: Path.posix.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/Path.posix.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Path.posix.cpp 7 May 2005 13:20:38 -0000 1.1 +++ Path.posix.cpp 16 Jun 2005 13:07:16 -0000 1.2 @@ -18,6 +18,7 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include "pclasses/Trace.h" #include "pclasses/System/Path.h" #include <errno.h> @@ -36,6 +37,8 @@ _path = path.substr(0,path.size()-1); else _path = path; + + P_TRACE(Path) << " Path('" << path << "') -> '" << _path << "'"; } Path::~Path() @@ -47,20 +50,30 @@ Unicode::String::size_type slashat = _path.find_last_of(separator()); + Unicode::String ret; + if(slashat == Unicode::String::npos || slashat == 0) - return _path; + ret = _path; + else + ret = _path.substr(0, slashat); - return _path.substr(0, slashat); + P_TRACE(Path) << "dirName() = '" << ret << "'"; + return ret; } Unicode::String Path::absDirName() const throw(SystemError) { char* absDirName = realpath(dirName().utf8().c_str(), 0); if(!absDirName) + { + P_TRACE(Path) << "absDirName() -> error=" << errno; throw SystemError(errno, "Could not resolve real path", P_SOURCEINFO); + } Unicode::String res = Unicode::String::fromUtf8(absDirName); free(absDirName); + + P_TRACE(Path) << "absDirName() = '" << res << "'"; return res; } @@ -69,10 +82,15 @@ Unicode::String::size_type slashat = _path.find_last_of(separator()); + Unicode::String ret; + if(slashat == Unicode::String::npos) - return _path; + ret = _path; + else + ret = _path.substr(slashat + 1); - return _path.substr(slashat + 1); + P_TRACE(Path) << "baseName() = '" << ret << "'"; + return ret; } Unicode::String Path::path() const throw() @@ -84,10 +102,15 @@ { char* absPath = realpath(_path.utf8().c_str(), 0); if(!absPath) + { + P_TRACE(Path) << "absPath() -> error=" << errno; throw SystemError(errno, "Could not resolve real path", P_SOURCEINFO); + } Unicode::String res = Unicode::String::fromUtf8(absPath); free(absPath); + + P_TRACE(Path) << "absPath() = '" << res << "'"; return res; } |
From: Christian P. <cp...@us...> - 2005-06-16 13:06:43
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25814/src/System Modified Files: Plugin.cpp Log Message: - Use Phoenix<> for PluginManager::instance() - Add "/usr/lib/pclasses" and "/usr/local/lib/pclasses" to PathFinder by default. Index: Plugin.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/Plugin.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- Plugin.cpp 7 May 2005 11:55:47 -0000 1.2 +++ Plugin.cpp 16 Jun 2005 13:06:33 -0000 1.3 @@ -20,6 +20,7 @@ #include "pclasses/pclasses-config.h" #include "pclasses/Factory.h" +#include "pclasses/Phoenix.h" #include "pclasses/Trace.h" #include "pclasses/System/Plugin.h" #include "pclasses/System/Directory.h" @@ -35,6 +36,15 @@ PluginManager::~PluginManager() { + P_TRACE(PluginManager) << "~PluginManager()"; + + PluginMap::iterator i = _pluginMap.begin(); + while(i != _pluginMap.end()) + { + delete i->second; + PluginMap::iterator del = i++; + _pluginMap.erase(del); + } } PathFinder& PluginManager::pathFinder(const std::string& ifaceType) @@ -46,6 +56,8 @@ PathFinder& pathFinder = _pathFinders[ifaceType]; pathFinder.addExtension(std::string(".")+SharedLib::extension()); + pathFinder.addPath("/usr/lib/pclasses"); + pathFinder.addPath("/usr/local/lib/pclasses"); return pathFinder; } @@ -94,10 +106,12 @@ return shl; } +struct plugin_manager_context_t { }; + PluginManager& PluginManager::instance() { - static PluginManager inst; - return inst; + typedef Phoenix<PluginManager, plugin_manager_context_t> PHX; + return PHX::instance(); } class PluginTypeLoader { |
From: Christian P. <cp...@us...> - 2005-06-16 13:06:43
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25814/include/pclasses/System Modified Files: Plugin.h Log Message: - Use Phoenix<> for PluginManager::instance() - Add "/usr/lib/pclasses" and "/usr/local/lib/pclasses" to PathFinder by default. Index: Plugin.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/System/Plugin.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Plugin.h 27 May 2005 15:28:57 -0000 1.3 +++ Plugin.h 16 Jun 2005 13:06:32 -0000 1.4 @@ -52,6 +52,9 @@ typedef std::map<Unicode::String, SharedLib*> PluginMap; typedef std::map<std::string, PathFinder> PathFinderMap; + PluginManager(); + ~PluginManager(); + void addPluginDir(const std::string& ifaceType, const Unicode::String& dir) throw(SystemError); @@ -77,9 +80,6 @@ private: PathFinder& pathFinder(const std::string& ifaceType); - PluginManager(); - ~PluginManager(); - PathFinderMap _pathFinders; PluginMap _pluginMap; CriticalSection _mutex; |
From: Christian P. <cp...@us...> - 2005-06-07 22:46:49
|
Update of /cvsroot/pclasses/pclasses2/win32 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17277 Modified Files: Core.vcproj IO.vcproj Unicode.vcproj Log Message: - Updated win32 VS.NET 2003 project files Index: IO.vcproj =================================================================== RCS file: /cvsroot/pclasses/pclasses2/win32/IO.vcproj,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- IO.vcproj 24 Jan 2005 01:33:28 -0000 1.1 +++ IO.vcproj 7 Jun 2005 22:46:38 -0000 1.2 @@ -23,7 +23,8 @@ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;PIO_BUILD" MinimalRebuild="TRUE" BasicRuntimeChecks="3" - RuntimeLibrary="1" + RuntimeLibrary="3" + RuntimeTypeInfo="TRUE" UsePrecompiledHeader="0" WarningLevel="3" Detect64BitPortabilityProblems="TRUE" @@ -33,11 +34,11 @@ Name="VCCustomBuildTool"/> <Tool Name="VCLinkerTool" - AdditionalDependencies="$(OutDir)/pclasses_core.lib zdll.lib libbz2.lib" + AdditionalDependencies="$(OutDir)/pclasses_core.lib zdll.lib libbz2.lib $(NOINHERIT)" OutputFile="$(OutDir)/pclasses_io.dll" LinkIncremental="2" GenerateDebugInformation="TRUE" - ProgramDatabaseFile="$(OutDir)/IO.pdb" + ProgramDatabaseFile="$(OutDir)/pclasses_io.pdb" SubSystem="2" ImportLibrary="$(OutDir)/pclasses_io.lib" TargetMachine="1"/> @@ -70,9 +71,13 @@ CharacterSet="2"> <Tool Name="VCCLCompilerTool" + EnableIntrinsicFunctions="TRUE" + FavorSizeOrSpeed="1" + OmitFramePointers="TRUE" AdditionalIncludeDirectories="./include;../include" PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;IO_EXPORTS" - RuntimeLibrary="0" + RuntimeLibrary="2" + RuntimeTypeInfo="TRUE" UsePrecompiledHeader="0" WarningLevel="3" Detect64BitPortabilityProblems="TRUE" @@ -82,10 +87,11 @@ Name="VCCustomBuildTool"/> <Tool Name="VCLinkerTool" - AdditionalDependencies="$(OutDir)/pclasses_core.lib zdll.lib libbz2.lib" + AdditionalDependencies="$(OutDir)/pclasses_core.lib zdll.lib libbz2.lib $(NOINHERIT)" OutputFile="$(OutDir)/pclasses_io.dll" LinkIncremental="1" GenerateDebugInformation="TRUE" + ProgramDatabaseFile="$(OutDir)/pclasses_io.pdb" SubSystem="2" OptimizeReferences="2" EnableCOMDATFolding="2" @@ -136,10 +142,19 @@ RelativePath="..\src\Io\IOFilter.cpp"> </File> <File - RelativePath="..\src\Io\IOStream.cpp"> + RelativePath="..\src\Io\IOHandler.cpp"> </File> <File - RelativePath="..\src\Io\StringDevice.cpp"> + RelativePath="..\src\Io\IOListener.cpp"> + </File> + <File + RelativePath="..\src\Io\IOManager.cpp"> + </File> + <File + RelativePath="..\src\Io\IORequest.cpp"> + </File> + <File + RelativePath="..\src\Io\IOStream.cpp"> </File> <File RelativePath="..\src\Io\URL.cpp"> @@ -171,13 +186,19 @@ RelativePath="..\include\pclasses\Io\IOFilter.h"> </File> <File + RelativePath="..\include\pclasses\Io\IOHandler.h"> + </File> + <File + RelativePath="..\include\pclasses\Io\IOListener.h"> + </File> + <File RelativePath="..\include\pclasses\Io\IOManager.h"> </File> <File - RelativePath="..\include\pclasses\Io\IOStream.h"> + RelativePath="..\include\pclasses\Io\IORequest.h"> </File> <File - RelativePath="..\include\pclasses\Io\StringDevice.h"> + RelativePath="..\include\pclasses\Io\IOStream.h"> </File> <File RelativePath="..\include\pclasses\Io\URL.h"> Index: Core.vcproj =================================================================== RCS file: /cvsroot/pclasses/pclasses2/win32/Core.vcproj,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Core.vcproj 24 Jan 2005 01:33:28 -0000 1.1 +++ Core.vcproj 7 Jun 2005 22:46:38 -0000 1.2 @@ -19,11 +19,13 @@ <Tool Name="VCCLCompilerTool" Optimization="0" + EnableIntrinsicFunctions="TRUE" AdditionalIncludeDirectories="./include;../include" PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;PCORE_BUILD" MinimalRebuild="TRUE" BasicRuntimeChecks="3" - RuntimeLibrary="1" + RuntimeLibrary="3" + RuntimeTypeInfo="TRUE" UsePrecompiledHeader="0" WarningLevel="3" Detect64BitPortabilityProblems="TRUE" @@ -33,10 +35,11 @@ Name="VCCustomBuildTool"/> <Tool Name="VCLinkerTool" + AdditionalDependencies="kernel32.lib $(NOINHERIT)" OutputFile="$(OutDir)/pclasses_core.dll" LinkIncremental="2" GenerateDebugInformation="TRUE" - ProgramDatabaseFile="$(OutDir)/Core.pdb" + ProgramDatabaseFile="$(OutDir)/pclasses_core.pdb" SubSystem="2" ImportLibrary="$(OutDir)/pclasses_core.lib" TargetMachine="1"/> @@ -69,9 +72,13 @@ CharacterSet="2"> <Tool Name="VCCLCompilerTool" + EnableIntrinsicFunctions="TRUE" + FavorSizeOrSpeed="1" + OmitFramePointers="TRUE" AdditionalIncludeDirectories="./include;../include" PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;PCORE_BUILD" - RuntimeLibrary="0" + RuntimeLibrary="2" + RuntimeTypeInfo="TRUE" UsePrecompiledHeader="0" WarningLevel="3" Detect64BitPortabilityProblems="TRUE" @@ -81,9 +88,11 @@ Name="VCCustomBuildTool"/> <Tool Name="VCLinkerTool" + AdditionalDependencies="kernel32.lib $(NOINHERIT)" OutputFile="$(OutDir)/pclasses_core.dll" LinkIncremental="1" GenerateDebugInformation="TRUE" + ProgramDatabaseFile="$(OutDir)/pclasses_core.pdb" SubSystem="2" OptimizeReferences="2" EnableCOMDATFolding="2" @@ -128,6 +137,12 @@ RelativePath="..\src\ByteOrderTraits.cpp"> </File> <File + RelativePath="..\src\Callback.cpp"> + </File> + <File + RelativePath="..\src\CoreMutex.win32.cpp"> + </File> + <File RelativePath="..\src\Date.cpp"> </File> <File @@ -137,7 +152,7 @@ RelativePath="..\src\Exception.cpp"> </File> <File - RelativePath="..\src\LinkedItem.cpp"> + RelativePath="..\src\Factory.cpp"> </File> <File RelativePath="..\src\Time.cpp"> @@ -169,6 +184,9 @@ RelativePath="..\include\pclasses\BasicTypes.h"> </File> <File + RelativePath="..\include\pclasses\Buffer.h"> + </File> + <File RelativePath="..\include\pclasses\ByteOrderTraits.h"> </File> <File @@ -178,6 +196,9 @@ RelativePath="..\include\pclasses\CircularQueue.h"> </File> <File + RelativePath="..\include\pclasses\CoreMutex.h"> + </File> + <File RelativePath="..\include\pclasses\Date.h"> </File> <File @@ -205,21 +226,12 @@ RelativePath="..\include\pclasses\IntTypes.h"> </File> <File - RelativePath="..\include\pclasses\LinkedItem.h"> - </File> - <File - RelativePath="..\include\pclasses\List.h"> - </File> - <File RelativePath="..\include\pclasses\LockTraits.h"> </File> <File RelativePath="..\include\pclasses\NonCopyable.h"> </File> <File - RelativePath="..\include\pclasses\Pair.h"> - </File> - <File RelativePath=".\include\pclasses\pclasses-config.h"> </File> <File @@ -229,9 +241,6 @@ RelativePath="..\include\pclasses\PropertyMap.h"> </File> <File - RelativePath="..\include\pclasses\Queue.h"> - </File> - <File RelativePath="..\include\pclasses\ScopedArrayPtr.h"> </File> <File @@ -250,7 +259,7 @@ RelativePath="..\include\pclasses\SourceInfo.h"> </File> <File - RelativePath="..\include\pclasses\Stack.h"> + RelativePath="..\include\pclasses\StringList.h"> </File> <File RelativePath="..\include\pclasses\Time.h"> @@ -267,9 +276,6 @@ <File RelativePath="..\include\pclasses\ValueType.h"> </File> - <File - RelativePath="..\include\pclasses\Vector.h"> - </File> </Filter> <Filter Name="Ressourcendateien" Index: Unicode.vcproj =================================================================== RCS file: /cvsroot/pclasses/pclasses2/win32/Unicode.vcproj,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Unicode.vcproj 24 Jan 2005 01:33:28 -0000 1.1 +++ Unicode.vcproj 7 Jun 2005 22:46:38 -0000 1.2 @@ -19,11 +19,13 @@ <Tool Name="VCCLCompilerTool" Optimization="0" + OmitFramePointers="FALSE" AdditionalIncludeDirectories="./include;../include;../src/Unicode" PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;PUNICODE_BUILD" MinimalRebuild="TRUE" BasicRuntimeChecks="3" - RuntimeLibrary="1" + RuntimeLibrary="3" + RuntimeTypeInfo="TRUE" UsePrecompiledHeader="0" WarningLevel="3" Detect64BitPortabilityProblems="TRUE" @@ -33,11 +35,11 @@ Name="VCCustomBuildTool"/> <Tool Name="VCLinkerTool" - AdditionalDependencies="$(OutDir)/pclasses_core.lib" + AdditionalDependencies="$(OutDir)/pclasses_core.lib icuuc.lib $(NOINHERIT)" OutputFile="$(OutDir)/pclasses_unicode.dll" LinkIncremental="2" GenerateDebugInformation="TRUE" - ProgramDatabaseFile="$(OutDir)/Unicode.pdb" + ProgramDatabaseFile="$(OutDir)/pclasses_unicode.pdb" SubSystem="2" ImportLibrary="$(OutDir)/pclasses_unicode.lib" TargetMachine="1"/> @@ -70,9 +72,13 @@ CharacterSet="2"> <Tool Name="VCCLCompilerTool" + EnableIntrinsicFunctions="TRUE" + FavorSizeOrSpeed="1" + OmitFramePointers="TRUE" AdditionalIncludeDirectories="./include;../include;../src/Unicode" PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;PUNICODE_BUILD" - RuntimeLibrary="0" + RuntimeLibrary="2" + RuntimeTypeInfo="TRUE" UsePrecompiledHeader="0" WarningLevel="3" Detect64BitPortabilityProblems="TRUE" @@ -82,10 +88,11 @@ Name="VCCustomBuildTool"/> <Tool Name="VCLinkerTool" - AdditionalDependencies="$(OutDir)/pclasses_core.lib" + AdditionalDependencies="$(OutDir)/pclasses_core.lib icuuc.lib $(NOINHERIT)" OutputFile="$(OutDir)/pclasses_unicode.dll" LinkIncremental="1" GenerateDebugInformation="TRUE" + ProgramDatabaseFile="$(OutDir)/pclasses_unicode.pdb" SubSystem="2" OptimizeReferences="2" EnableCOMDATFolding="2" @@ -124,19 +131,16 @@ RelativePath="..\src\Unicode\Char.cpp"> </File> <File - RelativePath="..\src\Unicode\String.cpp"> - </File> - <File - RelativePath="..\src\Unicode\TextStream.cpp"> + RelativePath="..\src\Unicode\Converter.cpp"> </File> <File - RelativePath="..\src\Unicode\uctype.cpp"> + RelativePath="..\src\Unicode\String.cpp"> </File> <File - RelativePath="..\src\Unicode\unicodedata.cpp"> + RelativePath="..\src\Unicode\TextStream.cpp"> </File> <File - RelativePath="..\src\Unicode\ustring.cpp"> + RelativePath="..\src\Unicode\UnicodeError.cpp"> </File> </Filter> <Filter @@ -147,25 +151,16 @@ RelativePath="..\include\pclasses\Unicode\Char.h"> </File> <File - RelativePath="..\include\pclasses\Unicode\String.h"> - </File> - <File - RelativePath="..\include\pclasses\Unicode\TextStream.h"> - </File> - <File - RelativePath="..\include\pclasses\Unicode\uctype.h"> - </File> - <File - RelativePath="..\src\Unicode\unicodedata.h"> + RelativePath="..\include\pclasses\Unicode\Converter.h"> </File> <File - RelativePath="..\src\Unicode\unicodedata_db.h"> + RelativePath="..\include\pclasses\Unicode\String.h"> </File> <File - RelativePath="..\src\Unicode\unicodedata_extra_db.h"> + RelativePath="..\include\pclasses\Unicode\TextStream.h"> </File> <File - RelativePath="..\include\pclasses\Unicode\ustring.h"> + RelativePath="..\include\pclasses\Unicode\UnicodeError.h"> </File> </Filter> <Filter |
From: Christian P. <cp...@us...> - 2005-06-07 22:45:54
|
Update of /cvsroot/pclasses/pclasses2/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16706 Modified Files: CoreMutex.posix.cpp CoreMutex.win32.cpp Log Message: - Changed CoreMutex::_handle from "unsigned long" to "void*" Index: CoreMutex.posix.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/CoreMutex.posix.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- CoreMutex.posix.cpp 7 May 2005 11:53:43 -0000 1.2 +++ CoreMutex.posix.cpp 7 Jun 2005 22:45:45 -0000 1.3 @@ -26,7 +26,7 @@ namespace Traits { CoreMutex::CoreMutex() -: _handle((unsigned long)new pthread_mutex_t) +: _handle((void*)new pthread_mutex_t) { pthread_mutexattr_t attrs; pthread_mutexattr_init(&attrs); Index: CoreMutex.win32.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/CoreMutex.win32.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- CoreMutex.win32.cpp 6 May 2005 15:21:01 -0000 1.1 +++ CoreMutex.win32.cpp 7 Jun 2005 22:45:45 -0000 1.2 @@ -23,28 +23,26 @@ namespace P { -namespace Traits { - CoreMutex::CoreMutex() -: _handle((unsigned long)new CRITICAL_SECTION) +: _handle((void*)new CRITICAL_SECTION) { - InitializeCriticalSection((CRITICAL_SECTION*)_handle)); + InitializeCriticalSection((CRITICAL_SECTION*)_handle); } CoreMutex::~CoreMutex() { - DeleteCriticalSection((CRITICAL_SECTION*)_handle)); + DeleteCriticalSection((CRITICAL_SECTION*)_handle); delete (CRITICAL_SECTION*)_handle; } void CoreMutex::lock() throw() { - EnterCriticalSection((CRITICAL_SECTION*)_handle)); + EnterCriticalSection((CRITICAL_SECTION*)_handle); } void CoreMutex::unlock() throw() { - LeaveCriticalSection((CRITICAL_SECTION*)_handle)); + LeaveCriticalSection((CRITICAL_SECTION*)_handle); } CoreMutex::ScopedLock::ScopedLock(CoreMutex& mtx) @@ -58,6 +56,4 @@ _mtx.unlock(); } -} // !namespace Traits - } // !namespace P |
From: Christian P. <cp...@us...> - 2005-06-07 22:45:08
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16272 Modified Files: CoreMutex.h Log Message: - Changed CoreMutex::_handle from "unsigned long" to "void*" Index: CoreMutex.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/CoreMutex.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- CoreMutex.h 7 May 2005 13:26:02 -0000 1.2 +++ CoreMutex.h 7 Jun 2005 22:44:58 -0000 1.3 @@ -49,7 +49,7 @@ }; private: - unsigned long _handle; + void* _handle; }; } // !namespace P |
From: Christian P. <cp...@us...> - 2005-06-07 22:43:44
|
Update of /cvsroot/pclasses/pclasses2/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15534 Modified Files: Date.cpp Log Message: - Added some validity checks to class Date Index: Date.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Date.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- Date.cpp 23 Jan 2005 01:13:20 -0000 1.5 +++ Date.cpp 7 Jun 2005 22:43:35 -0000 1.6 @@ -26,7 +26,8 @@ Date::Date(unsigned int year, unsigned int month, unsigned int day) throw(InvalidDate) : _year(year), _month(month), _day(day) { - if(month > 12 || day > daysInMonth(month, year)) + if(month < 1 || month > 12 || day < 1 + || day > daysInMonth(month, year)) throw InvalidDate("Invalid date", P_SOURCEINFO); } @@ -51,7 +52,7 @@ void Date::setMonth(unsigned int month) throw(InvalidDate) { - if(month > 12) + if(month < 1 || month > 12) throw InvalidDate("Invalid month", P_SOURCEINFO); _month = month; } @@ -122,6 +123,9 @@ unsigned int Date::daysInMonth(unsigned int month, unsigned int year) throw(InvalidDate) { + if(month < 1 || month > 12) + throw InvalidDate("Invalid month", P_SOURCEINFO); + unsigned int dim = _daysInMonth[month - 1]; if(isLeapYear(year) && month > 1) return dim + 1; |
From: Christian P. <cp...@us...> - 2005-06-07 22:42:27
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14600 Modified Files: Directory.win32.cpp IOHandle.h Added Files: IOHandle.win32.cpp Log Message: - Added win32 implementation of IOHandle and Directory Index: Directory.win32.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/Directory.win32.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- Directory.win32.cpp 7 Jun 2005 12:15:46 -0000 1.2 +++ Directory.win32.cpp 7 Jun 2005 22:42:09 -0000 1.3 @@ -54,7 +54,7 @@ if(lastError == ERROR_NO_MORE_FILES) return; - throw SystemError(lastError, "Could not read directory", P_SOURCEINFO); + throw IO::IOError(lastError, "Could not read directory", P_SOURCEINFO); } _entries.push_back(findData.cFileName); @@ -67,7 +67,7 @@ FindClose(h); if(lastError != ERROR_NO_MORE_FILES) - throw SystemError(lastError, "Could not read directory", P_SOURCEINFO); + throw IO::IOError(lastError, "Could not read directory", P_SOURCEINFO); } Directory::Iterator Directory::begin() const @@ -85,7 +85,7 @@ DWORD reqdSize = GetCurrentDirectory(0, 0); char* cwd = new char[reqdSize + 1]; - DWORD cwdRet = GetCurrentDirectory(cwdSize, cwd); + DWORD cwdRet = GetCurrentDirectory(reqdSize + 1, cwd); if(cwdRet == 0) throw IO::IOError(GetLastError(), "Could not get current working directroy", P_SOURCEINFO); Index: IOHandle.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/IOHandle.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- IOHandle.h 7 Jun 2005 12:01:19 -0000 1.2 +++ IOHandle.h 7 Jun 2005 22:42:09 -0000 1.3 @@ -25,6 +25,10 @@ #include "pclasses/IO/IOError.h" #include "pclasses/Unicode/String.h" +#ifdef WIN32 +#include <windows.h> +#endif + namespace P { namespace System { --- NEW FILE: IOHandle.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 "IOHandle.h" #include <windows.h> namespace P { namespace System { #define INVALID_HANDLE INVALID_HANDLE_VALUE DWORD OpenMode2Flags(IO::IODevice::OpenMode omode) { DWORD flags = 0; switch(omode) { case IO::IODevice::OpenCreate: flags = OPEN_ALWAYS; break; case IO::IODevice::CreateFail: flags = CREATE_NEW; break; case IO::IODevice::OpenFail: flags = OPEN_EXISTING; break; } return flags; } DWORD ShareMode2Flags(IO::IODevice::ShareMode smode) { DWORD flags = 0; switch(smode) { case IO::IODevice::AllowNone: break; case IO::IODevice::AllowRead: flags = FILE_SHARE_READ; break; case IO::IODevice::AllowWrite: flags = FILE_SHARE_WRITE; break; case IO::IODevice::AllowReadWrite: flags = FILE_SHARE_READ|FILE_SHARE_WRITE; break; } return flags; } DWORD AccessMode2Flags(IO::IODevice::AccessMode amode) { DWORD flags = 0; switch(amode) { case IO::IODevice::None: break; case IO::IODevice::Read: flags = GENERIC_READ; break; case IO::IODevice::Write: flags = GENERIC_WRITE; break; case IO::IODevice::ReadWrite: flags = GENERIC_READ|GENERIC_WRITE; break; } return flags; } IOHandle::IOHandle(const IOHandle& h) throw(IO::IOError) { HANDLE handle; DWORD ret = DuplicateHandle(GetCurrentProcess(), h._handle, GetCurrentProcess(), &handle, DUPLICATE_SAME_ACCESS, TRUE, 0); if(ret == 0) throw IO::IOError(GetLastError(), "Could not duplicate handle", P_SOURCEINFO); _handle = handle; } IOHandle::IOHandle(iohandle_t h, bool takeOwnership) throw(IO::IOError) { if(takeOwnership) { _handle = h; } else { HANDLE handle; DWORD ret = DuplicateHandle(GetCurrentProcess(), h, GetCurrentProcess(), &handle, DUPLICATE_SAME_ACCESS, TRUE, 0); if(ret == 0) throw IO::IOError(GetLastError(), "Could not duplicate handle", P_SOURCEINFO); _handle = handle; } } IOHandle::IOHandle(const Unicode::String& name, IO::IODevice::AccessMode amode, IO::IODevice::OpenMode omode, IO::IODevice::ShareMode smode) throw(IO::IOError) : _handle(INVALID_HANDLE) { DWORD accessMode = AccessMode2Flags(amode); DWORD shareMode = ShareMode2Flags(smode); DWORD createMode = OpenMode2Flags(omode); HANDLE handle = ::CreateFile(name.utf8().c_str(), accessMode, shareMode, NULL, createMode, FILE_ATTRIBUTE_NORMAL, NULL); if(handle == INVALID_HANDLE) throw IO::IOError(GetLastError(), "Could not open handle", P_SOURCEINFO); _handle = handle; } IOHandle::~IOHandle() throw() { if(_handle != INVALID_HANDLE) { try { close(); } catch(...) { } } } void IOHandle::close() throw(IO::IOError) { if(!::CloseHandle(_handle)) throw IO::IOError(GetLastError(), "Could not close handle", P_SOURCEINFO); _handle = INVALID_HANDLE; } size_t IOHandle::read(char* buffer, size_t count) throw(IO::IOError) { DWORD bytesRead = 0; DWORD bytesToRead = count > (DWORD)-1 ? (DWORD)-1 : count; if(!::ReadFile(_handle, (void*)buffer, bytesToRead, &bytesRead, NULL)) throw IO::IOError(GetLastError(), "Could not read from handle", P_SOURCEINFO); return bytesRead; } size_t IOHandle::write(const char* buffer, size_t count) throw(IO::IOError) { DWORD bytesWritten = 0; DWORD bytesToWrite = count > (DWORD)-1 ? (DWORD)-1 : count; if(!::WriteFile(_handle, (const void*)buffer, bytesToWrite, &bytesWritten, NULL)) throw IO::IOError(GetLastError(), "Could not read from handle", P_SOURCEINFO); return bytesWritten; } bool IOHandle::isSeekable() const throw() { DWORD fileType = ::GetFileType(_handle); if(fileType == FILE_TYPE_DISK) return true; return false; } offset_t IOHandle::seek(offset_t offset, IO::IODevice::SeekMode mode) throw(IO::IOError) { DWORD moveMethod; switch(mode) { case IO::IODevice::SeekSet: moveMethod = FILE_BEGIN; break; case IO::IODevice::SeekCurrent: moveMethod = FILE_CURRENT; break; case IO::IODevice::SeekEnd: moveMethod = FILE_END; break; } LARGE_INTEGER moveDist, newPos; moveDist.QuadPart = offset; if(!SetFilePointerEx(_handle, moveDist, &newPos, moveMethod)) throw IO::IOError(GetLastError(), "Could not seek on handle", P_SOURCEINFO); return (offset_t)newPos.QuadPart; } size_t IOHandle::peek(char* buffer, size_t count) throw(IO::IOError) { DWORD bytesRead = 0; DWORD bytesToRead = count > (DWORD)-1 ? (DWORD)-1 : count; if(!::ReadFile(_handle, (void*)buffer, bytesToRead, &bytesRead, NULL)) throw IO::IOError(GetLastError(), "Could not read from handle", P_SOURCEINFO); offset_t seekOff = bytesRead; seek(-seekOff, IO::IODevice::SeekCurrent); return bytesRead; } void IOHandle::sync() const throw(IO::IOError) { if(!::FlushFileBuffers(_handle)) throw IO::IOError(GetLastError(), "Could not sync handle", P_SOURCEINFO); } offset_t IOHandle::size() const throw(IO::IOError) { LARGE_INTEGER fSize; if(!::GetFileSizeEx(_handle, &fSize)) throw IO::IOError(GetLastError(), "Could not stat file", P_SOURCEINFO); return (offset_t)fSize.QuadPart; } void IOHandle::resize(size_t sz) throw(IO::IOError) { if(!::SetFileValidData(_handle, sz)) throw IO::IOError(GetLastError(), "Could not truncate file", P_SOURCEINFO); } iohandle_t IOHandle::handle() const throw() { return _handle; } } // !namespace System } // !namespace P |
From: Christian P. <cp...@us...> - 2005-06-07 12:15:58
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28530/include/pclasses/System Modified Files: Directory.h Log Message: - Changed Directory::_handle from "unsigned long" to "void*" Index: Directory.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/System/Directory.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Directory.h 6 May 2005 16:07:40 -0000 1.3 +++ Directory.h 7 Jun 2005 12:15:45 -0000 1.4 @@ -56,7 +56,7 @@ static void remove(const Unicode::String& path) throw(IO::IOError); private: - unsigned long _handle; + void* _handle; Unicode::String _path; EntryList _entries; }; |
From: Christian P. <cp...@us...> - 2005-06-07 12:15:57
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28530/src/System Modified Files: Directory.posix.cpp Directory.win32.cpp Log Message: - Changed Directory::_handle from "unsigned long" to "void*" Index: Directory.posix.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/Directory.posix.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- Directory.posix.cpp 27 May 2005 15:28:34 -0000 1.4 +++ Directory.posix.cpp 7 Jun 2005 12:15:45 -0000 1.5 @@ -37,7 +37,7 @@ if(!d) throw IO::IOError(errno, "Could not open directory", P_SOURCEINFO); - _handle = (unsigned long)d; + _handle = (void*)d; reload(); } Index: Directory.win32.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/Directory.win32.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Directory.win32.cpp 24 Jan 2005 09:57:28 -0000 1.1 +++ Directory.win32.cpp 7 Jun 2005 12:15:46 -0000 1.2 @@ -26,14 +26,14 @@ namespace System { Directory::Directory(const Unicode::String& path) throw(IO::IOError) -: _path(path), _handle(INVALID_HANDLE_VALUE) +: _path(path), _handle((void*)INVALID_HANDLE_VALUE) { reload(); } Directory::~Directory() throw() { - if(_handle != INVALID_HANDLE_VALUE) + if(_handle != (void*)INVALID_HANDLE_VALUE) FindClose((HANDLE)_handle); } @@ -82,25 +82,16 @@ Unicode::String Directory::current() throw(IO::IOError) { - size_t cwdSize = PATH_MAX; - char* cwd = new char[PATH_MAX]; + DWORD reqdSize = GetCurrentDirectory(0, 0); + char* cwd = new char[reqdSize + 1]; -getCurrentDirectory: - DWORD ret = GetCurrentDirectory(cwdSize, cwd); - if(ret == 0) - { - if(ret > cwdSize) - { - delete[] cwd; - cwdSize += cwdSize; - cwd = new char[cwdSize]; - goto getCurrentDirectory; - } - - throw IO::IOError(errno, "Could not get current working directroy", P_SOURCEINFO); - } + DWORD cwdRet = GetCurrentDirectory(cwdSize, cwd); + if(cwdRet == 0) + throw IO::IOError(GetLastError(), "Could not get current working directroy", P_SOURCEINFO); - return Unicode::String(cwd); + Unicode::String retStr(cwd); + delete[] cwd; + return retStr; } void Directory::change(const Unicode::String& path) throw(IO::IOError) |
From: Christian P. <cp...@us...> - 2005-06-07 12:01:35
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21523/include/pclasses/System Modified Files: File.h Pipe.h Process.h StorageDevice.h Log Message: - Changed "unsigned long _handle" in I/O classes to "IOHandle* _handld" - Changed "unsigned long _handle" in Process class to "void* _handle" Index: Process.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/System/Process.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Process.h 23 Apr 2005 17:57:13 -0000 1.3 +++ Process.h 7 Jun 2005 12:01:20 -0000 1.4 @@ -112,7 +112,7 @@ ProcessIO& processIO() const throw(LogicError); private: - unsigned long _handle; + void* _handle; ProcessIO* _procIO; State _state; Unicode::String _workDir; Index: Pipe.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/System/Pipe.h,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- Pipe.h 24 Apr 2005 11:40:20 -0000 1.10 +++ Pipe.h 7 Jun 2005 12:01:20 -0000 1.11 @@ -29,13 +29,15 @@ namespace System { +class IOHandle; + //! Anonymous pipe device class PSYSTEM_EXPORT Pipe: public IO::IODevice { public: typedef std::pair<Pipe,Pipe> Pair; Pipe(const Pipe& f) throw(IO::IOError); - Pipe(unsigned long handle, bool readEnd) throw(); + Pipe(IOHandle* handle, bool readEnd) throw(); ~Pipe() throw(); static Pair create() throw(IO::IOError); @@ -44,17 +46,14 @@ protected: 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); - void _sync() const throw(IO::IOError); - unsigned long handle() const throw(); + IOHandle* handle() const throw(); private: - unsigned long _handle; + IOHandle* _handle; }; } // !namespace System Index: StorageDevice.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/System/StorageDevice.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- StorageDevice.h 31 Jan 2005 11:19:11 -0000 1.2 +++ StorageDevice.h 7 Jun 2005 12:01:20 -0000 1.3 @@ -28,6 +28,8 @@ namespace System { +class IOHandle; + //! System Storage device (block device) class PSYSTEM_EXPORT StorageDevice: public IO::IODevice { public: @@ -55,10 +57,10 @@ offset_t _size() const throw(IO::IOError); //! Returns the native O/S handle - unsigned long handle() const throw(); + IOHandle* handle() const throw(); private: - unsigned long _handle; + IOHandle* _handle; }; Index: File.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/System/File.h,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- File.h 24 Apr 2005 11:40:20 -0000 1.12 +++ File.h 7 Jun 2005 12:01:19 -0000 1.13 @@ -31,6 +31,7 @@ namespace System { +class IOHandle; class FileInfo; /** @@ -84,10 +85,10 @@ offset_t _size() const throw(IO::IOError); //! Returns the native O/S handle - unsigned long handle() const throw(); + IOHandle* handle() const throw(); private: - unsigned long _handle; + IOHandle* _handle; }; } // !namespace System |
From: Christian P. <cp...@us...> - 2005-06-07 12:01:35
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21523/src/System Modified Files: CdRomDevice.linux.cpp File.common.cpp File.win32.cpp IOHandle.h IOHandle.posix.cpp Pipe.common.cpp Pipe.posix.cpp Process.common.cpp Process.posix.cpp StorageDevice.common.cpp Log Message: - Changed "unsigned long _handle" in I/O classes to "IOHandle* _handld" - Changed "unsigned long _handle" in Process class to "void* _handle" Index: File.common.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/File.common.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- File.common.cpp 30 Jan 2005 17:07:03 -0000 1.1 +++ File.common.cpp 7 Jun 2005 12:01:19 -0000 1.2 @@ -36,8 +36,7 @@ { if(f.valid()) { - IOHandle* h = new IOHandle(f.handle(), false); - _handle = (unsigned long)h; + _handle = new IOHandle(f.handle()->handle(), false); } } @@ -62,9 +61,8 @@ if(valid()) close(); - IOHandle* h = new IOHandle(name, amode, omode, smode); + _handle = new IOHandle(name, amode, omode, smode); - _handle = (unsigned long)h; IODevice::setAccess(amode); IODevice::setValid(true); IODevice::setEof(false); @@ -72,9 +70,8 @@ void File::_close() throw(IO::IOError) { - IOHandle* h = (IOHandle*)_handle; - h->close(); - delete h; + _handle->close(); + delete _handle; _handle = 0; IODevice::setAccess(None); @@ -83,8 +80,7 @@ size_t File::_read(char* buffer, size_t count) throw(IO::IOError) { - IOHandle* h = (IOHandle*)_handle; - size_t ret = h->read(buffer, count); + size_t ret = _handle->read(buffer, count); if(ret == 0 && !eof()) setEof(true); @@ -93,46 +89,39 @@ size_t File::_peek(char* buffer, size_t count) throw(IO::IOError) { - IOHandle* h = (IOHandle*)_handle; - return h->peek(buffer, count); + return _handle->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); + return _handle->write(buffer, count); } offset_t File::_seek(offset_t offset, SeekMode mode) throw(IO::IOError) { - IOHandle* h = (IOHandle*)_handle; - return h->seek(offset, mode); + return _handle->seek(offset, mode); } bool File::_isSeekable() const throw() { - IOHandle* h = (IOHandle*)_handle; - return h->isSeekable(); + return _handle->isSeekable(); } void File::_sync() const throw(IO::IOError) { - IOHandle* h = (IOHandle*)_handle; - h->sync(); + _handle->sync(); } offset_t File::_size() const throw(IO::IOError) { - IOHandle* h = (IOHandle*)_handle; - return h->size(); + return _handle->size(); } void File::resize(size_t sz) throw(IO::IOError) { sync(); - IOHandle* h = (IOHandle*)_handle; - h->resize(sz); + _handle->resize(sz); } File& File::operator=(const File& f) throw(IO::IOError) @@ -140,7 +129,7 @@ // strong exception guarantee... if(f.valid()) { - IOHandle* h = new IOHandle(f.handle(), false); + IOHandle* h = new IOHandle(f.handle()->handle(), false); if(valid()) { try @@ -155,7 +144,7 @@ } IODevice::operator=(f); - _handle = (unsigned long)h; + _handle = h; } else { @@ -175,9 +164,9 @@ return FileInfo(path); } -unsigned long File::handle() const throw() +IOHandle* File::handle() const throw() { - return ((IOHandle*)_handle)->handle(); + return _handle; } Index: Process.common.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/Process.common.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Process.common.cpp 31 Dec 2004 03:22:57 -0000 1.1 +++ Process.common.cpp 7 Jun 2005 12:01:19 -0000 1.2 @@ -25,13 +25,15 @@ namespace System { Process::Process(const Unicode::String& program, const ArgList& args) -: _handle((unsigned long)-1), _procIO(0), _state(Stopped), _program(program), +: _handle((void*)-1), _procIO(0), _state(Stopped), _program(program), _args(args) { } Process::~Process() throw() { + if(_procIO) + delete _procIO; } Process::State Process::state() const Index: File.win32.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/File.win32.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- File.win32.cpp 30 Jan 2005 17:07:03 -0000 1.1 +++ File.win32.cpp 7 Jun 2005 12:01:19 -0000 1.2 @@ -19,6 +19,7 @@ ***************************************************************************/ #include "pclasses/System/File.h" +#include <windows.h> namespace P { @@ -27,7 +28,7 @@ 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); + throw IO::IOError(GetLastError(), "Could not unlink file", P_SOURCEINFO); } } // !namespace System Index: IOHandle.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/IOHandle.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- IOHandle.h 30 Jan 2005 17:07:03 -0000 1.1 +++ IOHandle.h 7 Jun 2005 12:01:19 -0000 1.2 @@ -29,11 +29,17 @@ namespace System { +#ifdef WIN32 +typedef HANDLE iohandle_t; +#else +typedef int iohandle_t; +#endif + //! 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(iohandle_t h, 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) @@ -62,10 +68,10 @@ void resize(size_t sz) throw(IO::IOError); //! Returns the native O/S handle - unsigned long handle() const throw(); + iohandle_t handle() const throw(); private: - unsigned long _handle; + iohandle_t _handle; }; } // !namespace System Index: Pipe.common.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/Pipe.common.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Pipe.common.cpp 30 Jan 2005 17:07:03 -0000 1.1 +++ Pipe.common.cpp 7 Jun 2005 12:01:19 -0000 1.2 @@ -25,13 +25,9 @@ namespace System { -Pipe::Pipe(unsigned long handle, bool readEnd) throw() -: IODevice(), _handle(0) +Pipe::Pipe(IOHandle* handle, bool readEnd) throw() +: IODevice(), _handle(handle) { - // 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); @@ -43,8 +39,7 @@ if(p.valid()) { // duplicates the handle ... - IOHandle* h = new IOHandle(p.handle(), false); - _handle = (unsigned long)h; + _handle = new IOHandle(p.handle()->handle(), false); } } @@ -58,9 +53,8 @@ void Pipe::_close() throw(IO::IOError) { - IOHandle* h = (IOHandle*)_handle; - h->close(); - delete h; + _handle->close(); + delete _handle; _handle = 0; IODevice::setAccess(None); @@ -69,14 +63,12 @@ size_t Pipe::_read(char* buffer, size_t count) throw(IO::IOError) { - IOHandle* h = (IOHandle*)_handle; - return h->read(buffer, count); + return _handle->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); + return _handle->write(buffer, count); } void Pipe::_sync() const throw(IO::IOError) @@ -91,7 +83,7 @@ { if(p.valid()) { - IOHandle* h = new IOHandle(p.handle(), false); + IOHandle* h = new IOHandle(p.handle()->handle(), false); if(valid()) { try @@ -106,7 +98,7 @@ } IODevice::operator=(p); - _handle = (unsigned long)h; + _handle = h; } else { @@ -121,9 +113,9 @@ return *this; } -unsigned long Pipe::handle() const throw() +IOHandle* Pipe::handle() const throw() { - return ((IOHandle*)_handle)->handle(); + return _handle; } } // !namespace System Index: CdRomDevice.linux.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/CdRomDevice.linux.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- CdRomDevice.linux.cpp 17 Feb 2005 14:28:08 -0000 1.6 +++ CdRomDevice.linux.cpp 7 Jun 2005 12:01:19 -0000 1.7 @@ -19,6 +19,8 @@ ***************************************************************************/ #include "pclasses/System/CdRomDevice.h" +#include "IOHandle.h" + #include <sys/ioctl.h> #include <linux/cdrom.h> #include <errno.h> @@ -55,7 +57,7 @@ { CdRomDevice::DriveCapability capability = CdRom; - int ret = ::ioctl((int)handle(), CDROM_GET_CAPABILITY, CDSL_CURRENT); + int ret = ::ioctl(handle()->handle(), CDROM_GET_CAPABILITY, CDSL_CURRENT); if(-1 == ret) { throw IO::IOError(errno, "ioctl CDROM_GET_CAPABILITY failed.", P_SOURCEINFO); } @@ -81,7 +83,7 @@ CdRomDevice::DriveStatus CdRomDevice::driveStatus() throw(IO::IOError) { - int ret = ::ioctl((int)handle(), CDROM_DRIVE_STATUS, CDSL_CURRENT); + int ret = ::ioctl(handle()->handle(), CDROM_DRIVE_STATUS, CDSL_CURRENT); if(ret == -1) throw IO::IOError(errno, "ioctl error on device", P_SOURCEINFO); @@ -111,7 +113,7 @@ CdRomDevice::DiscStatus CdRomDevice::discStatus() throw(IO::IOError) { - int ret = ::ioctl((int)handle(), CDROM_DISC_STATUS, CDSL_CURRENT); + int ret = ::ioctl(handle()->handle(), CDROM_DISC_STATUS, CDSL_CURRENT); if(ret == -1) throw IO::IOError(errno, "ioctl error on device", P_SOURCEINFO); @@ -158,7 +160,7 @@ msf.cdmsf_sec1 = endSec; msf.cdmsf_frame1 = endFrame; - int ret = ::ioctl((int)handle(), CDROMPLAYMSF, (void*)&msf); + int ret = ::ioctl(handle()->handle(), CDROMPLAYMSF, (void*)&msf); if(ret == -1) throw IO::IOError(errno, "ioctl error on device", P_SOURCEINFO); } @@ -177,14 +179,14 @@ void CdRomDevice::stop() throw(IO::IOError) { - int ret = ::ioctl((int)handle(), CDROMSTOP); + int ret = ::ioctl(handle()->handle(), CDROMSTOP); if(ret == -1) throw IO::IOError(errno, "ioctl error on device", P_SOURCEINFO); } bool CdRomDevice::mediaChanged() throw(IO::IOError) { // the return value indicates whether the media was changed. - int ret = ::ioctl((int)handle(), CDROM_MEDIA_CHANGED); + int ret = ::ioctl(handle()->handle(), CDROM_MEDIA_CHANGED); if(ret >= 0) return true; @@ -193,27 +195,27 @@ void CdRomDevice::eject() throw(IO::IOError) { - int ret = ::ioctl((int)handle(), CDROMEJECT); + int ret = ::ioctl(handle()->handle(), CDROMEJECT); if(ret == -1) throw IO::IOError(errno, "ioctl error on device", P_SOURCEINFO); } void CdRomDevice::closeTray() throw (IO::IOError) { - int ret = ::ioctl((int)handle(), CDROMEJECT); + int ret = ::ioctl(handle()->handle(), CDROMEJECT); if(ret == -1) throw IO::IOError(errno, "ioctl CDROMCLOSETRAY failed.", P_SOURCEINFO); } void CdRomDevice::pause() throw(IO::IOError) { - int ret = ::ioctl((int)handle(), CDROMPAUSE); + int ret = ::ioctl(handle()->handle(), CDROMPAUSE); if(ret == -1) throw IO::IOError(errno, "ioctl error on device", P_SOURCEINFO); } void CdRomDevice::resume() throw(IO::IOError) { - int ret = ::ioctl((int)handle(), CDROMRESUME); + int ret = ::ioctl(handle()->handle(), CDROMRESUME); if(ret == -1) throw IO::IOError(errno, "ioctl error on device", P_SOURCEINFO); } @@ -222,7 +224,7 @@ { struct cdrom_tochdr hdr; - int ret = ::ioctl((int)handle(), CDROMREADTOCHDR, (void*)&hdr); + int ret = ::ioctl(handle()->handle(), CDROMREADTOCHDR, (void*)&hdr); if(ret == -1) throw IO::IOError(errno, "ioctl error on device", P_SOURCEINFO); @@ -237,7 +239,7 @@ toc_entries[ti].cdte_track = track; toc_entries[ti].cdte_format = CDROM_LBA; - ret = ::ioctl((int)handle(), CDROMREADTOCENTRY, &toc_entries[ti++]); + ret = ::ioctl(handle()->handle(), CDROMREADTOCENTRY, &toc_entries[ti++]); if(ret == -1) throw IO::IOError(errno, "ioctl error on device", P_SOURCEINFO); } @@ -245,7 +247,7 @@ // read lead-out ... toc_entries[ti].cdte_track = CDROM_LEADOUT; toc_entries[ti].cdte_format = CDROM_LBA; - ret = ::ioctl((int)handle(), CDROMREADTOCENTRY, &toc_entries[ti++]); + ret = ::ioctl(handle()->handle(), CDROMREADTOCENTRY, &toc_entries[ti++]); if(ret == -1) throw IO::IOError(errno, "ioctl error on device", P_SOURCEINFO); Index: Process.posix.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/Process.posix.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Process.posix.cpp 23 Apr 2005 17:57:26 -0000 1.3 +++ Process.posix.cpp 7 Jun 2005 12:01:19 -0000 1.4 @@ -24,7 +24,8 @@ #include "pclasses/System/File.h" #include "pclasses/System/CriticalSection.h" -#include "../System/SignalListener.h" +#include "SignalListener.h" +#include "IOHandle.h" #include <sys/types.h> #include <sys/wait.h> @@ -40,6 +41,20 @@ namespace System { +inline void* pid2ptr(pid_t p) +{ + union { pid_t pid; void* ptr; } tmp; + tmp.pid = p; + return tmp.ptr; +} + +inline pid_t ptr2pid(void* p) +{ + union { pid_t pid; void* ptr; } tmp; + tmp.ptr = p; + return tmp.pid; +} + class ChildSignalHandler: public System::SignalListener { public: ChildSignalHandler() @@ -239,32 +254,34 @@ if(mode & RedirectStdErr) close(errfds[1]); - _handle = (unsigned long)child; + _handle = pid2ptr(child); if(mode) { - _procIO = new ProcessIO(Pipe(infds[1],false), - Pipe(outfds[0],true), - Pipe(errfds[0],true)); + _procIO = new ProcessIO(Pipe(new IOHandle(infds[1], true), false), + Pipe(new IOHandle(outfds[0], true), true), + Pipe(new IOHandle(errfds[0], true), true)); + } + else + { + close(infds[1]); + close(outfds[0]); + close(errfds[0]); } - - close(infds[1]); - close(outfds[0]); - close(errfds[0]); _state = Running; } void Process::stop() throw(SystemError) { - int ret = ::kill((pid_t)_handle, SIGTERM); + int ret = ::kill(ptr2pid(_handle), SIGTERM); if(ret == -1) throw SystemError(errno, "Could not stop process", P_SOURCEINFO); } void Process::kill() throw(SystemError) { - int ret = ::kill((pid_t)_handle, SIGKILL); + int ret = ::kill(ptr2pid(_handle), SIGKILL); if(ret == -1) throw SystemError(errno, "Could not kill process", P_SOURCEINFO); } @@ -272,7 +289,7 @@ bool Process::tryWait(int& exitCode) throw(SystemError) { int status = 0; - pid_t pid = waitpid((pid_t)_handle, &status, WNOHANG|WUNTRACED); + pid_t pid = waitpid(ptr2pid(_handle), &status, WNOHANG|WUNTRACED); if(pid == -1) throw SystemError(errno, "Could not wait for process", P_SOURCEINFO); else if(pid == 0) @@ -283,7 +300,7 @@ exitCode = WIFEXITED(status) ? WEXITSTATUS(status) : 127; _state = Stopped; - _handle = (unsigned long)-1; + _handle = (void*)-1; delete _procIO; _procIO = 0; @@ -299,7 +316,7 @@ int status = 0; Process_wait: - pid_t pid = waitpid((pid_t)_handle, &status, WUNTRACED); + pid_t pid = waitpid(ptr2pid(_handle), &status, WUNTRACED); if(pid == -1) { if(errno == EINTR) @@ -310,7 +327,7 @@ } _state = Stopped; - _handle = (unsigned long)-1; + _handle = (void*)-1; delete _procIO; _procIO = 0; Index: IOHandle.posix.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/IOHandle.posix.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- IOHandle.posix.cpp 30 Jan 2005 17:07:03 -0000 1.1 +++ IOHandle.posix.cpp 7 Jun 2005 12:01:19 -0000 1.2 @@ -31,6 +31,8 @@ namespace System { +#define INVALID_HANDLE -1 + int OpenMode2Flags(IO::IODevice::OpenMode omode) { int flags = 0; @@ -79,13 +81,13 @@ IOHandle::IOHandle(const IOHandle& h) throw(IO::IOError) { int handle = ::dup((int)h._handle); - if(handle == -1) + if(handle == INVALID_HANDLE) throw IO::IOError(errno, "Could not duplicate handle", P_SOURCEINFO); - _handle = (unsigned long)handle; + _handle = handle; } -IOHandle::IOHandle(unsigned long h, bool takeOwnership) throw(IO::IOError) +IOHandle::IOHandle(iohandle_t h, bool takeOwnership) throw(IO::IOError) { if(takeOwnership) { @@ -94,17 +96,17 @@ else { int handle = ::dup((int)h); - if(handle == -1) + if(handle == INVALID_HANDLE) throw IO::IOError(errno, "Could not duplicate handle", P_SOURCEINFO); - _handle = (unsigned long)handle; + _handle = 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) +: _handle(INVALID_HANDLE) { int flags = OpenMode2Flags(omode) | AccessMode2Flags(amode); @@ -114,15 +116,15 @@ else handle = ::open(name.utf8().c_str(), flags); - if(handle == -1) + if(handle == INVALID_HANDLE) throw IO::IOError(errno, "Could not open handle", P_SOURCEINFO); - _handle = (unsigned long)handle; + _handle = handle; } IOHandle::~IOHandle() throw() { - if((int)_handle != -1) + if(_handle != INVALID_HANDLE) { try { close(); } catch(...) { } } @@ -130,10 +132,10 @@ void IOHandle::close() throw(IO::IOError) { - if(::close((int)_handle) == -1) + if(::close(_handle) == -1) throw IO::IOError(errno, "Could not close handle", P_SOURCEINFO); - _handle = (unsigned long)-1; + _handle = INVALID_HANDLE; } size_t IOHandle::read(char* buffer, size_t count) throw(IO::IOError) @@ -142,7 +144,7 @@ count = SSIZE_MAX; Handle_read: - ssize_t ret = ::read((int)_handle, (void*)buffer, count); + ssize_t ret = ::read(_handle, (void*)buffer, count); if(ret == -1) { if(errno == EINTR) @@ -160,7 +162,7 @@ count = SSIZE_MAX; Handle_write: - ssize_t ret = ::write((int)_handle, (const void*)buffer, count); + ssize_t ret = ::write(_handle, (const void*)buffer, count); if(ret == -1) { if(errno == EINTR) @@ -175,7 +177,7 @@ bool IOHandle::isSeekable() const throw() { struct stat buff; - int ret = fstat((int)_handle, &buff); + int ret = fstat(_handle, &buff); if(ret == 0) { if(S_ISREG(buff.st_mode) || S_ISBLK(buff.st_mode)) @@ -204,7 +206,7 @@ break; } - off_t ret = lseek((int)_handle, offset, whence); + off_t ret = lseek(_handle, offset, whence); if(ret == (off_t)-1) throw IO::IOError(errno, "Could not seek on handle", P_SOURCEINFO); @@ -217,7 +219,7 @@ count = SSIZE_MAX; Handle_peek: - ssize_t ret = ::read((int)_handle, (void*)buffer, count); + ssize_t ret = ::read(_handle, (void*)buffer, count); if(ret == -1) { if(errno == EINTR) @@ -232,7 +234,7 @@ void IOHandle::sync() const throw(IO::IOError) { - int ret = fsync((int)_handle); + int ret = fsync(_handle); if(ret == -1) throw IO::IOError(errno, "Could not sync handle", P_SOURCEINFO); } @@ -240,7 +242,7 @@ offset_t IOHandle::size() const throw(IO::IOError) { struct stat buff; - int ret = fstat((int)_handle, &buff); + int ret = fstat(_handle, &buff); if(ret == -1) throw IO::IOError(errno, "Could not stat file", P_SOURCEINFO); @@ -249,12 +251,12 @@ void IOHandle::resize(size_t sz) throw(IO::IOError) { - int ret = ftruncate((int)_handle, sz); + int ret = ftruncate(_handle, sz); if(ret == -1) throw IO::IOError(errno, "Could not truncate file", P_SOURCEINFO); } -unsigned long IOHandle::handle() const throw() +iohandle_t IOHandle::handle() const throw() { return _handle; } Index: StorageDevice.common.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/StorageDevice.common.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- StorageDevice.common.cpp 30 Jan 2005 17:17:00 -0000 1.1 +++ StorageDevice.common.cpp 7 Jun 2005 12:01:19 -0000 1.2 @@ -51,55 +51,55 @@ if(valid()) close(); - _handle = (unsigned long)new IOHandle(str, access, IO::IODevice::OpenFail, share); + _handle = new IOHandle(str, access, IO::IODevice::OpenFail, share); } void StorageDevice::_close() throw(IO::IOError) { - delete (IOHandle*)_handle; + delete _handle; _handle = 0; } size_t StorageDevice::_read(char* buffer, size_t count) throw(IO::IOError) { - return ((IOHandle*)_handle)->read(buffer, count); + return _handle->read(buffer, count); } size_t StorageDevice::_peek(char* buffer, size_t count) throw(IO::IOError) { - return ((IOHandle*)_handle)->peek(buffer, count); + return _handle->peek(buffer, count); } size_t StorageDevice::_write(const char* buffer, size_t count) throw(IO::IOError) { - return ((IOHandle*)_handle)->write(buffer, count); + return _handle->write(buffer, count); } offset_t StorageDevice::_seek(offset_t offset, SeekMode mode) throw(IO::IOError) { - return ((IOHandle*)_handle)->seek(offset, mode); + return _handle->seek(offset, mode); } bool StorageDevice::_isSeekable() const throw() { - return ((IOHandle*)_handle)->isSeekable(); + return _handle->isSeekable(); } void StorageDevice::_sync() const throw(IO::IOError) { - ((IOHandle*)_handle)->sync(); + _handle->sync(); } offset_t StorageDevice::_size() const throw(IO::IOError) { - return ((IOHandle*)_handle)->size(); + return _handle->size(); } -unsigned long StorageDevice::handle() const throw() +IOHandle* StorageDevice::handle() const throw() { - return ((IOHandle*)_handle)->handle(); + return _handle; } } // !namespace System Index: Pipe.posix.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/Pipe.posix.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- Pipe.posix.cpp 30 Jan 2005 17:07:03 -0000 1.9 +++ Pipe.posix.cpp 7 Jun 2005 12:01:19 -0000 1.10 @@ -35,8 +35,8 @@ if(::pipe(fds) == -1) throw IO::IOError(errno, "Could not create pipe", P_SOURCEINFO); - Pipe readPipe((unsigned long)fds[0], true); - Pipe writePipe((unsigned long)fds[1], false); + Pipe readPipe(new IOHandle(fds[0], true), true); + Pipe writePipe(new IOHandle(fds[1], true), false); return std::make_pair(readPipe, writePipe); } |
From: Christian P. <cp...@us...> - 2005-06-06 12:12:00
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30606/src/System Modified Files: EventQueue.cpp Log Message: - Added some Trace messages Index: EventQueue.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/EventQueue.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- EventQueue.cpp 11 Feb 2005 12:00:09 -0000 1.3 +++ EventQueue.cpp 6 Jun 2005 12:11:46 -0000 1.4 @@ -18,6 +18,7 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include "pclasses/Trace.h" #include "pclasses/System/EventQueue.h" #include <set> @@ -92,11 +93,14 @@ void EventQueue::send(const Event& ev) { + P_TRACE(EventQueue) << "send event. sender=" << ev.sender() << ", id=" << ev.id(); dispatch(ev); } void EventQueue::post(const Event& ev) { + P_TRACE(EventQueue) << "post event. sender=" << ev.sender() << ", id=" << ev.id(); + CriticalSection::ScopedLock lck(_eventQueueCs); _eventQueue.push(ev); @@ -140,6 +144,8 @@ void EventQueue::dispatch(const Event& ev) { + P_TRACE(EventQueue) << "dispatch event. sender=" << ev.sender() << ", id=" << ev.id(); + // we should call the EventListener's without held mutex lock, since a // signaled EventListener may modify our list of listeners. std::set<EventListener*> dispatchers; |
From: Christian P. <cp...@us...> - 2005-06-06 12:09:43
|
Update of /cvsroot/pclasses/pclasses2/src/Net In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28363/src/Net Modified Files: InetSocket.cpp ServerSocketManager.cpp Socket.cpp Log Message: - Fixed Socket::setBlocking() - Added AsyncSocket, AsyncStreamSocket, AsyncInetSocket, AsyncTCPSocket Index: ServerSocketManager.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Net/ServerSocketManager.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- ServerSocketManager.cpp 10 Feb 2005 19:10:37 -0000 1.1 +++ ServerSocketManager.cpp 6 Jun 2005 12:09:31 -0000 1.2 @@ -82,11 +82,11 @@ // left empty... } -void ServerSocketManager::slotConnected(SocketListener& l) +void ServerSocketManager::slotConnected() { - StreamSocketServer& srv = (StreamSocketServer&)l.socket(); - onConnect(srv); - sigConnect.fire(srv); +// StreamSocketServer& srv = (StreamSocketServer&)l.device(); +// onConnect(srv); +// sigConnect.fire(srv); } Index: Socket.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Net/Socket.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- Socket.cpp 10 Feb 2005 19:13:45 -0000 1.9 +++ Socket.cpp 6 Jun 2005 12:09:31 -0000 1.10 @@ -19,6 +19,7 @@ ***************************************************************************/ #include "pclasses/pclasses-config.h" +#include "pclasses/Trace.h" #include "pclasses/Net/Socket.h" #include "SocketOption.h" #include "../System/timeout.h" @@ -472,12 +473,13 @@ P_SOURCEINFO); long flags = ret; - if(enable) - ret |= O_NONBLOCK; + if(!enable) + flags |= O_NONBLOCK; else - ret &= ~O_NONBLOCK; + flags &= ~O_NONBLOCK; ret = ::fcntl(handle(), F_SETFL, flags); + if(ret == -1) throw IO::IOError(errno, "Could not get file-descriptor flags", P_SOURCEINFO); } @@ -488,6 +490,327 @@ } +AsyncSocket::AsyncSocket() throw() +: _eventQueue(System::EventQueue::instance()), + _listener(0), + _connState(NotConnected) +{ +} + +AsyncSocket::AsyncSocket(System::EventQueue& evq) throw() +: _eventQueue(evq), + _listener(0), + _connState(NotConnected) +{ +} + +AsyncSocket::AsyncSocket(Domain domain, Type type, int proto) throw(IO::IOError) +: Socket(), + _eventQueue(System::EventQueue::instance()), + _listener(0), + _connState(NotConnected) +{ + open(domain, type, proto); +} + +AsyncSocket::~AsyncSocket() throw() +{ + close(); +} + +#define BLOCKING_ERROR(x) (x == EWOULDBLOCK || x == EINPROGRESS) + +void AsyncSocket::connect(const NetworkAddress& addr, port_t port) + throw(IO::IOError) +{ + try + { + Socket::connect(addr, port); + } + catch(IO::IOError& err) + { + if(BLOCKING_ERROR(err.errorNo())) + { + _connState = Connecting; + _listener->setEventMask(_listener->eventMask() | + SocketListener::NotifyWrite); + return; + } + + P_TRACE(AsyncSocket) << "connection failed"; + throw; + } + + P_TRACE(AsyncSocket) << "connection succeeded immediatly"; + + _connState = Connected; + onConnect(); +} + +void AsyncSocket::open(Domain domain, Type type, int proto) + throw(IO::IOError) +{ + Socket::open(domain, type, proto); + + _listener = new SocketListener(_eventQueue, *this); + _listener->sigRead.bind(make_method(this, &AsyncSocket::readNotify)); + _listener->sigWrite.bind(make_method(this, &AsyncSocket::writeNotify)); + _listener->sigError.bind(make_method(this, &AsyncSocket::errorNotify)); + + setBlocking(false); +} + +void AsyncSocket::open(int handle, Domain domain, Type type, int proto) + throw(IO::IOError) +{ + Socket::open(handle, domain, type, proto); + + _listener = new SocketListener(_eventQueue, *this); + _listener->sigRead.bind(make_method(this, &AsyncSocket::readNotify)); + _listener->sigWrite.bind(make_method(this, &AsyncSocket::writeNotify)); + _listener->sigError.bind(make_method(this, &AsyncSocket::errorNotify)); + + setBlocking(false); +} + +void AsyncSocket::_close() throw(IO::IOError) +{ + Socket::_close(); + + _connState = NotConnected; + + if(_listener) + { + delete _listener; + _listener = 0; + } + + if(!_writeBuffer.empty()) + _writeBuffer.clear(); +} + +size_t AsyncSocket::_read(char* buffer, size_t count) throw(IO::IOError) +{ + size_t ret; + try + { + ret = Socket::_read(buffer, count); + } + catch(IO::IOError& err) + { + if(BLOCKING_ERROR(err.errorNo())) + return 0; + + throw; + } + + return ret; +} + +size_t AsyncSocket::_peek(char* buffer, size_t count) throw(IO::IOError) +{ + return Socket::_peek(buffer, count); +} + +size_t AsyncSocket::_write(const char* buffer, size_t count) throw(IO::IOError) +{ + size_t ret; + + // we must write the previously buffered data first ... + if(!_writeBuffer.empty()) + { + try + { + ret = Socket::_write(_writeBuffer.data(), _writeBuffer.size()); + } + catch(IO::IOError& err) + { + if(BLOCKING_ERROR(err.errorNo())) + return 0; + + throw; + } + + // dequeue written data ... + if(ret > 0) + { + P_TRACE(AsyncSocket) << "Wrote " << ret << " bytes from buffer"; + _writeBuffer.pop(ret); + } + + // if we did not write everything from the buffer, queue the entire + // buffer that has been passed to us ... + if(!_writeBuffer.empty()) + { + P_TRACE(AsyncSocket) << "Queued " << count << " bytes into buffer"; + _writeBuffer.push(buffer, count); + + // we want to get notified on next write-event ... + _listener->setEventMask(_listener->eventMask() | + SocketListener::NotifyWrite); + + return count; + } + } + + try + { + ret = Socket::_write(buffer, count); + } + catch(IO::IOError& err) + { + if(BLOCKING_ERROR(err.errorNo())) + return 0; + + throw; + } + + // queue the remaining data from the buffer ... + if(ret < count) + { + P_TRACE(AsyncSocket) << "Wrote " << ret << " bytes, queued " << count - ret << " bytes"; + _writeBuffer.push(buffer + ret, count - ret); + + // we want to get notified on next write-event ... + _listener->setEventMask(_listener->eventMask() | + SocketListener::NotifyWrite); + } + else + { + P_TRACE(AsyncSocket) << "Wrote everything, buffer empty"; + + // buffer is empty, we dont want to get notified on next write-event ... + _listener->setEventMask(_listener->eventMask() & + ~SocketListener::NotifyWrite); + } + + return count; +} + +void AsyncSocket::readNotify() +{ + P_TRACE(AsyncSocket) << "readNotify()"; + + char tmp[4096]; + size_t ret; + + try + { + ret = read(tmp, sizeof(tmp)); + } + catch(IO::IOError& err) + { + switch(_connState) + { + case Connecting: + _connState = NotConnected; + onConnectFailed(err); + break; + + case Connected: + _connState = NotConnected; + onClose(); + break; + + default: + onError(err); + break; + } + + // dont get notified on further read-events ... + _listener->setEventMask(_listener->eventMask() & + ~SocketListener::NotifyRead); + + return; + } + + // if we did read nothing, EOF has been reached + if(!ret) + { + if(_connState == Connected) + { + _connState = NotConnected; + onClose(); + } + + // dont get notified on further read-events ... + _listener->setEventMask(_listener->eventMask() & + ~SocketListener::NotifyRead); + } + else + { + onRead(tmp, ret); + } +} + +void AsyncSocket::writeNotify() +{ + P_TRACE(AsyncSocket) << "writeNotify()"; + + // if connect() has been called previously, the connection has succeeded + if(_connState == Connecting) + { + P_TRACE(AsyncSocket) << "connection succeeded"; + _connState = Connected; + onConnect(); + } + + // write buffered data first ... + try + { + _write(0, 0); + } + catch(IO::IOError& err) + { + onError(err); + return; + } + + onWrite(); +} + +void AsyncSocket::errorNotify() +{ + P_TRACE(AsyncSocket) << "errorNotify()"; + //onError(); +} + +void AsyncSocket::onConnect() +{ + P_TRACE(AsyncSocket) << "onConnect()"; +} + +void AsyncSocket::onConnectFailed(const IO::IOError& err) +{ + P_TRACE(AsyncSocket) << "onConnectFailed()"; +} + +void AsyncSocket::onClose() +{ + P_TRACE(AsyncSocket) << "onClose()"; +} + +void AsyncSocket::onError(const IO::IOError& err) +{ + P_TRACE(AsyncSocket) << "onError()"; +} + +void AsyncSocket::onRead(const char* buffer, size_t count) +{ + P_TRACE(AsyncSocket) << "onRead(buffer,count)"; +} + +void AsyncSocket::onWrite() +{ + P_TRACE(AsyncSocket) << "onWrite()"; +} + +AsyncSocket::ConnectState AsyncSocket::connectState() const throw() +{ + return _connState; +} + + DatagramSocket::DatagramSocket() throw() : Socket() { @@ -509,6 +832,7 @@ return opt.get() == 1 ? true : false; } + StreamSocket::StreamSocket() throw() : Socket() { @@ -539,6 +863,36 @@ Socket::open(srv.accept(), srv.domain(), srv.type(), srv.protocol()); } + +AsyncStreamSocket::AsyncStreamSocket() throw() +{ +} + +AsyncStreamSocket::AsyncStreamSocket(Domain d, int proto) throw(IO::IOError) +{ + AsyncSocket::open(d, Socket::Stream, proto); +} + +AsyncStreamSocket::AsyncStreamSocket(StreamSocketServer& srv) throw(IO::IOError) +{ + open(srv); +} + +AsyncStreamSocket::~AsyncStreamSocket() throw() +{ +} + +void AsyncStreamSocket::open(Domain d, int proto) throw(IO::IOError) +{ + AsyncSocket::open(d, Socket::Stream, proto); +} + +void AsyncStreamSocket::open(StreamSocketServer& srv) throw(IO::IOError) +{ + AsyncSocket::open(srv.accept(), srv.domain(), srv.type(), srv.protocol()); +} + + StreamSocketServer::StreamSocketServer(Domain domain, int proto) throw(IO::IOError) : Socket(domain, Socket::Stream, proto) { @@ -607,6 +961,7 @@ return d; } + enum SocketEvent { SocketEventRead = 0, SocketEventWrite = 1, @@ -656,22 +1011,21 @@ }; - SocketListener::SocketListener(Socket& s) -: EventListener(&s) +: IOListener(s), EventListener(&s) { using System::FdListener; - _handle = (unsigned long)new SocketFdListener(this, s.handle(), + _handle = (void*)new SocketFdListener(this, s.handle(), FdListener::Read|FdListener::Write|FdListener::Error); } SocketListener::SocketListener(System::EventQueue& evq, Socket& s) -: EventListener(evq, &s) +: IOListener(s), EventListener(evq, &s) { using System::FdListener; - _handle = (unsigned long)new SocketFdListener(this, s.handle(), + _handle = (void*)new SocketFdListener(this, s.handle(), FdListener::Read|FdListener::Write|FdListener::Error); } @@ -680,18 +1034,16 @@ delete (SocketFdListener*)_handle; } -Socket& SocketListener::socket() const throw() -{ - return *((Socket*)sender()); -} - void SocketListener::setEventMask(int mask) { - ((SocketFdListener*)_handle)->setFlags(mask); - - // Wakeup the thread so it can get the new event flags ... - System::FdListenerList& lst = System::FdListenerList::instance(eventQueue()); - lst.wakeup(); + if(mask != eventMask()) + { + ((SocketFdListener*)_handle)->setFlags(mask); + + // Wakeup the thread so it can get the new event flags ... + System::FdListenerList& lst = System::FdListenerList::instance(eventQueue()); + lst.wakeup(); + } } int SocketListener::eventMask() const throw() @@ -701,35 +1053,25 @@ void SocketListener::signaled(const System::Event& ev) { + P_TRACE(SocketListener) << "got signaled. sender=" << ev.sender() << ", id=" << ev.id(); + switch(ev.id()) { case SocketEventRead: onRead(); - sigRead.fire(*this); + sigRead.fire(); break; case SocketEventWrite: onWrite(); - sigWrite.fire(*this); + sigWrite.fire(); break; case SocketEventError: onError(); - sigError.fire(*this); + sigError.fire(); break; } } -void SocketListener::onRead() -{ -} - -void SocketListener::onWrite() -{ -} - -void SocketListener::onError() -{ -} - } // !namespace Net Index: InetSocket.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Net/InetSocket.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- InetSocket.cpp 26 Jan 2005 10:25:40 -0000 1.3 +++ InetSocket.cpp 6 Jun 2005 12:09:30 -0000 1.4 @@ -73,6 +73,25 @@ return opt.get(); } +AsyncInetSocket::AsyncInetSocket() throw() +{ +} + +AsyncInetSocket::AsyncInetSocket(Type t, int proto) throw(IO::IOError) +{ + AsyncSocket::open(Socket::Inet, t, proto); +} + +AsyncInetSocket::~AsyncInetSocket() throw() +{ +} + +void AsyncInetSocket::open(Type type, int proto) throw(IO::IOError) +{ + AsyncSocket::open(Socket::Inet, type, proto); +} + + UDPSocket::UDPSocket() throw(IO::IOError) : InetSocket(), DatagramSocket() @@ -185,6 +204,31 @@ } +AsyncTCPSocket::AsyncTCPSocket() throw(IO::IOError) +{ + AsyncInetSocket::open(Socket::Stream, IPPROTO_TCP); +} + +AsyncTCPSocket::AsyncTCPSocket(StreamSocketServer& srv) throw(IO::IOError) +{ + open(srv); +} + +AsyncTCPSocket::~AsyncTCPSocket() throw() +{ +} + +void AsyncTCPSocket::open() throw(IO::IOError) +{ + AsyncInetSocket::open(Socket::Stream, IPPROTO_TCP); } +void AsyncTCPSocket::open(StreamSocketServer& srv) throw(IO::IOError) +{ + AsyncStreamSocket::open(srv); } + + +} // !namespace Net + +} // !namespace P |
From: Christian P. <cp...@us...> - 2005-06-06 12:09:42
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Net In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28363/include/pclasses/Net Modified Files: InetSocket.h ServerSocketManager.h Socket.h Log Message: - Fixed Socket::setBlocking() - Added AsyncSocket, AsyncStreamSocket, AsyncInetSocket, AsyncTCPSocket Index: ServerSocketManager.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Net/ServerSocketManager.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- ServerSocketManager.h 10 Feb 2005 19:10:36 -0000 1.1 +++ ServerSocketManager.h 6 Jun 2005 12:09:30 -0000 1.2 @@ -46,7 +46,7 @@ virtual void onConnect(StreamSocketServer& s); private: - void slotConnected(SocketListener&); + void slotConnected(); std::list< StreamSocketServer* Index: Socket.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Net/Socket.h,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- Socket.h 10 Feb 2005 19:13:46 -0000 1.8 +++ Socket.h 6 Jun 2005 12:09:30 -0000 1.9 @@ -20,11 +20,12 @@ #ifndef P_Net_Socket_h #define P_Net_Socket_h - + #include <pclasses/Export.h> #include <pclasses/BasicTypes.h> -#include <pclasses/Signal.h> +#include <pclasses/Buffer.h> #include <pclasses/IO/IODevice.h> +#include <pclasses/IO/IOListener.h> #include <pclasses/System/EventQueue.h> #include <pclasses/Net/NetworkAddress.h> @@ -71,7 +72,7 @@ //! Bind socket to given address and port void bind(const NetworkAddress& addr, port_t port) throw(IO::IOError); - void connect(const NetworkAddress& addr, port_t port) throw(IO::IOError); + virtual void connect(const NetworkAddress& addr, port_t port) throw(IO::IOError); void setSendTimeout(unsigned int timeout) throw(IO::IOError); unsigned int sendTimeout() const throw(IO::IOError); @@ -101,10 +102,10 @@ protected: Socket(Domain domain, Type type, int proto = 0) throw(IO::IOError); - void open(Domain domain, Type type, int proto) + virtual void open(Domain domain, Type type, int proto) throw(IO::IOError); - void open(int handle, Domain domain, Type type, int proto) + virtual void open(int handle, Domain domain, Type type, int proto) throw(IO::IOError); int handle() const throw(); @@ -124,37 +125,83 @@ //! Socket Event-listener -class PNET_EXPORT SocketListener: public System::EventListener { +class PNET_EXPORT SocketListener: public IO::IOListener, + public System::EventListener +{ public: - enum EventMask { - Read = 0x01, - Write = 0x02, - Error = 0x04 - }; - SocketListener(Socket& s); SocketListener(System::EventQueue& evq, Socket& s); ~SocketListener(); - Socket& socket() const throw(); - void setEventMask(int mask); int eventMask() const throw(); - Signal1<void, SocketListener&> sigRead; - Signal1<void, SocketListener&> sigWrite; - Signal1<void, SocketListener&> sigError; + private: + void signaled(const System::Event& ev); + void* _handle; +}; + + +//! Asynchronous socket +class PNET_EXPORT AsyncSocket: public virtual Socket { + public: + enum ConnectState { + NotConnected, + Connecting, + Connected + }; + + AsyncSocket() throw(); + AsyncSocket(System::EventQueue& evq) throw(); + ~AsyncSocket() throw(); + + void connect(const NetworkAddress& addr, port_t port) throw(IO::IOError); + + ConnectState connectState() const throw(); protected: - virtual void onRead(); + AsyncSocket(Domain domain, Type type, int proto = 0) throw(IO::IOError); + + void open(Domain domain, Type type, int proto) + throw(IO::IOError); + + void open(int handle, Domain domain, Type type, int proto) + throw(IO::IOError); + + //! Called after connection has been established + virtual void onConnect(); + + //! Called when a connection-attempt has been failed + virtual void onConnectFailed(const IO::IOError& err); + + //! Called when data has been received + virtual void onRead(const char* buffer, size_t count); + + //! Called when socket is ready for more data virtual void onWrite(); - virtual void onError(); + + //! Called on asynchronous socket error + virtual void onError(const IO::IOError& err); + + //! Called when connection has been closed + virtual void onClose(); + + // IODevice related methods + void _close() throw(IO::IOError); + size_t _read(char* buffer, size_t count) throw(IO::IOError); + size_t _peek(char* buffer, size_t count) throw(IO::IOError); + size_t _write(const char* buffer, size_t count) throw(IO::IOError); private: - void signaled(const System::Event& ev); - unsigned long _handle; -}; + void writeNotify(); + void readNotify(); + void errorNotify(); + System::EventQueue& _eventQueue; + SocketListener* _listener; + Buffer<char> _writeBuffer; + ConnectState _connState; +}; //! Datagram Socket @@ -168,6 +215,7 @@ }; + //! Streaming Socket Server class PNET_EXPORT StreamSocketServer: public Socket { public: @@ -191,6 +239,7 @@ int accept() throw(IO::IOError); }; + //! Streaming Socket class PNET_EXPORT StreamSocket: public virtual Socket { public: @@ -199,6 +248,21 @@ StreamSocket(StreamSocketServer& srv) throw(IO::IOError); ~StreamSocket() throw(); + virtual void open(Domain d, int proto) throw(IO::IOError); + virtual void open(StreamSocketServer& srv) throw(IO::IOError); +}; + + +//! Asynchronous streaming socket +class PNET_EXPORT AsyncStreamSocket: + public virtual AsyncSocket, public virtual StreamSocket +{ + public: + AsyncStreamSocket() throw(); + AsyncStreamSocket(Domain d, int proto) throw(IO::IOError); + AsyncStreamSocket(StreamSocketServer& srv) throw(IO::IOError); + ~AsyncStreamSocket() throw(); + void open(Domain d, int proto) throw(IO::IOError); void open(StreamSocketServer& srv) throw(IO::IOError); }; Index: InetSocket.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Net/InetSocket.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- InetSocket.h 26 Jan 2005 10:25:40 -0000 1.3 +++ InetSocket.h 6 Jun 2005 12:09:30 -0000 1.4 @@ -43,11 +43,26 @@ int timeToLive() const throw(IO::IOError); protected: + virtual void open(Type type, int proto) throw(IO::IOError); +}; + +//! Asynchronous IPv4 Socket +class PNET_EXPORT AsyncInetSocket: + public virtual AsyncSocket, public virtual InetSocket +{ + public: + AsyncInetSocket() throw(); + AsyncInetSocket(Type t, int proto) throw(IO::IOError); + ~AsyncInetSocket() throw(); + + protected: void open(Type type, int proto) throw(IO::IOError); }; //! UDP Datagram Socket -class PNET_EXPORT UDPSocket: public InetSocket, public DatagramSocket { +class PNET_EXPORT UDPSocket: + public virtual InetSocket, public virtual DatagramSocket +{ public: UDPSocket() throw(IO::IOError); ~UDPSocket() throw(); @@ -66,15 +81,28 @@ }; //! TCP Streaming Socket -class PNET_EXPORT TCPSocket: public InetSocket, public StreamSocket { +class PNET_EXPORT TCPSocket: + public virtual InetSocket, public virtual StreamSocket +{ public: TCPSocket() throw(IO::IOError); TCPSocket(StreamSocketServer& srv) throw(IO::IOError); ~TCPSocket() throw(); + virtual void open() throw(IO::IOError); + virtual void open(StreamSocketServer& srv) throw(IO::IOError); +}; + +class PNET_EXPORT AsyncTCPSocket: + public AsyncInetSocket, public AsyncStreamSocket, public TCPSocket +{ + public: + AsyncTCPSocket() throw(IO::IOError); + AsyncTCPSocket(StreamSocketServer& srv) throw(IO::IOError); + ~AsyncTCPSocket() throw(); + void open() throw(IO::IOError); void open(StreamSocketServer& srv) throw(IO::IOError); - }; } // !namespace Net |
From: Christian P. <cp...@us...> - 2005-06-06 12:01:35
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24622/src/System Modified Files: FdListener.h FdListener.posix.cpp Log Message: - Added some code to not wakeup the FdListener if running in the same thread Index: FdListener.posix.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/FdListener.posix.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- FdListener.posix.cpp 20 May 2005 14:21:58 -0000 1.6 +++ FdListener.posix.cpp 6 Jun 2005 12:01:19 -0000 1.7 @@ -19,6 +19,7 @@ ***************************************************************************/ #include "pclasses/Trace.h" +#include "pclasses/System/Thread.h" #include "FdListener.h" #include "timeout.h" @@ -93,7 +94,7 @@ InstMap FdListenerList::_theLists; FdListenerList::FdListenerList(EventQueue& evq) throw(SystemError) -: _eventQueue(evq) +: _eventQueue(evq), _threadId(Thread::threadId()) { // we use a pipe for wakeup signaling ... int ret = ::pipe(_wakeupPipe); @@ -131,8 +132,15 @@ void FdListenerList::wakeup() { - P_TRACE(FdListenerList) << "wakeup(): waking up FdListenerList..."; - ::write(_wakeupPipe[1], "W", 1); + if(Thread::threadId() != _threadId) + { + P_TRACE(FdListenerList) << "wakeup(): waking up FdListenerList..."; + ::write(_wakeupPipe[1], "W", 1); + } + else + { + P_TRACE(FdListenerList) << "wakeup(): not needed, called in same thread"; + } } FdListenerList& FdListenerList::instance(EventQueue& evq) Index: FdListener.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/FdListener.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- FdListener.h 23 Apr 2005 17:47:07 -0000 1.3 +++ FdListener.h 6 Jun 2005 12:01:19 -0000 1.4 @@ -93,6 +93,7 @@ ListenerSet _listeners; CriticalSection _listenersCs; + unsigned long _threadId; static std::map< EventQueue*, |
From: Christian P. <cp...@us...> - 2005-06-06 11:59:38
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23474/src/System Modified Files: Thread.posix.cpp Log Message: - Added Thread::id() and Thread::threadId() Index: Thread.posix.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/Thread.posix.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- Thread.posix.cpp 25 Apr 2005 10:51:15 -0000 1.4 +++ Thread.posix.cpp 6 Jun 2005 11:59:26 -0000 1.5 @@ -126,6 +126,19 @@ return _detached; } +unsigned long Thread::id() const throw(LogicError) +{ + if(!_handle) + throw LogicError("Thread is not running", P_SOURCEINFO); + + return _handle->thread; +} + +unsigned long Thread::threadId() throw() +{ + return pthread_self(); +} + } // !namespace System |
From: Christian P. <cp...@us...> - 2005-06-06 11:59:38
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23474/include/pclasses/System Modified Files: Thread.h Log Message: - Added Thread::id() and Thread::threadId() Index: Thread.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/System/Thread.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- Thread.h 25 Apr 2005 10:51:14 -0000 1.6 +++ Thread.h 6 Jun 2005 11:59:25 -0000 1.7 @@ -52,6 +52,8 @@ //! Test if thread is detached bool detached() const throw(); + unsigned long id() const throw(LogicError); + static void yield() throw(); static void sleep(unsigned int ms) throw(); @@ -60,6 +62,8 @@ static void spawn(const Callback& cb, const CallbackArgs& args, Semaphore* sem = 0) throw(SystemError); + static unsigned long threadId() throw(); + protected: virtual long main() = 0; |
From: Christian P. <cp...@us...> - 2005-06-06 11:58:16
|
Update of /cvsroot/pclasses/pclasses2/src/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22523/src/IO Modified Files: IOManager.cpp Log Message: - IOManager is now thread-safe - Added some documentation Index: IOManager.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/IO/IOManager.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- IOManager.cpp 25 May 2005 08:02:55 -0000 1.1 +++ IOManager.cpp 6 Jun 2005 11:58:03 -0000 1.2 @@ -33,6 +33,8 @@ IOManager::~IOManager() { + _requestsMtx.lock(); + // cleanup requests ... request_map::iterator ri = _requests.begin(); while(ri != _requests.end()) @@ -42,6 +44,9 @@ _requests.erase(di); } + _requestsMtx.unlock(); + _handlersMtx.lock(); + // cleanup handlers ... handler_map::iterator hi = _handlers.begin(); while(hi != _handlers.end()) @@ -50,6 +55,8 @@ handler_map::iterator di = hi++; _handlers.erase(di); } + + _handlersMtx.unlock(); } IORequest_Get* IOManager::get(const URL& url) @@ -61,7 +68,7 @@ { request = handler->get(url); if(request) - _requests.insert(std::make_pair(request, handler)); + addHandlerRequest(request, handler); } return request; @@ -76,7 +83,7 @@ { request = handler->put(url); if(request) - _requests.insert(std::make_pair(request, handler)); + addHandlerRequest(request, handler); } return request; @@ -91,7 +98,7 @@ { request = handler->unlink(url); if(request) - _requests.insert(std::make_pair(request, handler)); + addHandlerRequest(request, handler); } return request; @@ -106,7 +113,7 @@ { request = handler->mkdir(url); if(request) - _requests.insert(std::make_pair(request, handler)); + addHandlerRequest(request, handler); } return request; @@ -121,7 +128,7 @@ { request = handler->rmdir(url); if(request) - _requests.insert(std::make_pair(request, handler)); + addHandlerRequest(request, handler); } return request; @@ -136,7 +143,7 @@ { request = handler->lsdir(url); if(request) - _requests.insert(std::make_pair(request, handler)); + addHandlerRequest(request, handler); } return request; @@ -144,6 +151,8 @@ void IOManager::finish(IORequest* req) { + CoreMutex::ScopedLock lck(_requestsMtx); + request_map::iterator i = _requests.find(req); if(i != _requests.end()) { @@ -154,6 +163,8 @@ IOHandler* IOManager::findHandler(const std::string& proto) { + CoreMutex::ScopedLock lck(_handlersMtx); + handler_map::const_iterator i = _handlers.find(proto); if(i != _handlers.end()) return i->second; @@ -167,6 +178,12 @@ return handler; } +void IOManager::addHandlerRequest(IORequest* req, IOHandler* handler) +{ + CoreMutex::ScopedLock lck(_requestsMtx); + _requests.insert(std::make_pair(req, handler)); +} + struct IOManager_context_t { }; IOManager& IOManager::instance() |
From: Christian P. <cp...@us...> - 2005-06-06 11:58:16
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22523/include/pclasses/IO Modified Files: IOManager.h Log Message: - IOManager is now thread-safe - Added some documentation Index: IOManager.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/IO/IOManager.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- IOManager.h 25 May 2005 08:02:56 -0000 1.6 +++ IOManager.h 6 Jun 2005 11:58:02 -0000 1.7 @@ -22,6 +22,7 @@ #define P_IO_IOManager_h #include <pclasses/Export.h> +#include <pclasses/CoreMutex.h> #include <pclasses/IO/URL.h> #include <pclasses/IO/IORequest.h> @@ -34,32 +35,57 @@ class IOHandler; +//! Transparent Network Filesystem I/O manager +/*! + The IOManager is used to dispatch the various I/O requests to the + specific IOHandler's based on the protocol given in the request-URL's. + The IOHandler's are created by a call to Factory<IOHandler>::create() + and may therefore be registered statically by the Application itself + or dynamically loaded by the PluginManager. + Protocol-IOHandler classes must be named "IOHandler_<protocol>". + + All methods in this class are reentrant. +*/ class PIO_EXPORT IOManager { public: IOManager(); ~IOManager(); + //! Creates a GET request used to download a file IORequest_Get* get(const URL& url); + + //! Creates a PUT request used to upload a file IORequest_Put* put(const URL& url); + //! Creates a UNLINK request used to delete a file IORequest_Unlink* unlink(const URL& url); + //! Creates a MKDIR request used to create a directory IORequest_MakeDir* mkdir(const URL& url); + + //! Creates a RMDIR request used to remove a directory IORequest_RemoveDir* rmdir(const URL& url); + //! Creates a LSDIR request used to list the contents of a directory IORequest_ListDir* lsdir(const URL& url); + //! Cleans up and deletes a no longer needed IORequest void finish(IORequest* req); + //! Returns the global instance of the IOManager static IOManager& instance(); private: IOHandler* findHandler(const std::string& proto); + void addHandlerRequest(IORequest* req, IOHandler* handler); typedef std::map<std::string, IOHandler*> handler_map; typedef std::map<IORequest*, IOHandler*> request_map; + CoreMutex _handlersMtx; handler_map _handlers; + + CoreMutex _requestsMtx; request_map _requests; }; |
From: Christian P. <cp...@us...> - 2005-06-03 09:55:59
|
Update of /cvsroot/pclasses/pclasses2/src/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28075/src/IO Modified Files: IODevice.cpp IOListener.cpp Log Message: - More work on asynchronous I/O Index: IOListener.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/IO/IOListener.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- IOListener.cpp 29 May 2005 17:48:31 -0000 1.1 +++ IOListener.cpp 3 Jun 2005 09:55:44 -0000 1.2 @@ -24,17 +24,31 @@ namespace IO { -IOListener::IOListener(IODevice& dev, int flags) +IOListener::IOListener(IODevice& dev) : _dev(dev) { - dev.addListener(this); } IOListener::~IOListener() { - _dev.removeListener(this); } +IODevice& IOListener::device() const throw() +{ + return _dev; +} + +void IOListener::onRead() +{ +} + +void IOListener::onWrite() +{ +} + +void IOListener::onError() +{ +} } Index: IODevice.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/IO/IODevice.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- IODevice.cpp 29 May 2005 17:48:31 -0000 1.9 +++ IODevice.cpp 3 Jun 2005 09:55:44 -0000 1.10 @@ -197,15 +197,6 @@ return _filter; } -void IODevice::addListener(IOListener*) throw(IOError) -{ - throw IOError(0, "Listening on this device is not supported", P_SOURCEINFO); -} - -void IODevice::removeListener(IOListener*) throw() -{ -} - size_t IODevice::_peek(char* buffer, size_t count) throw(IOError) { return 0; |
From: Christian P. <cp...@us...> - 2005-06-03 09:55:59
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28075/include/pclasses/IO Modified Files: IODevice.h IOListener.h Log Message: - More work on asynchronous I/O Index: IOListener.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/IO/IOListener.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- IOListener.h 29 May 2005 17:48:31 -0000 1.1 +++ IOListener.h 3 Jun 2005 09:55:44 -0000 1.2 @@ -22,6 +22,7 @@ #define P_IO_IOListener_h #include <pclasses/Export.h> +#include <pclasses/Signal.h> #include <pclasses/IO/IODevice.h> namespace P { @@ -30,22 +31,28 @@ class PIO_EXPORT IOListener { public: - - //! Notify flags - enum NotifyFlags { - NotifyNone = 0x0, - NotifyRead = 0x1, - NotifyWrite = 0x2 + enum EventMask { + NotifyRead = 0x01, + NotifyWrite = 0x02, + NotifyError = 0x04 }; - IOListener(IODevice& dev, int flags = 0); + IOListener(IODevice& dev); virtual ~IOListener(); - virtual int flags() const = 0; - virtual void setFlags(int flags) = 0; + IODevice& device() const throw(); - virtual void onRead() = 0; - virtual void onWrite() = 0; + virtual void setEventMask(int mask) = 0; + virtual int eventMask() const throw() = 0; + + Signal0<void> sigRead; + Signal0<void> sigWrite; + Signal0<void> sigError; + + protected: + virtual void onRead(); + virtual void onWrite(); + virtual void onError(); private: IODevice& _dev; Index: IODevice.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/IO/IODevice.h,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- IODevice.h 29 May 2005 17:48:31 -0000 1.8 +++ IODevice.h 3 Jun 2005 09:55:44 -0000 1.9 @@ -31,7 +31,6 @@ // forward declaration class IOFilter; -class IOListener; //! I/O Device base class /*! @@ -198,14 +197,9 @@ IOFilter* filter() const throw(); protected: - friend class IOListener; - IODevice(const IODevice& dev) throw(); IODevice& operator=(const IODevice& dev) throw(); - virtual void addListener(IOListener*) throw(IOError); - virtual void removeListener(IOListener*) throw(); - //! Called when device should be closed /*! precondition: valid()==true |
From: Christian P. <cp...@us...> - 2005-06-03 09:50:23
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25254/include/pclasses Modified Files: CircularQueue.h Log Message: - Renamed size()->capacity(), count()->size() Index: CircularQueue.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/CircularQueue.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- CircularQueue.h 22 Dec 2004 17:54:40 -0000 1.1.1.1 +++ CircularQueue.h 3 Jun 2005 09:50:13 -0000 1.2 @@ -103,7 +103,7 @@ Returns the number of items the queue can maximum hold before an overrun occurs. */ - inline size_t size() const throw() + inline size_t capacity() const throw() { return _size - 1; } //! Tests if the queue is empty @@ -261,6 +261,9 @@ size_t _in, _out, _pos; }; + // for STL-compat + typedef Iterator iterator; + Iterator begin() const throw() { return Iterator(_size, _buffer, _in, _out, _out); } |