From: <ag...@us...> - 2008-07-25 02:51:38
|
Revision: 74 http://zoolib.svn.sourceforge.net/zoolib/?rev=74&view=rev Author: agreen Date: 2008-07-25 02:51:46 +0000 (Fri, 25 Jul 2008) Log Message: ----------- Don't assume X11 availability on POSX. Whitespace. ObjC compatibility. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZCONFIG_SPI.h trunk/zoolib/source/cxx/zoolib/ZLog.h trunk/zoolib/source/cxx/zoolib/ZUtil_NSObject.mm Modified: trunk/zoolib/source/cxx/zoolib/ZCONFIG_SPI.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZCONFIG_SPI.h 2008-07-14 03:25:27 UTC (rev 73) +++ trunk/zoolib/source/cxx/zoolib/ZCONFIG_SPI.h 2008-07-25 02:51:46 UTC (rev 74) @@ -430,9 +430,9 @@ // ================================================================================================= #pragma mark X11 -#ifndef ZCONFIG_SPI_Avail__X11 -# define ZCONFIG_SPI_Avail__X11 (ZCONFIG_SPI_Avail__POSIX && ZCONFIG_SPI_Desired__POSIX) -#endif +//#ifndef ZCONFIG_SPI_Avail__X11 +//# define ZCONFIG_SPI_Avail__X11 (ZCONFIG_SPI_Avail__POSIX && ZCONFIG_SPI_Desired__POSIX) +//#endif #ifndef ZCONFIG_SPI_Avail__X11 # define ZCONFIG_SPI_Avail__X11 0 Modified: trunk/zoolib/source/cxx/zoolib/ZLog.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZLog.h 2008-07-14 03:25:27 UTC (rev 73) +++ trunk/zoolib/source/cxx/zoolib/ZLog.h 2008-07-25 02:51:46 UTC (rev 74) @@ -109,7 +109,8 @@ public: virtual ~LogMeister(); virtual bool Enabled(EPriority iPriority, const std::string& iName); - virtual void LogIt(EPriority iPriority, const std::string& iName, const std::string& iMessage) = 0; + virtual void LogIt( + EPriority iPriority, const std::string& iName, const std::string& iMessage) = 0; }; void sSetLogMeister(LogMeister* iLogMeister); Modified: trunk/zoolib/source/cxx/zoolib/ZUtil_NSObject.mm =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZUtil_NSObject.mm 2008-07-14 03:25:27 UTC (rev 73) +++ trunk/zoolib/source/cxx/zoolib/ZUtil_NSObject.mm 2008-07-25 02:51:46 UTC (rev 74) @@ -22,7 +22,7 @@ #if ZCONFIG_SPI_Enabled(Cocoa) -#include <Foundation/NSString.h> +#import <Foundation/NSString.h> using std::vector; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-08-04 04:23:19
|
Revision: 80 http://zoolib.svn.sourceforge.net/zoolib/?rev=80&view=rev Author: agreen Date: 2008-08-04 04:23:27 +0000 (Mon, 04 Aug 2008) Log Message: ----------- I've broken the ZThread InitHelper stuff out into a separate file (ZThreadMain), which only has to be incorporated into a build if deadlock detection is being done, or you're building for Windows. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZThread.cpp trunk/zoolib/source/cxx/zoolib/ZThread.h Added Paths: ----------- trunk/zoolib/source/cxx/zoolib/ZThreadMain.cpp trunk/zoolib/source/cxx/zoolib/ZThreadMain.h Modified: trunk/zoolib/source/cxx/zoolib/ZThread.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZThread.cpp 2008-08-04 04:18:38 UTC (rev 79) +++ trunk/zoolib/source/cxx/zoolib/ZThread.cpp 2008-08-04 04:23:27 UTC (rev 80) @@ -164,38 +164,6 @@ ZAssertStop(kDebug_Thread, priorValue == 1); } -// ================================================================================================= -#pragma mark - -#pragma mark * ZThread Initialization/Tear Down - -namespace ZANONYMOUS { - -class MainThread : public ZThread - { -public: - MainThread() : ZThread((struct ZooLib::Dummy*)(0)){} - virtual void Run() {} - }; - -} // anonymous namespace - -static int sInitCount; - -ZThread::InitHelper::InitHelper() - { - if (sInitCount++ != 0) - return; - - new MainThread; - } - -ZThread::InitHelper::~InitHelper() - { - if (--sInitCount != 0) - return; - delete sMainThread; - } - // ================================================== #pragma mark - #pragma mark * ZThread ctor/dtor @@ -234,7 +202,9 @@ ZThread::ZThread(const char* iName) { - ZAssertStop(kDebug_Thread, sMainThread); + if (ZCONFIG_Thread_DeadlockDetect || ZCONFIG(API_Thread, Win32)) + ZAssertStop(kDebug_Thread, sMainThread); + fThreadID = kThreadID_None; fStarted = false; fName = iName; Modified: trunk/zoolib/source/cxx/zoolib/ZThread.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZThread.h 2008-08-04 04:18:38 UTC (rev 79) +++ trunk/zoolib/source/cxx/zoolib/ZThread.h 2008-08-04 04:23:27 UTC (rev 80) @@ -60,7 +60,7 @@ // Do we want deadlock detection to be active? #ifndef ZCONFIG_Thread_DeadlockDetect -# if ZCONFIG_Debug >= 1 +# if ZCONFIG_Debug >= 2 # define ZCONFIG_Thread_DeadlockDetect 1 # else # define ZCONFIG_Thread_DeadlockDetect 0 @@ -90,6 +90,10 @@ # define ZCONFIG_Thread_Preemptive 1 #endif +#if ZCONFIG_Thread_DeadlockDetect || ZCONFIG(API_Thread, Win32) +# include "zoolib/ZThreadMain.h" +#endif + // ================================================== // A macro that has proven to be useful. #define ZAssertLocked(a, b) ZAssertStop(a, (b).IsLocked()) @@ -157,7 +161,7 @@ class ZThread : ZooLib::NonCopyable { protected: - // This protected constructor is used indirectly by ZThread::InitHelper. + // This protected constructor is used indirectly by ZThreadMainInitHelper. ZThread(struct Dummy*); // Our destructor is protected, so even with its pointer semantics it's illegal to @@ -300,24 +304,6 @@ // ================================================================================================= #pragma mark - -#pragma mark * ZThread::InitHelper - -class ZThread::InitHelper - { -public: - InitHelper(); - ~InitHelper(); - }; - -// This static is what makes auto-initialization work. Every file that (transitively) includes ZThread.h will -// get their own instance of a ZThread::InitHelper, whose constructor creates the main thread object and -// whose destructor deletes it. This ensures that ZThread is initialized at static construction time -// and is usable regardless of the link order. - -static ZThread::InitHelper sZThread_InitHelper; - -// ================================================================================================= -#pragma mark - #pragma mark * ZThread::Ex_Disposed class ZThread::Ex_Disposed : public std::runtime_error Added: trunk/zoolib/source/cxx/zoolib/ZThreadMain.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZThreadMain.cpp (rev 0) +++ trunk/zoolib/source/cxx/zoolib/ZThreadMain.cpp 2008-08-04 04:23:27 UTC (rev 80) @@ -0,0 +1,53 @@ +/* ------------------------------------------------------------------------------------------------- +Copyright (c) 2008 Andrew Green +http://www.zoolib.org + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software +and associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +------------------------------------------------------------------------------------------------- */ + +#include "zoolib/ZThreadMain.h" + +// ================================================================================================= +#pragma mark - +#pragma mark * ZThreadMain + +namespace ZANONYMOUS { + +class MainThread : public ZThread + { +public: + MainThread() : ZThread((struct ZooLib::Dummy*)(0)){} + virtual void Run() {} + }; + +} // anonymous namespace + +static int sInitCount; + +ZThread::InitHelper::InitHelper() + { + if (sInitCount++ != 0) + return; + + new MainThread; + } + +ZThread::InitHelper::~InitHelper() + { + if (--sInitCount != 0) + return; + delete sMainThread; + } Added: trunk/zoolib/source/cxx/zoolib/ZThreadMain.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZThreadMain.h (rev 0) +++ trunk/zoolib/source/cxx/zoolib/ZThreadMain.h 2008-08-04 04:23:27 UTC (rev 80) @@ -0,0 +1,49 @@ +/* ------------------------------------------------------------------------------------------------- +Copyright (c) 2008 Andrew Green +http://www.zoolib.org + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software +and associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +------------------------------------------------------------------------------------------------- */ + +#ifndef __ZThreadMain__ +#define __ZThreadMain__ 1 +#include "zconfig.h" + +#include "zoolib/ZThread.h" + +// ================================================================================================= +#pragma mark - +#pragma mark * ZThreadMain + +namespace ZooLib { + +class ZThreadMainInitHelper + { +public: + ZThreadMainInitHelper(); + ~ZThreadMainInitHelper(); + }; + +// This static is what makes auto-initialization work. Every file that (transitively) includes ZThread.h will +// get their own instance of a ZThread::InitHelper, whose constructor creates the main thread object and +// whose destructor deletes it. This ensures that ZThread is initialized at static construction time +// and is usable regardless of the link order. + +static ZThreadMainInitHelper sZThread_InitHelper; + +} // namespace ZooLib + +#endif // __ZThreadMain__ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-08-04 04:25:36
|
Revision: 83 http://zoolib.svn.sourceforge.net/zoolib/?rev=83&view=rev Author: agreen Date: 2008-08-04 04:25:45 +0000 (Mon, 04 Aug 2008) Log Message: ----------- Add a constructor from a ZStreamR that takes a dummy boolean, to allow code like: ZTuple(false, theStreamR) Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZTuple.cpp trunk/zoolib/source/cxx/zoolib/ZTuple.h Modified: trunk/zoolib/source/cxx/zoolib/ZTuple.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZTuple.cpp 2008-08-04 04:24:42 UTC (rev 82) +++ trunk/zoolib/source/cxx/zoolib/ZTuple.cpp 2008-08-04 04:25:45 UTC (rev 83) @@ -292,6 +292,12 @@ this->pFromStream(iStreamR); } +ZTValue::ZTValue(bool dummy, const ZStreamR& iStreamR) + { + fType.fType = eZType_Null; + this->pFromStream(iStreamR); + } + void ZTValue::ToStream(const ZStreamW& iStreamW) const { if (fType.fType < 0) @@ -2309,6 +2315,10 @@ : fRep(sRepFromStream(iStreamR)) {} +ZTuple::ZTuple(bool dummy, const ZStreamR& iStreamR) +: fRep(sRepFromStream(iStreamR)) + {} + // ================================================================================================= #pragma mark - #pragma mark * ZTuple streaming Modified: trunk/zoolib/source/cxx/zoolib/ZTuple.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZTuple.h 2008-08-04 04:24:42 UTC (rev 82) +++ trunk/zoolib/source/cxx/zoolib/ZTuple.h 2008-08-04 04:25:45 UTC (rev 83) @@ -23,7 +23,6 @@ #include "zconfig.h" #include "zoolib/ZCompare.h" -#include "zoolib/ZMemory.h" // For ZBlockCopy #include "zoolib/ZRefCount.h" #include "zoolib/ZTime.h" #include "zoolib/ZTName.h" @@ -107,6 +106,7 @@ /** \name Constructing from flattened data in a stream */ //@{ explicit ZTValue(const ZStreamR& iStreamR); + ZTValue(bool dummy, const ZStreamR& iStreamR); //@} /** \name Efficient swapping with another instance @@ -622,6 +622,7 @@ /** \name Constructing from stream */ //@{ explicit ZTuple(const ZStreamR& iStreamR); + ZTuple(bool dummy, const ZStreamR& iStreamR); //@} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-09-09 16:26:43
|
Revision: 105 http://zoolib.svn.sourceforge.net/zoolib/?rev=105&view=rev Author: agreen Date: 2008-09-09 16:26:53 +0000 (Tue, 09 Sep 2008) Log Message: ----------- In ZBlackBerry_Streamer, handle the inability to authenticate properly -- we were just letting the channel dangle, rather than asking it to close after being challenged. Added ZBlackBerry::Device::GetPIN, using USB wire protocol, or BBDevMgr IDeviceProperty as appropriate. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZBlackBerry.cpp trunk/zoolib/source/cxx/zoolib/ZBlackBerry.h trunk/zoolib/source/cxx/zoolib/ZBlackBerryServer.cpp trunk/zoolib/source/cxx/zoolib/ZBlackBerry_BBDevMgr.cpp trunk/zoolib/source/cxx/zoolib/ZBlackBerry_Client.cpp trunk/zoolib/source/cxx/zoolib/ZBlackBerry_Streamer.cpp trunk/zoolib/source/cxx/zoolib/ZBlackBerry_Streamer.h Modified: trunk/zoolib/source/cxx/zoolib/ZBlackBerry.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZBlackBerry.cpp 2008-09-09 16:24:56 UTC (rev 104) +++ trunk/zoolib/source/cxx/zoolib/ZBlackBerry.cpp 2008-09-09 16:26:53 UTC (rev 105) @@ -334,6 +334,11 @@ s << "Finalize, deleted"; } +uint32 Device::GetPIN() + { + return 0; + } + void Device::ObserverAdd(Observer* iObserver) { ZMutexLocker locker(fMutex); Modified: trunk/zoolib/source/cxx/zoolib/ZBlackBerry.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZBlackBerry.h 2008-09-09 16:24:56 UTC (rev 104) +++ trunk/zoolib/source/cxx/zoolib/ZBlackBerry.h 2008-09-09 16:26:53 UTC (rev 105) @@ -115,6 +115,7 @@ virtual ZRef<Channel> Open( const std::string& iName, const PasswordHash* iPasswordHash, Error* oError) = 0; virtual ZMemoryBlock GetAttribute(uint16 iObject, uint16 iAttribute) = 0; + virtual uint32 GetPIN(); class Observer { Modified: trunk/zoolib/source/cxx/zoolib/ZBlackBerryServer.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZBlackBerryServer.cpp 2008-09-09 16:24:56 UTC (rev 104) +++ trunk/zoolib/source/cxx/zoolib/ZBlackBerryServer.cpp 2008-09-09 16:26:53 UTC (rev 105) @@ -393,6 +393,21 @@ w.WriteBool(false); } } + else if (req == 5) + { + // Synchronous get PIN + const uint64 deviceID = r.ReadUInt64(); + if (ZRef<ZBlackBerry::Device> theDevice = this->pGetDevice(deviceID)) + { + uint32 thePIN = theDevice->GetPIN(); + w.WriteBool(true); + w.WriteUInt32(thePIN); + } + else + { + w.WriteBool(false); + } + } } ZRef<ZBlackBerry::Device> ZBlackBerryServer::pGetDevice(uint64 iDeviceID) Modified: trunk/zoolib/source/cxx/zoolib/ZBlackBerry_BBDevMgr.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZBlackBerry_BBDevMgr.cpp 2008-09-09 16:24:56 UTC (rev 104) +++ trunk/zoolib/source/cxx/zoolib/ZBlackBerry_BBDevMgr.cpp 2008-09-09 16:26:53 UTC (rev 105) @@ -26,6 +26,8 @@ #include "zoolib/ZMemory.h" // For ZBlockCopy #include "zoolib/ZTime.h" +#include <oleauto.h> + using std::string; using std::vector; using std::wstring; @@ -506,12 +508,14 @@ virtual ZRef<Channel> Open( const string& iName, const PasswordHash* iPasswordHash, Error* oError); virtual ZMemoryBlock GetAttribute(uint16 iObject, uint16 iAttribute); + virtual uint32 GetPIN(); // Called by Manager_BBDevMgr bool Matches(IDevice* iDevice); void pDisconnected(); private: + bool pGetProperty(const string16& iName, VARIANT& oValue); IDevice* pUseDevice(); ZMutex fMutex; @@ -553,6 +557,7 @@ return theChannel; // FIXME. Failure may also be due to a bad/missing/expired password. + #warning NDY if (oError) *oError = error_UnknownChannel; } @@ -573,6 +578,23 @@ return ZMemoryBlock(); } +uint32 Device_BBDevMgr::GetPIN() + { + if (ZLOG(s, eDebug + 3, "ZBlackBerry::Device_BBDevMgr")) + s << "GetPIN"; + + VARIANT theV; + ::VariantInit(&theV); + uint32 thePIN = 0; + if (this->pGetProperty(ZUnicode::sAsUTF16("BBPIN"), theV)) + { + if (VT_I4 == theV.vt) + thePIN = theV.lVal; + } + ::VariantClear(&theV); + return thePIN; + } + bool Device_BBDevMgr::Matches(IDevice* iDevice) { int32 result = 0; @@ -587,17 +609,6 @@ return result == 1; } -ZBlackBerryCOM::IDevice* Device_BBDevMgr::pUseDevice() - { - ZMutexLocker locker(fMutex); - if (IDevice* theDevice = fDevice) - { - theDevice->AddRef(); - return theDevice; - } - return nil; - } - void Device_BBDevMgr::pDisconnected() { ZMutexLocker locker(fMutex); @@ -611,6 +622,54 @@ this->pFinished(); } +bool Device_BBDevMgr::pGetProperty(const string16& iName, VARIANT& oValue) + { + bool gotIt = false; + if (IDevice* theDevice = this->pUseDevice()) + { + ZBlackBerryCOM::IDeviceProperties* theDPs; + if (SUCCEEDED(theDevice->Properties(&theDPs))) + { + uint32 dpCount; + theDPs->Count(&dpCount); + for (uint32 x = 0; x < dpCount && !gotIt; ++x) + { + VARIANT indexV; + indexV.vt = VT_I4; + indexV.lVal = x; + ZBlackBerryCOM::IDeviceProperty* theDP; + if (SUCCEEDED(theDPs->Item(indexV, &theDP))) + { + BSTR theName; + if (SUCCEEDED(theDP->Name(&theName))) + { + if (iName == theName) + { + if (SUCCEEDED(theDP->Value(&oValue))) + gotIt = true; + } + ::SysFreeString(theName); + } + theDP->Release(); + } + } + theDPs->Release(); + } + } + return gotIt; + } + +ZBlackBerryCOM::IDevice* Device_BBDevMgr::pUseDevice() + { + ZMutexLocker locker(fMutex); + if (IDevice* theDevice = fDevice) + { + theDevice->AddRef(); + return theDevice; + } + return nil; + } + // ================================================================================================= #pragma mark - #pragma mark * ZBlackBerry::Manager_BBDevMgr Modified: trunk/zoolib/source/cxx/zoolib/ZBlackBerry_Client.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZBlackBerry_Client.cpp 2008-09-09 16:24:56 UTC (rev 104) +++ trunk/zoolib/source/cxx/zoolib/ZBlackBerry_Client.cpp 2008-09-09 16:26:53 UTC (rev 105) @@ -81,6 +81,7 @@ virtual ZRef<Channel> Open( const string& iName, const PasswordHash* iPasswordHash, Error* oError); virtual ZMemoryBlock GetAttribute(uint16 iObject, uint16 iAttribute); + virtual uint32 GetPIN(); // From ZStreamReader via ZCommer virtual void RunnerDetached(ZStreamReaderRunner* iRunner); @@ -190,6 +191,27 @@ return ZMemoryBlock(); } +uint32 Device_Client::GetPIN() + { + try + { + if (ZRef<ZStreamerRWCon> theSRWCon = fFactory->MakeStreamerRWCon()) + { + const ZStreamW& w = theSRWCon->GetStreamW(); + w.WriteUInt8(5); + w.WriteUInt64(fDeviceID); + w.Flush(); + + const ZStreamR& r = theSRWCon->GetStreamR(); + if (r.ReadBool()) + return r.ReadUInt32(); + } + } + catch (...) + {} + return false; + } + void Device_Client::RunnerDetached(ZStreamReaderRunner* iRunner) { ZCommer::RunnerDetached(iRunner); Modified: trunk/zoolib/source/cxx/zoolib/ZBlackBerry_Streamer.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZBlackBerry_Streamer.cpp 2008-09-09 16:24:56 UTC (rev 104) +++ trunk/zoolib/source/cxx/zoolib/ZBlackBerry_Streamer.cpp 2008-09-09 16:26:53 UTC (rev 105) @@ -200,6 +200,10 @@ // From ZRefCountedWithFinalization via ZStreamerRW virtual void Finalize(); +// From ZBlackBerry::Channel + virtual size_t GetIdealSize_Read(); + virtual size_t GetIdealSize_Write(); + // From ZStreamerR via ZStreamerRWCon virtual const ZStreamRCon& GetStreamRCon(); @@ -302,6 +306,12 @@ } } +size_t Channel_Streamer::GetIdealSize_Read() + { return fReceive_ChunkSize; } + +size_t Channel_Streamer::GetIdealSize_Write() + { return fSend_ChunkSize; } + const ZStreamRCon& Channel_Streamer::GetStreamRCon() { return *this; } @@ -492,6 +502,14 @@ return theGA.fResult; } +uint32 Device_Streamer::GetPIN() + { + ZMemoryBlock theMB_PIN = this->GetAttribute(8, 4); + if (theMB_PIN.GetSize() >= 15) + return ZByteSwap_ReadLittle32(static_cast<char*>(theMB_PIN.GetData()) + 11); + return 0; + } + bool Device_Streamer::Read(const ZStreamR& iStreamR) { ZMutexLocker locker(fMutex); @@ -1019,6 +1037,7 @@ { // Nack. ZAssert(theChannelID == 0xFF); + uint16 theError = iStreamR.ReadUInt16LE(); theChannel->fState = eState_Dead; theChannel->fError = error_UnknownChannel; theChannel->fCondition_Receive.Broadcast(); @@ -1046,15 +1065,15 @@ { if (!theChannel->fHasPasswordHash) { - theChannel->fState = eState_Dead; + theChannel->fState = eState_CloseNeeded; theChannel->fError = error_PasswordNeeded; - theChannel->fCondition_Receive.Broadcast(); + this->Wake(); } else if (remainingTries < 6) { - theChannel->fState = eState_Dead; + theChannel->fState = eState_CloseNeeded; theChannel->fError = error_PasswordExhausted; - theChannel->fCondition_Receive.Broadcast(); + this->Wake(); } else { Modified: trunk/zoolib/source/cxx/zoolib/ZBlackBerry_Streamer.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZBlackBerry_Streamer.h 2008-09-09 16:24:56 UTC (rev 104) +++ trunk/zoolib/source/cxx/zoolib/ZBlackBerry_Streamer.h 2008-09-09 16:26:53 UTC (rev 105) @@ -47,6 +47,7 @@ virtual ZRef<Channel> Open( const std::string& iName, const PasswordHash* iPasswordHash, Error* oError); virtual ZMemoryBlock GetAttribute(uint16 iObject, uint16 iAttribute); + virtual uint32 GetPIN(); // From ZStreamReader via ZCommer virtual bool Read(const ZStreamR& iStreamR); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-10-08 12:35:37
|
Revision: 138 http://zoolib.svn.sourceforge.net/zoolib/?rev=138&view=rev Author: agreen Date: 2008-10-08 12:35:29 +0000 (Wed, 08 Oct 2008) Log Message: ----------- Generic event-passing. Mac-only for the moment. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZNetscape_Host.cpp trunk/zoolib/source/cxx/zoolib/ZNetscape_Host.h Modified: trunk/zoolib/source/cxx/zoolib/ZNetscape_Host.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNetscape_Host.cpp 2008-10-07 21:49:59 UTC (rev 137) +++ trunk/zoolib/source/cxx/zoolib/ZNetscape_Host.cpp 2008-10-08 12:35:29 UTC (rev 138) @@ -499,6 +499,12 @@ NPError theErr = fNPPluginFuncs.event(&fNPP_t, &fakeEvent); } +void Host::HostEvent(const EventRecord& iEvent) + { + EventRecord localEvent = iEvent; + NPError theErr = fNPPluginFuncs.event(&fNPP_t, &localEvent); + } + void Host::HostIdle() { EventRecord fakeEvent; Modified: trunk/zoolib/source/cxx/zoolib/ZNetscape_Host.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNetscape_Host.h 2008-10-07 21:49:59 UTC (rev 137) +++ trunk/zoolib/source/cxx/zoolib/ZNetscape_Host.h 2008-10-08 12:35:29 UTC (rev 138) @@ -217,6 +217,7 @@ const ZStreamR& iStreamR); void HostActivate(bool iActivate); + void HostEvent(const EventRecord& iEvent); void HostIdle(); void HostDeliverData(); void HostDraw(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-10-15 22:48:04
|
Revision: 140 http://zoolib.svn.sourceforge.net/zoolib/?rev=140&view=rev Author: agreen Date: 2008-10-15 22:48:00 +0000 (Wed, 15 Oct 2008) Log Message: ----------- Extend the channel open protocol to allow a caller to require that boundaries be preserved. When reading data is returned with a 16 bit little-endian length prefix inserted into the data stream. When writing, buffers smaller than the value returned by GetIdealWriteSize will be written in a single hit of the requested size. This accomodates the BB database protocol's reliance on the underlying USB chunking protocol's preservation of boundaries. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZBlackBerry.cpp trunk/zoolib/source/cxx/zoolib/ZBlackBerry.h trunk/zoolib/source/cxx/zoolib/ZBlackBerryServer.cpp trunk/zoolib/source/cxx/zoolib/ZBlackBerry_BBDevMgr.cpp trunk/zoolib/source/cxx/zoolib/ZBlackBerry_Client.cpp trunk/zoolib/source/cxx/zoolib/ZBlackBerry_Streamer.cpp trunk/zoolib/source/cxx/zoolib/ZBlackBerry_Streamer.h Modified: trunk/zoolib/source/cxx/zoolib/ZBlackBerry.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZBlackBerry.cpp 2008-10-15 22:44:08 UTC (rev 139) +++ trunk/zoolib/source/cxx/zoolib/ZBlackBerry.cpp 2008-10-15 22:48:00 UTC (rev 140) @@ -24,6 +24,7 @@ #include "zoolib/ZUtil_STL.h" using std::set; +using std::string; /** These are some brief notes to get you started. If anything is unclear, drop me a line at ag...@em.... @@ -59,7 +60,7 @@ { using namespace ZBlackBerry; - // Instantiate the Manager. On Windws you would create a Manager_BBDevMgr. + // Instantiate the Manager. On Windows you would create a Manager_BBDevMgr. // If you're using BBDaemon you'd create a Manager_Client, passing a // ZStreamerRWConFactory that will open connections to the // appropriate TCP address. @@ -334,6 +335,22 @@ s << "Finalize, deleted"; } +void Device::Start() + { + ZMutexLocker locker(fMutex); + ++fStartCount; + fCondition.Broadcast(); + } + +void Device::Stop() + { + this->pFinished(); + } + +ZRef<Channel> Device::Open( + const string& iName, const PasswordHash* iPasswordHash, Error* oError) + { return this->Open(false, iName, iPasswordHash, oError); } + uint32 Device::GetPIN() { return 0; @@ -353,18 +370,6 @@ ZUtil_STL::sEraseMustContain(1, fObservers, iObserver); } -void Device::Start() - { - ZMutexLocker locker(fMutex); - ++fStartCount; - fCondition.Broadcast(); - } - -void Device::Stop() - { - this->pFinished(); - } - void Device::pFinished() { ZMutexLocker locker(fMutex); Modified: trunk/zoolib/source/cxx/zoolib/ZBlackBerry.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZBlackBerry.h 2008-10-15 22:44:08 UTC (rev 139) +++ trunk/zoolib/source/cxx/zoolib/ZBlackBerry.h 2008-10-15 22:48:00 UTC (rev 140) @@ -109,11 +109,16 @@ error_UnknownChannel, error_PasswordNeeded, error_PasswordExhausted, - error_PasswordIncorrect + error_PasswordIncorrect, + error_Generic }; virtual ZRef<Channel> Open( + const std::string& iName, const PasswordHash* iPasswordHash, Error* oError); + + virtual ZRef<Channel> Open(bool iPreserveBoundaries, const std::string& iName, const PasswordHash* iPasswordHash, Error* oError) = 0; + virtual ZMemoryBlock GetAttribute(uint16 iObject, uint16 iAttribute) = 0; virtual uint32 GetPIN(); Modified: trunk/zoolib/source/cxx/zoolib/ZBlackBerryServer.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZBlackBerryServer.cpp 2008-10-15 22:44:08 UTC (rev 139) +++ trunk/zoolib/source/cxx/zoolib/ZBlackBerryServer.cpp 2008-10-15 22:48:00 UTC (rev 140) @@ -358,10 +358,11 @@ const string channelName = sReadString(r); ZBlackBerry::Device::Error theError = ZBlackBerry::Device::error_DeviceClosed; + if (ZRef<ZBlackBerry::Device> theDevice = this->pGetDevice(deviceID)) { - if (ZRef<ZBlackBerry::Channel> deviceCon = - theDevice->Open(channelName, gotHash ? &thePasswordHash : nil, &theError)) + if (ZRef<ZBlackBerry::Channel> deviceCon = theDevice->Open(false, + channelName, gotHash ? &thePasswordHash : nil, &theError)) { w.WriteUInt32(ZBlackBerry::Device::error_None); const size_t readSize = deviceCon->GetIdealSize_Read(); @@ -408,6 +409,42 @@ w.WriteBool(false); } } + else if (req == 6) + { + // Open channel + const uint64 deviceID = r.ReadUInt64(); + + const bool preserveBoundaries = r.ReadBool(); + + const bool gotHash = r.ReadBool(); + ZBlackBerry::PasswordHash thePasswordHash; + if (gotHash) + r.Read(&thePasswordHash, sizeof(thePasswordHash)); + + const string channelName = sReadString(r); + + ZBlackBerry::Device::Error theError = ZBlackBerry::Device::error_DeviceClosed; + + if (ZRef<ZBlackBerry::Device> theDevice = this->pGetDevice(deviceID)) + { + if (ZRef<ZBlackBerry::Channel> deviceCon = theDevice->Open(preserveBoundaries, + channelName, gotHash ? &thePasswordHash : nil, &theError)) + { + const size_t readSize = deviceCon->GetIdealSize_Read(); + const size_t writeSize = deviceCon->GetIdealSize_Write(); + w.WriteUInt32(ZBlackBerry::Device::error_None); + w.WriteUInt32(readSize); + w.WriteUInt32(writeSize); + w.Flush(); + sStartReaderRunner(new ZStreamCopier(iSRWCon, readSize), deviceCon); + sStartReaderRunner(new ZStreamCopier(deviceCon, writeSize), iSRWCon); + return; + } + } + + ZAssert(theError != ZBlackBerry::Device::error_None); + w.WriteUInt32(theError); + } } ZRef<ZBlackBerry::Device> ZBlackBerryServer::pGetDevice(uint64 iDeviceID) Modified: trunk/zoolib/source/cxx/zoolib/ZBlackBerry_BBDevMgr.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZBlackBerry_BBDevMgr.cpp 2008-10-15 22:44:08 UTC (rev 139) +++ trunk/zoolib/source/cxx/zoolib/ZBlackBerry_BBDevMgr.cpp 2008-10-15 22:48:00 UTC (rev 140) @@ -52,8 +52,8 @@ typedef ZBlackBerryCOM::ChannelParams ChannelParams; typedef ZBlackBerryCOM::IChannelEvents IChannelEvents; - Channel_BBDevMgr(ZRef<Channel_BBDevMgr>& oChannel, - IDevice* iDevice, const string& iName, const PasswordHash* iPasswordHash); + Channel_BBDevMgr(ZRef<Channel_BBDevMgr>& oChannel, IDevice* iDevice, + bool iPreserveBoundaries, const string& iName, const PasswordHash* iPasswordHash); virtual ~Channel_BBDevMgr(); @@ -117,8 +117,8 @@ bool fClosed; }; -Channel_BBDevMgr::Channel_BBDevMgr(ZRef<Channel_BBDevMgr>& oChannel, - IDevice* iDevice, const string& iName, const PasswordHash* iPasswordHash) +Channel_BBDevMgr::Channel_BBDevMgr(ZRef<Channel_BBDevMgr>& oChannel, IDevice* iDevice, + bool iPreserveBoundaries, const string& iName, const PasswordHash* iPasswordHash) : fChannel(nil), fStart(0), fEnd(0), @@ -505,7 +505,7 @@ virtual ~Device_BBDevMgr(); // From ZBlackBerry::Device - virtual ZRef<Channel> Open( + virtual ZRef<Channel> Open(bool iPreserveBoundaries, const string& iName, const PasswordHash* iPasswordHash, Error* oError); virtual ZMemoryBlock GetAttribute(uint16 iObject, uint16 iAttribute); virtual uint32 GetPIN(); @@ -535,36 +535,44 @@ fDevice->Release(); } -ZRef<Channel> Device_BBDevMgr::Open( +ZRef<Channel> Device_BBDevMgr::Open(bool iPreserveBoundaries, const string& iName, const PasswordHash* iPasswordHash, Error* oError) { if (ZLOG(s, eDebug + 3, "ZBlackBerry::Device_BBDevMgr")) s << "Open, iName: " << iName; - if (IDevice* theDevice = this->pUseDevice()) + if (iPreserveBoundaries) { - // theChannel's refcount is manipulated by both COM and ZRef. When created it is zero, - // and in the ZRef scheme is not incremented to one until it is first assigned to a - // ZRef<>. The process of opening a channel, and failing, will AddRef and Release - // theChannel, and it will be Finalized and thus disposed. So we pass a reference to a - // ZRef to the constructor, to which the constructor assigns 'this', extending the - // lifetime appropriately. - ZRef<Channel_BBDevMgr> theChannel; - new Channel_BBDevMgr(theChannel, theDevice, iName, iPasswordHash); - theDevice->Release(); - - if (theChannel->IsOkay()) - return theChannel; - - // FIXME. Failure may also be due to a bad/missing/expired password. - #warning NDY if (oError) - *oError = error_UnknownChannel; + *oError = error_Generic; } else { - if (oError) - *oError = error_DeviceClosed; + if (IDevice* theDevice = this->pUseDevice()) + { + // theChannel's refcount is manipulated by both COM and ZRef. When created it is zero, + // and in the ZRef scheme is not incremented to one until it is first assigned to a + // ZRef<>. The process of opening a channel, and failing, will AddRef and Release + // theChannel, and it will be Finalized and thus disposed. So we pass a reference to a + // ZRef to the constructor, to which the constructor assigns 'this', extending the + // lifetime appropriately. + ZRef<Channel_BBDevMgr> theChannel; + new Channel_BBDevMgr(theChannel, theDevice, iPreserveBoundaries, iName, iPasswordHash); + theDevice->Release(); + + if (theChannel->IsOkay()) + return theChannel; + + // FIXME. Failure may also be due to a bad/missing/expired password. + #warning NDY + if (oError) + *oError = error_UnknownChannel; + } + else + { + if (oError) + *oError = error_DeviceClosed; + } } return ZRef<Channel>(); Modified: trunk/zoolib/source/cxx/zoolib/ZBlackBerry_Client.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZBlackBerry_Client.cpp 2008-10-15 22:44:08 UTC (rev 139) +++ trunk/zoolib/source/cxx/zoolib/ZBlackBerry_Client.cpp 2008-10-15 22:48:00 UTC (rev 140) @@ -35,7 +35,7 @@ class Channel_Client : public Channel { public: - Channel_Client(ZRef<ZStreamerRWCon> iSRWCon); + Channel_Client(ZRef<ZStreamerRWCon> iSRWCon, size_t iIdealReadSize, size_t iIdealWriteSize); virtual ~Channel_Client(); // From ZStreamerRCon via Channel @@ -44,12 +44,21 @@ // From ZStreamerWCon via Channel virtual const ZStreamWCon& GetStreamWCon(); +// From Channel + virtual size_t GetIdealSize_Read(); + virtual size_t GetIdealSize_Write(); + private: ZRef<ZStreamerRWCon> fSRWCon; + size_t fIdealReadSize; + size_t fIdealWriteSize; }; -Channel_Client::Channel_Client(ZRef<ZStreamerRWCon> iSRWCon) -: fSRWCon(iSRWCon) +Channel_Client::Channel_Client( + ZRef<ZStreamerRWCon> iSRWCon, size_t iIdealReadSize, size_t iIdealWriteSize) +: fSRWCon(iSRWCon), + fIdealReadSize(fIdealReadSize), + fIdealWriteSize(fIdealWriteSize) {} Channel_Client::~Channel_Client() @@ -61,6 +70,12 @@ const ZStreamWCon& Channel_Client::GetStreamWCon() { return fSRWCon->GetStreamWCon(); } +size_t Channel_Client::GetIdealSize_Read() + { return fIdealReadSize; } + +size_t Channel_Client::GetIdealSize_Write() + { return fIdealWriteSize; } + // ================================================================================================= #pragma mark - #pragma mark * Device_Client @@ -78,7 +93,7 @@ // From Device virtual void Stop(); - virtual ZRef<Channel> Open( + virtual ZRef<Channel> Open(bool iPreserveBoundaries, const string& iName, const PasswordHash* iPasswordHash, Error* oError); virtual ZMemoryBlock GetAttribute(uint16 iObject, uint16 iAttribute); virtual uint32 GetPIN(); @@ -125,7 +140,7 @@ this->Wake(); } -ZRef<Channel> Device_Client::Open( +ZRef<Channel> Device_Client::Open(bool iPreserveBoundaries, const string& iName, const PasswordHash* iPasswordHash, Error* oError) { try @@ -133,8 +148,10 @@ if (ZRef<ZStreamerRWCon> theSRWCon = fFactory->MakeStreamerRWCon()) { const ZStreamW& w = theSRWCon->GetStreamW(); - w.WriteUInt8(3); + w.WriteUInt8(6); w.WriteUInt64(fDeviceID); + w.WriteBool(iPreserveBoundaries); + if (iPasswordHash) { w.WriteBool(true); @@ -144,18 +161,22 @@ { w.WriteBool(false); } + sWriteString(w, iName); + w.Flush(); const ZStreamR& r = theSRWCon->GetStreamR(); - Error theError = static_cast<Error>(r.ReadUInt32()); + const Error theError = static_cast<Error>(r.ReadUInt32()); + const size_t idealReadSize = r.ReadUInt32(); + const size_t idealWriteSize = r.ReadUInt32(); if (oError) *oError = theError; if (theError == error_None) - return new Channel_Client(theSRWCon); + return new Channel_Client(theSRWCon, idealReadSize, idealWriteSize); } } catch (...) Modified: trunk/zoolib/source/cxx/zoolib/ZBlackBerry_Streamer.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZBlackBerry_Streamer.cpp 2008-10-15 22:44:08 UTC (rev 139) +++ trunk/zoolib/source/cxx/zoolib/ZBlackBerry_Streamer.cpp 2008-10-15 22:48:00 UTC (rev 140) @@ -191,8 +191,8 @@ private ZStreamWCon { friend class Device_Streamer; - Channel_Streamer( - Device_Streamer* iDevice_Streamer, const string& iName, const PasswordHash* iPasswordHash); + Channel_Streamer(Device_Streamer* iDevice_Streamer, + bool iPreserveBoundaries, const string& iName, const PasswordHash* iPasswordHash); public: virtual ~Channel_Streamer(); @@ -231,6 +231,7 @@ ZPtrUseCounted_T<Device_Streamer> fPUC_Device_Streamer; EState fState; Device::Error fError; + bool fPreserveBoundaries; string fName; bool fHasPasswordHash; PasswordHash fPasswordHash; @@ -249,11 +250,12 @@ size_t fSend_Size; }; -Channel_Streamer::Channel_Streamer( - Device_Streamer* iDevice_Streamer, const string& iName, const PasswordHash* iPasswordHash) +Channel_Streamer::Channel_Streamer(Device_Streamer* iDevice_Streamer, + bool iPreserveBoundaries, const string& iName, const PasswordHash* iPasswordHash) : fPUC_Device_Streamer(iDevice_Streamer), fState(eState_Dead), fError(Device::error_None), + fPreserveBoundaries(iPreserveBoundaries), fName(iName), fHasPasswordHash(0 != iPasswordHash), fChannelID(0), @@ -428,7 +430,7 @@ s << "Stop, Exit"; } -ZRef<Channel> Device_Streamer::Open( +ZRef<Channel> Device_Streamer::Open(bool iPreserveBoundaries, const string& iName, const PasswordHash* iPasswordHash, Error* oError) { ZMutexLocker locker(fMutex); @@ -438,7 +440,8 @@ if (fLifecycle == eLifecycle_Running) { - ZRef<Channel_Streamer> theChannel = new Channel_Streamer(this, iName, iPasswordHash); + ZRef<Channel_Streamer> theChannel + = new Channel_Streamer(this, iPreserveBoundaries, iName, iPasswordHash); fChannels.push_back(theChannel.GetObject()); theChannel->fState = eState_LookupNeeded; @@ -954,6 +957,14 @@ if (ZRef<Channel_Streamer> theChannel = this->pFindChannel(iChannelID)) { deque<uint8>& theBuffer = theChannel->fReceive_Buffer; + if (theChannel->fPreserveBoundaries) + { + // We're using little-endian notation here, as + // that's the standard BlackBerry generally uses. + theBuffer.insert(theBuffer.end(), iPayloadSize); + theBuffer.insert(theBuffer.end(), iPayloadSize >> 8); + } + theBuffer.insert(theBuffer.end(), readBuffer.begin(), readBuffer.end()); theChannel->fCondition_Receive.Broadcast(); } @@ -965,7 +976,6 @@ iChannelID, iPayloadSize); } } - } else { @@ -1344,17 +1354,29 @@ if (iChannel->fWaitingForSequence) return false; - iChannel->fWaitingForSequence = true; - StreamW_Chunked w; + if (ZLOG(s, eDebug + 1, "ZBlackBerry::Device_Streamer")) + { + s << "pWriteOne, Data"; + } size_t countToWrite = min(iChannel->fSend_ChunkSize, iChannel->fSend_Size); - // BB seems to be unable to receive a data packet that is an - // exact multiple of 64 bytes in length, so drop the last byte - // and let the caller requeue the remainder. + + // If the physical amount written is a multiple of 64 bytes we need to send + // a funky three byte packet. It is virtually certain that we're running over + // a USB channel, so the boundary of the write will be known to the receiver + // and although a regular stream won't be able to detect this weirdness, a BB + // will. Perhaps this should be a parameterizable behavior. if (0 == ((countToWrite + 4) % 0x40)) - countToWrite -= 1; + { + if (ZLOG(s, eDebug + 1, "ZBlackBerry::Device_Streamer")) + s << "pWriteOne, Sending funky"; + if (!this->pSendFunky(countToWrite + 4, iStreamW)) + return false; + } + + StreamW_Chunked w; size_t countWritten; w.Write(iChannel->fSend_Data, countToWrite, &countWritten); @@ -1362,10 +1384,7 @@ iChannel->fSend_Size = 0; iChannel->fCondition_Send.Broadcast(); - if (ZLOG(s, eDebug + 1, "ZBlackBerry::Device_Streamer")) - { - s << "pWriteOne, Data"; - } + iChannel->fWaitingForSequence = true; return this->pSend(w, iChannel->fChannelID, iStreamW); } @@ -1438,6 +1457,23 @@ return false; } +bool Device_Streamer::pSendFunky(uint16 iLength, const ZStreamW& iStreamW) + { + ZAssert(0 == (iLength % 0x40)); + const uint8 buffer[3] = { iLength, iLength >> 8, 0 }; + + fMutex.Release(); + size_t countWritten; + iStreamW.Write(buffer, 3, &countWritten); + fMutex.Acquire(); + + if (countWritten == 3) + return true; + + fLifecycle = eLifecycle_StreamsDead; + return false; + } + void Device_Streamer::pFlush(const ZStreamW& iStreamW) { fMutex.Release(); Modified: trunk/zoolib/source/cxx/zoolib/ZBlackBerry_Streamer.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZBlackBerry_Streamer.h 2008-10-15 22:44:08 UTC (rev 139) +++ trunk/zoolib/source/cxx/zoolib/ZBlackBerry_Streamer.h 2008-10-15 22:48:00 UTC (rev 140) @@ -44,9 +44,12 @@ // From ZBlackBerry::Device virtual void Stop(); - virtual ZRef<Channel> Open( + + virtual ZRef<Channel> Open(bool iPreserveBoundaries, const std::string& iName, const PasswordHash* iPasswordHash, Error* oError); + virtual ZMemoryBlock GetAttribute(uint16 iObject, uint16 iAttribute); + virtual uint32 GetPIN(); // From ZStreamReader via ZCommer @@ -84,6 +87,7 @@ class StreamW_Chunked; bool pSend(StreamW_Chunked& iSC, uint16 iChannelID, const ZStreamW& iStreamW); + bool pSendFunky(uint16 iLength, const ZStreamW& iStreamW); void pFlush(const ZStreamW& iStreamW); ZMutex fMutex; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-10-18 14:37:44
|
Revision: 143 http://zoolib.svn.sourceforge.net/zoolib/?rev=143&view=rev Author: agreen Date: 2008-10-18 14:37:41 +0000 (Sat, 18 Oct 2008) Log Message: ----------- Use NSCreateObjectFileImageFromFile/NSLinkModule to get an independent copy of a bundle's dynamic library, so that it has static data indpendent of any other load of the library. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZNetscape_GuestFactory_MacPlugin.cpp trunk/zoolib/source/cxx/zoolib/ZNetscape_GuestFactory_MacPlugin.h Modified: trunk/zoolib/source/cxx/zoolib/ZNetscape_GuestFactory_MacPlugin.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNetscape_GuestFactory_MacPlugin.cpp 2008-10-18 13:15:55 UTC (rev 142) +++ trunk/zoolib/source/cxx/zoolib/ZNetscape_GuestFactory_MacPlugin.cpp 2008-10-18 14:37:41 UTC (rev 143) @@ -29,10 +29,54 @@ // ================================================================================================= #pragma mark - +#pragma mark * Helper functions + +static void* sLookup(NSModule iModule, const char* iName) + { + if (NSSymbol theSymbol = ::NSLookupSymbolInModule(iModule, iName)) + return ::NSAddressOfSymbol(theSymbol); + return nil; + } + +static NSModule sLoadNSModule(CFBundleRef iBundleRef) + { + NSModule module = nil; + + if (CFURLRef executableURL = ::CFBundleCopyExecutableURL(iBundleRef)) + { + char buff[PATH_MAX]; + + if (::CFURLGetFileSystemRepresentation(executableURL, true, (UInt8*)buff, PATH_MAX)) + { + NSObjectFileImage image; + if (NSObjectFileImageSuccess == ::NSCreateObjectFileImageFromFile(buff, &image)) + { + module = ::NSLinkModule( + image, buff, + NSLINKMODULE_OPTION_BINDNOW + | NSLINKMODULE_OPTION_PRIVATE + | NSLINKMODULE_OPTION_RETURN_ON_ERROR); + } + } + ::CFRelease(executableURL); + } + + return module; + } + +template <typename P> +P sInvoke_T(NSModule iNSModule, const char* iName) + { + return reinterpret_cast<P>(sLookup(iNSModule, iName)); + } + +// ================================================================================================= +#pragma mark - #pragma mark * GuestFactory_MacPlugin GuestFactory_MacPlugin::GuestFactory_MacPlugin(const std::string& iPath) -: fPlugInRef(nil) +: fPlugInRef(nil), + fNSModule(nil) { CFStringRef thePath = ::CFStringCreateWithCString(nil, iPath.c_str(), kCFStringEncodingUTF8); if (thePath) @@ -45,21 +89,14 @@ fPlugInRef = ::CFPlugInCreate(nil, theURL); if (fPlugInRef) { - if (ZLOG(s, eDebug, "GuestFactory_MacPlugin")) - { - s.Writef("ctor, fPlugInRef refcount = %d", - ::CFGetRetainCount(fPlugInRef)); - } + fNSModule = sLoadNSModule(::CFPlugInGetBundle(fPlugInRef)); - CFBundleRef theBundleRef = ::CFPlugInGetBundle(fPlugInRef); NPNetscapeFuncs theNPNetscapeFuncs; this->GetNPNetscapeFuncs(theNPNetscapeFuncs); - - NP_InitializeFuncPtr theInitialize = (NP_InitializeFuncPtr) - ::CFBundleGetFunctionPointerForName( - theBundleRef, CFSTR("NP_Initialize")); - theInitialize(&theNPNetscapeFuncs); + sInvoke_T<NP_InitializeFuncPtr> + (fNSModule, "_NP_Initialize") + (&theNPNetscapeFuncs); } } } @@ -70,33 +107,18 @@ GuestFactory_MacPlugin::~GuestFactory_MacPlugin() { - CFBundleRef theBundleRef = ::CFPlugInGetBundle(fPlugInRef); + sInvoke_T<NPP_ShutdownProcPtr> + (fNSModule, "_NP_Shutdown")(); - NPP_ShutdownProcPtr theShutdown = - (NPP_ShutdownProcPtr) - ::CFBundleGetFunctionPointerForName( - theBundleRef, CFSTR("NP_Shutdown")); - - theShutdown(); - - if (ZLOG(s, eDebug, "GuestFactory_MacPlugin")) - { - s.Writef("dtor, fPlugInRef refcount = %d", - ::CFGetRetainCount(fPlugInRef)); - } - + ::NSUnLinkModule(fNSModule, NSUNLINKMODULE_OPTION_NONE); ::CFRelease(fPlugInRef); } void GuestFactory_MacPlugin::GetEntryPoints(NPPluginFuncs& oNPPluginFuncs) { - CFBundleRef theBundleRef = ::CFPlugInGetBundle(fPlugInRef); - - NP_GetEntryPointsFuncPtr theGetEntryPoints = (NP_GetEntryPointsFuncPtr) - ::CFBundleGetFunctionPointerForName( - theBundleRef, CFSTR("NP_GetEntryPoints")); - - theGetEntryPoints(&oNPPluginFuncs); + sInvoke_T<NP_GetEntryPointsFuncPtr> + (fNSModule, "_NP_GetEntryPoints") + (&oNPPluginFuncs); } } // namespace ZNetscape Modified: trunk/zoolib/source/cxx/zoolib/ZNetscape_GuestFactory_MacPlugin.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNetscape_GuestFactory_MacPlugin.h 2008-10-18 13:15:55 UTC (rev 142) +++ trunk/zoolib/source/cxx/zoolib/ZNetscape_GuestFactory_MacPlugin.h 2008-10-18 14:37:41 UTC (rev 143) @@ -28,6 +28,8 @@ #include "zoolib/ZNetscape_Host.h" +#include <mach-o/dyld.h> // For NSModule + #include <string> namespace ZNetscape { @@ -46,10 +48,11 @@ private: CFPlugInRef fPlugInRef; + NSModule fNSModule; }; } // namespace ZNetscape -#endif //ZCONFIG_SPI_Enabled(MacOSX) +#endif // ZCONFIG_SPI_Enabled(MacOSX) #endif // __ZNetscape_GuestFactory_MacPlugin__ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-10-25 14:45:05
|
Revision: 158 http://zoolib.svn.sourceforge.net/zoolib/?rev=158&view=rev Author: agreen Date: 2008-10-25 14:45:01 +0000 (Sat, 25 Oct 2008) Log Message: ----------- Remove the use of ZCONFIG(OS Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZStackCrawl.cpp trunk/zoolib/source/cxx/zoolib/ZStackCrawl.h Modified: trunk/zoolib/source/cxx/zoolib/ZStackCrawl.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZStackCrawl.cpp 2008-10-25 14:44:26 UTC (rev 157) +++ trunk/zoolib/source/cxx/zoolib/ZStackCrawl.cpp 2008-10-25 14:45:01 UTC (rev 158) @@ -35,7 +35,7 @@ #pragma mark - #pragma mark * Win32 Helpers -#if ZCONFIG(OS, Win32) +#if ZCONFIG_SPI_Enabled(Win) #include <csetjmp> #include "zoolib/ZWinHeader.h" @@ -232,7 +232,7 @@ } } -#endif // ZCONFIG(OS, Win32) +#endif // ZCONFIG_SPI_Enabled(Win) // ================================================================================================= #pragma mark - @@ -546,7 +546,7 @@ sPopulateStackFrames(fFrames); #endif - #if ZCONFIG(OS, Win32) + #if ZCONFIG_SPI_Enabled(Win) sPopulateStackFrames(fFrames); #endif } @@ -583,7 +583,7 @@ return result; #endif - #if ZCONFIG(OS, Win32) + #if ZCONFIG_SPI_Enabled(Win) const pFrame_t& theFrame = fFrames.at(iIndex); result.fPC = theFrame.fPC; Modified: trunk/zoolib/source/cxx/zoolib/ZStackCrawl.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZStackCrawl.h 2008-10-25 14:44:26 UTC (rev 157) +++ trunk/zoolib/source/cxx/zoolib/ZStackCrawl.h 2008-10-25 14:45:01 UTC (rev 158) @@ -89,7 +89,7 @@ static void sPopulateStackFrames(std::vector<ZStackCrawl::pFrame_t>& oFrames); #endif - #if ZCONFIG(OS, Win32) + #if ZCONFIG_SPI_Enabled(Win) static void sPopulateStackFrames(std::vector<ZStackCrawl::pFrame_t>& oFrames); #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-10-27 19:10:25
|
Revision: 162 http://zoolib.svn.sourceforge.net/zoolib/?rev=162&view=rev Author: agreen Date: 2008-10-27 19:10:19 +0000 (Mon, 27 Oct 2008) Log Message: ----------- First cut at migrating socket stuff into a generic intermediate base class, and hooking into it for local (domain) sockets. Added Paths: ----------- trunk/zoolib/source/cxx/zoolib/ZNet_Local.cpp trunk/zoolib/source/cxx/zoolib/ZNet_Local.h trunk/zoolib/source/cxx/zoolib/ZNet_Local_Socket.cpp trunk/zoolib/source/cxx/zoolib/ZNet_Local_Socket.h trunk/zoolib/source/cxx/zoolib/ZNet_Socket.cpp trunk/zoolib/source/cxx/zoolib/ZNet_Socket.h Added: trunk/zoolib/source/cxx/zoolib/ZNet_Local.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNet_Local.cpp (rev 0) +++ trunk/zoolib/source/cxx/zoolib/ZNet_Local.cpp 2008-10-27 19:10:19 UTC (rev 162) @@ -0,0 +1,109 @@ +/* ------------------------------------------------------------------------------------------------- +Copyright (c) 2008 Andrew Green +http://www.zoolib.org + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software +and associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +------------------------------------------------------------------------------------------------- */ + +#include "zoolib/ZNet_Local.h" +#include "zoolib/ZFactoryChain.h" +#include "zoolib/ZString.h" + +using std::string; + +// ================================================================================================= +#pragma mark - +#pragma mark * Factories + +ZOOLIB_FACTORYCHAIN_HEAD(ZRef<ZNetNameLookup>, ZNetName_Local::LookupParam_t); +ZOOLIB_FACTORYCHAIN_HEAD(ZRef<ZNetListener_Local>, string); +ZOOLIB_FACTORYCHAIN_HEAD(ZRef<ZNetEndpoint_Local>, string); + +// ================================================================================================= +#pragma mark - +#pragma mark * ZNetAddress_Local + +ZNetAddress_Local::ZNetAddress_Local() + {} + +ZNetAddress_Local::ZNetAddress_Local(const ZNetAddress_Local& other) +: fPath(other.fPath) + {} + +ZNetAddress_Local::ZNetAddress_Local(const string& iPath) +: fPath(iPath) + {} + +ZNetAddress_Local::~ZNetAddress_Local() + {} + +ZRef<ZNetEndpoint> ZNetAddress_Local::Connect() const + { return ZNetEndpoint_Local::sCreateConnectedEndpoint(fPath); } + +const string& ZNetAddress_Local::GetPath() const + { return fPath ;} + +// ================================================================================================= +#pragma mark - +#pragma mark * ZNetName_Local + +ZNetName_Local::ZNetName_Local() + {} + +ZNetName_Local::ZNetName_Local(const ZNetName_Local& other) +: fPath(other.fPath) + {} + +ZNetName_Local::ZNetName_Local(const string& iPath) +: fPath(iPath) + {} + +ZNetName_Local::~ZNetName_Local() + {} + +string ZNetName_Local::AsString() const + { return fPath; } + +ZRef<ZNetNameLookup> ZNetName_Local::CreateLookup(size_t iMaxAddresses) const + { + return ZFactoryChain_T<ZRef<ZNetNameLookup>, LookupParam_t> + ::sMake(LookupParam_t(fPath, iMaxAddresses)); + } + +const string& ZNetName_Local::GetPath() const + { return fPath; } + +// ================================================================================================= +#pragma mark - +#pragma mark * ZNetListener_Local + +ZRef<ZNetListener_Local> ZNetListener_Local::sCreateListener( + const string& iPath, size_t iListenQueueSize) + { + return ZFactoryChain_T<ZRef<ZNetListener_Local>, string> + ::sMake(iPath); + } + +// ================================================================================================= +#pragma mark - +#pragma mark * ZNetEndpoint_Local + +ZRef<ZNetEndpoint_Local> ZNetEndpoint_Local::sCreateConnectedEndpoint( + const string& iPath) + { + return ZFactoryChain_T<ZRef<ZNetEndpoint_Local>, string> + ::sMake(iPath); + } Added: trunk/zoolib/source/cxx/zoolib/ZNet_Local.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNet_Local.h (rev 0) +++ trunk/zoolib/source/cxx/zoolib/ZNet_Local.h 2008-10-27 19:10:19 UTC (rev 162) @@ -0,0 +1,99 @@ +/* ------------------------------------------------------------------------------------------------- +Copyright (c) 2008 Andrew Green +http://www.zoolib.org + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software +and associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +------------------------------------------------------------------------------------------------- */ + +#ifndef __ZNet_Local__ +#define __ZNet_Local__ 1 +#include "zconfig.h" + +#include "zoolib/ZMulti_T.h" +#include "zoolib/ZNet.h" + +#include <string> + +// ================================================================================================= +#pragma mark - +#pragma mark * ZNetAddress_Local + +class ZNetAddress_Local : public ZNetAddress + { +public: + ZNetAddress_Local(); + ZNetAddress_Local(const ZNetAddress_Local& other); + ZNetAddress_Local(const std::string& iPath); + virtual ~ZNetAddress_Local(); + +// From ZNetAddress + virtual ZRef<ZNetEndpoint> Connect() const; + +// Our protocol + const std::string& GetPath() const; + +private: + std::string fPath; + }; + +// ================================================================================================= +#pragma mark - +#pragma mark * ZNetName_Local + +class ZNetName_Local : public ZNetName + { +public: + typedef ZMulti_T2<std::string, size_t> LookupParam_t; + + ZNetName_Local(); + ZNetName_Local(const ZNetName_Local& other); + ZNetName_Local(const std::string& iPath); + virtual ~ZNetName_Local(); + +// From ZNetName + virtual std::string AsString() const; + virtual ZRef<ZNetNameLookup> CreateLookup(size_t iMaxAddresses) const; + +// Our protocol + const std::string& GetPath() const; + +private: + std::string fPath; + }; + +// ================================================================================================= +#pragma mark - +#pragma mark * ZNetListener_TCP + +class ZNetListener_Local : public virtual ZNetListener + { +public: + static ZRef<ZNetListener_Local> sCreateListener( + const std::string& iPath, size_t iListenQueueSize); + }; + +// ================================================================================================= +#pragma mark - +#pragma mark * ZNetEndpoint_Local + +class ZNetEndpoint_Local : public virtual ZNetEndpoint + { +public: + static ZRef<ZNetEndpoint_Local> sCreateConnectedEndpoint( + const std::string& iPath); + }; + +#endif // __ZNet_Local__ Added: trunk/zoolib/source/cxx/zoolib/ZNet_Local_Socket.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNet_Local_Socket.cpp (rev 0) +++ trunk/zoolib/source/cxx/zoolib/ZNet_Local_Socket.cpp 2008-10-27 19:10:19 UTC (rev 162) @@ -0,0 +1,215 @@ +/* ------------------------------------------------------------------------------------------------- +Copyright (c) 2001 Andrew Green and Learning in Motion, Inc. +http://www.zoolib.org + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software +and associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +------------------------------------------------------------------------------------------------- */ + +#include "zoolib/ZNet_Local_Socket.h" + +// ================================================================================================= +#if ZCONFIG_API_Enabled(Net_Local_Socket) + +#include "zoolib/ZMemory.h" +#include "zoolib/ZTime.h" + +#include <unistd.h> + +#ifndef errno +# include <errno.h> +#endif + +//#include <stdio.h> +#include <fcntl.h> + +#include <sys/socket.h> +#include <sys/un.h> + +using std::string; + +// ================================================================================================= +#pragma mark - +#pragma mark * Helper functions + +// ================================================================================================= +#pragma mark - +#pragma mark * ZNetNameLookup_Local_Socket + +ZNetNameLookup_Local_Socket::ZNetNameLookup_Local_Socket(const std::string& iPath) +: fPath(iPath), + fFinished(false) + { + if (fPath.empty()) + fFinished = true; + } + +ZNetNameLookup_Local_Socket::~ZNetNameLookup_Local_Socket() + {} + +void ZNetNameLookup_Local_Socket::Start() + {} + +bool ZNetNameLookup_Local_Socket::Finished() + { return fFinished; } + +void ZNetNameLookup_Local_Socket::Advance() + { + ZAssertStop(2, !fFinished); + fFinished = true; + } + +ZRef<ZNetAddress> ZNetNameLookup_Local_Socket::CurrentAddress() + { + if (!fFinished) + return new ZNetAddress_Local(fPath); + + return ZRef<ZNetAddress>(); + } + +ZRef<ZNetName> ZNetNameLookup_Local_Socket::CurrentName() + { return new ZNetName_Local(fPath); } + +// ================================================================================================= +#pragma mark - +#pragma mark * ZNetListener_Local_Socket + +ZRef<ZNetListener_Local_Socket> ZNetListener_Local_Socket::sCreateWithFD(int iFD, size_t iListenQueueSize) + { + try + { + return new ZNetListener_Local_Socket(iFD, iListenQueueSize, true); + } + catch (...) + {} + return ZRef<ZNetListener_Local_Socket>(); + } + +static int sEnsureLocal(int iSocketFD) + { + sockaddr_un localSockAddr; + socklen_t length = sizeof(localSockAddr); + if (::getsockname(iSocketFD, (sockaddr*)&localSockAddr, &length) >= 0) + { + if (localSockAddr.sun_family == AF_LOCAL) + return iSocketFD; + } + throw std::runtime_error("ZNetListener_Local_Socket, not a local socket"); + } + +ZNetListener_Local_Socket::ZNetListener_Local_Socket( + int iSocketFD, size_t iListenQueueSize, bool iKnowWhatImDoing) +: ZNetListener_Socket(sEnsureLocal(iSocketFD), iListenQueueSize) + { + // We could ensure that iSocketFD + ZAssert(iKnowWhatImDoing); + } + +static int sListen(const string& iPath) + { + int theSocketFD = ::socket(PF_LOCAL, SOCK_STREAM, 0); + if (theSocketFD < 0) + { + int err = errno; + throw ZNetEx(ZNet_Socket::sTranslateError(err)); + } + + // Enable SO_REUSEADDR, cause it's a real pain waiting for TIME_WAIT to expire + int reuseAddrFlag = 1; + ::setsockopt( + theSocketFD, SOL_SOCKET, SO_REUSEADDR, (char*)&reuseAddrFlag, sizeof(reuseAddrFlag)); + + sockaddr_un localSockAddr; + ZBlockSet(&localSockAddr, sizeof(localSockAddr), 0); + localSockAddr.sun_family = AF_LOCAL; + strcpy(localSockAddr.sun_path, iPath.c_str()); + + if (::bind(theSocketFD, (sockaddr*)&localSockAddr, sizeof(localSockAddr)) < 0) + { + int err = errno; + ::close(theSocketFD); + throw ZNetEx(ZNet_Socket::sTranslateError(err)); + } + return theSocketFD; + } + +ZNetListener_Local_Socket::ZNetListener_Local_Socket(const std::string& iPath, size_t iListenQueueSize) +: ZNetListener_Socket(sListen(iPath), iListenQueueSize) + {} + +ZNetListener_Local_Socket::~ZNetListener_Local_Socket() + {} + +ZRef<ZNetEndpoint> ZNetListener_Local_Socket::Imp_MakeStreamer(int iSocketFD) + { + return new ZNetEndpoint_Local_Socket(iSocketFD); + } + +// ================================================================================================= +#pragma mark - +#pragma mark * ZNetEndpoint_Local_Socket + +static void sSetSocketOptions(int iSocketFD) + {} + +ZNetEndpoint_Local_Socket::ZNetEndpoint_Local_Socket(int iSocketFD) +: ZNetEndpoint_Socket(iSocketFD) + { + sSetSocketOptions(this->GetSocketFD()); + } + +static int sConnect(const string& iPath) + { + int socketFD = ::socket(PF_LOCAL, SOCK_STREAM, 0); + if (socketFD < 0) + throw ZNetEx(ZNet_Socket::sTranslateError(errno)); + + sockaddr_un remoteSockAddr; + ZBlockSet(&remoteSockAddr, sizeof(remoteSockAddr), 0); + remoteSockAddr.sun_family = AF_LOCAL; + strcpy(remoteSockAddr.sun_path, iPath.c_str()); + + if (::connect(socketFD, (sockaddr*)&remoteSockAddr, sizeof(remoteSockAddr)) < 0) + { + ::close(socketFD); + throw ZNetEx(ZNet_Socket::sTranslateError(errno)); + } + return socketFD; + } + +ZNetEndpoint_Local_Socket::ZNetEndpoint_Local_Socket(const std::string& iRemotePath) +: ZNetEndpoint_Socket(sConnect(iRemotePath)) + { + sSetSocketOptions(this->GetSocketFD()); + } + +ZNetEndpoint_Local_Socket::~ZNetEndpoint_Local_Socket() + {} + +ZRef<ZNetAddress> ZNetEndpoint_Local_Socket::GetRemoteAddress() + { + sockaddr_un remoteSockAddr; + socklen_t length = sizeof(remoteSockAddr); + if (::getpeername(this->GetSocketFD(), (sockaddr*)&remoteSockAddr, &length) >= 0) + { + if (remoteSockAddr.sun_family == AF_LOCAL) + return new ZNetAddress_Local(remoteSockAddr.sun_path); + } + + return ZRef<ZNetAddress>(); + } + +#endif // ZCONFIG_API_Enabled(Net_Local_Socket) +// ================================================================================================= Added: trunk/zoolib/source/cxx/zoolib/ZNet_Local_Socket.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNet_Local_Socket.h (rev 0) +++ trunk/zoolib/source/cxx/zoolib/ZNet_Local_Socket.h 2008-10-27 19:10:19 UTC (rev 162) @@ -0,0 +1,112 @@ +/* ------------------------------------------------------------------------------------------------- +Copyright (c) 2001 Andrew Green and Learning in Motion, Inc. +http://www.zoolib.org + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software +and associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +------------------------------------------------------------------------------------------------- */ + +#ifndef __ZNet_Local_Socket__ +#define __ZNet_Local_Socket__ 1 +#include "zconfig.h" +#include "zoolib/ZCONFIG_API.h" +#include "zoolib/ZCONFIG_SPI.h" + +#include "zoolib/ZNet_Local.h" +#include "zoolib/ZNet_Socket.h" + +#ifndef ZCONFIG_API_Avail__Net_Local_Socket +# if ZCONFIG_API_Enabled(Net_Socket) +# define ZCONFIG_API_Avail__Net_Local_Socket 1 +# endif +#endif + +#ifndef ZCONFIG_API_Avail__Net_Local_Socket +# define ZCONFIG_API_Avail__Net_Local_Socket 0 +#endif + +#ifndef ZCONFIG_API_Desired__Net_Local_Socket +# define ZCONFIG_API_Desired__Net_Local_Socket 1 +#endif + + +#if ZCONFIG_API_Enabled(Net_Local_Socket) + +// ================================================================================================= +#pragma mark - +#pragma mark * ZNetNameLookup_Local_Socket + +class ZNetNameLookup_Local_Socket : public ZNetNameLookup + { +public: + ZNetNameLookup_Local_Socket(const std::string& iPath); + virtual ~ZNetNameLookup_Local_Socket(); + +// From ZNetNameLookup + virtual void Start(); + virtual bool Finished(); + virtual void Advance(); + + virtual ZRef<ZNetAddress> CurrentAddress(); + virtual ZRef<ZNetName> CurrentName(); + +protected: + std::string fPath; + bool fFinished; + }; + +// ================================================================================================= +#pragma mark - +#pragma mark * ZNetListener_Local_Socket + +class ZNetListener_Local_Socket +: public ZNetListener_Local, + public ZNetListener_Socket + + { + ZNetListener_Local_Socket(int iFD, size_t iListenQueueSize, bool iKnowWhatImDoing); +public: + static ZRef<ZNetListener_Local_Socket> sCreateWithFD(int iFD, size_t iListenQueueSize); + + ZNetListener_Local_Socket(const std::string& iPath, size_t iListenQueueSize); + virtual ~ZNetListener_Local_Socket(); + +// From ZNetListener_Socket + virtual ZRef<ZNetEndpoint> Imp_MakeStreamer(int iSocketFD); + }; + +// ================================================================================================= +#pragma mark - +#pragma mark * ZNetEndpoint_Local_Socket + +class ZNetEndpoint_Local_Socket +: public ZNetEndpoint_Local, + public ZNetEndpoint_Socket + { +public: + ZNetEndpoint_Local_Socket(int iSocketFD); + ZNetEndpoint_Local_Socket(const std::string& iRemotePath); + + virtual ~ZNetEndpoint_Local_Socket(); + +// From ZNetEndpoint via ZNetEndpoint_Socket + virtual ZRef<ZNetAddress> GetRemoteAddress(); + }; + +// ================================================================================================= + +#endif // ZCONFIG_API_Enabled(Net_Local_Socket) + +#endif // __ZNet_Local_Socket__ Added: trunk/zoolib/source/cxx/zoolib/ZNet_Socket.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNet_Socket.cpp (rev 0) +++ trunk/zoolib/source/cxx/zoolib/ZNet_Socket.cpp 2008-10-27 19:10:19 UTC (rev 162) @@ -0,0 +1,542 @@ +/* ------------------------------------------------------------------------------------------------- +Copyright (c) 2008 Andrew Green +http://www.zoolib.org + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software +and associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +------------------------------------------------------------------------------------------------- */ + +#include "zoolib/ZNet_Socket.h" + +// ================================================================================================= +#if ZCONFIG_API_Enabled(Net_Socket) + +#include "zoolib/ZMemory.h" +#include "zoolib/ZTime.h" + +#include <unistd.h> + +#ifndef errno +# include <errno.h> +#endif + +#include <signal.h> + +#include <stdio.h> +#include <fcntl.h> +//#include <arpa/inet.h> + +// See comment in Solaris' /usr/include/sys/ioctl.h +#if __sun__ +# define BSD_COMP +#endif +#include <sys/ioctl.h> + +#include <sys/socket.h> +//#include <netdb.h> +//#include <netinet/in.h> + +// AG 2005-01-04. It looks like poll.h is not always present on MacOS X. +// We don't use poll on MacOS, so we can just skip the include for now. +#ifndef __APPLE__ +# define POLL_NO_WARN // Switch off Apple warning re poll(). +# include <poll.h> +#endif + +using std::string; + +// ================================================================================================= +#pragma mark - +#pragma mark * Helper functions + +// On MacOS X (and FreeBSD) and Linux a send or receive on a socket where the other end +// has closed can cause delivery of a sigpipe. These helper functions, and the conditional +// code in the ZNetEndpoint_Socket constructor, work around that issue. + +#ifdef __APPLE__ +// For MacOS X we set an option on the socket to indicate that sigpipe should not +// be delivered when the far end closes on us. That option was not defined in headers +// prior to 10.2, so we define it ourselves if necessary. + +#ifndef SO_NOSIGPIPE +# define SO_NOSIGPIPE 0x1022 +#endif + +#ifndef TCP_NODELAY +# include <netinet/tcp.h> +#endif + +static void sSetSocketOptions(int iSocket) + { + // Set the socket to be non blocking + ::fcntl(iSocket, F_SETFL, ::fcntl(iSocket, F_GETFL,0) | O_NONBLOCK); + + // Enable keep alive + int keepAliveFlag = 1; + ::setsockopt(iSocket, SOL_SOCKET, SO_KEEPALIVE, (char*)&keepAliveFlag, sizeof(keepAliveFlag)); + + // Disable sigpipe when writing/reading a far-closed socket. + int noSigPipeFlag = 1; + ::setsockopt(iSocket, SOL_SOCKET, SO_NOSIGPIPE, (char*)&noSigPipeFlag, sizeof(noSigPipeFlag)); + } + +static int sSend(int iSocket, const char* iSource, size_t iCount) + { return ::send(iSocket, iSource, iCount, 0); } + +static int sReceive(int iSocket, char* iDest, size_t iCount) + { return ::recv(iSocket, iDest, iCount, 0); } + +static bool sWaitReadable(int iSocket, int iMilliseconds) + { + fd_set readSet, exceptSet; + FD_ZERO(&readSet); + FD_ZERO(&exceptSet); + FD_SET(iSocket, &readSet); + FD_SET(iSocket, &exceptSet); + + struct timeval timeOut; + timeOut.tv_sec = iMilliseconds / 1000; + timeOut.tv_usec = (iMilliseconds % 1000) * 1000; + return 0 < ::select(iSocket + 1, &readSet, nil, &exceptSet, &timeOut); + } + +static void sWaitWriteable(int iSocket) + { + fd_set writeSet; + FD_ZERO(&writeSet); + FD_SET(iSocket, &writeSet); + + struct timeval timeOut; + timeOut.tv_sec = 1; + timeOut.tv_usec = 0; + + ::select(iSocket + 1, nil, &writeSet, nil, &timeOut); + } + +#elif defined(linux) || defined(__sun__) + +// RedHat Linux 6.1 adds the sigpipe on closed behavior to recv and send, and also adds +// a new flag that can be passed to supress that behavior. Older kernels return EINVAL +// if they don't recognize the flag, and thus don't have the behavior. So we use a static +// bool to remember if MSG_NOSIGNAL is available in the kernel. + +static void sSetSocketOptions(int iSocket) + { + // Set the socket to be non blocking + ::fcntl(iSocket, F_SETFL, ::fcntl(iSocket, F_GETFL,0) | O_NONBLOCK); + + // Enable keep alive + int keepAliveFlag = 1; + ::setsockopt(iSocket, SOL_SOCKET, SO_KEEPALIVE, (char*)&keepAliveFlag, sizeof(keepAliveFlag)); + } + +#ifndef MSG_NOSIGNAL +# define MSG_NOSIGNAL 0x2000 +#endif + +static bool sCanUse_MSG_NOSIGNAL = false; +static bool sChecked_MSG_NOSIGNAL = false; + +static int sSend(int iSocket, const char* iSource, size_t iCount) + { + if (sCanUse_MSG_NOSIGNAL) + { + return ::send(iSocket, iSource, iCount, MSG_NOSIGNAL); + } + else + { + if (sChecked_MSG_NOSIGNAL) + { + return ::send(iSocket, iSource, iCount, 0); + } + else + { + int result = ::send(iSocket, iSource, iCount, MSG_NOSIGNAL); + if (result >= 0) + { + sCanUse_MSG_NOSIGNAL = true; + sChecked_MSG_NOSIGNAL = true; + } + else + { + if (errno == EINVAL) + { + sChecked_MSG_NOSIGNAL = true; + return ::send(iSocket, iSource, iCount, 0); + } + } + return result; + } + } + } + +static int sReceive(int iSocket, char* iDest, size_t iCount) + { + if (sCanUse_MSG_NOSIGNAL) + { + return ::recv(iSocket, iDest, iCount, MSG_NOSIGNAL); + } + else + { + if (sChecked_MSG_NOSIGNAL) + { + return ::recv(iSocket, iDest, iCount, 0); + } + else + { + int result = ::recv(iSocket, iDest, iCount, MSG_NOSIGNAL); + + if (result >= 0) + { + sCanUse_MSG_NOSIGNAL = true; + sChecked_MSG_NOSIGNAL = true; + } + else + { + if (errno == EINVAL) + { + sChecked_MSG_NOSIGNAL = true; + return ::recv(iSocket, iDest, iCount, 0); + } + } + return result; + } + } + } + +static bool sWaitReadable(int iSocket, int iMilliseconds) + { + pollfd thePollFD; + thePollFD.fd = iSocket; + thePollFD.events = POLLIN | POLLPRI; + thePollFD.revents = 0; + return 0 < ::poll(&thePollFD, 1, iMilliseconds); + } + +static void sWaitWriteable(int iSocket) + { + pollfd thePollFD; + thePollFD.fd = iSocket; + thePollFD.events = POLLOUT; + ::poll(&thePollFD, 1, 1000); + } + +#endif + +// ================================================================================================= +#pragma mark - +#pragma mark * ZNet_Socket + +ZNet::Error ZNet_Socket::sTranslateError(int iNativeError) + { + ZNet::Error theError = ZNet::errorGeneric; + switch (iNativeError) + { + case EADDRINUSE: theError = ZNet::errorLocalPortInUse; break; + case EINVAL: theError = ZNet::errorBadState; break; + case EBADF: theError = ZNet::errorBadState; break; + case ECONNREFUSED: theError = ZNet::errorCouldntConnect; break; + case 0: theError = ZNet::errorNone; break; + default: break; + } + return theError; + } + +// ================================================================================================= +#pragma mark - +#pragma mark * ZNetListener_Socket + +static bool sFastCancellationEnabled; + +ZNetListener_Socket::ZNetListener_Socket(int iSocketFD, size_t iListenQueueSize) +: fSocketFD(iSocketFD) + { + if (::listen(fSocketFD, iListenQueueSize) < 0) + { + int err = errno; + ::close(fSocketFD); + throw ZNetEx(sTranslateError(err)); + } + + ::fcntl(fSocketFD, F_SETFL, ::fcntl(fSocketFD, F_GETFL,0) | O_NONBLOCK); + + fThreadID_Listening = 0; + } + +ZNetListener_Socket::~ZNetListener_Socket() + { + ::close(fSocketFD); + } + +ZRef<ZNetEndpoint> ZNetListener_Socket::Listen() + { + fMutexNR.Acquire(); + while (fThreadID_Listening) + fCondition.Wait(fMutexNR); + fThreadID_Listening = ZThread::sCurrentID(); + + int sleepTime; + if (sFastCancellationEnabled) + sleepTime = 10000; + else + sleepTime = 1000; + + fMutexNR.Release(); + + sWaitReadable(fSocketFD, sleepTime); + + char remoteSockAddr[128]; + ZBlockSet(&remoteSockAddr, sizeof(remoteSockAddr), 0); + socklen_t addrSize = sizeof(remoteSockAddr); + int result = ::accept(fSocketFD, (sockaddr*)&remoteSockAddr, &addrSize); + + fMutexNR.Acquire(); + + fThreadID_Listening = 0; + fCondition.Broadcast(); + fMutexNR.Release(); + + if (result > 0) + { + try + { + return this->Imp_MakeStreamer(result); + } + catch (...) + {} + ::close(result); + } + + return ZRef<ZNetEndpoint>(); + } + +void ZNetListener_Socket::CancelListen() + { + fMutexNR.Acquire(); + + // It's not essential that we do anything here other than wait for a call to Listen + // to drop out. However, if sFastCancellationEnabled, then we issue a SIGALRM to + // the blocked thread, which will drop out of its call to poll or select with + // an inncoccuous EINTR. + + #if ZCONFIG(API_Thread, POSIX) + if (sFastCancellationEnabled && fThreadID_Listening) + { + ::pthread_kill(fThreadID_Listening, SIGALRM); + } + #endif + + while (fThreadID_Listening) + fCondition.Wait(fMutexNR); + + fMutexNR.Release(); + } + +int ZNetListener_Socket::GetSocketFD() + { return fSocketFD; } + +static void sDummyAction(int iSignal) + {} + +void ZNetListener_Socket::sEnableFastCancellation() + { + #if ZCONFIG(API_Thread, POSIX) + struct sigaction sigaction_new; + sigaction_new.sa_handler = sDummyAction; + sigaction_new.sa_flags = 0; + sigemptyset(&sigaction_new.sa_mask); + ::sigaction(SIGALRM, &sigaction_new, nil); + sFastCancellationEnabled = true; + #endif + } + +// ================================================================================================= +#pragma mark - +#pragma mark * ZNetEndpoint_Socket + +ZNetEndpoint_Socket::ZNetEndpoint_Socket(int iSocketFD) + { + fSocketFD = iSocketFD; + ZAssertStop(2, fSocketFD != -1); + + sSetSocketOptions(fSocketFD); + } + +ZNetEndpoint_Socket::~ZNetEndpoint_Socket() + { + ::close(fSocketFD); + } + +const ZStreamRCon& ZNetEndpoint_Socket::GetStreamRCon() + { return *this; } + +const ZStreamWCon& ZNetEndpoint_Socket::GetStreamWCon() + { return *this; } + +int ZNetEndpoint_Socket::GetSocketFD() + { return fSocketFD; } + +void ZNetEndpoint_Socket::Imp_Read(void* iDest, size_t iCount, size_t* oCountRead) + { + char* localDest = static_cast<char*>(iDest); + while (iCount) + { + int result = ::sReceive(fSocketFD, localDest, iCount); + + if (result < 0) + { + int err = errno; + if (err == EAGAIN) + { + sWaitReadable(fSocketFD, 1000); + } + else if (err != EINTR) + { + break; + } + } + else + { + if (result == 0) + { + // result is zero, indicating that the other end has sent FIN. + break; + } + else + { + localDest += result; + iCount -= result; + break; + } + } + } + if (oCountRead) + *oCountRead = localDest - static_cast<char*>(iDest); + } + +size_t ZNetEndpoint_Socket::Imp_CountReadable() + { + int localResult; + if (0 <= ::ioctl(fSocketFD, FIONREAD, &localResult)) + return localResult; + return 0; + } + +void ZNetEndpoint_Socket::Imp_Write(const void* iSource, size_t iCount, size_t* oCountWritten) + { + const char* localSource = static_cast<const char*>(iSource); + while (iCount) + { + int result = ::sSend(fSocketFD, localSource, iCount); + + if (result < 0) + { + int err = errno; + if (err == EAGAIN) + { + sWaitWriteable(fSocketFD); + } + else if (err != EINTR) + { + break; + } + } + else + { + if (result == 0) + { + // result is zero, indicating that the other end has closed its receive side. + break; + } + else + { + localSource += result; + iCount -= result; + } + } + } + if (oCountWritten) + *oCountWritten = localSource - static_cast<const char*>(iSource); + } + +bool ZNetEndpoint_Socket::Imp_WaitReadable(int iMilliseconds) + { + return sWaitReadable(fSocketFD, iMilliseconds); + } + +bool ZNetEndpoint_Socket::Imp_ReceiveDisconnect(int iMilliseconds) + { + ZTime endTime = ZTime::sSystem() + double(iMilliseconds) / 1000; + + bool gotIt = false; + for (;;) + { + int result = ::sReceive(fSocketFD, ZooLib::sGarbageBuffer, sizeof(ZooLib::sGarbageBuffer)); + if (result == 0) + { + // result is zero, indicating that the other end has sent FIN. + gotIt = true; + break; + } + else if (result < 0) + { + int err = errno; + if (err == EAGAIN) + { + if (iMilliseconds < 0) + { + sWaitReadable(fSocketFD, 1000); + } + else + { + ZTime now = ZTime::sSystem(); + if (endTime < now) + break; + sWaitReadable(fSocketFD, int(1000 * (endTime - now))); + } + } + else if (err != EINTR) + { + break; + } + } + } + return gotIt; + } + +void ZNetEndpoint_Socket::Imp_SendDisconnect() + { + ::shutdown(fSocketFD, SHUT_WR); + } + +void ZNetEndpoint_Socket::Imp_Abort() + { + // Cause a RST to be sent when we close(). See UNIX Network + // Programming, 2nd Ed, Stevens, page 423 + + struct linger theLinger; + theLinger.l_onoff = 1; + + // AG 2001-10-04. [Stevens] says that l_linger should be 0. The code previously set l_linger + // to be 1, I'm not sure if we found that to be correct in practice so I'm correcting it -- + // if we experience problems, let me know. + theLinger.l_linger = 0; + + ::setsockopt(fSocketFD, SOL_SOCKET, SO_LINGER, (char*)&theLinger, sizeof(theLinger)); + ::shutdown(fSocketFD, SHUT_RDWR); + } + +// ================================================================================================= +#endif // ZCONFIG_API_Enabled(Net_Socket) Added: trunk/zoolib/source/cxx/zoolib/ZNet_Socket.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNet_Socket.h (rev 0) +++ trunk/zoolib/source/cxx/zoolib/ZNet_Socket.h 2008-10-27 19:10:19 UTC (rev 162) @@ -0,0 +1,139 @@ +/* ------------------------------------------------------------------------------------------------- +Copyright (c) 2008 Andrew Green +http://www.zoolib.org + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software +and associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +------------------------------------------------------------------------------------------------- */ + +#ifndef __ZNet_Socket__ +#define __ZNet_Socket__ 1 +#include "zconfig.h" +#include "zoolib/ZCONFIG_API.h" +#include "zoolib/ZCONFIG_SPI.h" + +#ifndef ZCONFIG_API_Avail__Net_Socket +# define ZCONFIG_API_Avail__Net_Socket ZCONFIG_SPI_Enabled(POSIX) +#endif + +#ifndef ZCONFIG_API_Desired__Net_Socket +# define ZCONFIG_API_Desired__Net_Socket 1 +#endif + +#include "zoolib/ZStreamer.h" +#include "zoolib/ZNet.h" // For ZNet::Error etc. + +#if ZCONFIG_API_Enabled(Net_Socket) + +// ================================================================================================= + +#include <sys/time.h> +#include <sys/types.h> +#include <sys/socket.h> + +// ================================================================================================= +#pragma mark - +#pragma mark * ZNet_Socket + +class ZNet_Socket + { +public: + static ZNet::Error sTranslateError(int iNativeError); + }; + +// ================================================================================================= +#pragma mark - +#pragma mark * ZNetListener_Socket + +class ZNetListener_Socket +: public virtual ZNetListener, + protected ZNet_Socket + { +protected: + ZNetListener_Socket(int iSocketFD, size_t iListenQueueSize); + +public: + virtual ~ZNetListener_Socket(); + +// From ZNetListener + virtual ZRef<ZNetEndpoint> Listen(); + virtual void CancelListen(); + +// Our protocol + int GetSocketFD(); + + virtual ZRef<ZNetEndpoint> Imp_MakeStreamer(int iSocketFD) = 0; + + static void sEnableFastCancellation(); + +protected: + ZMutexNR fMutexNR; + ZCondition fCondition; + int fSocketFD; + ZThread::ThreadID fThreadID_Listening; + }; + +// ================================================================================================= +#pragma mark - +#pragma mark * ZNetEndpoint_Socket + +class ZNetEndpoint_Socket +: public virtual ZNetEndpoint, + private ZStreamRCon, + private ZStreamWCon, + protected ZNet_Socket + { +protected: + ZNetEndpoint_Socket(int iSocketFD); + +public: + virtual ~ZNetEndpoint_Socket(); + +// From ZStreamerRCon via ZNetEndpoint + virtual const ZStreamRCon& GetStreamRCon(); + +// From ZStreamerWCon via ZNetEndpoint + virtual const ZStreamWCon& GetStreamWCon(); + +// Our protocol + int GetSocketFD(); + +private: +// From ZStreamR via ZStreamRCon + virtual void Imp_Read(void* iDest, size_t iCount, size_t* oCountRead); + virtual size_t Imp_CountReadable(); + +// From ZStreamW via ZStreamWCon + virtual void Imp_Write(const void* iSource, size_t iCount, size_t* oCountWritten); + +// From ZStreamRCon + virtual bool Imp_WaitReadable(int iMilliseconds); + virtual bool Imp_ReceiveDisconnect(int iMilliseconds); + +// From ZStreamWCon + virtual void Imp_SendDisconnect(); + +// From ZStreamRCon and ZStreamWCon + virtual void Imp_Abort(); + +private: + int fSocketFD; + }; + +// ================================================================================================= + +#endif // ZCONFIG_API_Enabled(Net_Socket) + +#endif // __ZNet_Socket__ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-10-27 23:59:02
|
Revision: 163 http://zoolib.svn.sourceforge.net/zoolib/?rev=163&view=rev Author: agreen Date: 2008-10-27 23:58:55 +0000 (Mon, 27 Oct 2008) Log Message: ----------- More progress. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZNet_Local.cpp trunk/zoolib/source/cxx/zoolib/ZNet_Local.h trunk/zoolib/source/cxx/zoolib/ZNet_Local_Socket.cpp trunk/zoolib/source/cxx/zoolib/ZNet_Local_Socket.h trunk/zoolib/source/cxx/zoolib/ZNet_Socket.cpp trunk/zoolib/source/cxx/zoolib/ZNet_Socket.h Modified: trunk/zoolib/source/cxx/zoolib/ZNet_Local.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNet_Local.cpp 2008-10-27 19:10:19 UTC (rev 162) +++ trunk/zoolib/source/cxx/zoolib/ZNet_Local.cpp 2008-10-27 23:58:55 UTC (rev 163) @@ -29,8 +29,8 @@ #pragma mark * Factories ZOOLIB_FACTORYCHAIN_HEAD(ZRef<ZNetNameLookup>, ZNetName_Local::LookupParam_t); -ZOOLIB_FACTORYCHAIN_HEAD(ZRef<ZNetListener_Local>, string); -ZOOLIB_FACTORYCHAIN_HEAD(ZRef<ZNetEndpoint_Local>, string); +ZOOLIB_FACTORYCHAIN_HEAD(ZRef<ZNetListener_Local>, ZNetListener_Local::MakeParam_t); +ZOOLIB_FACTORYCHAIN_HEAD(ZRef<ZNetEndpoint_Local>, ZNetEndpoint_Local::MakeParam_t); // ================================================================================================= #pragma mark - @@ -93,8 +93,8 @@ ZRef<ZNetListener_Local> ZNetListener_Local::sCreateListener( const string& iPath, size_t iListenQueueSize) { - return ZFactoryChain_T<ZRef<ZNetListener_Local>, string> - ::sMake(iPath); + return ZFactoryChain_T<ZRef<ZNetListener_Local>, MakeParam_t> + ::sMake(MakeParam_t(iPath, iListenQueueSize)); } // ================================================================================================= @@ -104,6 +104,6 @@ ZRef<ZNetEndpoint_Local> ZNetEndpoint_Local::sCreateConnectedEndpoint( const string& iPath) { - return ZFactoryChain_T<ZRef<ZNetEndpoint_Local>, string> - ::sMake(iPath); + return ZFactoryChain_T<ZRef<ZNetEndpoint_Local>, MakeParam_t> + ::sMake(MakeParam_t(iPath)); } Modified: trunk/zoolib/source/cxx/zoolib/ZNet_Local.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNet_Local.h 2008-10-27 19:10:19 UTC (rev 162) +++ trunk/zoolib/source/cxx/zoolib/ZNet_Local.h 2008-10-27 23:58:55 UTC (rev 163) @@ -56,7 +56,7 @@ class ZNetName_Local : public ZNetName { public: - typedef ZMulti_T2<std::string, size_t> LookupParam_t; + typedef std::string LookupParam_t; ZNetName_Local(); ZNetName_Local(const ZNetName_Local& other); @@ -81,6 +81,8 @@ class ZNetListener_Local : public virtual ZNetListener { public: + typedef ZMulti_T2<std::string, size_t> MakeParam_t; + static ZRef<ZNetListener_Local> sCreateListener( const std::string& iPath, size_t iListenQueueSize); }; @@ -92,6 +94,8 @@ class ZNetEndpoint_Local : public virtual ZNetEndpoint { public: + typedef std::string MakeParam_t; + static ZRef<ZNetEndpoint_Local> sCreateConnectedEndpoint( const std::string& iPath); }; Modified: trunk/zoolib/source/cxx/zoolib/ZNet_Local_Socket.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNet_Local_Socket.cpp 2008-10-27 19:10:19 UTC (rev 162) +++ trunk/zoolib/source/cxx/zoolib/ZNet_Local_Socket.cpp 2008-10-27 23:58:55 UTC (rev 163) @@ -32,7 +32,6 @@ # include <errno.h> #endif -//#include <stdio.h> #include <fcntl.h> #include <sys/socket.h> @@ -42,8 +41,55 @@ // ================================================================================================= #pragma mark - -#pragma mark * Helper functions +#pragma mark * Factory functions +#include "zoolib/ZFactoryChain.h" + +static bool sMake_NameLookup(ZRef<ZNetNameLookup>& oResult, ZNetName_Local::LookupParam_t iParam) + { + try + { + oResult = new ZNetNameLookup_Local_Socket(iParam); + return true; + } + catch (...) + {} + return false; + } + +static ZFactoryChain_Maker_T<ZRef<ZNetNameLookup>, ZNetName_Local::LookupParam_t> + sMaker1(sMake_NameLookup); + +static bool sMake_Listener(ZRef<ZNetListener_Local>& oResult, ZNetListener_Local::MakeParam_t iParam) + { + try + { + oResult = new ZNetListener_Local_Socket(iParam.f0, iParam.f1); + return true; + } + catch (...) + {} + return false; + } + +static ZFactoryChain_Maker_T<ZRef<ZNetListener_Local>, ZNetListener_Local::MakeParam_t> + sMaker2(sMake_Listener); + +static bool sMake_Endpoint(ZRef<ZNetEndpoint_Local>& oResult, ZNetEndpoint_Local::MakeParam_t iParam) + { + try + { + oResult = new ZNetEndpoint_Local_Socket(iParam); + return true; + } + catch (...) + {} + return false; + } + +static ZFactoryChain_Maker_T<ZRef<ZNetEndpoint_Local>, ZNetEndpoint_Local::MakeParam_t> + sMaker3(sMake_Endpoint); + // ================================================================================================= #pragma mark - #pragma mark * ZNetNameLookup_Local_Socket @@ -119,19 +165,14 @@ static int sListen(const string& iPath) { + sockaddr_un localSockAddr; + if (iPath.empty() || iPath.length() >= sizeof(localSockAddr.sun_path)) + throw ZNetEx(ZNet::errorGeneric); + int theSocketFD = ::socket(PF_LOCAL, SOCK_STREAM, 0); if (theSocketFD < 0) - { - int err = errno; - throw ZNetEx(ZNet_Socket::sTranslateError(err)); - } + throw ZNetEx(ZNet_Socket::sTranslateError(errno)); - // Enable SO_REUSEADDR, cause it's a real pain waiting for TIME_WAIT to expire - int reuseAddrFlag = 1; - ::setsockopt( - theSocketFD, SOL_SOCKET, SO_REUSEADDR, (char*)&reuseAddrFlag, sizeof(reuseAddrFlag)); - - sockaddr_un localSockAddr; ZBlockSet(&localSockAddr, sizeof(localSockAddr), 0); localSockAddr.sun_family = AF_LOCAL; strcpy(localSockAddr.sun_path, iPath.c_str()); @@ -152,7 +193,7 @@ ZNetListener_Local_Socket::~ZNetListener_Local_Socket() {} -ZRef<ZNetEndpoint> ZNetListener_Local_Socket::Imp_MakeStreamer(int iSocketFD) +ZRef<ZNetEndpoint> ZNetListener_Local_Socket::Imp_MakeEndpoint(int iSocketFD) { return new ZNetEndpoint_Local_Socket(iSocketFD); } Modified: trunk/zoolib/source/cxx/zoolib/ZNet_Local_Socket.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNet_Local_Socket.h 2008-10-27 19:10:19 UTC (rev 162) +++ trunk/zoolib/source/cxx/zoolib/ZNet_Local_Socket.h 2008-10-27 23:58:55 UTC (rev 163) @@ -84,7 +84,7 @@ virtual ~ZNetListener_Local_Socket(); // From ZNetListener_Socket - virtual ZRef<ZNetEndpoint> Imp_MakeStreamer(int iSocketFD); + virtual ZRef<ZNetEndpoint> Imp_MakeEndpoint(int iSocketFD); }; // ================================================================================================= Modified: trunk/zoolib/source/cxx/zoolib/ZNet_Socket.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNet_Socket.cpp 2008-10-27 19:10:19 UTC (rev 162) +++ trunk/zoolib/source/cxx/zoolib/ZNet_Socket.cpp 2008-10-27 23:58:55 UTC (rev 163) @@ -312,7 +312,7 @@ { try { - return this->Imp_MakeStreamer(result); + return this->Imp_MakeEndpoint(result); } catch (...) {} Modified: trunk/zoolib/source/cxx/zoolib/ZNet_Socket.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNet_Socket.h 2008-10-27 19:10:19 UTC (rev 162) +++ trunk/zoolib/source/cxx/zoolib/ZNet_Socket.h 2008-10-27 23:58:55 UTC (rev 163) @@ -74,7 +74,7 @@ // Our protocol int GetSocketFD(); - virtual ZRef<ZNetEndpoint> Imp_MakeStreamer(int iSocketFD) = 0; + virtual ZRef<ZNetEndpoint> Imp_MakeEndpoint(int iSocketFD) = 0; static void sEnableFastCancellation(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-10-28 02:37:18
|
Revision: 167 http://zoolib.svn.sourceforge.net/zoolib/?rev=167&view=rev Author: agreen Date: 2008-10-28 02:37:07 +0000 (Tue, 28 Oct 2008) Log Message: ----------- Move the TCP socket stuff to use the new shared socket implementation. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZNet_Internet.cpp trunk/zoolib/source/cxx/zoolib/ZNet_Internet.h trunk/zoolib/source/cxx/zoolib/ZNet_Internet_Socket.cpp trunk/zoolib/source/cxx/zoolib/ZNet_Internet_Socket.h trunk/zoolib/source/cxx/zoolib/ZNet_Local.cpp trunk/zoolib/source/cxx/zoolib/ZNet_Local.h trunk/zoolib/source/cxx/zoolib/ZNet_Local_Socket.cpp trunk/zoolib/source/cxx/zoolib/ZNet_Socket.cpp Modified: trunk/zoolib/source/cxx/zoolib/ZNet_Internet.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNet_Internet.cpp 2008-10-28 01:42:20 UTC (rev 166) +++ trunk/zoolib/source/cxx/zoolib/ZNet_Internet.cpp 2008-10-28 02:37:07 UTC (rev 167) @@ -59,7 +59,7 @@ {} ZRef<ZNetEndpoint> ZNetAddress_Internet::Connect() const - { return ZNetEndpoint_TCP::sCreateConnectedEndpoint(fHost, fPort); } + { return ZNetEndpoint_TCP::sCreateConnected(fHost, fPort); } // ================================================================================================= #pragma mark - @@ -101,6 +101,19 @@ #pragma mark - #pragma mark * ZNetListener_TCP +ZRef<ZNetListener_TCP> ZNetListener_TCP::sCreate(ip_port iPort, size_t iListenQueueSize) + { + return ZFactoryChain_T<ZRef<ZNetListener_TCP>, MakeParam_t> + ::sMake(MakeParam_t(0, iPort, iListenQueueSize)); + } + +ZRef<ZNetListener_TCP> ZNetListener_TCP::sCreate( + ip_addr iAddress, ip_port iPort, size_t iListenQueueSize) + { + return ZFactoryChain_T<ZRef<ZNetListener_TCP>, MakeParam_t> + ::sMake(MakeParam_t(iAddress, iPort, iListenQueueSize)); + } + ZRef<ZNetListener_TCP> ZNetListener_TCP::sCreateListener(ip_port iPort, size_t iListenQueueSize) { return ZFactoryChain_T<ZRef<ZNetListener_TCP>, MakeParam_t> @@ -118,6 +131,13 @@ #pragma mark - #pragma mark * ZNetEndpoint_TCP +ZRef<ZNetEndpoint_TCP> ZNetEndpoint_TCP::sCreateConnected( + ip_addr iRemoteHost, ip_port iRemotePort) + { + return ZFactoryChain_T<ZRef<ZNetEndpoint_TCP>, MakeParam_t> + ::sMake(MakeParam_t(iRemoteHost, iRemotePort)); + } + ZRef<ZNetEndpoint_TCP> ZNetEndpoint_TCP::sCreateConnectedEndpoint( ip_addr iRemoteHost, ip_port iRemotePort) { Modified: trunk/zoolib/source/cxx/zoolib/ZNet_Internet.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNet_Internet.h 2008-10-28 01:42:20 UTC (rev 166) +++ trunk/zoolib/source/cxx/zoolib/ZNet_Internet.h 2008-10-28 02:37:07 UTC (rev 167) @@ -96,6 +96,12 @@ virtual ip_port GetPort() = 0; + static ZRef<ZNetListener_TCP> sCreate( + ip_port iPort, size_t iListenQueueSize); + + static ZRef<ZNetListener_TCP> sCreate( + ip_addr iAddress, ip_port iPort, size_t iListenQueueSize); + static ZRef<ZNetListener_TCP> sCreateListener( ip_port iPort, size_t iListenQueueSize); @@ -112,6 +118,9 @@ public: typedef ZMulti_T2<ip_addr, ip_port> MakeParam_t; + static ZRef<ZNetEndpoint_TCP> sCreateConnected( + ip_addr iRemoteHost, ip_port iRemotePort); + static ZRef<ZNetEndpoint_TCP> sCreateConnectedEndpoint( ip_addr iRemoteHost, ip_port iRemotePort); }; Modified: trunk/zoolib/source/cxx/zoolib/ZNet_Internet_Socket.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNet_Internet_Socket.cpp 2008-10-28 01:42:20 UTC (rev 166) +++ trunk/zoolib/source/cxx/zoolib/ZNet_Internet_Socket.cpp 2008-10-28 02:37:07 UTC (rev 167) @@ -20,41 +20,17 @@ #include "zoolib/ZNet_Internet_Socket.h" -// ================================================================================================= #if ZCONFIG_API_Enabled(Net_Internet_Socket) #include "zoolib/ZMemory.h" -#include "zoolib/ZTime.h" -#include <unistd.h> - -#ifndef errno -# include <errno.h> -#endif - -#include <signal.h> - -#include <stdio.h> -#include <fcntl.h> +#include <errno.h> #include <arpa/inet.h> - -// See comment in Solaris' /usr/include/sys/ioctl.h -#if __sun__ -# define BSD_COMP -#endif -#include <sys/ioctl.h> - -#include <sys/socket.h> #include <netdb.h> #include <netinet/in.h> +#include <netinet/tcp.h> +#include <sys/socket.h> -// AG 2005-01-04. It looks like poll.h is not always present on MacOS X. -// We don't use poll on MacOS, so we can just skip the include for now. -#ifndef __APPLE__ -# define POLL_NO_WARN // Switch off Apple warning re poll(). -# include <poll.h> -#endif - using std::string; // ================================================================================================= @@ -112,210 +88,8 @@ #pragma mark - #pragma mark * Helper functions -// On MacOS X (and FreeBSD) and Linux a send or receive on a socket where the other end -// has closed can cause delivery of a sigpipe. These helper functions, and the conditional -// code in the ZNetEndpoint_TCP_Socket constructor, work around that issue. - -#ifdef __APPLE__ -// For MacOS X we set an option on the socket to indicate that sigpipe should not -// be delivered when the far end closes on us. That option was not defined in headers -// prior to 10.2, so we define it ourselves if necessary. - -#ifndef SO_NOSIGPIPE -# define SO_NOSIGPIPE 0x1022 -#endif - -#ifndef TCP_NODELAY -# include <netinet/tcp.h> -#endif - -static void sSetSocketOptions(int iSocket) - { - // Set the socket to be non blocking - ::fcntl(iSocket, F_SETFL, ::fcntl(iSocket, F_GETFL,0) | O_NONBLOCK); - - // Enable keep alive - int keepAliveFlag = 1; - ::setsockopt(iSocket, SOL_SOCKET, SO_KEEPALIVE, (char*)&keepAliveFlag, sizeof(keepAliveFlag)); - - // Disable sigpipe when writing/reading a far-closed socket. - int noSigPipeFlag = 1; - ::setsockopt(iSocket, SOL_SOCKET, SO_NOSIGPIPE, (char*)&noSigPipeFlag, sizeof(noSigPipeFlag)); - - // There's no simple way to flush a socket under MacOS X. We could hold on to the last byte - // written, then set NODELAY, write the byte, and clear NODELAY. I don't want to munge - // this code to do that right now. So for the moment on MacOS X we simply set NODELAY and - // expect higher level code to do buffering if it doesn't want to flood the connection with - // lots of small packets. This is a reasonable expectation because it's what has to be done - // anyway under Linux to prevent Nagle algorithm from kicking in. - int noDelayFlag = 1; - ::setsockopt(iSocket, IPPROTO_TCP, TCP_NODELAY, (char*)&noDelayFlag, sizeof(noDelayFlag)); - } - -static int sSend(int iSocket, const char* iSource, size_t iCount) - { return ::send(iSocket, iSource, iCount, 0); } - -static int sReceive(int iSocket, char* iDest, size_t iCount) - { return ::recv(iSocket, iDest, iCount, 0); } - -static bool sWaitReadable(int iSocket, int iMilliseconds) - { - fd_set readSet, exceptSet; - FD_ZERO(&readSet); - FD_ZERO(&exceptSet); - FD_SET(iSocket, &readSet); - FD_SET(iSocket, &exceptSet); - - struct timeval timeOut; - timeOut.tv_sec = iMilliseconds / 1000; - timeOut.tv_usec = (iMilliseconds % 1000) * 1000; - return 0 < ::select(iSocket + 1, &readSet, nil, &exceptSet, &timeOut); - } - -static void sWaitWriteable(int iSocket) - { - fd_set writeSet; - FD_ZERO(&writeSet); - FD_SET(iSocket, &writeSet); - - struct timeval timeOut; - timeOut.tv_sec = 1; - timeOut.tv_usec = 0; - - ::select(iSocket + 1, nil, &writeSet, nil, &timeOut); - } - -#elif defined(linux) || defined(__sun__) - -// RedHat Linux 6.1 adds the sigpipe on closed behavior to recv and send, and also adds -// a new flag that can be passed to supress that behavior. Older kernels return EINVAL -// if they don't recognize the flag, and thus don't have the behavior. So we use a static -// bool to remember if MSG_NOSIGNAL is available in the kernel. - -static void sSetSocketOptions(int iSocket) - { - // Set the socket to be non blocking - ::fcntl(iSocket, F_SETFL, ::fcntl(iSocket, F_GETFL,0) | O_NONBLOCK); - - // Enable keep alive - int keepAliveFlag = 1; - ::setsockopt(iSocket, SOL_SOCKET, SO_KEEPALIVE, (char*)&keepAliveFlag, sizeof(keepAliveFlag)); - } - -#ifndef MSG_NOSIGNAL -# define MSG_NOSIGNAL 0x2000 -#endif - -static bool sCanUse_MSG_NOSIGNAL = false; -static bool sChecked_MSG_NOSIGNAL = false; - -static int sSend(int iSocket, const char* iSource, size_t iCount) - { - if (sCanUse_MSG_NOSIGNAL) - { - return ::send(iSocket, iSource, iCount, MSG_NOSIGNAL); - } - else - { - if (sChecked_MSG_NOSIGNAL) - { - return ::send(iSocket, iSource, iCount, 0); - } - else - { - int result = ::send(iSocket, iSource, iCount, MSG_NOSIGNAL); - if (result >= 0) - { - sCanUse_MSG_NOSIGNAL = true; - sChecked_MSG_NOSIGNAL = true; - } - else - { - if (errno == EINVAL) - { - sChecked_MSG_NOSIGNAL = true; - return ::send(iSocket, iSource, iCount, 0); - } - } - return result; - } - } - } - -static int sReceive(int iSocket, char* iDest, size_t iCount) - { - if (sCanUse_MSG_NOSIGNAL) - { - return ::recv(iSocket, iDest, iCount, MSG_NOSIGNAL); - } - else - { - if (sChecked_MSG_NOSIGNAL) - { - return ::recv(iSocket, iDest, iCount, 0); - } - else - { - int result = ::recv(iSocket, iDest, iCount, MSG_NOSIGNAL); - - if (result >= 0) - { - sCanUse_MSG_NOSIGNAL = true; - sChecked_MSG_NOSIGNAL = true; - } - else - { - if (errno == EINVAL) - { - sChecked_MSG_NOSIGNAL = true; - return ::recv(iSocket, iDest, iCount, 0); - } - } - return result; - } - } - } - -static bool sWaitReadable(int iSocket, int iMilliseconds) - { - pollfd thePollFD; - thePollFD.fd = iSocket; - thePollFD.events = POLLIN | POLLPRI; - thePollFD.revents = 0; - return 0 < ::poll(&thePollFD, 1, iMilliseconds); - } - -static void sWaitWriteable(int iSocket) - { - pollfd thePollFD; - thePollFD.fd = iSocket; - thePollFD.events = POLLOUT; - ::poll(&thePollFD, 1, 1000); - } - -#endif - // ================================================================================================= #pragma mark - -#pragma mark * ZNet_Internet_Socket - -ZNet::Error ZNet_Internet_Socket::sTranslateError(int iNativeError) - { - ZNet::Error theError = ZNet::errorGeneric; - switch (iNativeError) - { - case EADDRINUSE: theError = ZNet::errorLocalPortInUse; break; - case EINVAL: theError = ZNet::errorBadState; break; - case EBADF: theError = ZNet::errorBadState; break; - case ECONNREFUSED: theError = ZNet::errorCouldntConnect; break; - case 0: theError = ZNet::errorNone; break; - default: break; - } - return theError; - } - -// ================================================================================================= -#pragma mark - #pragma mark * ZNetNameLookup_Internet_Socket ZNetNameLookup_Internet_Socket::ZNetNameLookup_Internet_Socket( @@ -423,16 +197,6 @@ #pragma mark - #pragma mark * ZNetListener_TCP_Socket -static bool sFastCancellationEnabled; - -ZNetListener_TCP_Socket::ZNetListener_TCP_Socket( - int iFD, size_t iListenQueueSize, bool iKnowWhatImDoing) - { - ZAssert(iKnowWhatImDoing); - fSocketFD = iFD; - this->pInitRemainder(iListenQueueSize); - } - ZRef<ZNetListener_TCP_Socket> ZNetListener_TCP_Socket::sCreateWithFD(int iFD, size_t iListenQueueSize) { try @@ -444,204 +208,143 @@ return ZRef<ZNetListener_TCP_Socket>(); } -ZNetListener_TCP_Socket::ZNetListener_TCP_Socket(ip_port iLocalPort, size_t iListenQueueSize) +static int sEnsureInet(int iSocketFD) { - this->pInit(INADDR_ANY, iLocalPort, iListenQueueSize); - } - -ZNetListener_TCP_Socket::ZNetListener_TCP_Socket( - ip_addr iLocalAddress, ip_port iLocalPort, size_t iListenQueueSize) - { - this->pInit(iLocalAddress, iLocalPort, iListenQueueSize); - } - -ZNetListener_TCP_Socket::~ZNetListener_TCP_Socket() - { - ::close(fSocketFD); - } - -ZRef<ZNetEndpoint> ZNetListener_TCP_Socket::Listen() - { - fMutexNR.Acquire(); - while (fThreadID_Listening) - fCondition.Wait(fMutexNR); - fThreadID_Listening = ZThread::sCurrentID(); - - int sleepTime; - if (sFastCancellationEnabled) - sleepTime = 10000; - else - sleepTime = 1000; - - fMutexNR.Release(); - - sWaitReadable(fSocketFD, sleepTime); - - sockaddr_in remoteSockAddr; - ZBlockSet(&remoteSockAddr, sizeof(remoteSockAddr), 0); - socklen_t addrSize = sizeof(remoteSockAddr); - int result = ::accept(fSocketFD, (sockaddr*)&remoteSockAddr, &addrSize); - - fMutexNR.Acquire(); - - fThreadID_Listening = 0; - fCondition.Broadcast(); - fMutexNR.Release(); - - if (result > 0) + sockaddr_in localSockAddr; + socklen_t length = sizeof(localSockAddr); + if (::getsockname(iSocketFD, (sockaddr*)&localSockAddr, &length) >= 0) { - try - { - return new ZNetEndpoint_TCP_Socket(result); - } - catch (...) - {} + if (localSockAddr.sin_family == AF_INET) + return iSocketFD; } - - return ZRef<ZNetEndpoint>(); + throw std::runtime_error("ZNetListener_TCP_Socket, not an inet socket"); } -void ZNetListener_TCP_Socket::CancelListen() +ZNetListener_TCP_Socket::ZNetListener_TCP_Socket( + int iSocketFD, size_t iListenQueueSize, bool iKnowWhatImDoing) +: ZNetListener_Socket(sEnsureInet(iSocketFD), iListenQueueSize) { - fMutexNR.Acquire(); - - // It's not essential that we do anything here other than wait for a call to Listen - // to drop out. However, if sFastCancellationEnabled, then we issue a SIGALRM to - // the blocked thread, which will drop out of its call to poll or select with - // an inncoccuous EINTR. - - #if ZCONFIG(API_Thread, POSIX) - if (sFastCancellationEnabled && fThreadID_Listening) - { - ::pthread_kill(fThreadID_Listening, SIGALRM); - } - #endif - - while (fThreadID_Listening) - fCondition.Wait(fMutexNR); - - fMutexNR.Release(); + // We could ensure that iSocketFD + ZAssert(iKnowWhatImDoing); } -ip_port ZNetListener_TCP_Socket::GetPort() +static int sListen(ip_addr iLocalAddress, ip_port iLocalPort) { - sockaddr_in localSockAddr; - socklen_t length = sizeof(localSockAddr); - if (::getsockname(fSocketFD, (sockaddr*)&localSockAddr, &length) >= 0) - return ntohs(localSockAddr.sin_port); - return 0; - } - -void ZNetListener_TCP_Socket::pInit( - ip_addr iLocalAddress, ip_port iLocalPort, size_t iListenQueueSize) - { - fSocketFD = ::socket(PF_INET, SOCK_STREAM, 0); - if (fSocketFD < 0) + int theSocketFD = ::socket(PF_INET, SOCK_STREAM, 0); + if (theSocketFD < 0) { int err = errno; - throw ZNetEx(sTranslateError(err)); + throw ZNetEx(ZNet_Socket::sTranslateError(err)); } + // Enable SO_REUSEADDR, cause it's a real pain waiting for TIME_WAIT to expire + int reuseAddrFlag = 1; + ::setsockopt( + theSocketFD, SOL_SOCKET, SO_REUSEADDR, (char*)&reuseAddrFlag, sizeof(reuseAddrFlag)); + sockaddr_in localSockAddr; ZBlockSet(&localSockAddr, sizeof(localSockAddr), 0); localSockAddr.sin_family = AF_INET; localSockAddr.sin_port = htons(iLocalPort); localSockAddr.sin_addr.s_addr = htonl(iLocalAddress); - // Enable SO_REUSEADDR, cause it's a real pain waiting for TIME_WAIT to expire - int reuseAddrFlag = 1; - ::setsockopt(fSocketFD, SOL_SOCKET, SO_REUSEADDR, (char*)&reuseAddrFlag, sizeof(reuseAddrFlag)); - - if (::bind(fSocketFD, (sockaddr*)&localSockAddr, sizeof(localSockAddr)) < 0) + if (::bind(theSocketFD, (sockaddr*)&localSockAddr, sizeof(localSockAddr)) < 0) { int err = errno; - ::close(fSocketFD); - throw ZNetEx(sTranslateError(err)); + ::close(theSocketFD); + throw ZNetEx(ZNet_Socket::sTranslateError(err)); } - - this->pInitRemainder(iListenQueueSize); + return theSocketFD; } -void ZNetListener_TCP_Socket::pInitRemainder(size_t iListenQueueSize) - { - if (::listen(fSocketFD, iListenQueueSize) < 0) - { - int err = errno; - ::close(fSocketFD); - throw ZNetEx(sTranslateError(err)); - } - ::fcntl(fSocketFD, F_SETFL, ::fcntl(fSocketFD, F_GETFL,0) | O_NONBLOCK); +ZNetListener_TCP_Socket::ZNetListener_TCP_Socket(ip_port iLocalPort, size_t iListenQueueSize) +: ZNetListener_Socket(sListen(0, iLocalPort), iListenQueueSize) + {} - fThreadID_Listening = 0; - } +ZNetListener_TCP_Socket::ZNetListener_TCP_Socket( + ip_addr iLocalAddress, ip_port iLocalPort, size_t iListenQueueSize) +: ZNetListener_Socket(sListen(iLocalAddress, iLocalPort), iListenQueueSize) + {} -static void sDummyAction(int iSignal) +ZNetListener_TCP_Socket::~ZNetListener_TCP_Socket() {} -void ZNetListener_TCP_Socket::sEnableFastCancellation() +ip_port ZNetListener_TCP_Socket::GetPort() { - #if ZCONFIG(API_Thread, POSIX) - struct sigaction sigaction_new; - sigaction_new.sa_handler = sDummyAction; - sigaction_new.sa_flags = 0; - sigemptyset(&sigaction_new.sa_mask); - ::sigaction(SIGALRM, &sigaction_new, nil); - sFastCancellationEnabled = true; - #endif + sockaddr_in localSockAddr; + socklen_t length = sizeof(localSockAddr); + if (::getsockname(this->GetSocketFD(), (sockaddr*)&localSockAddr, &length) >= 0) + return ntohs(localSockAddr.sin_port); + return 0; } +ZRef<ZNetEndpoint> ZNetListener_TCP_Socket::Imp_MakeEndpoint(int iSocketFD) + { + return new ZNetEndpoint_TCP_Socket(iSocketFD); + } + // ================================================================================================= #pragma mark - #pragma mark * ZNetEndpoint_TCP_Socket -ZNetEndpoint_TCP_Socket::ZNetEndpoint_TCP_Socket(int iSocketFD) +static void sSetSocketOptions(int iSocketFD) { - fSocketFD = iSocketFD; - ZAssertStop(2, fSocketFD != -1); + // There's no simple way to flush a socket under MacOS X. We could hold on to the last byte + // written, then set NODELAY, write the byte, and clear NODELAY. I don't want to munge + // this code to do that right now. So for the moment on MacOS X we simply set NODELAY and + // expect higher level code to do buffering if it doesn't want to flood the connection with + // lots of small packets. This is a reasonable expectation because it's what has to be done + // anyway under Linux to prevent Nagle algorithm from kicking in. + int noDelayFlag = 1; + ::setsockopt(iSocketFD, IPPROTO_TCP, TCP_NODELAY, (char*)&noDelayFlag, sizeof(noDelayFlag)); + } - sSetSocketOptions(fSocketFD); +ZNetEndpoint_TCP_Socket::ZNetEndpoint_TCP_Socket(int iSocketFD) +: ZNetEndpoint_Socket(iSocketFD) + { + sSetSocketOptions(this->GetSocketFD()); } -ZNetEndpoint_TCP_Socket::ZNetEndpoint_TCP_Socket(ip_addr iRemoteHost, ip_port iRemotePort) +static int sConnect(ip_addr iRemoteHost, ip_port iRemotePort) { - fSocketFD = ::socket(PF_INET, SOCK_STREAM, 0); - if (fSocketFD < 0) - throw ZNetEx(sTranslateError(errno)); + int socketFD = ::socket(PF_INET, SOCK_STREAM, 0); + if (socketFD < 0) + throw ZNetEx(ZNet_Socket::sTranslateError(errno)); sockaddr_in remoteSockAddr; ZBlockSet(&remoteSockAddr, sizeof(remoteSockAddr), 0); remoteSockAddr.sin_family = AF_INET; remoteSockAddr.sin_port = htons(iRemotePort); remoteSockAddr.sin_addr.s_addr = htonl(iRemoteHost); - if (::connect(fSocketFD, (sockaddr*)&remoteSockAddr, sizeof(remoteSockAddr)) < 0) + if (::connect(socketFD, (sockaddr*)&remoteSockAddr, sizeof(remoteSockAddr)) < 0) { - ::close(fSocketFD); - throw ZNetEx(sTranslateError(errno)); + ::close(socketFD); + throw ZNetEx(ZNet_Socket::sTranslateError(errno)); } - - sSetSocketOptions(fSocketFD); + return socketFD; } -ZNetEndpoint_TCP_Socket::~ZNetEndpoint_TCP_Socket() +ZNetEndpoint_TCP_Socket::ZNetEndpoint_TCP_Socket(ip_addr iRemoteHost, ip_port iRemotePort) +: ZNetEndpoint_Socket(sConnect(iRemoteHost, iRemotePort)) { - ::close(fSocketFD); + sSetSocketOptions(this->GetSocketFD()); } -const ZStreamRCon& ZNetEndpoint_TCP_Socket::GetStreamRCon() - { return *this; } +ZNetEndpoint_TCP_Socket::~ZNetEndpoint_TCP_Socket() + {} -const ZStreamWCon& ZNetEndpoint_TCP_Socket::GetStreamWCon() - { return *this; } - ZRef<ZNetAddress> ZNetEndpoint_TCP_Socket::GetLocalAddress() { sockaddr_in localSockAddr; socklen_t length = sizeof(localSockAddr); - if (::getsockname(fSocketFD, (sockaddr*)&localSockAddr, &length) >= 0) + if (::getsockname(this->GetSocketFD(), (sockaddr*)&localSockAddr, &length) >= 0) { - return new ZNetAddress_Internet( - ntohl(localSockAddr.sin_addr.s_addr), ntohs(localSockAddr.sin_port)); + if (localSockAddr.sin_family == AF_INET) + { + return new ZNetAddress_Internet( + ntohl(localSockAddr.sin_addr.s_addr), ntohs(localSockAddr.sin_port)); + } } return ZRef<ZNetAddress>(); @@ -651,164 +354,18 @@ { sockaddr_in remoteSockAddr; socklen_t length = sizeof(remoteSockAddr); - if (::getpeername(fSocketFD, (sockaddr*)&remoteSockAddr, &length) >= 0) + if (::getpeername(this->GetSocketFD(), (sockaddr*)&remoteSockAddr, &length) >= 0) { - return new ZNetAddress_Internet( - ntohl(remoteSockAddr.sin_addr.s_addr), ntohs(remoteSockAddr.sin_port)); - } - - return ZRef<ZNetAddress>(); - } - -void ZNetEndpoint_TCP_Socket::Imp_Read(void* iDest, size_t iCount, size_t* oCountRead) - { - char* localDest = static_cast<char*>(iDest); - while (iCount) - { - int result = ::sReceive(fSocketFD, localDest, iCount); - - if (result < 0) + if (remoteSockAddr.sin_family == AF_INET) { - int err = errno; - if (err == EAGAIN) - { - sWaitReadable(fSocketFD, 1000); - } - else if (err != EINTR) - { - break; - } + return new ZNetAddress_Internet( + ntohl(remoteSockAddr.sin_addr.s_addr), ntohs(remoteSockAddr.sin_port)); } - else - { - if (result == 0) - { - // result is zero, indicating that the other end has sent FIN. - break; - } - else - { - localDest += result; - iCount -= result; - break; - } - } } - if (oCountRead) - *oCountRead = localDest - static_cast<char*>(iDest); - } -size_t ZNetEndpoint_TCP_Socket::Imp_CountReadable() - { - int localResult; - if (0 <= ::ioctl(fSocketFD, FIONREAD, &localResult)) - return localResult; - return 0; + return ZRef<ZNetAddress>(); } -void ZNetEndpoint_TCP_Socket::Imp_Write(const void* iSource, size_t iCount, size_t* oCountWritten) - { - const char* localSource = static_cast<const char*>(iSource); - while (iCount) - { - int result = ::sSend(fSocketFD, localSource, iCount); +// ================================================================================================= - if (result < 0) - { - int err = errno; - if (err == EAGAIN) - { - sWaitWriteable(fSocketFD); - } - else if (err != EINTR) - { - break; - } - } - else - { - if (result == 0) - { - // result is zero, indicating that the other end has closed its receive side. - break; - } - else - { - localSource += result; - iCount -= result; - } - } - } - if (oCountWritten) - *oCountWritten = localSource - static_cast<const char*>(iSource); - } - -bool ZNetEndpoint_TCP_Socket::Imp_WaitReadable(int iMilliseconds) - { - return sWaitReadable(fSocketFD, iMilliseconds); - } - -bool ZNetEndpoint_TCP_Socket::Imp_ReceiveDisconnect(int iMilliseconds) - { - ZTime endTime = ZTime::sSystem() + double(iMilliseconds) / 1000; - - bool gotIt = false; - for (;;) - { - int result = ::sReceive(fSocketFD, ZooLib::sGarbageBuffer, sizeof(ZooLib::sGarbageBuffer)); - if (result == 0) - { - // result is zero, indicating that the other end has sent FIN. - gotIt = true; - break; - } - else if (result < 0) - { - int err = errno; - if (err == EAGAIN) - { - if (iMilliseconds < 0) - { - sWaitReadable(fSocketFD, 1000); - } - else - { - ZTime now = ZTime::sSystem(); - if (endTime < now) - break; - sWaitReadable(fSocketFD, int(1000 * (endTime - now))); - } - } - else if (err != EINTR) - { - break; - } - } - } - return gotIt; - } - -void ZNetEndpoint_TCP_Socket::Imp_SendDisconnect() - { - ::shutdown(fSocketFD, SHUT_WR); - } - -void ZNetEndpoint_TCP_Socket::Imp_Abort() - { - // Cause a RST to be sent when we close(). See UNIX Network - // Programming, 2nd Ed, Stevens, page 423 - - struct linger theLinger; - theLinger.l_onoff = 1; - - // AG 2001-10-04. [Stevens] says that l_linger should be 0. The code previously set l_linger - // to be 1, I'm not sure if we found that to be correct in practice so I'm correcting it -- - // if we experience problems, let me know. - theLinger.l_linger = 0; - - ::setsockopt(fSocketFD, SOL_SOCKET, SO_LINGER, (char*)&theLinger, sizeof(theLinger)); - ::shutdown(fSocketFD, SHUT_RDWR); - } - #endif // ZCONFIG_API_Enabled(Net_Internet_Socket) -// ================================================================================================= Modified: trunk/zoolib/source/cxx/zoolib/ZNet_Internet_Socket.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNet_Internet_Socket.h 2008-10-28 01:42:20 UTC (rev 166) +++ trunk/zoolib/source/cxx/zoolib/ZNet_Internet_Socket.h 2008-10-28 02:37:07 UTC (rev 167) @@ -24,37 +24,28 @@ #include "zoolib/ZCONFIG_API.h" #include "zoolib/ZCONFIG_SPI.h" +#include "zoolib/ZNet_Internet.h" +#include "zoolib/ZNet_Socket.h" + #ifndef ZCONFIG_API_Avail__Net_Internet_Socket -# define ZCONFIG_API_Avail__Net_Internet_Socket ZCONFIG_SPI_Enabled(POSIX) +# if ZCONFIG_API_Enabled(Net_Socket) +# define ZCONFIG_API_Avail__Net_Internet_Socket 1 +# endif #endif +#ifndef ZCONFIG_API_Avail__Net_Internet_Socket +# define ZCONFIG_API_Avail__Net_Internet_Socket 0 +#endif + #ifndef ZCONFIG_API_Desired__Net_Internet_Socket # define ZCONFIG_API_Desired__Net_Internet_Socket 1 #endif -#include "zoolib/ZNet_Internet.h" #if ZCONFIG_API_Enabled(Net_Internet_Socket) // ================================================================================================= - -#include <sys/time.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> - -// ================================================================================================= #pragma mark - -#pragma mark * ZNet_Internet_Socket - -class ZNet_Internet_Socket - { -public: - static ZNet::Error sTranslateError(int iNativeError); - }; - -// ================================================================================================= -#pragma mark - #pragma mark * ZNetNameLookup_Internet_Socket class ZNetNameLookup_Internet_Socket : public ZNetNameLookup @@ -84,33 +75,23 @@ #pragma mark - #pragma mark * ZNetListener_TCP_Socket -class ZNetListener_TCP_Socket : public ZNetListener_TCP, - private ZNet_Internet_Socket +class ZNetListener_TCP_Socket +: public ZNetListener_TCP, + public ZNetListener_Socket { ZNetListener_TCP_Socket(int iFD, size_t iListenQueueSize, bool iKnowWhatImDoing); public: static ZRef<ZNetListener_TCP_Socket> sCreateWithFD(int iFD, size_t iListenQueueSize); + ZNetListener_TCP_Socket(ip_port iLocalPort, size_t iListenQueueSize); ZNetListener_TCP_Socket(ip_addr iLocalAddress, ip_port iLocalPort, size_t iListenQueueSize); virtual ~ZNetListener_TCP_Socket(); -// From ZNetListener via ZNetListener_TCP - virtual ZRef<ZNetEndpoint> Listen(); - virtual void CancelListen(); - // From ZNetListener_TCP virtual ip_port GetPort(); - static void sEnableFastCancellation(); - -protected: - void pInit(ip_addr iLocalAddress, ip_port iLocalPort, size_t iListenQueueSize); - void pInitRemainder(size_t iListenQueueSize); - - ZMutexNR fMutexNR; - ZCondition fCondition; - int fSocketFD; - ZThread::ThreadID fThreadID_Listening; +// From ZNetListener_Socket + virtual ZRef<ZNetEndpoint> Imp_MakeEndpoint(int iSocketFD); }; // ================================================================================================= @@ -119,9 +100,7 @@ class ZNetEndpoint_TCP_Socket : public ZNetEndpoint_TCP, - private ZStreamRCon, - private ZStreamWCon, - private ZNet_Internet_Socket + public ZNetEndpoint_Socket { public: ZNetEndpoint_TCP_Socket(int iSocketFD); @@ -129,35 +108,9 @@ virtual ~ZNetEndpoint_TCP_Socket(); -// From ZStreamerRCon via ZNetEndpoint_TCP - virtual const ZStreamRCon& GetStreamRCon(); - -// From ZStreamerWCon via ZNetEndpoint_TCP - virtual const ZStreamWCon& GetStreamWCon(); - // From ZNetEndpoint via ZNetEndpoint_TCP virtual ZRef<ZNetAddress> GetLocalAddress(); virtual ZRef<ZNetAddress> GetRemoteAddress(); - -// From ZStreamR via ZStreamRCon - virtual void Imp_Read(void* iDest, size_t iCount, size_t* oCountRead); - virtual size_t Imp_CountReadable(); - -// From ZStreamW via ZStreamWCon - virtual void Imp_Write(const void* iSource, size_t iCount, size_t* oCountWritten); - -// From ZStreamRCon - virtual bool Imp_WaitReadable(int iMilliseconds); - virtual bool Imp_ReceiveDisconnect(int iMilliseconds); - -// From ZStreamWCon - virtual void Imp_SendDisconnect(); - -// From ZStreamRCon and ZStreamWCon - virtual void Imp_Abort(); - -private: - int fSocketFD; }; // ================================================================================================= Modified: trunk/zoolib/source/cxx/zoolib/ZNet_Local.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNet_Local.cpp 2008-10-28 01:42:20 UTC (rev 166) +++ trunk/zoolib/source/cxx/zoolib/ZNet_Local.cpp 2008-10-28 02:37:07 UTC (rev 167) @@ -51,7 +51,7 @@ {} ZRef<ZNetEndpoint> ZNetAddress_Local::Connect() const - { return ZNetEndpoint_Local::sCreateConnectedEndpoint(fPath); } + { return ZNetEndpoint_Local::sCreateConnected(fPath); } const string& ZNetAddress_Local::GetPath() const { return fPath ;} @@ -90,7 +90,7 @@ #pragma mark - #pragma mark * ZNetListener_Local -ZRef<ZNetListener_Local> ZNetListener_Local::sCreateListener( +ZRef<ZNetListener_Local> ZNetListener_Local::sCreate( const string& iPath, size_t iListenQueueSize) { return ZFactoryChain_T<ZRef<ZNetListener_Local>, MakeParam_t> @@ -101,8 +101,7 @@ #pragma mark - #pragma mark * ZNetEndpoint_Local -ZRef<ZNetEndpoint_Local> ZNetEndpoint_Local::sCreateConnectedEndpoint( - const string& iPath) +ZRef<ZNetEndpoint_Local> ZNetEndpoint_Local::sCreateConnected(const string& iPath) { return ZFactoryChain_T<ZRef<ZNetEndpoint_Local>, MakeParam_t> ::sMake(MakeParam_t(iPath)); Modified: trunk/zoolib/source/cxx/zoolib/ZNet_Local.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNet_Local.h 2008-10-28 01:42:20 UTC (rev 166) +++ trunk/zoolib/source/cxx/zoolib/ZNet_Local.h 2008-10-28 02:37:07 UTC (rev 167) @@ -83,7 +83,7 @@ public: typedef ZMulti_T2<std::string, size_t> MakeParam_t; - static ZRef<ZNetListener_Local> sCreateListener( + static ZRef<ZNetListener_Local> sCreate( const std::string& iPath, size_t iListenQueueSize); }; @@ -96,8 +96,7 @@ public: typedef std::string MakeParam_t; - static ZRef<ZNetEndpoint_Local> sCreateConnectedEndpoint( - const std::string& iPath); + static ZRef<ZNetEndpoint_Local> sCreateConnected(const std::string& iPath); }; #endif // __ZNet_Local__ Modified: trunk/zoolib/source/cxx/zoolib/ZNet_Local_Socket.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNet_Local_Socket.cpp 2008-10-28 01:42:20 UTC (rev 166) +++ trunk/zoolib/source/cxx/zoolib/ZNet_Local_Socket.cpp 2008-10-28 02:37:07 UTC (rev 167) @@ -20,20 +20,11 @@ #include "zoolib/ZNet_Local_Socket.h" -// ================================================================================================= #if ZCONFIG_API_Enabled(Net_Local_Socket) #include "zoolib/ZMemory.h" -#include "zoolib/ZTime.h" -#include <unistd.h> - -#ifndef errno -# include <errno.h> -#endif - -#include <fcntl.h> - +#include <errno.h> #include <sys/socket.h> #include <sys/un.h> @@ -177,6 +168,8 @@ localSockAddr.sun_family = AF_LOCAL; strcpy(localSockAddr.sun_path, iPath.c_str()); + ::unlink(localSockAddr.sun_path); + if (::bind(theSocketFD, (sockaddr*)&localSockAddr, sizeof(localSockAddr)) < 0) { int err = errno; @@ -252,5 +245,6 @@ return ZRef<ZNetAddress>(); } -#endif // ZCONFIG_API_Enabled(Net_Local_Socket) // ================================================================================================= + +#endif // ZCONFIG_API_Enabled(Net_Local_Socket) Modified: trunk/zoolib/source/cxx/zoolib/ZNet_Socket.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNet_Socket.cpp 2008-10-28 01:42:20 UTC (rev 166) +++ trunk/zoolib/source/cxx/zoolib/ZNet_Socket.cpp 2008-10-28 02:37:07 UTC (rev 167) @@ -20,33 +20,21 @@ #include "zoolib/ZNet_Socket.h" -// ================================================================================================= #if ZCONFIG_API_Enabled(Net_Socket) #include "zoolib/ZMemory.h" #include "zoolib/ZTime.h" -#include <unistd.h> - -#ifndef errno -# include <errno.h> -#endif - +#include <errno.h> +#include <fcntl.h> #include <signal.h> -#include <stdio.h> -#include <fcntl.h> -//#include <arpa/inet.h> - // See comment in Solaris' /usr/include/sys/ioctl.h #if __sun__ # define BSD_COMP #endif #include <sys/ioctl.h> - #include <sys/socket.h> -//#include <netdb.h> -//#include <netinet/in.h> // AG 2005-01-04. It looks like poll.h is not always present on MacOS X. // We don't use poll on MacOS, so we can just skip the include for now. @@ -297,7 +285,7 @@ sWaitReadable(fSocketFD, sleepTime); - char remoteSockAddr[128]; + char remoteSockAddr[1024]; ZBlockSet(&remoteSockAddr, sizeof(remoteSockAddr), 0); socklen_t addrSize = sizeof(remoteSockAddr); int result = ::accept(fSocketFD, (sockaddr*)&remoteSockAddr, &addrSize); @@ -539,4 +527,5 @@ } // ================================================================================================= + #endif // ZCONFIG_API_Enabled(Net_Socket) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-10-28 02:38:16
|
Revision: 168 http://zoolib.svn.sourceforge.net/zoolib/?rev=168&view=rev Author: agreen Date: 2008-10-28 02:38:11 +0000 (Tue, 28 Oct 2008) Log Message: ----------- Add couple more listeners for high speed variants. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZBlackBerry_OSXUSB.cpp trunk/zoolib/source/cxx/zoolib/ZBlackBerry_OSXUSB.h Modified: trunk/zoolib/source/cxx/zoolib/ZBlackBerry_OSXUSB.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZBlackBerry_OSXUSB.cpp 2008-10-28 02:37:07 UTC (rev 167) +++ trunk/zoolib/source/cxx/zoolib/ZBlackBerry_OSXUSB.cpp 2008-10-28 02:38:11 UTC (rev 168) @@ -168,18 +168,24 @@ ::CFRunLoopAddSource(theRunLoopRef, ::IONotificationPortGetRunLoopSource(fIONotificationPortRef), kCFRunLoopDefaultMode); - fUSBWatcher_Traditional = new ZUSBWatcher(fIONotificationPortRef, 0xFCA, 1); - fUSBWatcher_Traditional->SetObserver(this); + fUSBWatcher_Trad = new ZUSBWatcher(fIONotificationPortRef, 0xFCA, 1); + fUSBWatcher_Trad->SetObserver(this); fUSBWatcher_Pearl = new ZUSBWatcher(fIONotificationPortRef, 0xFCA, 6); fUSBWatcher_Pearl->SetObserver(this); - fUSBWatcher_PearlDual = new ZUSBWatcher(fIONotificationPortRef, 0xFCA, 4); - fUSBWatcher_PearlDual->SetObserver(this); + fUSBWatcher_Dual = new ZUSBWatcher(fIONotificationPortRef, 0xFCA, 4); + fUSBWatcher_Dual->SetObserver(this); - fUSBWatcher_Pearl8120 = new ZUSBWatcher(fIONotificationPortRef, 0xFCA, 0x8004); - fUSBWatcher_Pearl8120->SetObserver(this); + fUSBWatcher_Trad_HS = new ZUSBWatcher(fIONotificationPortRef, 0xFCA, 0x8001); + fUSBWatcher_Trad_HS->SetObserver(this); + fUSBWatcher_Pearl_HS = new ZUSBWatcher(fIONotificationPortRef, 0xFCA, 0x8006); + fUSBWatcher_Pearl_HS->SetObserver(this); + + fUSBWatcher_Dual_HS = new ZUSBWatcher(fIONotificationPortRef, 0xFCA, 0x8004); + fUSBWatcher_Dual_HS->SetObserver(this); + Manager::Start(); } @@ -188,11 +194,14 @@ if (ZLOG(s, eDebug, "ZBlackBerry::Manager_OSXUSB")) s << "Stop"; - fUSBWatcher_Traditional.Clear(); + fUSBWatcher_Trad.Clear(); fUSBWatcher_Pearl.Clear(); - fUSBWatcher_PearlDual.Clear(); - fUSBWatcher_Pearl8120.Clear(); + fUSBWatcher_Dual.Clear(); + fUSBWatcher_Trad_HS.Clear(); + fUSBWatcher_Pearl_HS.Clear(); + fUSBWatcher_Dual_HS.Clear(); + if (fIONotificationPortRef) { ::IONotificationPortDestroy(fIONotificationPortRef); @@ -285,34 +294,16 @@ } } - if (theIDProduct == 6) + if (theIDProduct == 6 || theIDProduct == 0x8006) { if (ZLOG(s, eDebug, "ZBlackBerry::Manager_OSXUSB")) - s << "Got an 8xxx series, changing modes"; + s << "Mass storage only, changing modes."; sChangeMode(iUSBDevice, fAllowMassStorage); return; } - if (theIDProduct == 4) - { - if (ZLOG(s, eDebug, "ZBlackBerry::Manager_OSXUSB")) - s << "Got an 8xxx series, dual mode"; - } - - if (theIDProduct == 0x8004) - { - if (ZLOG(s, eDebug, "ZBlackBerry::Manager_OSXUSB")) - s << "Got an 8xxx series, dual mode, high-speed USB"; - } - - if (theIDProduct == 1) - { - if (ZLOG(s, eDebug, "ZBlackBerry::Manager_OSXUSB")) - s << "Got an older BlackBerry"; - } - ZMutexLocker locker(fMutex); Device_t theD; theD.fID = fNextID++; Modified: trunk/zoolib/source/cxx/zoolib/ZBlackBerry_OSXUSB.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZBlackBerry_OSXUSB.h 2008-10-28 02:37:07 UTC (rev 167) +++ trunk/zoolib/source/cxx/zoolib/ZBlackBerry_OSXUSB.h 2008-10-28 02:38:11 UTC (rev 168) @@ -87,11 +87,14 @@ mach_port_t fMasterPort; IONotificationPortRef fIONotificationPortRef; - ZRef<ZUSBWatcher> fUSBWatcher_Traditional; + ZRef<ZUSBWatcher> fUSBWatcher_Trad; ZRef<ZUSBWatcher> fUSBWatcher_Pearl; - ZRef<ZUSBWatcher> fUSBWatcher_PearlDual; - ZRef<ZUSBWatcher> fUSBWatcher_Pearl8120; + ZRef<ZUSBWatcher> fUSBWatcher_Dual; + ZRef<ZUSBWatcher> fUSBWatcher_Trad_HS; + ZRef<ZUSBWatcher> fUSBWatcher_Pearl_HS; + ZRef<ZUSBWatcher> fUSBWatcher_Dual_HS; + struct Device_t { ZRef<ZUSBDevice> fUSBDevice; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-10-29 01:16:21
|
Revision: 170 http://zoolib.svn.sourceforge.net/zoolib/?rev=170&view=rev Author: agreen Date: 2008-10-29 01:16:16 +0000 (Wed, 29 Oct 2008) Log Message: ----------- Some basic ARM support. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/zconfigd.h trunk/zoolib/source/cxx/zoolib/zconfigl.h Modified: trunk/zoolib/source/cxx/zoolib/zconfigd.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/zconfigd.h 2008-10-28 02:39:24 UTC (rev 169) +++ trunk/zoolib/source/cxx/zoolib/zconfigd.h 2008-10-29 01:16:16 UTC (rev 170) @@ -32,6 +32,7 @@ #define ZCONFIG_Processor_x86 4 #define ZCONFIG_Processor_Sparc 8 #define ZCONFIG_Processor_Alpha 16 +#define ZCONFIG_Processor_ARM 32 // Byte order -- ZCONFIG_Endian #define ZCONFIG_Endian_Big 1 Modified: trunk/zoolib/source/cxx/zoolib/zconfigl.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/zconfigl.h 2008-10-28 02:39:24 UTC (rev 169) +++ trunk/zoolib/source/cxx/zoolib/zconfigl.h 2008-10-29 01:16:16 UTC (rev 170) @@ -74,15 +74,18 @@ # define ZCONFIG_Processor ZCONFIG_Processor_x86 # elif #cpu(sparc) # define ZCONFIG_Processor ZCONFIG_Processor_Sparc -# elif #cpu(powerpc) || __APPLE__ +# elif #cpu(powerpc) # define ZCONFIG_Processor ZCONFIG_Processor_PPC # elif #cpu(alpha) # define ZCONFIG_Processor ZCONFIG_Processor_Alpha +# elif defined(__arm__) +# define ZCONFIG_Processor ZCONFIG_Processor_ARM # endif # elif defined(_MSC_VER) # define ZCONFIG_Processor ZCONFIG_Processor_x86 # endif #endif + #ifndef ZCONFIG_Processor # error "Don't know what processor we're using." #endif @@ -93,6 +96,8 @@ #ifndef ZCONFIG_Endian # if (ZCONFIG_Processor == ZCONFIG_Processor_x86) # define ZCONFIG_Endian ZCONFIG_Endian_Little +# elif (ZCONFIG_Processor == ZCONFIG_Processor_ARM) +# define ZCONFIG_Endian ZCONFIG_Endian_Little # else # define ZCONFIG_Endian ZCONFIG_Endian_Big # endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-11-16 01:12:52
|
Revision: 201 http://zoolib.svn.sourceforge.net/zoolib/?rev=201&view=rev Author: agreen Date: 2008-11-16 01:12:44 +0000 (Sun, 16 Nov 2008) Log Message: ----------- Functionality migrated from ZNSPlugin, conforming to the current npapi headers. Added Paths: ----------- trunk/zoolib/source/cxx/zoolib/ZNetscape_Guest.cpp trunk/zoolib/source/cxx/zoolib/ZNetscape_Guest.h trunk/zoolib/source/cxx/zoolib/ZNetscape_Guest_Std.cpp trunk/zoolib/source/cxx/zoolib/ZNetscape_Guest_Std.h Added: trunk/zoolib/source/cxx/zoolib/ZNetscape_Guest.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNetscape_Guest.cpp (rev 0) +++ trunk/zoolib/source/cxx/zoolib/ZNetscape_Guest.cpp 2008-11-16 01:12:44 UTC (rev 201) @@ -0,0 +1,335 @@ +/* ------------------------------------------------------------------------------------------------- +Copyright (c) 2002 Andrew Green +http://www.zoolib.org + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software +and associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +------------------------------------------------------------------------------------------------- */ + +#include "zoolib/ZDebug.h" +#include "zoolib/ZMemory.h" +#include "zoolib/ZNetscape_Guest.h" + +#pragma export on +// Mach-o entry points +extern "C" NPError NP_Initialize(NPNetscapeFuncs*); +extern "C" NPError NP_GetEntryPoints(NPPluginFuncs*); +extern "C" NPError NP_Shutdown(); + +// For compatibility with CFM browsers. +extern "C" int main( + NPNetscapeFuncs *browserFuncs, NPPluginFuncs *pluginFuncs, NPP_ShutdownProcPtr *shutdown); +#pragma export off + + +NPError NP_Initialize(NPNetscapeFuncs* iBrowserFuncs) + { return ZNetscape::GuestMeister::sGet()->Initialize(iBrowserFuncs); } + +NPError NP_GetEntryPoints(NPPluginFuncs* oPluginFuncs) + { return ZNetscape::GuestMeister::sGet()->GetEntryPoints(oPluginFuncs); } + +NPError NP_Shutdown() + { return ZNetscape::GuestMeister::sGet()->Shutdown(); } + +namespace ZNetscape { + +// ================================================================================================= +#pragma mark - +#pragma mark * GuestMeister + +static GuestMeister* sGuestMeister; + +GuestMeister::GuestMeister() + { + ZAssert(!sGuestMeister); + sGuestMeister = this; + ZBlockZero(&fNPNF, sizeof(fNPNF)); + } + +GuestMeister::~GuestMeister() + { + ZAssert(sGuestMeister == this); + sGuestMeister = nil; + } + +GuestMeister* GuestMeister::sGet() + { + ZAssert(sGuestMeister); + return sGuestMeister; + } + +NPError GuestMeister::Initialize(NPNetscapeFuncs* iBrowserFuncs) + { + fNPNF.geturl = iBrowserFuncs->geturl; + fNPNF.posturl = iBrowserFuncs->posturl; + fNPNF.requestread = iBrowserFuncs->requestread; + fNPNF.newstream = iBrowserFuncs->newstream; + fNPNF.write = iBrowserFuncs->write; + fNPNF.destroystream = iBrowserFuncs->destroystream; + fNPNF.status = iBrowserFuncs->status; + fNPNF.uagent = iBrowserFuncs->uagent; + fNPNF.memalloc = iBrowserFuncs->memalloc; + fNPNF.memfree = iBrowserFuncs->memfree; + fNPNF.memflush = iBrowserFuncs->memflush; + fNPNF.reloadplugins = iBrowserFuncs->reloadplugins; + fNPNF.getJavaEnv = iBrowserFuncs->getJavaEnv; + fNPNF.getJavaPeer = iBrowserFuncs->getJavaPeer; + fNPNF.geturlnotify = iBrowserFuncs->geturlnotify; + fNPNF.posturlnotify = iBrowserFuncs->posturlnotify; + fNPNF.getvalue = iBrowserFuncs->getvalue; + fNPNF.setvalue = iBrowserFuncs->setvalue; + fNPNF.invalidaterect = iBrowserFuncs->invalidaterect; + fNPNF.invalidateregion = iBrowserFuncs->invalidateregion; + fNPNF.forceredraw = iBrowserFuncs->forceredraw; + + fNPNF.getstringidentifier = iBrowserFuncs->getstringidentifier; + fNPNF.getstringidentifiers = iBrowserFuncs->getstringidentifiers; + fNPNF.getintidentifier = iBrowserFuncs->getintidentifier; + fNPNF.identifierisstring = iBrowserFuncs->identifierisstring; + fNPNF.utf8fromidentifier = iBrowserFuncs->utf8fromidentifier; + fNPNF.intfromidentifier = iBrowserFuncs->intfromidentifier; + fNPNF.createobject = iBrowserFuncs->createobject; + fNPNF.retainobject = iBrowserFuncs->retainobject; + fNPNF.releaseobject = iBrowserFuncs->releaseobject; + fNPNF.invoke = iBrowserFuncs->invoke; + fNPNF.invokeDefault = iBrowserFuncs->invokeDefault; + fNPNF.evaluate = iBrowserFuncs->evaluate; + fNPNF.getproperty = iBrowserFuncs->getproperty; + fNPNF.setproperty = iBrowserFuncs->setproperty; + fNPNF.removeproperty = iBrowserFuncs->removeproperty; + fNPNF.hasproperty = iBrowserFuncs->hasproperty; + fNPNF.hasmethod = iBrowserFuncs->hasmethod; + fNPNF.releasevariantvalue = iBrowserFuncs->releasevariantvalue; + fNPNF.setexception = iBrowserFuncs->setexception; + + return NPERR_NO_ERROR; + } + +NPError GuestMeister::GetEntryPoints(NPPluginFuncs* oPluginFuncs) + { + oPluginFuncs->size = sizeof(NPPluginFuncs); + oPluginFuncs->version = 11; + + oPluginFuncs->newp = sNew; + oPluginFuncs->destroy = sDestroy; + oPluginFuncs->setwindow = sSetWindow; + oPluginFuncs->newstream = sNewStream; + oPluginFuncs->destroystream = sDestroyStream; + oPluginFuncs->asfile = sStreamAsFile; + oPluginFuncs->writeready = sWriteReady; + oPluginFuncs->write = sWrite; + oPluginFuncs->print = sPrint; + oPluginFuncs->event = sHandleEvent; + oPluginFuncs->urlnotify = sURLNotify; + oPluginFuncs->getvalue = sGetValue; + oPluginFuncs->setvalue = sSetValue; + + return NPERR_NO_ERROR; + } + +NPError GuestMeister::Shutdown() + { + return NPERR_NO_ERROR; + } + +const NPNetscapeFuncs& GuestMeister::GetNPNetscapeFuncs() + { return fNPNF; } + +NPError GuestMeister::sNew( + NPMIMEType pluginType, NPP instance, uint16 mode, + int16 argc, char* argn[], char* argv[], NPSavedData* saved) + { return sGet()->New(pluginType, instance, mode, argc, argn, argv, saved); } + +NPError GuestMeister::sDestroy(NPP instance, NPSavedData** save) + { return sGet()->Destroy(instance, save); } + +NPError GuestMeister::sSetWindow(NPP instance, NPWindow* window) + { return sGet()->SetWindow(instance, window); } + +NPError GuestMeister::sNewStream( + NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype) + { return sGet()->NewStream(instance, type, stream, seekable, stype); } + +NPError GuestMeister::sDestroyStream(NPP instance, NPStream* stream, NPReason reason) + { return sGet()->DestroyStream(instance, stream, reason); } + +int32 GuestMeister::sWriteReady(NPP instance, NPStream* stream) + { return sGet()->WriteReady(instance, stream); } + +int32 GuestMeister::sWrite(NPP instance, NPStream* stream, int32 offset, int32 len, void* buffer) + { return sGet()->Write(instance, stream, offset, len, buffer); } + +void GuestMeister::sStreamAsFile(NPP instance, NPStream* stream, const char* fname) + { return sGet()->StreamAsFile(instance, stream, fname); } + +void GuestMeister::sPrint(NPP instance, NPPrint* platformPrint) + { return sGet()->Print(instance, platformPrint); } + +int16 GuestMeister::sHandleEvent(NPP instance, void* event) + { return sGet()->HandleEvent(instance, event); } + +void GuestMeister::sURLNotify(NPP instance, const char* url, NPReason reason, void* notifyData) + { return sGet()->URLNotify(instance, url, reason, notifyData); } + +jref GuestMeister::sGetJavaClass() + { return sGet()->GetJavaClass(); } + +NPError GuestMeister::sGetValue(NPP instance, NPPVariable variable, void *value) + { return sGet()->GetValue(instance, variable, value); } + +NPError GuestMeister::sSetValue(NPP instance, NPNVariable variable, void *value) + { return sGet()->SetValue(instance, variable, value); } + +// ================================================================================================= +#pragma mark - +#pragma mark * Guest + +Guest::Guest(NPP iNPP, const NPNetscapeFuncs& iNPNetscapeFuncs) +: fNPP(iNPP), + fNPNF(iNPNetscapeFuncs) + { +// ZBlockZero(&fNPP, sizeof(fNPP)); +// ZBlockZero(&fNPNF, sizeof(fNPNF)); + } + +Guest::~Guest() + {} + +NPError Guest::Host_GetURL(const char* url, const char* target) + { return fNPNF.geturl(fNPP, url, target); } + +NPError Guest::Host_PostURL( + const char* url, const char* target, uint32 len, const char* buf, NPBool file) + { return fNPNF.posturl(fNPP, url, target, len, buf, file); } + +NPError Guest::Host_RequestRead(NPStream* stream, NPByteRange* rangeList) + { return fNPNF.requestread(stream, rangeList); } + +NPError Guest::Host_NewStream(NPMIMEType type, const char* target, NPStream** stream) + { return fNPNF.newstream(fNPP, type, target, stream); } + +int32 Guest::Host_Write(NPStream* stream, int32 len, void* buffer) + { return fNPNF.write(fNPP, stream, len, buffer); } + +NPError Guest::Host_DestroyStream(NPStream* stream, NPReason reason) + { return fNPNF.destroystream(fNPP, stream, reason); } + +void Guest::Host_Status(const char* message) + { return fNPNF.status(fNPP, message); } + +const char* Guest::Host_UserAgent() + { return fNPNF.uagent(fNPP); } + +void* Guest::Host_MemAlloc(uint32 size) + { return fNPNF.memalloc(size); } + +void Guest::Host_MemFree(void* ptr) + { return fNPNF.memfree(ptr); } + +uint32 Guest::Host_MemFlush(uint32 size) + { return fNPNF.memflush(size); } + +void Guest::Host_ReloadPlugins(NPBool reloadPages) + { return fNPNF.reloadplugins(reloadPages); } + +JRIEnv* Guest::Host_GetJavaEnv() + { return fNPNF.getJavaEnv(); } + +jref Guest::Host_GetJavaPeer() + { return fNPNF.getJavaPeer(fNPP); } + +NPError Guest::Host_GetURLNotify(const char* url, const char* target, void* notifyData) + { return fNPNF.geturlnotify(fNPP, url, target, notifyData); } + +NPError Guest::Host_PostURLNotify(const char* url, const char* target, + uint32 len, const char* buf, NPBool file, void* notifyData) + { return fNPNF.posturlnotify(fNPP, url, target, len, buf, file, notifyData); } + +NPError Guest::Host_GetValue(NPNVariable variable, void *value) + { return fNPNF.getvalue(fNPP, variable, value); } + +NPError Guest::Host_SetValue(NPPVariable variable, void *value) + { return fNPNF.setvalue(fNPP, variable, value); } + +void Guest::Host_InvalidateRect(NPRect *invalidRect) + { return fNPNF.invalidaterect(fNPP, invalidRect); } + +void Guest::Host_InvalidateRegion(NPRegion invalidRegion) + { return fNPNF.invalidateregion(fNPP, invalidRegion); } + +void Guest::Host_ForceRedraw() + { return fNPNF.forceredraw(fNPP); } + +NPIdentifier Guest::Host_GetStringIdentifier(const NPUTF8* name) + { return fNPNF.getstringidentifier(name); } + +void Guest::Host_GetStringIdentifiers( + const NPUTF8** names, int32_t nameCount, NPIdentifier* identifiers) + { return fNPNF.getstringidentifiers(names, nameCount, identifiers); } + +NPIdentifier Guest::Host_GetIntIdentifier(int32_t intid) + { return fNPNF.getintidentifier(intid); } + +bool Guest::Host_IdentifierIsString(NPIdentifier identifier) + { return fNPNF.identifierisstring(identifier); } + +NPUTF8* Guest::Host_UTF8FromIdentifier(NPIdentifier identifier) + { return fNPNF.utf8fromidentifier(identifier); } + +int32_t Guest::Host_IntFromIdentifier(NPIdentifier identifier) + { return reinterpret_cast<int32_t>(fNPNF.intfromidentifier(identifier)); } + +NPObject* Guest::Host_CreateObject(NPClass* aClass) + { return fNPNF.createobject(fNPP, aClass); } + +NPObject* Guest::Host_RetainObject(NPObject* obj) + { return fNPNF.retainobject(obj); } + +void Guest::Host_ReleaseObject(NPObject* obj) + { return fNPNF.releaseobject(obj); } + +bool Guest::Host_Invoke(NPObject* obj, + NPIdentifier methodName, const NPVariant* args, unsigned argCount, NPVariant* result) + { return fNPNF.invoke(fNPP, obj, methodName, args, argCount, result); } + +bool Guest::Host_InvokeDefault( + NPObject* obj, const NPVariant* args, unsigned argCount, NPVariant* result) + { return fNPNF.invokeDefault(fNPP, obj, args, argCount, result); } + +bool Guest::Host_Evaluate(NPObject* obj, NPString* script, NPVariant* result) + { return fNPNF.evaluate(fNPP, obj, script, result); } + +bool Guest::Host_GetProperty(NPObject* obj, NPIdentifier propertyName, NPVariant* result) + { return fNPNF.getproperty(fNPP, obj, propertyName, result); } + +bool Guest::Host_SetProperty(NPObject* obj, NPIdentifier propertyName, const NPVariant* value) + { return fNPNF.setproperty(fNPP, obj, propertyName, value); } + +bool Guest::Host_RemoveProperty(NPObject* obj, NPIdentifier propertyName) + { return fNPNF.removeproperty(fNPP, obj, propertyName); } + +bool Guest::Host_HasProperty(NPObject* npobj, NPIdentifier propertyName) + { return fNPNF.hasproperty(fNPP, npobj, propertyName); } + +bool Guest::Host_HasMethod(NPObject* npobj, NPIdentifier methodName) + { return fNPNF.hasmethod(fNPP, npobj, methodName); } + +void Guest::Host_ReleaseVariantValue(NPVariant* variant) + { return fNPNF.releasevariantvalue(variant); } + +void Guest::Host_SetException(NPObject* obj, const NPUTF8* message) + { return fNPNF.setexception(obj, message); } + +} // namespace ZNetscape Added: trunk/zoolib/source/cxx/zoolib/ZNetscape_Guest.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNetscape_Guest.h (rev 0) +++ trunk/zoolib/source/cxx/zoolib/ZNetscape_Guest.h 2008-11-16 01:12:44 UTC (rev 201) @@ -0,0 +1,220 @@ +/* ------------------------------------------------------------------------------------------------- +Copyright (c) 2002 Andrew Green +http://www.zoolib.org + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software +and associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +------------------------------------------------------------------------------------------------- */ + +#ifndef __ZNetscape_Guest__ +#define __ZNetscape_Guest__ 1 +#include "zconfig.h" + +#include "zoolib/ZCompat_npapi.h" + +namespace ZNetscape { + +// ================================================================================================= +#pragma mark - +#pragma mark * GuestMeister + +// You must have a concrete instance of a subclass of GuestMeister in your project +class GuestMeister + { +protected: + GuestMeister(); + +public: + virtual ~GuestMeister(); + + static GuestMeister* sGet(); + + virtual NPError Initialize(NPNetscapeFuncs* iNPNF); + virtual NPError GetEntryPoints(NPPluginFuncs* oPluginFuncs); + virtual NPError Shutdown(); + + const NPNetscapeFuncs& GetNPNetscapeFuncs(); + + virtual NPError New( + NPMIMEType pluginType, NPP instance, uint16 mode, + int16 argc, char* argn[], char* argv[], NPSavedData* saved) = 0; + + virtual NPError Destroy(NPP instance, NPSavedData** ave) = 0; + + virtual NPError SetWindow(NPP instance, NPWindow* window) = 0; + + virtual NPError NewStream(NPP instance, + NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype) = 0; + + virtual NPError DestroyStream(NPP instance, NPStream* stream, NPReason reason) = 0; + + virtual int32 WriteReady(NPP instance, NPStream* stream) = 0; + + virtual int32 Write(NPP instance, NPStream* stream, int32 offset, int32 len, void* buffer) = 0; + + virtual void StreamAsFile(NPP instance, NPStream* stream, const char* fname) = 0; + + virtual void Print(NPP instance, NPPrint* platformPrint) = 0; + + virtual int16 HandleEvent(NPP instance, void* event) = 0; + + virtual void URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData) = 0; + + virtual jref GetJavaClass() = 0; + + virtual NPError GetValue(NPP instance, NPPVariable variable, void *value) = 0; + + virtual NPError SetValue(NPP instance, NPNVariable variable, void *value) = 0; + +private: + static NPError sNew( + NPMIMEType pluginType, NPP instance, uint16 mode, + int16 argc, char* argn[], char* argv[], NPSavedData* saved); + + static NPError sDestroy(NPP instance, NPSavedData** save); + + static NPError sSetWindow(NPP instance, NPWindow* window); + + static NPError sNewStream(NPP instance, + NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype); + + static NPError sDestroyStream(NPP instance, NPStream* stream, NPReason reason); + + static int32 sWriteReady(NPP instance, NPStream* stream); + + static int32 sWrite(NPP instance, NPStream* stream, int32 offset, int32 len, void* buffer); + + static void sStreamAsFile(NPP instance, NPStream* stream, const char* fname); + + static void sPrint(NPP instance, NPPrint* platformPrint); + + static int16 sHandleEvent(NPP instance, void* event); + + static void sURLNotify(NPP instance, const char* url, NPReason reason, void* notifyData); + + static jref sGetJavaClass(); + + static NPError sGetValue(NPP instance, NPPVariable variable, void *value); + + static NPError sSetValue(NPP instance, NPNVariable variable, void *value); + + NPNetscapeFuncs fNPNF; + }; + +// ================================================================================================= +#pragma mark - +#pragma mark * Guest + +class Guest + { +protected: + Guest(NPP iNPP, const NPNetscapeFuncs& iNPNetscapeFuncs); + +public: + virtual ~Guest(); + + NPError Host_GetURL(const char* url, const char* target); + + NPError Host_PostURL( + const char* url, const char* target, uint32 len, const char* buf, NPBool file); + + NPError Host_RequestRead(NPStream* stream, NPByteRange* rangeList); + + NPError Host_NewStream(NPMIMEType type, const char* target, NPStream** stream); + + int32 Host_Write(NPStream* stream, int32 len, void* buffer); + + NPError Host_DestroyStream(NPStream* stream, NPReason reason); + + void Host_Status(const char* message); + + const char* Host_UserAgent(); + + void* Host_MemAlloc(uint32 size); + + void Host_MemFree(void* ptr); + + uint32 Host_MemFlush(uint32 size); + + void Host_ReloadPlugins(NPBool reloadPages); + + JRIEnv* Host_GetJavaEnv(); + + jref Host_GetJavaPeer(); + + NPError Host_GetURLNotify(const char* url, const char* target, void* notifyData); + + NPError Host_PostURLNotify(const char* url, const char* target, + uint32 len, const char* buf, NPBool file, void* notifyData); + + NPError Host_GetValue(NPNVariable variable, void *value); + + NPError Host_SetValue(NPPVariable variable, void *value); + + void Host_InvalidateRect(NPRect *invalidRect); + + void Host_InvalidateRegion(NPRegion invalidRegion); + + void Host_ForceRedraw(); + + NPIdentifier Host_GetStringIdentifier(const NPUTF8* name); + + void Host_GetStringIdentifiers( + const NPUTF8** names, int32_t nameCount, NPIdentifier* identifiers); + + NPIdentifier Host_GetIntIdentifier(int32_t intid); + + bool Host_IdentifierIsString(NPIdentifier identifier); + + NPUTF8* Host_UTF8FromIdentifier(NPIdentifier identifier); + + int32_t Host_IntFromIdentifier(NPIdentifier identifier); + + NPObject* Host_CreateObject(NPClass* aClass); + + NPObject* Host_RetainObject(NPObject* obj); + + void Host_ReleaseObject(NPObject* obj); + + bool Host_Invoke(NPObject* obj, + NPIdentifier methodName, const NPVariant* args, unsigned argCount, NPVariant* result); + + bool Host_InvokeDefault( + NPObject* obj, const NPVariant* args, unsigned argCount, NPVariant* result); + + bool Host_Evaluate(NPObject* obj, NPString* script, NPVariant* result); + + bool Host_GetProperty(NPObject* obj, NPIdentifier propertyName, NPVariant* result); + + bool Host_SetProperty(NPObject* obj, NPIdentifier propertyName, const NPVariant* value); + + bool Host_RemoveProperty(NPObject* obj, NPIdentifier propertyName); + + bool Host_HasProperty(NPObject* npobj, NPIdentifier propertyName); + + bool Host_HasMethod(NPObject* npobj, NPIdentifier methodName); + + void Host_ReleaseVariantValue(NPVariant* variant); + + void Host_SetException(NPObject* obj, const NPUTF8* message); + +private: + NPP fNPP; + NPNetscapeFuncs fNPNF; + }; + +} // namespace ZNetscape + +#endif // __ZNetscape_Guest__ Added: trunk/zoolib/source/cxx/zoolib/ZNetscape_Guest_Std.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNetscape_Guest_Std.cpp (rev 0) +++ trunk/zoolib/source/cxx/zoolib/ZNetscape_Guest_Std.cpp 2008-11-16 01:12:44 UTC (rev 201) @@ -0,0 +1,150 @@ +/* ------------------------------------------------------------------------------------------------- +Copyright (c) 2008 Andrew Green +http://www.zoolib.org + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software +and associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +------------------------------------------------------------------------------------------------- */ + +#include "zoolib/ZNetscape_Guest_Std.h" + +#include "zoolib/ZDebug.h" +#include "zoolib/ZMemory.h" + +namespace ZNetscape { + +// ================================================================================================= +#pragma mark - +#pragma mark * GuestMeister + +static Guest_Std* sGuest(NPP instance) + { return static_cast<Guest_Std*>(instance->pdata); } + +GuestMeister_Std::GuestMeister_Std() + {} + +GuestMeister_Std::~GuestMeister_Std() + {} + +NPError GuestMeister_Std::New( + NPMIMEType pluginType, NPP instance, uint16 mode, + int16 argc, char* argn[], char* argv[], NPSavedData* saved) + { + try + { + Guest_Std* theG = this->MakeGuest(pluginType, instance, mode, argc, argn, argv, saved); + instance->pdata = theG; + } + catch (...) + { + return NPERR_GENERIC_ERROR; + } + return NPERR_NO_ERROR; + } + +NPError GuestMeister_Std::Destroy(NPP instance, NPSavedData** save) + { return sGuest(instance)->Guest_Destroy(save); } + +NPError GuestMeister_Std::SetWindow(NPP instance, NPWindow* window) + { return sGuest(instance)->Guest_SetWindow(window); } + +NPError GuestMeister_Std::NewStream(NPP instance, + NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype) + { return sGuest(instance)->Guest_NewStream(type, stream, seekable, stype); } + +NPError GuestMeister_Std::DestroyStream(NPP instance, NPStream* stream, NPReason reason) + { return sGuest(instance)->Guest_DestroyStream(stream, reason); } + +int32 GuestMeister_Std::WriteReady(NPP instance, NPStream* stream) + { return sGuest(instance)->Guest_WriteReady(stream); } + +int32 GuestMeister_Std::Write(NPP instance, + NPStream* stream, int32 offset, int32 len, void* buffer) + { return sGuest(instance)->Guest_Write(stream, offset, len, buffer); } + +void GuestMeister_Std::StreamAsFile(NPP instance, NPStream* stream, const char* fname) + { return sGuest(instance)->Guest_StreamAsFile(stream, fname); } + +void GuestMeister_Std::Print(NPP instance, NPPrint* platformPrint) + { return sGuest(instance)->Guest_Print(platformPrint); } + +int16 GuestMeister_Std::HandleEvent(NPP instance, void* event) + { return sGuest(instance)->Guest_HandleEvent(event); } + +void GuestMeister_Std::URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData) + { return sGuest(instance)->Guest_URLNotify(url, reason, notifyData); } + +jref GuestMeister_Std::GetJavaClass() + { return nil; } + +NPError GuestMeister_Std::GetValue(NPP instance, NPPVariable variable, void *value) + { return sGuest(instance)->Guest_GetValue(variable, value); } + +NPError GuestMeister_Std::SetValue(NPP instance, NPNVariable variable, void *value) + { return sGuest(instance)->Guest_SetValue(variable, value); } + +// ================================================================================================= +#pragma mark - +#pragma mark * Guest_Std + +Guest_Std::Guest_Std(NPP iNPP, const NPNetscapeFuncs& iNPNetscapeFuncs) +: Guest(iNPP, iNPNetscapeFuncs) + {} + +Guest_Std::~Guest_Std() + {} + +NPError Guest_Std::Guest_Destroy(NPSavedData** save) + { return NPERR_NO_ERROR; } + +NPError Guest_Std::Guest_SetWindow(NPWindow* window) + { return NPERR_GENERIC_ERROR; } + +NPError Guest_Std::Guest_NewStream( + NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype) + { return NPERR_GENERIC_ERROR; } + +NPError Guest_Std::Guest_DestroyStream(NPStream* stream, NPReason reason) + { return NPERR_GENERIC_ERROR; } + +int32 Guest_Std::Guest_WriteReady(NPStream* stream) + { return 0; } + +int32 Guest_Std::Guest_Write(NPStream* stream, int32 offset, int32 len, void* buffer) + { return 0; } + +void Guest_Std::Guest_StreamAsFile(NPStream* stream, const char* fname) + {} + +void Guest_Std::Guest_Print(NPPrint* platformPrint) + {} + +int16 Guest_Std::Guest_HandleEvent(void* event) + { + return 0; // ?? + } + +void Guest_Std::Guest_URLNotify(const char* url, NPReason reason, void* notifyData) + { + ZUnimplemented(); + } + +NPError Guest_Std::Guest_GetValue(NPPVariable variable, void *value) + { return NPERR_GENERIC_ERROR; } + +NPError Guest_Std::Guest_SetValue(NPNVariable variable, void *value) + { return NPERR_GENERIC_ERROR; } + +} // namespace ZNetscape Added: trunk/zoolib/source/cxx/zoolib/ZNetscape_Guest_Std.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNetscape_Guest_Std.h (rev 0) +++ trunk/zoolib/source/cxx/zoolib/ZNetscape_Guest_Std.h 2008-11-16 01:12:44 UTC (rev 201) @@ -0,0 +1,122 @@ +/* ------------------------------------------------------------------------------------------------- +Copyright (c) 2008 Andrew Green +http://www.zoolib.org + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software +and associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +------------------------------------------------------------------------------------------------- */ + +#ifndef __ZNetscape_Guest_Std__ +#define __ZNetscape_Guest_Std__ 1 +#include "zconfig.h" + +#include "zoolib/ZNetscape_Guest.h" + +namespace ZNetscape { + +class Guest_Std; + +// ================================================================================================= +#pragma mark - +#pragma mark * GuestMeister_Std + +class GuestMeister_Std : public GuestMeister + { +protected: + GuestMeister_Std(); + +public: + virtual ~GuestMeister_Std(); + +// From GuestMeister + virtual NPError New( + NPMIMEType pluginType, NPP instance, uint16 mode, + int16 argc, char* argn[], char* argv[], NPSavedData* saved); + + virtual NPError Destroy(NPP instance, NPSavedData** save); + + virtual NPError SetWindow(NPP instance, NPWindow* window); + + virtual NPError NewStream(NPP instance, + NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype); + + virtual NPError DestroyStream(NPP instance, NPStream* stream, NPReason reason); + + virtual int32 WriteReady(NPP instance, NPStream* stream); + + virtual int32 Write(NPP instance, NPStream* stream, int32 offset, int32 len, void* buffer); + + virtual void StreamAsFile(NPP instance, NPStream* stream, const char* fname); + + virtual void Print(NPP instance, NPPrint* platformPrint); + + virtual int16 HandleEvent(NPP instance, void* event); + + virtual void URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData); + + virtual jref GetJavaClass(); + + virtual NPError GetValue(NPP instance, NPPVariable variable, void *value); + + virtual NPError SetValue(NPP instance, NPNVariable variable, void *value); + +// Our protocol + virtual Guest_Std* MakeGuest( + NPMIMEType pluginType, NPP instance, uint16 mode, + int16 argc, char* argn[], char* argv[], NPSavedData* saved) = 0; + }; + +// ================================================================================================= +#pragma mark - +#pragma mark * Guest_Std + +class Guest_Std : public Guest + { +protected: + Guest_Std(NPP iNPP, const NPNetscapeFuncs& iNPNetscapeFuncs); + +public: + virtual ~Guest_Std(); + +// Our protocol + virtual NPError Guest_Destroy(NPSavedData** save); + + virtual NPError Guest_SetWindow(NPWindow* window); + + virtual NPError Guest_NewStream( + NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype); + + virtual NPError Guest_DestroyStream(NPStream* stream, NPReason reason); + + virtual int32 Guest_WriteReady(NPStream* stream); + + virtual int32 Guest_Write(NPStream* stream, int32 offset, int32 len, void* buffer); + + virtual void Guest_StreamAsFile(NPStream* stream, const char* fname); + + virtual void Guest_Print(NPPrint* platformPrint); + + virtual int16 Guest_HandleEvent(void* event); + + virtual void Guest_URLNotify(const char* url, NPReason reason, void* notifyData); + + virtual NPError Guest_GetValue(NPPVariable variable, void *value); + + virtual NPError Guest_SetValue(NPNVariable variable, void *value); + }; + +} // namespace ZNetscape + +#endif // __ZNetscape_Guest__ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-11-17 20:19:59
|
Revision: 216 http://zoolib.svn.sourceforge.net/zoolib/?rev=216&view=rev Author: agreen Date: 2008-11-17 20:19:57 +0000 (Mon, 17 Nov 2008) Log Message: ----------- Remove ZNSPlugin stuff. Removed Paths: ------------- trunk/zoolib/source/cxx/zoolib/ZNSPlugin.cpp trunk/zoolib/source/cxx/zoolib/ZNSPlugin.def trunk/zoolib/source/cxx/zoolib/ZNSPlugin.h Deleted: trunk/zoolib/source/cxx/zoolib/ZNSPlugin.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNSPlugin.cpp 2008-11-17 20:19:32 UTC (rev 215) +++ trunk/zoolib/source/cxx/zoolib/ZNSPlugin.cpp 2008-11-17 20:19:57 UTC (rev 216) @@ -1,1196 +0,0 @@ -#include "zoolib/ZDebug.h" -#include "zoolib/ZNSPlugin.h" - -#if ZCONFIG(OS, MacOS7) || ZCONFIG(OS, Carbon) -# include <CodeFragments.h> -# include <Gestalt.h> -# include <Processes.h> -# include <Resources.h> -# include <Sound.h> -#endif - -#if ZCONFIG(OS, POSIX) -#endif - -#define kDebug_NSPlugin 0 - -ZNSPluginMeister* ZNSPlugin::sMeister; - -// ================================================================================================= -#define USE_UPP (TARGET_RT_MAC_CFM && !TARGET_API_MAC_CARBON) - -#if USE_UPP -# define CreateUPP(proc, func)(proc##_UPP)NewRoutineDescriptor((ProcPtr)func, proc##_ProcInfo, GetCurrentArchitecture()) -#else -# define CreateUPP(proc, func) func -#endif - -// ================================================================================================= -// 0 Arguments ----- - -#define Priv_DefineProcPtr0(ret, proc) \ - typedef ret(*proc##_ProcPtr)() - -#if USE_UPP -# define Call0(ret, proc, upp) \ - (ret) CallUniversalProc(upp, proc##_ProcInfo) -# define Priv_DefineUPP0(ret, proc) \ - typedef UniversalProcPtr proc##_UPP; \ - enum \ - { \ - proc##_ProcInfo = kThinkCStackBased \ - | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(0)) \ - | RESULT_SIZE(SIZE_CODE(sizeof(ret))) \ - }; - -# define Priv_DefineUPP0_Void(proc) \ - typedef UniversalProcPtr proc##_UPP; \ - enum \ - { \ - proc##_ProcInfo = kThinkCStackBased \ - | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(0)) \ - }; -#else -# define Call0(ret, proc, upp) \ - upp() -# define Priv_DefineUPP0(ret, proc) \ - typedef proc##_ProcPtr proc##_UPP - -# define Priv_DefineUPP0_Void(proc) \ - typedef proc##_ProcPtr proc##_UPP -#endif -#define DefineProc0(ret, upp) \ - Priv_DefineProcPtr0(ret, upp); \ - Priv_DefineUPP0(ret, upp) -#define DefineProc0_Void(upp) \ - Priv_DefineProcPtr0(void, upp); \ - Priv_DefineUPP0_Void(upp) - -// ================================================================================================= -// 1 Argument - -#define Priv_DefineProcPtr1(ret, proc, arg1) \ - typedef ret(*proc##_ProcPtr)(arg1) - -#if USE_UPP - #define Call1(ret, proc, upp, arg1) \ - (ret) CallUniversalProc(upp, proc##_ProcInfo, arg1) - #define Priv_DefineUPP1(ret, proc, arg1) \ - typedef UniversalProcPtr proc##_UPP; \ - enum \ - { \ - proc##_ProcInfo = kThinkCStackBased \ - | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(arg1))) \ - | RESULT_SIZE(SIZE_CODE(sizeof(ret))) \ - }; - #define Priv_DefineUPP1_Void(proc, arg1) \ - typedef UniversalProcPtr proc##_UPP; \ - enum \ - { \ - proc##_ProcInfo = kThinkCStackBased \ - | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(arg1))) \ - }; -#else - #define Call1(ret, proc, upp, arg1) \ - upp(arg1) - #define Priv_DefineUPP1(ret, proc, arg1) \ - typedef proc##_ProcPtr proc##_UPP - #define Priv_DefineUPP1_Void(proc, arg1) \ - typedef proc##_ProcPtr proc##_UPP -#endif -#define DefineProc1(ret, upp, arg1) \ - Priv_DefineProcPtr1(ret, upp, arg1); \ - Priv_DefineUPP1(ret, upp, arg1) - -#define DefineProc1_Void(upp, arg1) \ - Priv_DefineProcPtr1(void, upp, arg1); \ - Priv_DefineUPP1_Void(upp, arg1) - -// ================================================================================================= -// 2 Arguments - -#define Priv_DefineProcPtr2(ret, proc, arg1, arg2) \ - typedef ret(*proc##_ProcPtr)(arg1, arg2) - -#if USE_UPP - #define Call2(ret, proc, upp, arg1, arg2) \ - (ret) CallUniversalProc(upp, proc##_ProcInfo, arg1, arg2) - #define Priv_DefineUPP2(ret, proc, arg1, arg2) \ - typedef UniversalProcPtr proc##_UPP; \ - enum \ - { \ - proc##_ProcInfo = kThinkCStackBased \ - | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(arg1))) \ - | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(arg2))) \ - | RESULT_SIZE(SIZE_CODE(sizeof(ret))) \ - }; - #define Priv_DefineUPP2_Void(proc, arg1, arg2) \ - typedef UniversalProcPtr proc##_UPP; \ - enum \ - { \ - proc##_ProcInfo = kThinkCStackBased \ - | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(arg1))) \ - | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(arg2))) \ - }; -#else - #define Call2(ret, proc, upp, arg1, arg2) \ - upp(arg1, arg2) - #define Priv_DefineUPP2(ret, proc, arg1, arg2) \ - typedef proc##_ProcPtr proc##_UPP - #define Priv_DefineUPP2_Void(proc, arg1, arg2) \ - typedef proc##_ProcPtr proc##_UPP -#endif -#define DefineProc2(ret, upp, arg1, arg2) \ - Priv_DefineProcPtr2(ret, upp, arg1, arg2); \ - Priv_DefineUPP2(ret, upp, arg1, arg2) -#define DefineProc2_Void(upp, arg1, arg2) \ - Priv_DefineProcPtr2(void, upp, arg1, arg2); \ - Priv_DefineUPP2_Void(upp, arg1, arg2) - -// ================================================================================================= -// 3 Arguments - -#define Priv_DefineProcPtr3(ret, proc, arg1, arg2, arg3) \ - typedef ret(*proc##_ProcPtr)(arg1, arg2, arg3) - -#if USE_UPP - #define Call3(ret, proc, upp, arg1, arg2, arg3) \ - (ret) CallUniversalProc(upp, proc##_ProcInfo, arg1, arg2, arg3) - #define Priv_DefineUPP3(ret, proc, arg1, arg2, arg3) \ - typedef UniversalProcPtr proc##_UPP; \ - enum \ - { \ - proc##_ProcInfo = kThinkCStackBased \ - | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(arg1))) \ - | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(arg2))) \ - | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(arg3))) \ - | RESULT_SIZE(SIZE_CODE(sizeof(ret))) \ - }; - #define Priv_DefineUPP3_Void(proc, arg1, arg2, arg3) \ - typedef UniversalProcPtr proc##_UPP; \ - enum \ - { \ - proc##_ProcInfo = kThinkCStackBased \ - | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(arg1))) \ - | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(arg2))) \ - | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(arg3))) \ - }; -#else - #define Call3(ret, proc, upp, arg1, arg2, arg3) \ - upp(arg1, arg2, arg3) - #define Priv_DefineUPP3(ret, proc, arg1, arg2, arg3) \ - typedef proc##_ProcPtr proc##_UPP - #define Priv_DefineUPP3_Void(proc, arg1, arg2, arg3) \ - typedef proc##_ProcPtr proc##_UPP -#endif -#define DefineProc3(ret, upp, arg1, arg2, arg3) \ - Priv_DefineProcPtr3(ret, upp, arg1, arg2, arg3); \ - Priv_DefineUPP3(ret, upp, arg1, arg2, arg3) -#define DefineProc3_Void(upp, arg1, arg2, arg3) \ - Priv_DefineProcPtr3(void, upp, arg1, arg2, arg3); \ - Priv_DefineUPP3_Void(upp, arg1, arg2, arg3) - -// ================================================================================================= -// 4 Arguments - -#define Priv_DefineProcPtr4(ret, proc, arg1, arg2, arg3, arg4) \ - typedef ret(*proc##_ProcPtr)(arg1, arg2, arg3, arg4) - -#if USE_UPP - #define Call4(ret, proc, upp, arg1, arg2, arg3, arg4) \ - (ret) CallUniversalProc(upp, proc##_ProcInfo, arg1, arg2, arg3, arg4) - #define Priv_DefineUPP4(ret, proc, arg1, arg2, arg3, arg4) \ - typedef UniversalProcPtr proc##_UPP; \ - enum \ - { \ - proc##_ProcInfo = kThinkCStackBased \ - | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(arg1))) \ - | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(arg2))) \ - | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(arg3))) \ - | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(arg4))) \ - | RESULT_SIZE(SIZE_CODE(sizeof(ret))) \ - }; - #define Priv_DefineUPP4_Void(proc, arg1, arg2, arg3, arg4) \ - typedef UniversalProcPtr proc##_UPP; \ - enum \ - { \ - proc##_ProcInfo = kThinkCStackBased \ - | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(arg1))) \ - | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(arg2))) \ - | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(arg3))) \ - | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(arg4))) \ - }; -#else - #define Call4(ret, proc, upp, arg1, arg2, arg3, arg4) \ - upp(arg1, arg2, arg3, arg4) - #define Priv_DefineUPP4(ret, proc, arg1, arg2, arg3, arg4) \ - typedef proc##_ProcPtr proc##_UPP - #define Priv_DefineUPP4_Void(proc, arg1, arg2, arg3, arg4) \ - typedef proc##_ProcPtr proc##_UPP -#endif -#define DefineProc4(ret, upp, arg1, arg2, arg3, arg4) \ - Priv_DefineProcPtr4(ret, upp, arg1, arg2, arg3, arg4); \ - Priv_DefineUPP4(ret, upp, arg1, arg2, arg3, arg4) -#define DefineProc4_Void(upp, arg1, arg2, arg3, arg4) \ - Priv_DefineProcPtr4(void, upp, arg1, arg2, arg3, arg4); \ - Priv_DefineUPP4_Void(upp, arg1, arg2, arg3, arg4) - -// ================================================================================================= -// 5 Arguments - -#define Priv_DefineProcPtr5(ret, proc, arg1, arg2, arg3, arg4, arg5) \ - typedef ret(*proc##_ProcPtr)(arg1, arg2, arg3, arg4, arg5) - -#if USE_UPP - #define Call5(ret, proc, upp, arg1, arg2, arg3, arg4, arg5) \ - (ret) CallUniversalProc(upp, proc##_ProcInfo, arg1, arg2, arg3, arg4, arg5) - #define Priv_DefineUPP5(ret, proc, arg1, arg2, arg3, arg4, arg5) \ - typedef UniversalProcPtr proc##_UPP; \ - enum \ - { \ - proc##_ProcInfo = kThinkCStackBased \ - | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(arg1))) \ - | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(arg2))) \ - | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(arg3))) \ - | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(arg4))) \ - | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(arg5))) \ - | RESULT_SIZE(SIZE_CODE(sizeof(ret))) \ - }; -#else - #define Call5(ret, proc, upp, arg1, arg2, arg3, arg4, arg5) \ - upp(arg1, arg2, arg3, arg4, arg5) - #define Priv_DefineUPP5(ret, proc, arg1, arg2, arg3, arg4, arg5) \ - typedef proc##_ProcPtr proc##_UPP -#endif -#define DefineProc5(ret, upp, arg1, arg2, arg3, arg4, arg5) \ - Priv_DefineProcPtr5(ret, upp, arg1, arg2, arg3, arg4, arg5); \ - Priv_DefineUPP5(ret, upp, arg1, arg2, arg3, arg4, arg5) - -// ================================================================================================= -// 6 Arguments - -#define Priv_DefineProcPtr6(ret, proc, arg1, arg2, arg3, arg4, arg5, arg6) \ - typedef ret(*proc##_ProcPtr)(arg1, arg2, arg3, arg4, arg5, arg6) - -#if USE_UPP - #define Call6(ret, proc, upp, arg1, arg2, arg3, arg4, arg5, arg6) \ - (ret) CallUniversalProc(upp, proc##_ProcInfo, arg1, arg2, arg3, arg4, arg5, arg6) - #define Priv_DefineUPP6(ret, proc, arg1, arg2, arg3, arg4, arg5, arg6) \ - typedef UniversalProcPtr proc##_UPP; \ - enum \ - { \ - proc##_ProcInfo = kThinkCStackBased \ - | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(arg1))) \ - | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(arg2))) \ - | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(arg3))) \ - | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(arg4))) \ - | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(arg5))) \ - | STACK_ROUTINE_PARAMETER(6, SIZE_CODE(sizeof(arg6))) \ - | RESULT_SIZE(SIZE_CODE(sizeof(ret))) \ - }; -#else - #define Call6(ret, proc, upp, arg1, arg2, arg3, arg4, arg5, arg6) \ - upp(arg1, arg2, arg3, arg4, arg5, arg6) - #define Priv_DefineUPP6(ret, proc, arg1, arg2, arg3, arg4, arg5, arg6) \ - typedef proc##_ProcPtr proc##_UPP -#endif -#define DefineProc6(ret, upp, arg1, arg2, arg3, arg4, arg5, arg6) \ - Priv_DefineProcPtr6(ret, upp, arg1, arg2, arg3, arg4, arg5, arg6); \ - Priv_DefineUPP6(ret, upp, arg1, arg2, arg3, arg4, arg5, arg6) - -// ================================================================================================= -// 7 Arguments - -#define Priv_DefineProcPtr7(ret, proc, arg1, arg2, arg3, arg4, arg5, arg6, arg7) \ - typedef ret(*proc##_ProcPtr)(arg1, arg2, arg3, arg4, arg5, arg6, arg7) - -#if USE_UPP - #define Call7(ret, proc, upp, arg1, arg2, arg3, arg4, arg5, arg6, arg7) \ - (ret) CallUniversalProc(upp, proc##_ProcInfo, arg1, arg2, arg3, arg4, arg5, arg6, arg7) - #define Priv_DefineUPP7(ret, proc, arg1, arg2, arg3, arg4, arg5, arg6, arg7) \ - typedef UniversalProcPtr proc##_UPP; \ - enum \ - { \ - proc##_ProcInfo = kThinkCStackBased \ - | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(arg1))) \ - | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(arg2))) \ - | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(arg3))) \ - | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(arg4))) \ - | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(arg5))) \ - | STACK_ROUTINE_PARAMETER(6, SIZE_CODE(sizeof(arg6))) \ - | STACK_ROUTINE_PARAMETER(7, SIZE_CODE(sizeof(arg7))) \ - | RESULT_SIZE(SIZE_CODE(sizeof(ret))) \ - }; -#else - #define Call7(ret, proc, upp, arg1, arg2, arg3, arg4, arg5, arg6, arg7) \ - upp(arg1, arg2, arg3, arg4, arg5, arg6, arg7) - #define Priv_DefineUPP7(ret, proc, arg1, arg2, arg3, arg4, arg5, arg6, arg7) \ - typedef proc##_ProcPtr proc##_UPP -#endif -#define DefineProc7(ret, upp, arg1, arg2, arg3, arg4, arg5, arg6, arg7) \ - Priv_DefineProcPtr7(ret, upp, arg1, arg2, arg3, arg4, arg5, arg6, arg7); \ - Priv_DefineUPP7(ret, upp, arg1, arg2, arg3, arg4, arg5, arg6, arg7) - -// ================================================================================================= -// Plugin entry points - -DefineProc0_Void(Dispatch_Shutdown); -DefineProc7(ZNSPlugin::EError, Dispatch_New, const char*, ZNSPlugin::NPP, ZNSPlugin::EMode, int16, const char**, const char**, ZNSPlugin::NPSavedData*); -DefineProc2(ZNSPlugin::EError, Dispatch_Destroy, ZNSPlugin::NPP, ZNSPlugin::NPSavedData*&); -DefineProc2(ZNSPlugin::EError, Dispatch_SetWindow, ZNSPlugin::NPP, ZNSPlugin::NPWindow*); -DefineProc5(ZNSPlugin::EError, Dispatch_NewStream, ZNSPlugin::NPP, const char*, ZNSPlugin::NPStream*, ZNSPlugin::NPBool, ZNSPlugin::EStreamType&); -DefineProc3(ZNSPlugin::EError, Dispatch_DestroyStream, ZNSPlugin::NPP, ZNSPlugin::NPStream*, ZNSPlugin::EReason); -DefineProc2(int32, Dispatch_WriteReady, ZNSPlugin::NPP, ZNSPlugin::NPStream*); -DefineProc5(int32, Dispatch_Write, ZNSPlugin::NPP, ZNSPlugin::NPStream*, int32, int32, const void*); -DefineProc3_Void(Dispatch_StreamAsFile, ZNSPlugin::NPP, ZNSPlugin::NPStream*, const char*); -DefineProc2_Void(Dispatch_Print, ZNSPlugin::NPP, ZNSPlugin::NPPrint&); -DefineProc2(int16, Dispatch_HandleEvent, ZNSPlugin::NPP, void*); -DefineProc4_Void(Dispatch_URLNotify, ZNSPlugin::NPP, const char*, ZNSPlugin::EReason, void*); -DefineProc3(ZNSPlugin::EError, Dispatch_GetValue, ZNSPlugin::NPP, ZNSPlugin::NPPVariable, void*); -DefineProc3(ZNSPlugin::EError, Dispatch_SetValue, ZNSPlugin::NPP, ZNSPlugin::NPNVariable, void*); - -// Netscape entry points - -DefineProc3(ZNSPlugin::EError, Navigator_GetValue, ZNSPlugin::NPP, ZNSPlugin::NPNVariable, void*); -DefineProc3(ZNSPlugin::EError, Navigator_SetValue, ZNSPlugin::NPP, ZNSPlugin::NPPVariable, void*); -DefineProc4(ZNSPlugin::EError, Navigator_GetURLNotify, ZNSPlugin::NPP, const char*, const char*, void*); -DefineProc7(ZNSPlugin::EError, Navigator_PostURLNotify, ZNSPlugin::NPP, const char*, const char*, uint32, const char*, ZNSPlugin::NPBool, void*); -DefineProc3(ZNSPlugin::EError, Navigator_GetURL, ZNSPlugin::NPP, const char*, const char*); -DefineProc6(ZNSPlugin::EError, Navigator_PostURL, ZNSPlugin::NPP, const char*, const char*, uint32, const char*, ZNSPlugin::NPBool); -DefineProc2(ZNSPlugin::EError, Navigator_RequestRead, ZNSPlugin::NPStream*, ZNSPlugin::NPByteRange*); -DefineProc4(ZNSPlugin::EError, Navigator_NewStream, ZNSPlugin::NPP, const char*, const char*, ZNSPlugin::NPStream**); -DefineProc4(int32, Navigator_Write, ZNSPlugin::NPP, ZNSPlugin::NPStream*, int32, const void*); -DefineProc3(ZNSPlugin::EError, Navigator_DestroyStream, ZNSPlugin::NPP, ZNSPlugin::NPStream*, ZNSPlugin::EReason); -DefineProc2_Void(Navigator_Status, ZNSPlugin::NPP, const char*); -DefineProc1(const char*, Navigator_UserAgent, ZNSPlugin::NPP); -DefineProc1(void*, Navigator_MemAlloc, uint32); -DefineProc1_Void(Navigator_MemFree, void*); -DefineProc1(uint32, Navigator_MemFlush, uint32); -DefineProc1_Void(Navigator_ReloadPlugins, ZNSPlugin::NPBool); -DefineProc0(ZNSPlugin::JRIEnv*, Navigator_GetJavaEnv); -DefineProc1(ZNSPlugin::jref, Navigator_GetJavaPeer, ZNSPlugin::NPP); -DefineProc2_Void(Navigator_InvalidateRect, ZNSPlugin::NPP, const ZNSPlugin::NPRect&); -DefineProc2_Void(Navigator_InvalidateRegion, ZNSPlugin::NPP, ZNSPlugin::NPRegion); -DefineProc1_Void(Navigator_ForceRedraw, ZNSPlugin::NPP); - -#if ZCONFIG(OS, MacOS7) || ZCONFIG(OS, Carbon) -# pragma align=mac68k -#endif - -struct NPPluginFuncs - { - uint16 fSize; - uint16 fVersion; - Dispatch_New_UPP fNew; - Dispatch_Destroy_UPP fDestroy; - Dispatch_SetWindow_UPP fSetWindow; - Dispatch_NewStream_UPP fNewStream; - Dispatch_DestroyStream_UPP fDestroyStream; - Dispatch_StreamAsFile_UPP fStreamAsFile; - Dispatch_WriteReady_UPP fWriteReady; - Dispatch_Write_UPP fWrite; - Dispatch_Print_UPP fPrint; - Dispatch_HandleEvent_UPP fHandleEvent; - Dispatch_URLNotify_UPP fURLNotify; - ZNSPlugin::JRIGlobalRef fJavaClass; - Dispatch_GetValue_UPP fGetValue; - Dispatch_SetValue_UPP fSetValue; - }; - -struct NPNetscapeFuncs - { - uint16 fSize; - uint16 fVersion; - Navigator_GetURL_UPP fGetURL; - Navigator_PostURL_UPP fPostURL; - Navigator_RequestRead_UPP fRequestRead; - Navigator_NewStream_UPP fNewStream; - Navigator_Write_UPP fWrite; - Navigator_DestroyStream_UPP fDestroyStream; - Navigator_Status_UPP fStatus; - Navigator_UserAgent_UPP fUserAgent; - Navigator_MemAlloc_UPP fMemAlloc; - Navigator_MemFree_UPP fMemFree; - Navigator_MemFlush_UPP fMemFlush; - Navigator_ReloadPlugins_UPP fReloadPlugins; - Navigator_GetJavaEnv_UPP fGetJavaEnv; - Navigator_GetJavaPeer_UPP fGetJavaPeer; - Navigator_GetURLNotify_UPP fGetURLNotify; - Navigator_PostURLNotify_UPP fPostURLNotify; - Navigator_GetValue_UPP fGetValue; - Navigator_SetValue_UPP fSetValue; - Navigator_InvalidateRect_UPP fInvalidateRect; - Navigator_InvalidateRegion_UPP fInvalidateRegion; - Navigator_ForceRedraw_UPP fForceRedraw; - }; - -#if ZCONFIG(OS, MacOS7) || ZCONFIG(OS, Carbon) -# pragma align=reset -#endif - -// ================================================================================================= -#pragma mark - -#pragma mark * Calls to Navigator - -static NPNetscapeFuncs* sNPNetscapeFuncsPtr; - -void ZNSPlugin::sNavigator_Version(int* oPluginMajor, int* oPluginMinor, int* oNavigatorMajor, int* oNavigatorMinor) - { - if (oPluginMajor) - *oPluginMajor = ZNSPlugin::kVersionMajor; - if (oPluginMinor) - *oPluginMinor = ZNSPlugin::kVersionMinor; - if (oNavigatorMajor) - *oNavigatorMajor = sNPNetscapeFuncsPtr->fVersion >> 8; - if (oNavigatorMinor) - *oNavigatorMinor = sNPNetscapeFuncsPtr->fVersion & 0xFF; - } - -ZNSPlugin::EError ZNSPlugin::sNavigator_GetURL(NPP iNPP, const char* iURL, const char* iTarget) - { return Call3(EError, Navigator_GetURL, sNPNetscapeFuncsPtr->fGetURL, iNPP, iURL, iTarget); } - -ZNSPlugin::EError ZNSPlugin::sNavigator_PostURL(NPP iNPP, const char* iURL, const char* iTarget, uint32 iLen, const char* iBuf, NPBool iIsFileName) - { return Call6(EError, Navigator_PostURL, sNPNetscapeFuncsPtr->fPostURL, iNPP, iURL, iTarget, iLen, iBuf, iIsFileName); } - -ZNSPlugin::EError ZNSPlugin::sNavigator_RequestRead(NPP iNPP, NPStream* iStream, NPByteRange* iRangeList) - { return Call2(EError, Navigator_RequestRead, sNPNetscapeFuncsPtr->fRequestRead, iStream, iRangeList); } - -ZNSPlugin::EError ZNSPlugin::sNavigator_NewStream(NPP iNPP, const char* iMIMEType, const char* iTarget, NPStream** iStream) - { - if (ZNSPlugin::eFeature_HasStreamOutput <= (sNPNetscapeFuncsPtr->fVersion & 0xFF)) - return Call4(EError, Navigator_NewStream, sNPNetscapeFuncsPtr->fNewStream, iNPP, iMIMEType, iTarget, iStream); - return ZNSPlugin::eError_IncompatibleVersion; - } - -int32 ZNSPlugin::sNavigator_Write(NPP iNPP, NPStream* iStream, int32 iLen, const void* iSource) - { - if (ZNSPlugin::eFeature_HasStreamOutput <= (sNPNetscapeFuncsPtr->fVersion & 0xFF)) - return Call4(int32, Navigator_Write, sNPNetscapeFuncsPtr->fWrite, iNPP, iStream, iLen, iSource); - return ZNSPlugin::eError_IncompatibleVersion; - } - -ZNSPlugin::EError ZNSPlugin::sNavigator_DestroyStream(NPP iNPP, NPStream* iStream, EReason iReason) - { - if (ZNSPlugin::eFeature_HasStreamOutput <= (sNPNetscapeFuncsPtr->fVersion & 0xFF)) - return Call3(EError, Navigator_DestroyStream, sNPNetscapeFuncsPtr->fDestroyStream, iNPP, iStream, iReason); - return ZNSPlugin::eError_IncompatibleVersion; - } - -void ZNSPlugin::sNavigator_Status(NPP iNPP, const char* iMessage) - { Call2(void, Navigator_Status, sNPNetscapeFuncsPtr->fStatus, iNPP, iMessage); } - -const char* ZNSPlugin::sNavigator_UserAgent(NPP iNPP) - { return Call1(const char*, Navigator_UserAgent, sNPNetscapeFuncsPtr->fUserAgent, iNPP); } - -void* ZNSPlugin::sNavigator_MemAlloc(uint32 iSize) - { return Call1(void*, Navigator_MemAlloc, sNPNetscapeFuncsPtr->fMemAlloc, iSize); } - -void ZNSPlugin::sNavigator_MemFree(void* iPtr) - { Call1(void, Navigator_MemFree, sNPNetscapeFuncsPtr->fMemFree, iPtr); } - -uint32 ZNSPlugin::sNavigator_MemFlush(uint32 iSize) - { return Call1(uint32, Navigator_MemFlush, sNPNetscapeFuncsPtr->fMemFlush, iSize); } - -void ZNSPlugin::sNavigator_ReloadPlugins(NPBool iReloadPages) - { Call1(void, Navigator_ReloadPlugins, sNPNetscapeFuncsPtr->fReloadPlugins, iReloadPages); } - -ZNSPlugin::JRIEnv* ZNSPlugin::sNavigator_GetJavaEnv() - { return Call0(JRIEnv*, Navigator_GetJavaEnv, sNPNetscapeFuncsPtr->fGetJavaEnv); } - -ZNSPlugin::jref ZNSPlugin::sNavigator_GetJavaPeer(NPP iNPP) - { return Call1(jref, Navigator_GetJavaPeer, sNPNetscapeFuncsPtr->fGetJavaPeer, iNPP); } - -ZNSPlugin::EError ZNSPlugin::sNavigator_GetURLNotify(NPP iNPP, const char* iURL, const char* iTarget, void* iRefCon) - { - if (eFeature_HasNotification <= (sNPNetscapeFuncsPtr->fVersion & 0xFF)) - return Call4(EError, Navigator_GetURLNotify, sNPNetscapeFuncsPtr->fGetURLNotify, iNPP, iURL, iTarget, iRefCon); - return ZNSPlugin::eError_IncompatibleVersion; - } - -ZNSPlugin::EError ZNSPlugin::sNavigator_PostURLNotify(NPP iNPP, const char* iURL, const char* iTarget, uint32 iLen, const char* iBuf, NPBool iFile, void* iRefCon) - { - if (eFeature_HasNotification <= (sNPNetscapeFuncsPtr->fVersion & 0xFF)) - return Call7(EError, Navigator_PostURLNotify, sNPNetscapeFuncsPtr->fPostURLNotify, iNPP, iURL, iTarget, iLen, iBuf, iFile, iRefCon); - return ZNSPlugin::eError_IncompatibleVersion; - } - -ZNSPlugin::EError ZNSPlugin::sNavigator_GetValue(NPP iNPP, NPNVariable iVariable, void* oValue) - { - // ?? Version check okay? - if (ZNSPlugin::eFeature_HasWindowless <= (sNPNetscapeFuncsPtr->fVersion & 0xFF)) - return Call3(EError, Navigator_GetValue, sNPNetscapeFuncsPtr->fGetValue, iNPP, iVariable, oValue); - return ZNSPlugin::eError_IncompatibleVersion; - } - -ZNSPlugin::EError ZNSPlugin::sNavigator_SetValue(NPP iNPP, NPPVariable iVariable, void* iValue) - { - if (ZNSPlugin::eFeature_HasWindowless <= (sNPNetscapeFuncsPtr->fVersion & 0xFF)) - return Call3(EError, Navigator_SetValue, sNPNetscapeFuncsPtr->fSetValue, iNPP, iVariable, iValue); - return ZNSPlugin::eError_IncompatibleVersion; - } - -void ZNSPlugin::sNavigator_InvalidateRect(NPP iNPP, const NPRect& iRect) - { - if (ZNSPlugin::eFeature_HasWindowless <= (sNPNetscapeFuncsPtr->fVersion & 0xFF)) - Call2(void, Navigator_InvalidateRect, sNPNetscapeFuncsPtr->fInvalidateRect, iNPP, iRect); - } - -void ZNSPlugin::sNavigator_InvalidateRegion(NPP iNPP, NPRegion iRegion) - { - if (ZNSPlugin::eFeature_HasWindowless <= (sNPNetscapeFuncsPtr->fVersion & 0xFF)) - Call2(void, Navigator_InvalidateRegion, sNPNetscapeFuncsPtr->fInvalidateRegion, iNPP, iRegion); - } - -void ZNSPlugin::sNavigator_ForceRedraw(NPP iNPP) - { - if (ZNSPlugin::eFeature_HasWindowless <= (sNPNetscapeFuncsPtr->fVersion & 0xFF)) - Call1(void, Navigator_ForceRedraw, sNPNetscapeFuncsPtr->fForceRedraw, iNPP); - } - -// ================================================================================================= -#pragma mark - -#pragma mark * Dispatch wrappers - -namespace ZANONYMOUS { - -void sDispatch_Shutdown(); -ZNSPlugin::EError sDispatch_New(const char* iMIMEType, ZNSPlugin::NPP iNPP, ZNSPlugin::EMode iMode, int16 iArgc, const char* iArgn[], const char* iArgv[], ZNSPlugin::NPSavedData* iSavedData); -ZNSPlugin::EError sDispatch_Destroy(ZNSPlugin::NPP iNPP, ZNSPlugin::NPSavedData*& oSavedData); -ZNSPlugin::EError sDispatch_SetWindow(ZNSPlugin::NPP iNPP, ZNSPlugin::NPWindow* iNPWindow); -ZNSPlugin::EError sDispatch_NewStream(ZNSPlugin::NPP iNPP, const char* iMIMEType, ZNSPlugin::NPStream* iStream, ZNSPlugin::NPBool iSeekable, uint16& oType); -ZNSPlugin::EError sDispatch_DestroyStream(ZNSPlugin::NPP iNPP, ZNSPlugin::NPStream* iStream, ZNSPlugin::EReason iReason); -int32 sDispatch_WriteReady(ZNSPlugin::NPP iNPP, ZNSPlugin::NPStream* iStream); -int32 sDispatch_Write(ZNSPlugin::NPP iNPP, ZNSPlugin::NPStream* iStream, int32 iOffset, int32 iLen, const void* iBuffer); -void sDispatch_StreamAsFile(ZNSPlugin::NPP iNPP, ZNSPlugin::NPStream* iStream, const char* iFilePath); -void sDispatch_Print(ZNSPlugin::NPP iNPP, ZNSPlugin::NPPrint& iPlatformPrint); -int16 sDispatch_HandleEvent(ZNSPlugin::NPP iNPP, void* iEvent); -void sDispatch_URLNotify(ZNSPlugin::NPP iNPP, const char* iURL, ZNSPlugin::EReason iReason, void* iRefCon); -//JRIGlobalRef sDispatch_GetJavaClass(); - -void sDispatch_Shutdown() - { - try - { - if (ZNSPlugin::sMeister) - ZNSPlugin::sMeister->Shutdown(); - } - catch (...) - {} - } - -ZNSPlugin::EError sDispatch_New(const char* iMIMEType, ZNSPlugin::NPP iNPP, ZNSPlugin::EMode iMode, int16 iArgc, const char* iArgn[], const char* iArgv[], ZNSPlugin::NPSavedData* iSavedData) - { - try - { - if (ZNSPlugin::sMeister) - return ZNSPlugin::sMeister->New(iMIMEType, iNPP, iMode, iArgc, iArgn, iArgv, iSavedData); - } - catch (...) - {} - return ZNSPlugin::eError_Generic; - } - -ZNSPlugin::EError sDispatch_Destroy(ZNSPlugin::NPP iNPP, ZNSPlugin::NPSavedData*& oSavedData) - { - try - { - if (ZNSPlugin::sMeister) - return ZNSPlugin::sMeister->Destroy(iNPP, oSavedData); - } - catch (...) - {} - return ZNSPlugin::eError_Generic; - } - -ZNSPlugin::EError sDispatch_SetWindow(ZNSPlugin::NPP iNPP, ZNSPlugin::NPWindow* iNPWindow) - { - try - { - if (ZNSPlugin::sMeister) - return ZNSPlugin::sMeister->SetWindow(iNPP, iNPWindow); - } - catch (...) - {} - return ZNSPlugin::eError_Generic; - } - -ZNSPlugin::EError sDispatch_NewStream(ZNSPlugin::NPP iNPP, const char* iMIMEType, ZNSPlugin::NPStream* iStream, ZNSPlugin::NPBool iSeekable, uint16& oType) - { - try - { - if (ZNSPlugin::sMeister) - return ZNSPlugin::sMeister->NewStream(iNPP, iMIMEType, iStream, iSeekable, oType); - } - catch (...) - {} - return ZNSPlugin::eError_Generic; - } - -ZNSPlugin::EError sDispatch_DestroyStream(ZNSPlugin::NPP iNPP, ZNSPlugin::NPStream* iStream, ZNSPlugin::EReason iReason) - { - try - { - if (ZNSPlugin::sMeister) - return ZNSPlugin::sMeister->DestroyStream(iNPP, iStream, iReason); - } - catch (...) - {} - return ZNSPlugin::eError_Generic; - } - -int32 sDispatch_WriteReady(ZNSPlugin::NPP iNPP, ZNSPlugin::NPStream* iStream) - { - try - { - if (ZNSPlugin::sMeister) - return ZNSPlugin::sMeister->WriteReady(iNPP, iStream); - } - catch (...) - {} - return ZNSPlugin::eError_Generic; - } - -int32 sDispatch_Write(ZNSPlugin::NPP iNPP, ZNSPlugin::NPStream* iStream, int32 iOffset, int32 iLen, const void* iBuffer) - { - try - { - if (ZNSPlugin::sMeister) - return ZNSPlugin::sMeister->Write(iNPP, iStream, iOffset, iLen, iBuffer); - } - catch (...) - {} - return ZNSPlugin::eError_Generic; - } - -void sDispatch_StreamAsFile(ZNSPlugin::NPP iNPP, ZNSPlugin::NPStream* iStream, const char* iFilePath) - { - try - { - if (ZNSPlugin::sMeister) - ZNSPlugin::sMeister->StreamAsFile(iNPP, iStream, iFilePath); - } - catch (...) - {} - } - -void sDispatch_Print(ZNSPlugin::NPP iNPP, ZNSPlugin::NPPrint& iPlatformPrint) - { - try - { - if (ZNSPlugin::sMeister) - ZNSPlugin::sMeister->Print(iNPP, iPlatformPrint); - } - catch (...) - {} - } - -int16 sDispatch_HandleEvent(ZNSPlugin::NPP iNPP, void* iEvent) - { - try - { - if (ZNSPlugin::sMeister) - return ZNSPlugin::sMeister->HandleEvent(iNPP, iEvent); - } - catch (...) - {} - return false; - } - -void sDispatch_URLNotify(ZNSPlugin::NPP iNPP, const char* iURL, ZNSPlugin::EReason iReason, void* iRefCon) - { - try - { - if (ZNSPlugin::sMeister) - ZNSPlugin::sMeister->URLNotify(iNPP, iURL, iReason, iRefCon); - } - catch (...) - {} - } - -#if 0 -JRIGlobalRef sDispatch_GetJavaClass() - { -// if (jref clazz = Plugin_GetJavaClass()) -// { -// JRIEnv* env = Navigator_GetJavaEnv(); -// return JRI_NewGlobalRef(env, clazz); -// } - return nil; - } -#endif -} // anonymous namespace - -// ================================================================================================= -// ================================================================================================= -#pragma mark - -#pragma mark * Win32 - -#if ZCONFIG(OS, Win32) - -extern "C" { - -ZNSPlugin::EError WINAPI NP_GetEntryPoints(NPPluginFuncs* oNPPluginFuncs); -ZNSPlugin::EError WINAPI NP_Initialize(NPNetscapeFuncs* iNPNetscapeFuncs); -ZNSPlugin::EError WINAPI NP_Shutdown(); - -} // extern "C" - -HINSTANCE sHINSTANCE; - -extern "C" BOOL WINAPI DllMain(HINSTANCE iHINSTANCE, DWORD fdwReason, LPVOID lpvReserved); -extern "C" BOOL WINAPI DllMain(HINSTANCE iHINSTANCE, DWORD fdwReason, LPVOID lpvReserved) - { - switch (fdwReason) - { - case DLL_PROCESS_ATTACH: - sHINSTANCE = iHINSTANCE; - break; - case DLL_THREAD_ATTACH: - case DLL_PROCESS_DETACH: - case DLL_THREAD_DETACH: - break; - } - return TRUE; - } - -static NPPluginFuncs* sNPPluginFuncs_Stashed; - -ZNSPlugin::EError WINAPI NP_GetEntryPoints(NPPluginFuncs* oNPPluginFuncs) - { - if (!oNPPluginFuncs) - return ZNSPlugin::eError_InvalidFunctionTable; - - oNPPluginFuncs->fVersion = (ZNSPlugin::kVersionMajor << 8) | ZNSPlugin::kVersionMinor; - - oNPPluginFuncs->fNew = CreateUPP(Dispatch_New, sDispatch_New); - oNPPluginFuncs->fDestroy = CreateUPP(Dispatch_Destroy, sDispatch_Destroy); - oNPPluginFuncs->fSetWindow = CreateUPP(Dispatch_SetWindow, sDispatch_SetWindow); - oNPPluginFuncs->fNewStream = CreateUPP(Dispatch_NewStream, sDispatch_NewStream); - oNPPluginFuncs->fDestroyStream = CreateUPP(Dispatch_DestroyStream, sDispatch_DestroyStream); - oNPPluginFuncs->fStreamAsFile = CreateUPP(Dispatch_StreamAsFile, sDispatch_StreamAsFile); - oNPPluginFuncs->fWriteReady = CreateUPP(Dispatch_WriteReady, sDispatch_WriteReady); - oNPPluginFuncs->fWrite = CreateUPP(Dispatch_Write, sDispatch_Write); - oNPPluginFuncs->fPrint = CreateUPP(Dispatch_Print, sDispatch_Print); - oNPPluginFuncs->fHandleEvent = 0; - sNPPluginFuncs_Stashed = oNPPluginFuncs; - - return ZNSPlugin::eError_None; - } - -ZNSPlugin::EError WINAPI NP_Initialize(NPNetscapeFuncs* iNPNetscapeFuncs) - { - if (!iNPNetscapeFuncs) - return ZNSPlugin::eError_InvalidFunctionTable; - - sNPNetscapeFuncsPtr = iNPNetscapeFuncs; - - int navigatorMinorVersion = iNPNetscapeFuncs->fVersion & 0xFF; - int navigatorMajorVersion = iNPNetscapeFuncs->fVersion >> 8; - - if(navigatorMajorVersion > ZNSPlugin::kVersionMajor) - return ZNSPlugin::eError_IncompatibleVersion; - - if (navigatorMinorVersion >= ZNSPlugin::eFeature_HasNotification) - sNPPluginFuncs_Stashed->fURLNotify = CreateUPP(Plugin_URLNotify, sDispatch_URLNotify); - -// if (navigatorMinorVersion >= ZNSPlugin::eFeature_HasLiveConnect) -// sNPPluginFuncs_Stashed->fJavaClass = sDispatch_GetJavaClass(); - - try - { - ZNSPluginMeister::sCreate(); - } - catch (...) - { - return ZNSPlugin::eError_Generic; - } - - return ZNSPlugin::eError_None; - } - -ZNSPlugin::EError WINAPI NP_Shutdown() - { - sDispatch_Shutdown(); - return ZNSPlugin::eError_None; - } - -#endif // ZCONFIG(OS, Win32) - -// ================================================================================================= -#pragma mark - -#pragma mark * MacOS7 - -#if ZCONFIG(OS, MacOS7) - ZNSPlugin::EError main(NPNetscapeFuncs* iNPNetscapeFuncs, NPPluginFuncs* oNPPluginFuncs, Dispatch_Shutdown_UPP& oDispatch_Shutdown_UPP); - DefineProc3(ZNSPlugin::EError, main, NPNetscapeFuncs*, NPPluginFuncs*, Dispatch_Shutdown_UPP&); - - #pragma export on - RoutineDescriptor mainRD = BUILD_ROUTINE_DESCRIPTOR(main_ProcInfo, main); - #pragma export off - - static void sSetUpQD(); -#endif // ZCONFIG(OS, MacOS7) - -#if ZCONFIG(OS, Carbon) - #pragma export on - ZNSPlugin::EError main(NPNetscapeFuncs* iNPNetscapeFuncs, NPPluginFuncs* oNPPluginFuncs, Dispatch_Shutdown_UPP& oDispatch_Shutdown_UPP); - #pragma export off -#endif // ZCONFIG(OS, Carbon) - -#if ZCONFIG(OS, MacOS7) || ZCONFIG(OS, Carbon) - -static NPNetscapeFuncs sNPNetscapeFuncs; - -ZNSPlugin::EError main(NPNetscapeFuncs* iNPNetscapeFuncs, NPPluginFuncs* oNPPluginFuncs, Dispatch_Shutdown_UPP& oDispatch_Shutdown_UPP) - { - ZNSPlugin::EError err = ZNSPlugin::eError_None; - - // Ensure that everything Netscape passed us is valid! - if (!iNPNetscapeFuncs || !oNPPluginFuncs || !&oDispatch_Shutdown_UPP) - return ZNSPlugin::eError_InvalidFunctionTable; - - int navigatorMinorVersion = iNPNetscapeFuncs->fVersion & 0xFF; - int navigatorMajorVersion = iNPNetscapeFuncs->fVersion >> 8; - - // Check the "major" version passed in Netscape's function table. - // We won't load if the major version is newer than what we expect. - if (navigatorMajorVersion > ZNSPlugin::kVersionMajor) - return ZNSPlugin::eError_IncompatibleVersion; - - // Copy Netscape's function table field by field, as it may be missing - // the last few fields if the plugin is running on an older browser. - sNPNetscapeFuncs.fVersion = iNPNetscapeFuncs->fVersion; - sNPNetscapeFuncs.fSize = iNPNetscapeFuncs->fSize; - sNPNetscapeFuncs.fPostURL = iNPNetscapeFuncs->fPostURL; - sNPNetscapeFuncs.fGetURL = iNPNetscapeFuncs->fGetURL; - sNPNetscapeFuncs.fRequestRead = iNPNetscapeFuncs->fRequestRead; - sNPNetscapeFuncs.fNewStream = iNPNetscapeFuncs->fNewStream; - sNPNetscapeFuncs.fWrite = iNPNetscapeFuncs->fWrite; - sNPNetscapeFuncs.fDestroyStream = iNPNetscapeFuncs->fDestroyStream; - sNPNetscapeFuncs.fStatus = iNPNetscapeFuncs->fStatus; - sNPNetscapeFuncs.fUserAgent = iNPNetscapeFuncs->fUserAgent; - sNPNetscapeFuncs.fMemAlloc = iNPNetscapeFuncs->fMemAlloc; - sNPNetscapeFuncs.fMemFree = iNPNetscapeFuncs->fMemFree; - sNPNetscapeFuncs.fMemFlush = iNPNetscapeFuncs->fMemFlush; - sNPNetscapeFuncs.fReloadPlugins = iNPNetscapeFuncs->fReloadPlugins; - - if (navigatorMinorVersion >= ZNSPlugin::eFeature_HasLiveConnect) - { - sNPNetscapeFuncs.fGetJavaEnv = iNPNetscapeFuncs->fGetJavaEnv; - sNPNetscapeFuncs.fGetJavaPeer = iNPNetscapeFuncs->fGetJavaPeer; - } - - if (navigatorMinorVersion >= ZNSPlugin::eFeature_HasNotification) - { - sNPNetscapeFuncs.fGetURLNotify = iNPNetscapeFuncs->fGetURLNotify; - sNPNetscapeFuncs.fPostURLNotify = iNPNetscapeFuncs->fPostURLNotify; - } - - if (navigatorMinorVersion >= ZNSPlugin::eFeature_HasWindowless) - { - sNPNetscapeFuncs.fInvalidateRect = iNPNetscapeFuncs->fInvalidateRect; - sNPNetscapeFuncs.fInvalidateRegion = iNPNetscapeFuncs->fInvalidateRegion; - } - - sNPNetscapeFuncsPtr = &sNPNetscapeFuncs; - - // Set up the plugin function table that Netscape will use to - // call us. Netscape needs to know about our version and size - // and have a UniversalProcPointer for every function we implement. - - oNPPluginFuncs->fVersion = (ZNSPlugin::kVersionMajor << 8) + ZNSPlugin::kVersionMinor; - - oNPPluginFuncs->fNew = CreateUPP(Dispatch_New, sDispatch_New); - oNPPluginFuncs->fDestroy = CreateUPP(Dispatch_Destroy, sDispatch_Destroy); - oNPPluginFuncs->fSetWindow = CreateUPP(Dispatch_SetWindow, sDispatch_SetWindow); - oNPPluginFuncs->fNewStream = CreateUPP(Dispatch_NewStream, sDispatch_NewStream); - oNPPluginFuncs->fDestroyStream = CreateUPP(Dispatch_DestroyStream, sDispatch_DestroyStream); - oNPPluginFuncs->fStreamAsFile = CreateUPP(Dispatch_StreamAsFile, sDispatch_StreamAsFile); - oNPPluginFuncs->fWriteReady = CreateUPP(Dispatch_WriteReady, sDispatch_WriteReady); - oNPPluginFuncs->fWrite = CreateUPP(Dispatch_Write, sDispatch_Write); - oNPPluginFuncs->fPrint = CreateUPP(Dispatch_Print, sDispatch_Print); - oNPPluginFuncs->fHandleEvent = CreateUPP(Dispatch_HandleEvent, sDispatch_HandleEvent); - - if (navigatorMinorVersion >= ZNSPlugin::eFeature_HasNotification) - oNPPluginFuncs->fURLNotify = CreateUPP(Dispatch_URLNotify, sDispatch_URLNotify); - -// if (navigatorMinorVersion >= ZNSPlugin::eFeature_HasLiveConnect) -// oNPPluginFuncs->fJavaClass = sDispatch_GetJavaClass(); - - oDispatch_Shutdown_UPP = CreateUPP(Dispatch_Shutdown, sDispatch_Shutdown); - - #if ZCONFIG(OS, MacOS7) - sSetUpQD(); - #endif - - try - { - ZNSPluginMeister::sCreate(); - } - catch (...) - { - return ZNSPlugin::eError_Generic; - } - - return ZNSPlugin::eError_None; - } -#endif // ZCONFIG(OS, MacOS7) || ZCONFIG(OS, Carbon) - -#if ZCONFIG(OS, MacOS7) -static QDGlobals* sQDPtr; // Pointer to Netscape's QuickDraw globals -static short sResFile; // Refnum of the plugin's resource file -static void sSetUpQD() - { - OSErr result = noErr; - - // Memorize the plugin's resource file refnum for later use. - sResFile = CurResFile(); - - Str63 appName; - FSSpec appFSSpec; - - long response; - if (noErr == ::Gestalt(gestaltCFMAttr, &response) && (response & (1 << gestaltCFMPresent))) - { - // GetProcessInformation takes a process serial number and - // will give us back the name and FSSpec of the application. - // See the Process Manager in IM. - ProcessInfoRec infoRec; - infoRec.processInfoLength = sizeof(ProcessInfoRec); - infoRec.processName = appName; - infoRec.processAppSpec = &appFSSpec; - - ProcessSerialNumber thePSN; - thePSN.highLongOfPSN = 0; - thePSN.lowLongOfPSN = kCurrentProcess; - - result = ::GetProcessInformation(&thePSN, &infoRec); - if (result != noErr) - {}//PLUGINDEBUGSTR("\pFailed in GetProcessInformation"); - } - else - { - // If no CFM installed, assume it must be a 68K app. - result = -1; - } - - CFragConnectionID connID; - if (result == noErr) - { - // Now that we know the app name and FSSpec, we can call GetDiskFragment - // to get a connID to use in a subsequent call to FindSymbol (it will also - // return the address of "main" in app, which we ignore). If GetDiskFragment - // returns an error, we assume the app must be 68K. - Ptr mainAddr; - Str255 errName; - result = ::GetDiskFragment(&appFSSpec, 0L, 0L, appName, kReferenceCFrag, &connID, &mainAddr, errName); - } - - if (result == noErr) - { - // The app is a PPC code fragment, so call FindSymbol to get the exported - // "qd" symbol so we can access its QuickDraw globals. - CFragSymbolClass symClass; - result = ::FindSymbol(connID, "\pqd", (Ptr*)&sQDPtr, &symClass); - if (result != noErr) - {}//PLUGINDEBUGSTR("\pFailed in FindSymbol qd"); - } - else - { - // The app is 68K, so use its A5 to compute the address of its QuickDraw globals. - sQDPtr = (QDGlobals*)(*((long*)SetCurrentA5()) - (sizeof(QDGlobals) - sizeof(GrafPtr))); - } - } -#endif // ZCONFIG(OS, MacOS7) - -// ================================================================================================= -#pragma mark - -#pragma mark * ZNSPluginInstance - -ZNSPluginInstance::ZNSPluginInstance(NPP iNPP) -: fNPP(iNPP) - {} - -ZNSPluginInstance::~ZNSPluginInstance() - {} - -ZNSPlugin::EError ZNSPluginInstance::Destroy(NPSavedData*& oSavedData) - { - delete this; - return eError_None; - } - -ZNSPlugin::EError ZNSPluginInstance::NewStream(const char* iMIMEType, NPStream* iStream, NPBool iSeekable, EStreamType& oType) - { - return eError_None; - } - -ZNSPlugin::EError ZNSPluginInstance::DestroyStream(NPStream* iStream, EReason iReason) - { - return eError_None; - } - -void ZNSPluginInstance::StreamAsFile(NPStream* iStream, const char* iFilePath) - { - } - -int32 ZNSPluginInstance::WriteReady(NPStream* iStream) - { - return 0x7FFFFFFF; - } - -int32 ZNSPluginInstance::Write(NPStream* iStream, int32 iOffset, int32 iLen, const void* iBuffer) - { - return iLen; - } - -void ZNSPluginInstance::Print(NPPrint& iPlatformPrint) - { - } - -#if ZCONFIG(OS, MacOS7) || ZCONFIG(OS, Carbon) -int16 ZNSPluginInstance::HandleEvent(const EventRecord& iEvent) - { - return false; - } -#endif // ZCONFIG(OS, MacOS7) || ZCONFIG(OS, Carbon) - -void ZNSPluginInstance::URLNotify(const char* iURL, EReason iReason, void* iRefCon) - { - } - -ZNSPlugin::EError ZNSPluginInstance::GetValue(void* iInstance, NPPVariable variable, void* oValue) - { - return eError_Generic; - } - -ZNSPlugin::EError ZNSPluginInstance::SetValue(void* iInstance, NPNVariable variable, void* iValue) - { - return eError_Generic; - } - - -// ================================================================================================= -#pragma mark - -#pragma mark * ZNSPluginMeister - -ZNSPluginMeister::ZNSPluginMeister() - { - ZAssertStop(kDebug_NSPlugin, !sMeister); - sMeister = this; - } - -ZNSPluginMeister::~ZNSPluginMeister() - { - ZAssertStop(kDebug_NSPlugin, sMeister == this); - sMeister = nil; - } - -void ZNSPluginMeister::Shutdown() - { - delete this; - } - -ZNSPlugin::EError ZNSPluginMeister::New(const char* iMIMEType, NPP iNPP, EMode iMode, int16 iArgc, const char* iArgn[], const char* iArgv[], NPSavedData* iSavedData) - { - ZNSPluginInstance* theInstance; - this->New(iNPP, iMIMEType, iMode, iArgc, iArgn, iArgv, iSavedData, theInstance); - if (theInstance) - { - iNPP->fData_Plugin = theInstance; - return eError_None; - } - return eError_Generic; - } - -ZNSPlugin::EError ZNSPluginMeister::Destroy(NPP iNPP, NPSavedData*& oSavedData) - { - if (ZNSPluginInstance* theInstance = this->NPPToInstance(iNPP)) - return theInstance->Destroy(oSavedData); - return eError_Generic; - } - -ZNSPlugin::EError ZNSPluginMeister::SetWindow(NPP iNPP, NPWindow* iNPWindow) - { - if (ZNSPluginInstance* theInstance = this->NPPToInstance(iNPP)) - return theInstance->SetWindow(iNPWindow); - return eError_Generic; - } - -ZNSPlugin::EError ZNSPluginMeister::NewStream(NPP iNPP, const char* iMIMEType, NPStream* iStream, NPBool iSeekable, EStreamType& oType) - { - if (ZNSPluginInstance* theInstance = this->NPPToInstance(iNPP)) - return theInstance->NewStream(iMIMEType, iStream, iSeekable, oType); - return eError_Generic; - } - -ZNSPlugin::EError ZNSPluginMeister::DestroyStream(NPP iNPP, NPStream* iStream, EReason iReason) - { - if (ZNSPluginInstance* theInstance = this->NPPToInstance(iNPP)) - return theInstance->DestroyStream(iStream, iReason); - return eError_Generic; - } - -void ZNSPluginMeister::StreamAsFile(NPP iNPP, NPStream* iStream, const char* iFilePath) - { - if (ZNSPluginInstance* theInstance = this->NPPToInstance(iNPP)) - theInstance->StreamAsFile(iStream, iFilePath); - } - -int32 ZNSPluginMeister::WriteReady(NPP iNPP, NPStream* iStream) - { - if (ZNSPluginInstance* theInstance = this->NPPToInstance(iNPP)) - return theInstance->WriteReady(iStream); - return 0x7FFFFFFF; - } - -int32 ZNSPluginMeister::Write(NPP iNPP, NPStream* iStream, int32 iOffset, int32 iLen, const void* iBuffer) - { - if (ZNSPluginInstance* theInstance = this->NPPToInstance(iNPP)) - return theInstance->Write(iStream, iOffset, iLen, iBuffer); - return iLen; - } - -void ZNSPluginMeister::Print(NPP iNPP, NPPrint& iPlatformPrint) - { - if (ZNSPluginInstance* theInstance = this->NPPToInstance(iNPP)) - return theInstance->Print(iPlatformPrint); - } - -int16 ZNSPluginMeister::HandleEvent(NPP iNPP, void* iEvent) - { - if (ZNSPluginInstance* theInstance = this->NPPToInstance(iNPP)) - { - #if ZCONFIG(OS, MacOS7) || ZCONFIG(OS, Carbon) - return theInstance->HandleEvent(*static_cast<const EventRecord*>(iEvent)); - #endif // ZCONFIG(OS, MacOS7) || ZCONFIG(OS, Carbon) - } - return 0; - } - -void ZNSPluginMeister::URLNotify(NPP iNPP, const char* iURL, EReason iReason, void* iRefCon) - { - if (ZNSPluginInstance* theInstance = this->NPPToInstance(iNPP)) - return theInstance->URLNotify(iURL, iReason, iRefCon); - } - -ZNSPlugin::EError ZNSPluginMeister::GetValue(NPP iNPP, void* iInstance, NPPVariable variable, void* oValue) - { - if (ZNSPluginInstance* theInstance = this->NPPToInstance(iNPP)) - return theInstance->GetValue(iInstance, variable, oValue); - return eError_Generic; - } - -ZNSPlugin::EError ZNSPluginMeister::SetValue(NPP iNPP, void* iInstance, NPNVariable variable, void* iValue) - { - if (ZNSPluginInstance* theInstance = this->NPPToInstance(iNPP)) - return theInstance->SetValue(iInstance, variable, iValue); - return eError_Generic; - } - -ZNSPluginInstance* ZNSPluginMeister::NPPToInstance(NPP iNPP) - { - if (iNPP) - return static_cast<ZNSPluginInstance*>(iNPP->fData_Plugin); - return nil; - } Deleted: trunk/zoolib/source/cxx/zoolib/ZNSPlugin.def =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNSPlugin.def 2008-11-17 20:19:32 UTC (rev 215) +++ trunk/zoolib/source/cxx/zoolib/ZNSPlugin.def 2008-11-17 20:19:57 UTC (rev 216) @@ -1,5 +0,0 @@ -EXPORTS - -_NP_GetEntryPoints@4 @1 NP_GetEntryPoints -_NP_Initialize@4 @2 NP_Initialize -_NP_Shutdown@0 @1 NP_Shutdown Deleted: trunk/zoolib/source/cxx/zoolib/ZNSPlugin.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNSPlugin.h 2008-11-17 20:19:32 UTC (rev 215) +++ trunk/zoolib/source/cxx/zoolib/ZNSPlugin.h 2008-11-17 20:19:57 UTC (rev 216) @@ -1,412 +0,0 @@ -#ifndef __ZNSPlugin__ -#define __ZNSPlugin__ 1 -#include "zconfig.h" - -#include "zoolib/ZTypes.h" - -#if ZCONFIG(OS, MacOS7) || ZCONFIG(OS, Carbon) -# include <Events.h> -# include <QuickDraw.h> -#endif - -#if ZCONFIG(OS, Win32) -# include "ZWinHeader.h" -#endif - -#if ZCONFIG(OS, POSIX) -# include <X11/Xlib.h> -# include <X11/Xutil.h> -#endif - -class ZNSPluginMeister; -class ZNSPlugin - { -public: - static ZNSPluginMeister* sMeister; - - #if ZCONFIG(OS, MacOS7) || ZCONFIG(OS, Carbon) - # pragma options align=mac68k - #endif - - static const unsigned int kVersionMajor = 0; - static const unsigned int kVersionMinor = 11; - - typedef uint8 NPBool; - - // ================================================== - typedef int16 EError; - enum - { - eError_None = 0, - eError_Generic = 1, - eError_INVALID_INSTANCE_ERROR = 2, - eError_InvalidFunctionTable = 3, - eError_MODULE_LOAD_FAILED_ERROR = 4, - eError_OUT_OF_MEMORY_ERROR = 5, - eError_INVALID_PLUGIN_ERROR = 6, - eError_INVALID_PLUGIN_DIR_ERROR = 7, - eError_IncompatibleVersion = 8, - eError_INVALID_PARAM = 9, - eError_INVALID_URL = 10, - eError_FILE_NOT_FOUND = 11, - eError_NO_DATA = 12, - eError_STREAM_NOT_SEEKABLE = 13 - }; - - - typedef int16 EReason; - enum - { - eReason_DONE = 0, - eReason_NETWORK_ERR = 1, - eReason_USER_BREAK = 2 - }; - - - // Version feature information - typedef int EFeature; - enum - { - eFeature_HasStreamOutput = 8, - eFeature_HasNotification = 9, - eFeature_HasLiveConnect = 9, - eFeature_HasLiveConnectWin16 = 9, - eFeature_HasLiveConnect68K = 9, - eFeature_HasWindowless = 11 - }; - - // ================================================== - - typedef class _jobject* jobject; - typedef jobject jref; - typedef const struct JRIEnvInterface* JRIEnv; - typedef void* JRIGlobalRef; - - - struct NPRect - { - uint16 top; - uint16 left; - uint16 bottom; - uint16 right; - }; - - - struct NPP_t - { - void* fData_Plugin; // plug-in private data - void* fData_Navigator; // netscape private data - }; - - typedef NPP_t *NPP; - - struct NPSavedData - { - int32 fLen; - void* fBuf; - }; - - - // The type of a NPWindow - it specifies the type of the data structure - // returned in the window field. - typedef int EWindowType; - enum - { - eWindowType_Window = 1, - eWindowType_Drawable - }; - - - struct NPWindow - { - void* fPlatformWindow; // Platform specific window handle - int32 fLocationH; // Position of top left corner relative - int32 fLocationV; //to a netscape page. - uint32 fWidth; // Maximum window size - uint32 fHeight; - NPRect fClipRect; // Clipping rectangle in port coordinates - // Used by MAC only. - #if ZCONFIG(OS, POSIX) - void* ws_info; // Platform-dependent additonal data - #endif - EWindowType fType; // Is this a window or a drawable? - }; - - - struct NPStream - { - void* fPluginData; - void* fPrivate; // netscape private data - const char* fURL; - uint32 fEnd; - uint32 fLastModified; - void* notifydata; - }; - - - struct NPFullPrint - { - NPBool fPluginPrinted; // Set TRUE if plugin handled fullscreen printing - NPBool fPrintOne; // TRUE if plugin should print one copy to default printer - void* fPlatformPrint; // Platform-specific printing info - }; - - - struct NPEmbedPrint - { - NPWindow fWindow; - void* fPlatformPrint; // Platform-specific printing info - }; - - // Values for mode passed to Plugin_New: - typedef uint16 EMode; - enum - { - eMode_Embed = 1, - eMode_Full = 2 - }; - - struct NPPrint - { - EMode fMode; - union - { - NPFullPrint fFullPrint; // if mode is full - NPEmbedPrint fEmbedPrint; // if mode is embed - }; - }; - - - // List of variable names for which Plugin_GetValue shall be implemented - typedef int NPPVariable; - enum - { - NPPVpluginNameString = 1, - NPPVpluginDescriptionString, - NPPVpluginWindowBool, - NPPVpluginTransparentBool, - NPPVjavaClass, /* Not implemented in Mozilla 1.0 */ - NPPVpluginWindowSize, - NPPVpluginTimerInterval, - - NPPVpluginScriptableInstance = 10, - NPPVpluginScriptableIID = 11, - - /* 12 and over are available on Mozilla builds starting with 0.9.9 */ - NPPVjavascriptPushCallerBool = 12, - NPPVpluginKeepLibraryInMemory = 13 /* available in Mozilla 1.0 */ - }; - - - // List of variable names for which Navigator_GetValue is implemented by Mozilla - typedef int NPNVariable; - enum - { - NPNVxDisplay = 1, - NPNVxtAppContext, - NPNVnetscapeWindow, - NPNVjavascriptEnabledBool, - NPNVasdEnabledBool, - NPNVisOfflineBool, - - /* 10 and over are available on Mozilla builds starting with 0.9.4 */ - NPNVserviceManager = 10, - NPNVDOMElement = 11, /* available in Mozilla 1.2 */ - NPNVDOMDocument = 12, - NPNVDOMWindow = 13 - }; - - - struct NPByteRange - { - int32 offset; // negative offset means from the end - uint32 length; - NPByteRange* next; - }; - - - - // Values for stream type passed to Plugin_NewStream: - typedef uint16 EStreamType; - enum - { - eStreamType_Normal = 1, - eStreamType_Seek = 2, - eStreamType_AsFile = 3, - eStreamType_AsFileOnly = 4 - }; - - // ================================================== - - #if ZCONFIG(OS, MacOS7) || ZCONFIG(OS, Carbon) - - typedef RgnHandle NPRegion; - typedef EventRecord NPEvent; - - struct NPPort - { - CGrafPtr fPort; // Grafport - int32 fPortH; // position inside the topmost window - int32 fPortV; - }; - - // Non-standard event types that can be passed to HandleEvent - enum EEventType - { - eEventType_GetFocusEvent = (osEvt + 16), - eEventType_LoseFocusEvent, - eEventType_AdjustCursorEvent, - eEventType_MenuCommandEvent, - eEventType_ClippingChangedEvent, - eEventType_ScrollingBeginsEvent = 1000, - eEventType_ScrollingEndsEvent - }; - - #endif // ZCONFIG(OS, MacOS7) || ZCONFIG(OS, Carbon) - - // ================================================== - - #if ZCONFIG(OS, Win32) - - typedef HRGN NPRegion; - struct NPEvent - { - uint16 fEvent; - uint32 fWPARAM; - uint32 fLPARAM; - }; - - #endif // ZCONFIG(OS, Win32) - - // ================================================== - - #if ZCONFIG(OS, POSIX) - - typedef Region NPRegion; - typedef XEvent NPEvent; - - typedef int32 ECallbackType; - enum - { - eCallbackType_SetWindow = 1, - eCallbackType_Print = 2 - }; - - struct NPAnyCallbackStruct - { - ECallbackType fType; - }; - - struct NPSetWindowCallbackStruct - { - ECallbackType fType; - Display* fDisplay; - Visual* fVisual; - Colormap fColormap; - unsigned int fDepth; - }; - - struct NPPrintCallbackStruct - { - ECallbackType fType; - FILE* fFILE; - }; - #endif // ZCONFIG(OS, POSIX) - - // ================================================== - - #if ZCONFIG(OS, MacOS7) || ZCONFIG(OS, Carbon) - # pragma options align=reset - #endif - - // ================================================== - // Navigator_* functions are provided by the navigator and called by the plugin. - - static void sNavigator_Version(int* oPluginMajor, int* oPluginMinor, int* oNavigatorMajor, int* oNavigatorMinor); - static EError sNavigator_GetURL(NPP iNPP, const char* iURL, const char* iTarget); - static EError sNavigator_PostURL(NPP iNPP, const char* iURL, const char* iTarget, uint32 iLen, const char* iBuf, NPBool iIsFileName); - static EError sNavigator_RequestRead(NPP iNPP, NPStream* iStream, NPByteRange* iRangeList); - static EError sNavigator_NewStream(NPP iNPP, const char* iMIMEType, const char* iTarget, NPStream** iStream); - static int32 sNavigator_Write(NPP iNPP, NPStream* iStream, int32 iLen, const void* iSource); - static EError sNavigator_DestroyStream(NPP iNPP, NPStream* iStream, EReason iReason); - static void sNavigator_Status(NPP iNPP, const char* iMessage); - static const char* sNavigator_UserAgent(NPP iNPP); - static void* sNavigator_MemAlloc(uint32 iSize); - static void sNavigator_MemFree( void* iPtr); - static uint32 sNavigator_MemFlush(uint32 iSize); - static void sNavigator_ReloadPlugins(NPBool iReloadPages); - static JRIEnv* sNavigator_GetJavaEnv(); - static jref sNavigator_GetJavaPeer(NPP iNPP); - static EError sNavigator_GetURLNotify(NPP iNPP, const char* iURL, const char* iTarget, void* iRefCon); - static EError sNavigator_PostURLNotify(NPP iNPP, const char* iURL, const char* iTarget, uint32 iLen, const char* iBuf, NPBool iFile, void* iRefCon); - static EError sNavigator_GetValue(NPP iNPP, NPNVariable iVariable, void* oValue); - static EError sNavigator_SetValue(NPP iNPP, NPPVariable iVariable, void* iValue); - static void sNavigator_InvalidateRect(NPP iNPP, const NPRect& iRect); - static void sNavigator_InvalidateRegion(NPP iNPP, NPRegion iRegion); - static void sNavigator_ForceRedraw(NPP iNPP); - }; - -// ================================================================================================= -#pragma mark - -#pragma mark * ZNSPluginInstance - -class ZNSPluginInstance : public ZNSPlugin - { -public: -// Plugin_* functions are provided by the plugin and called by navigator. - ZNSPluginInstance(NPP iNPP); - virtual ~ZNSPluginInstance(); - - virtual EError Destroy(NPSavedData*& oSavedData); - virtual EError SetWindow(NPWindow* iNPWindow) = 0; - virtual EError NewStream(const char* iMIMEType, NPStream* iStream, NPBool iSeekable, EStreamType& oType); - virtual EError DestroyStream(NPStream* iStream, EReason iReason); - virtual void StreamAsFile(NPStream* iStream, const char* iFilePath); - virtual int32 WriteReady(NPStream* iStream); - virtual int32 Write(NPStream* iStream, int32 iOffset, int32 iLen, const void* iBuffer); - virtual void Print(NPPrint& iPlatformPrint); -#if ZCONFIG(OS, MacOS7) || ZCONFIG(OS, Carbon) - virtual int16 HandleEvent(const EventRecord& iEvent); -#endif // ZCONFIG(OS, MacOS7) || ZCONFIG(OS, Carbon) - virtual void URLNotify(const char* iURL, EReason iReason, void* iRefCon); - virtual EError GetValue(void* iInstance, NPPVariable variable, void* oValue); - virtual EError SetValue(void* iInstance, NPNVariable variable, void* iValue); - -protected: - NPP fNPP; - }; - -// ================================================================================================= -#pragma mark - -#pragma mark * ZNSPluginMeister - -class ZNSPluginMeister : public ZNSPlugin - { -public: - /*! This must be implemented in your code and should instantiate a concrete subclass of ZNSPluginMeister.*/ - static void sCreate(); - - ZNSPluginMeister(); - virtual ~ZNSPluginMeister(); - - virtual void Shutdown(); - virtual void New(NPP iNPP, const char* iMIMEType, EMode iMode, int16 iArgc, const char* iArgn[], const char* iArgv[], NPSavedData* iSavedData, ZNSPluginInstance*& oInstance) = 0; - virtual EError New(const char* iMIMEType, NPP iNPP, EMode iMode, int16 iArgc, const char* iArgn[], const char* iArgv[], NPSavedData* iSavedData); - virtual EError Destroy(NPP iNPP, NPSavedData*& oSavedData); - virtual EError SetWindow(NPP iNPP, NPWindow* iNPWindow); - virtual EError NewStream(NPP iNPP, const char* iMIMEType, NPStream* iStream, NPBool iSeekable, EStreamType& oType); - virtual EError DestroyStream(NPP iNPP, NPStream* iStream, EReason iReason); - virtual void StreamAsFile(NPP iNPP, NPStream* iStream, const char* iFilePath); - virtual int32 WriteReady(NPP iNPP, NPStream* iStream); - virtual int32 Write(NPP iNPP, NPStream* iStream, int32 iOffset, int32 iLen, const void* iBuffer); - virtual void Print(NPP iNPP, NPPrint& iPlatformPrint); - virtual int16 HandleEvent(NPP iNPP, void* iEvent); - virtual void URLNotify(NPP iNPP, const char* iURL, EReason iReason, void* iRefCon); - virtual EError GetValue(NPP iNPP, void* iInstance, NPPVariable variable, void* oValue); - virtual EError SetValue(NPP iNPP, void* iInstance, NPNVariable variable, void* iValue); - -private: - ZNSPluginInstance* NPPToInstance(NPP iNPP); - }; - -#endif // __ZNSPlugin__ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-11-19 13:18:25
|
Revision: 222 http://zoolib.svn.sourceforge.net/zoolib/?rev=222&view=rev Author: agreen Date: 2008-11-19 13:18:23 +0000 (Wed, 19 Nov 2008) Log Message: ----------- Namespace and conditional compilation fixes. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZYad.cpp trunk/zoolib/source/cxx/zoolib/ZYad_CFType.cpp trunk/zoolib/source/cxx/zoolib/ZYad_ZooLibStream.cpp Modified: trunk/zoolib/source/cxx/zoolib/ZYad.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZYad.cpp 2008-11-19 13:12:39 UTC (rev 221) +++ trunk/zoolib/source/cxx/zoolib/ZYad.cpp 2008-11-19 13:18:23 UTC (rev 222) @@ -21,6 +21,7 @@ #include "zoolib/ZYad.h" #include "zoolib/ZMemoryBlock.h" +using std::min; using std::string; using std::vector; Modified: trunk/zoolib/source/cxx/zoolib/ZYad_CFType.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZYad_CFType.cpp 2008-11-19 13:12:39 UTC (rev 221) +++ trunk/zoolib/source/cxx/zoolib/ZYad_CFType.cpp 2008-11-19 13:18:23 UTC (rev 222) @@ -19,6 +19,9 @@ ------------------------------------------------------------------------------------------------- */ #include "zoolib/ZYad_CFType.h" + +#if ZCONFIG_SPI_Enabled(CFType) + #include "zoolib/ZStream_CFData.h" #include "zoolib/ZUtil_CFType.h" @@ -214,10 +217,11 @@ void ZYadListMapRPos_CFDictionary::SetPosition(const std::string& iName) { - #warning NDY - ZUnimplemented(); -// fPosition = find( -// fIter = fTuple.IteratorOf(iName); + for (fPosition = 0; /*no test*/; ++fPosition) + { + if (iName == ZUtil_CFType::sAsUTF8(fNames.at(fPosition))) + break; + } } // ================================================================================================= @@ -322,3 +326,5 @@ } } } + +#endif // ZCONFIG_SPI_Enabled(CFType) Modified: trunk/zoolib/source/cxx/zoolib/ZYad_ZooLibStream.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZYad_ZooLibStream.cpp 2008-11-19 13:12:39 UTC (rev 221) +++ trunk/zoolib/source/cxx/zoolib/ZYad_ZooLibStream.cpp 2008-11-19 13:18:23 UTC (rev 222) @@ -21,6 +21,10 @@ #include "zoolib/ZYad_ZooLibStream.h" #include "zoolib/ZStream_Limited.h" +using std::min; +using std::string; +using std::vector; + class ZYadR_ZooLibStream; // ================================================================================================= This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-11-25 03:27:49
|
Revision: 229 http://zoolib.svn.sourceforge.net/zoolib/?rev=229&view=rev Author: agreen Date: 2008-11-25 03:27:38 +0000 (Tue, 25 Nov 2008) Log Message: ----------- The ZYad_ML's most important component is ZYadListMapR_ML, which treats a ZML::Reader as a ListMap, where the tag name is returned as an entry name, text appears under entries with empty names. Added Paths: ----------- trunk/zoolib/source/cxx/zoolib/ZYad_ML.cpp trunk/zoolib/source/cxx/zoolib/ZYad_ML.h Added: trunk/zoolib/source/cxx/zoolib/ZYad_ML.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZYad_ML.cpp (rev 0) +++ trunk/zoolib/source/cxx/zoolib/ZYad_ML.cpp 2008-11-25 03:27:38 UTC (rev 229) @@ -0,0 +1,151 @@ +/* ------------------------------------------------------------------------------------------------- +Copyright (c) 2008 Andrew Green +http://www.zoolib.org + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software +and associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +------------------------------------------------------------------------------------------------- */ + +#include "zoolib/ZYad_ML.h" + +using std::string; +using std::vector; + +// ================================================================================================= +#pragma mark - +#pragma mark * Static helpers + +static void sThrowParseException(const string& iMessage) + { + throw ZYadParseException_ML(iMessage); + } + +// ================================================================================================= +#pragma mark - +#pragma mark * ZYadParseException_ML + +ZYadParseException_ML::ZYadParseException_ML(const string& iWhat) +: ZYadParseException(iWhat) + {} + +ZYadParseException_ML::ZYadParseException_ML(const char* iWhat) +: ZYadParseException(iWhat) + {} + +// ================================================================================================= +#pragma mark - +#pragma mark * ZYadPrimR_ML + +ZYadPrimR_ML::ZYadPrimR_ML(const string& iString) +: ZYadR_TValue(iString) + {} + +void ZYadPrimR_ML::Finish() + {} + +// ================================================================================================= +#pragma mark - +#pragma mark * ZYadListMapR_ML + +ZYadListMapR_ML::ZYadListMapR_ML(ZML::Reader& iR) +: fR(iR), + fPosition(0) + {} + +ZYadListMapR_ML::ZYadListMapR_ML( + ZML::Reader& iR, const string& iTagName, const ZTuple& iAttrs) +: fR(iR), + fTagName(iTagName), + fAttrs(iAttrs), + fPosition(0) + {} + +void ZYadListMapR_ML::Finish() + { + if (!fTagName.empty()) + { + if (!sSkip(fR, fTagName)) + sThrowParseException("Expected end tag '" + fTagName + "'"); + fTagName.clear(); + } + } + +bool ZYadListMapR_ML::HasChild() + { + this->pMoveIfNecessary(); + return fValue_Current; + } + +ZRef<ZYadR> ZYadListMapR_ML::NextChild() + { + this->pMoveIfNecessary(); + + if (fValue_Current) + { + fValue_Prior = fValue_Current; + fValue_Current.Clear(); + ++fPosition; + } + + return fValue_Prior; + } + +size_t ZYadListMapR_ML::GetPosition() + { return fPosition; } + +string ZYadListMapR_ML::Name() + { return fChildName; } + +ZTuple ZYadListMapR_ML::GetAttrs() + { return fAttrs; } + +void ZYadListMapR_ML::pMoveIfNecessary() + { + if (fValue_Current) + return; + + if (fValue_Prior) + { + fValue_Prior->Finish(); + fValue_Prior.Clear(); + } + + fChildName = fR.Name(); + switch (fR.Current()) + { + case ZML::eToken_TagBegin: + { + ZTuple theAttrs = fR.Attrs(); + fR.Advance(); + fValue_Current = new ZYadListMapR_ML(fR, fChildName, theAttrs); + break; + } + case ZML::eToken_TagEmpty: + { + ZTuple theAttrs = fR.Attrs(); + fR.Advance(); + fValue_Current = new ZYadListMapR_ML(fR, "", theAttrs); + break; + } + case ZML::eToken_Text: + { + string theString; + ZStrimW_String(theString).CopyAllFrom(fR.Text()); + fR.Advance(); + fValue_Current = new ZYadPrimR_ML(theString); + break; + } + } + } Added: trunk/zoolib/source/cxx/zoolib/ZYad_ML.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZYad_ML.h (rev 0) +++ trunk/zoolib/source/cxx/zoolib/ZYad_ML.h 2008-11-25 03:27:38 UTC (rev 229) @@ -0,0 +1,109 @@ +/* ------------------------------------------------------------------------------------------------- +Copyright (c) 2008 Andrew Green +http://www.zoolib.org + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software +and associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +------------------------------------------------------------------------------------------------- */ + +#ifndef __ZYad_ML__ +#define __ZYad_ML__ 1 +#include "zconfig.h" + +#include "zoolib/ZML.h" +#include "zoolib/ZYad_ZooLib.h" + +// ================================================================================================= +#pragma mark - +#pragma mark * ZYadParseException_ML + +class ZYadParseException_ML : public ZYadParseException + { +public: + ZYadParseException_ML(const std::string& iWhat); + ZYadParseException_ML(const char* iWhat); + }; + +// ================================================================================================= +#pragma mark - +#pragma mark * ZYadR_ML + +class ZYadR_ML : public virtual ZYadR + { +public: + // Our protocol + virtual void Finish() = 0; + }; + +// ================================================================================================= +#pragma mark - +#pragma mark * ZYadPrimR_ML + +class ZYadPrimR_ML +: public ZYadR_TValue, + public ZYadPrimR, + public ZYadR_ML + { +public: + ZYadPrimR_ML(const std::string& iString); + +// From ZYadR_ML + virtual void Finish(); + }; + +// ================================================================================================= +#pragma mark - +#pragma mark * YadListMapR_ML + +class ZYadListMapR_ML +: public ZYadListMapR, + public ZYadR_ML + { +public: + ZYadListMapR_ML(ZML::Reader& iR); + ZYadListMapR_ML(ZML::Reader& iR, const std::string& iTagName, const ZTuple& iAttrs); + +// From ZYadR_ML + virtual void Finish(); + +// From ZYadListR and ZYadMapR via ZYadListMapR + virtual bool HasChild(); + virtual ZRef<ZYadR> NextChild(); + +// From ZYadListR via ZYadListMapR + virtual size_t GetPosition(); + +// From ZYadMapR via ZYadListMapR + virtual std::string Name(); + +// Our protocol + ZTuple GetAttrs(); + +private: + void pMoveIfNecessary(); + + ZML::Reader& fR; + + ZRef<ZYadR_ML> fValue_Current; + ZRef<ZYadR_ML> fValue_Prior; + + std::string fTagName; + ZTuple fAttrs; + size_t fPosition; + bool fExhausted; + std::string fChildName; + }; + +#endif // __ZYad_ML__ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-11-25 03:43:02
|
Revision: 233 http://zoolib.svn.sourceforge.net/zoolib/?rev=233&view=rev Author: agreen Date: 2008-11-25 03:42:51 +0000 (Tue, 25 Nov 2008) Log Message: ----------- Neat-freaking (s, ms, us rather than s, us, ms). Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZUtil_Time.cpp trunk/zoolib/source/cxx/zoolib/ZUtil_Time.h Modified: trunk/zoolib/source/cxx/zoolib/ZUtil_Time.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZUtil_Time.cpp 2008-11-25 03:41:58 UTC (rev 232) +++ trunk/zoolib/source/cxx/zoolib/ZUtil_Time.cpp 2008-11-25 03:42:51 UTC (rev 233) @@ -433,16 +433,16 @@ return ZUtil_Time::sAsStringUTC(iTime, "%Y-%m-%d %H:%M:%S"); } -string ZUtil_Time::sAsString_ISO8601_us(ZTime iTime, bool iIncludeT) +string ZUtil_Time::sAsString_ISO8601_ms(ZTime iTime, bool iIncludeT) { const string YmdHM = sYmdHM(iTime, iIncludeT); - return YmdHM + ZString::sFormat("%09.6f", fmod(iTime.fVal, 60)); + return YmdHM + ZString::sFormat("%06.3f", fmod(iTime.fVal, 60)); } -string ZUtil_Time::sAsString_ISO8601_ms(ZTime iTime, bool iIncludeT) +string ZUtil_Time::sAsString_ISO8601_us(ZTime iTime, bool iIncludeT) { const string YmdHM = sYmdHM(iTime, iIncludeT); - return YmdHM + ZString::sFormat("%06.3f", fmod(iTime.fVal, 60)); + return YmdHM + ZString::sFormat("%09.6f", fmod(iTime.fVal, 60)); } ZTime ZUtil_Time::sFromString_ISO8601(const string& iString) Modified: trunk/zoolib/source/cxx/zoolib/ZUtil_Time.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZUtil_Time.h 2008-11-25 03:41:58 UTC (rev 232) +++ trunk/zoolib/source/cxx/zoolib/ZUtil_Time.h 2008-11-25 03:42:51 UTC (rev 233) @@ -43,8 +43,8 @@ std::string sAsString_ISO8601(ZTime iTime, bool iIncludeT); std::string sAsString_ISO8601_s(ZTime iTime, bool iIncludeT); +std::string sAsString_ISO8601_ms(ZTime iTime, bool iIncludeT); std::string sAsString_ISO8601_us(ZTime iTime, bool iIncludeT); -std::string sAsString_ISO8601_ms(ZTime iTime, bool iIncludeT); ZTime sFromString_ISO8601(const std::string& iString); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-11-25 03:59:10
|
Revision: 240 http://zoolib.svn.sourceforge.net/zoolib/?rev=240&view=rev Author: agreen Date: 2008-11-25 03:59:06 +0000 (Tue, 25 Nov 2008) Log Message: ----------- Move much of the functionality of NPVariantG, NPVariantH into a shared base class NPVariantBase. The subclasses still need to exist, because guest and host have different notions of who's responsible for allocating and disposing NPObjects. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZNetscape.cpp trunk/zoolib/source/cxx/zoolib/ZNetscape.h trunk/zoolib/source/cxx/zoolib/ZNetscape_Guest.cpp trunk/zoolib/source/cxx/zoolib/ZNetscape_Guest.h trunk/zoolib/source/cxx/zoolib/ZNetscape_Host.cpp trunk/zoolib/source/cxx/zoolib/ZNetscape_Host.h trunk/zoolib/source/cxx/zoolib/ZNetscape_Host_Std.cpp trunk/zoolib/source/cxx/zoolib/ZNetscape_Host_Std.h Modified: trunk/zoolib/source/cxx/zoolib/ZNetscape.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNetscape.cpp 2008-11-25 03:56:31 UTC (rev 239) +++ trunk/zoolib/source/cxx/zoolib/ZNetscape.cpp 2008-11-25 03:59:06 UTC (rev 240) @@ -21,6 +21,8 @@ #include "zoolib/ZNetscape.h" #include "zoolib/ZString.h" +using std::string; + // ================================================================================================= #pragma mark - #pragma mark * ZNetscape @@ -77,4 +79,146 @@ #undef CASE +// ================================================================================================= +#pragma mark - +#pragma mark * NPVariantBase + +NPVariantBase::NPVariantBase() + { + type = NPVariantType_Void; + } + +NPVariantBase::NPVariantBase(bool iValue) + { + type = NPVariantType_Bool; + value.boolValue = iValue; + } + +NPVariantBase::NPVariantBase(int32 iValue) + { + type = NPVariantType_Int32; + value.intValue = iValue; + } + +NPVariantBase::NPVariantBase(double iValue) + { + type = NPVariantType_Double; + value.doubleValue = iValue; + } + +NPVariantBase::NPVariantBase(const string& iValue) + { + this->pSetString(iValue); + type = NPVariantType_String; + } + +bool NPVariantBase::IsVoid() const + { return type == NPVariantType_Void; } + +bool NPVariantBase::IsNull() const + { return type == NPVariantType_Null; } + +bool NPVariantBase::IsBool() const + { return type == NPVariantType_Bool; } + +bool NPVariantBase::IsInt32() const + { return type == NPVariantType_Int32; } + +bool NPVariantBase::IsDouble() const + { return type == NPVariantType_Double; } + +bool NPVariantBase::IsString() const + { return type == NPVariantType_String; } + +bool NPVariantBase::IsObject() const + { return type == NPVariantType_Object; } + +bool NPVariantBase::GetBool() const + { return this->DGetBool(false); } + +bool NPVariantBase::GetBool(bool& oValue) const + { + if (type != NPVariantType_Bool) + return false; + oValue = value.boolValue; + return true; + } + +bool NPVariantBase::DGetBool(bool iDefault) const + { + if (type == NPVariantType_Bool) + return value.boolValue; + return iDefault; + } + +int32 NPVariantBase::GetInt32() const + { return this->DGetInt32(0); } + +bool NPVariantBase::GetInt32(int32& oValue) const + { + if (type != NPVariantType_Int32) + return false; + oValue = value.intValue; + return true; + } + +int32 NPVariantBase::DGetInt32(int32 iDefault) const + { + if (type == NPVariantType_Int32) + return value.intValue; + return iDefault; + } + +double NPVariantBase::GetDouble() const + { return this->DGetDouble(0); } + +bool NPVariantBase::GetDouble(double& oValue) const + { + if (type != NPVariantType_Double) + return false; + oValue = value.doubleValue; + return true; + } + +double NPVariantBase::DGetDouble(double iDefault) const + { + if (type == NPVariantType_Double) + return value.doubleValue; + return iDefault; + } + +string NPVariantBase::GetString() const + { return this->DGetString(string()); } + +bool NPVariantBase::GetString(string& oValue) const + { + if (type != NPVariantType_String) + return false; + oValue = + string(sNPStringCharsConst(value.stringValue), sNPStringLengthConst(value.stringValue)); + return true; + } + +string NPVariantBase::DGetString(const string& iDefault) const + { + if (type != NPVariantType_String) + return iDefault; + return string(sNPStringCharsConst(value.stringValue), sNPStringLengthConst(value.stringValue)); + } + +void NPVariantBase::pSetString(const char* iChars, size_t iLength) + { + sNPStringLength(value.stringValue) = iLength; + sNPStringChars(value.stringValue) = static_cast<char*>(malloc(iLength)); + strncpy(sNPStringChars(value.stringValue), iChars, iLength); + } + +void NPVariantBase::pSetString(const std::string& iString) + { + if (size_t theLength = iString.length()) + this->pSetString(iString.data(), theLength); + else + this->pSetString(nil, 0); + } + } // namespace ZNetscape Modified: trunk/zoolib/source/cxx/zoolib/ZNetscape.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNetscape.h 2008-11-25 03:56:31 UTC (rev 239) +++ trunk/zoolib/source/cxx/zoolib/ZNetscape.h 2008-11-25 03:59:06 UTC (rev 240) @@ -35,6 +35,53 @@ std::string sAsString(NPNVariable iVar); std::string sAsString(NPPVariable iVar); +// ================================================================================================= +#pragma mark - +#pragma mark * NPVariantBase + +class NPVariantBase : public NPVariant + { +public: + NPVariantBase(); + + NPVariantBase(bool iValue); + NPVariantBase(int32 iValue); + NPVariantBase(double iValue); + NPVariantBase(const std::string& iValue); + + bool IsVoid() const; + bool IsNull() const; + + bool IsBool() const; + bool IsInt32() const; + bool IsDouble() const; + bool IsString() const; + bool IsObject() const; + + void SetVoid(); + void SetNull(); + + bool GetBool() const; + bool GetBool(bool& oValue) const; + bool DGetBool(bool iDefault) const; + + int32 GetInt32() const; + bool GetInt32(int32& oValue) const; + int32 DGetInt32(int32 iDefault) const; + + double GetDouble() const; + bool GetDouble(double& oValue) const; + double DGetDouble(double iDefault) const; + + std::string GetString() const; + bool GetString(std::string& oValue) const; + std::string DGetString(const std::string& iDefault) const; + +protected: + void pSetString(const char* iChars, size_t iLength); + void pSetString(const std::string& iString); + }; + } // namespace ZNetscape #endif // __ZNetscape__ Modified: trunk/zoolib/source/cxx/zoolib/ZNetscape_Guest.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNetscape_Guest.cpp 2008-11-25 03:56:31 UTC (rev 239) +++ trunk/zoolib/source/cxx/zoolib/ZNetscape_Guest.cpp 2008-11-25 03:59:06 UTC (rev 240) @@ -25,29 +25,35 @@ #include <string> + using std::string; #pragma export on // Mach-o entry points -extern "C" NPError NP_Initialize(NPNetscapeFuncs*); -extern "C" NPError NP_GetEntryPoints(NPPluginFuncs*); -extern "C" NPError NP_Shutdown(); -// For compatibility with CFM browsers. -extern "C" int main( - NPNetscapeFuncs *browserFuncs, NPPluginFuncs *pluginFuncs, NPP_ShutdownProcPtr *shutdown); -#pragma export off +extern "C" { - +NPError NP_Initialize(NPNetscapeFuncs*); NPError NP_Initialize(NPNetscapeFuncs* iBrowserFuncs) { return ZNetscape::GuestMeister::sGet()->Initialize(iBrowserFuncs); } +NPError NP_GetEntryPoints(NPPluginFuncs*); NPError NP_GetEntryPoints(NPPluginFuncs* oPluginFuncs) { return ZNetscape::GuestMeister::sGet()->GetEntryPoints(oPluginFuncs); } +NPError NP_Shutdown(); NPError NP_Shutdown() { return ZNetscape::GuestMeister::sGet()->Shutdown(); } +// For compatibility with CFM browsers. +//int main( +// NPNetscapeFuncs* browserFuncs, NPPluginFuncs* pluginFuncs, NPP_ShutdownProcPtr* shutdown); + +} // extern "C" + +#pragma export off + + // ================================================================================================= #pragma mark - #pragma mark * ZNetscape @@ -103,11 +109,9 @@ } case NPVariantType_String: { - size_t theLength = iOther.value.stringValue.UTF8Length; - value.stringValue.UTF8Length = theLength; - value.stringValue.UTF8Characters = static_cast<char*>(malloc(theLength)); - strncpy(const_cast<char*>(value.stringValue.UTF8Characters), - iOther.value.stringValue.UTF8Characters, theLength); + this->pSetString( + sNPStringCharsConst(iOther.value.stringValue), + sNPStringLengthConst(iOther.value.stringValue)); break; } case NPVariantType_Object: @@ -121,9 +125,7 @@ } NPVariantG::NPVariantG() - { - type = NPVariantType_Void; - } + {} NPVariantG::NPVariantG(const NPVariant& iOther) { @@ -147,28 +149,20 @@ } NPVariantG::NPVariantG(bool iValue) - { - type = NPVariantType_Bool; - value.boolValue = iValue; - } +: NPVariantBase(iValue) + {} NPVariantG::NPVariantG(int32 iValue) - { - type = NPVariantType_Int32; - value.intValue = iValue; - } +: NPVariantBase(iValue) + {} NPVariantG::NPVariantG(double iValue) - { - type = NPVariantType_Double; - value.doubleValue = iValue; - } +: NPVariantBase(iValue) + {} NPVariantG::NPVariantG(const string& iValue) - { - type = NPVariantType_Void; - this->SetString(iValue); - } +: NPVariantBase(iValue) + {} NPVariantG::NPVariantG(NPObjectG* iValue) { @@ -206,27 +200,6 @@ return *this; } -bool NPVariantG::IsVoid() const - { return type == NPVariantType_Void; } - -bool NPVariantG::IsNull() const - { return type == NPVariantType_Null; } - -bool NPVariantG::IsBool() const - { return type == NPVariantType_Bool; } - -bool NPVariantG::IsInt32() const - { return type == NPVariantType_Int32; } - -bool NPVariantG::IsDouble() const - { return type == NPVariantType_Double; } - -bool NPVariantG::IsString() const - { return type == NPVariantType_String; } - -bool NPVariantG::IsObject() const - { return type == NPVariantType_Object; } - void NPVariantG::SetVoid() { this->pRelease(); @@ -239,24 +212,6 @@ type = NPVariantType_Null; } -bool NPVariantG::GetBool() const - { return this->DGetBool(false); } - -bool NPVariantG::GetBool(bool& oValue) const - { - if (type != NPVariantType_Bool) - return false; - oValue = value.boolValue; - return true; - } - -bool NPVariantG::DGetBool(bool iDefault) const - { - if (type == NPVariantType_Bool) - return value.boolValue; - return iDefault; - } - void NPVariantG::SetBool(bool iValue) { this->pRelease(); @@ -264,24 +219,6 @@ value.boolValue = iValue; } -int32 NPVariantG::GetInt32() const - { return this->DGetInt32(0); } - -bool NPVariantG::GetInt32(int32& oValue) const - { - if (type != NPVariantType_Int32) - return false; - oValue = value.intValue; - return true; - } - -int32 NPVariantG::DGetInt32(int32 iDefault) const - { - if (type == NPVariantType_Int32) - return value.intValue; - return iDefault; - } - void NPVariantG::SetInt32(int32 iValue) { this->pRelease(); @@ -289,24 +226,6 @@ value.intValue = iValue; } -double NPVariantG::GetDouble() const - { return this->DGetDouble(0); } - -bool NPVariantG::GetDouble(double& oValue) const - { - if (type != NPVariantType_Double) - return false; - oValue = value.doubleValue; - return true; - } - -double NPVariantG::DGetDouble(double iDefault) const - { - if (type == NPVariantType_Double) - return value.doubleValue; - return iDefault; - } - void NPVariantG::SetDouble(double iValue) { this->pRelease(); @@ -314,31 +233,10 @@ value.doubleValue = iValue; } -string NPVariantG::GetString() const - { return this->DGetString(string()); } - -bool NPVariantG::GetString(string& oValue) const - { - if (type != NPVariantType_String) - return false; - oValue = string(value.stringValue.UTF8Characters, value.stringValue.UTF8Length); - return true; - } - -string NPVariantG::DGetString(const string& iDefault) const - { - if (type != NPVariantType_String) - return iDefault; - return string(value.stringValue.UTF8Characters, value.stringValue.UTF8Length); - } - void NPVariantG::SetString(const string& iValue) { this->pRelease(); - size_t theLength = iValue.length(); - value.stringValue.UTF8Length = theLength; - value.stringValue.UTF8Characters = static_cast<char*>(malloc(theLength)); - strncpy(const_cast<char*>(value.stringValue.UTF8Characters), iValue.data(), theLength); + this->pSetString(iValue); type = NPVariantType_String; } @@ -722,7 +620,8 @@ { return fNPNF.utf8fromidentifier(identifier); } int32_t GuestMeister::Host_IntFromIdentifier(NPIdentifier identifier) - { return reinterpret_cast<int32_t>(fNPNF.intfromidentifier(identifier)); } + { return (int32_t)(fNPNF.intfromidentifier(identifier)); } +// { return reinterpret_cast<int32_t>(fNPNF.intfromidentifier(identifier)); } NPObject* GuestMeister::Host_CreateObject(NPP iNPP, NPClass* aClass) { return fNPNF.createobject(iNPP, aClass); } Modified: trunk/zoolib/source/cxx/zoolib/ZNetscape_Guest.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNetscape_Guest.h 2008-11-25 03:56:31 UTC (rev 239) +++ trunk/zoolib/source/cxx/zoolib/ZNetscape_Guest.h 2008-11-25 03:59:06 UTC (rev 240) @@ -22,7 +22,7 @@ #define __ZNetscape_Guest__ 1 #include "zconfig.h" -#include "zoolib/ZCompat_npapi.h" +#include "zoolib/ZNetscape.h" #include <string> @@ -40,7 +40,7 @@ #pragma mark - #pragma mark * NPVariantG -class NPVariantG : public NPVariant +class NPVariantG : public NPVariantBase { public: NPVariantG(); @@ -60,36 +60,11 @@ NPVariantG& operator=(const std::string& iValue); NPVariantG& operator=(NPObjectG* iValue); - bool IsVoid() const; - bool IsNull() const; - - bool IsBool() const; - bool IsInt32() const; - bool IsDouble() const; - bool IsString() const; - bool IsObject() const; - void SetVoid(); void SetNull(); - - bool GetBool() const; - bool GetBool(bool& oValue) const; - bool DGetBool(bool iDefault) const; void SetBool(bool iValue); - - int32 GetInt32() const; - bool GetInt32(int32& oValue) const; - int32 DGetInt32(int32 iDefault) const; void SetInt32(int32 iValue); - - double GetDouble() const; - bool GetDouble(double& oValue) const; - double DGetDouble(double iDefault) const; void SetDouble(double iValue); - - std::string GetString() const; - bool GetString(std::string& oValue) const; - std::string DGetString(const std::string& iDefault) const; void SetString(const std::string& iValue); NPObjectG* GetObject() const; Modified: trunk/zoolib/source/cxx/zoolib/ZNetscape_Host.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNetscape_Host.cpp 2008-11-25 03:56:31 UTC (rev 239) +++ trunk/zoolib/source/cxx/zoolib/ZNetscape_Host.cpp 2008-11-25 03:59:06 UTC (rev 240) @@ -102,11 +102,9 @@ } case NPVariantType_String: { - size_t theLength = iOther.value.stringValue.UTF8Length; - value.stringValue.UTF8Length = theLength; - value.stringValue.UTF8Characters = static_cast<char*>(malloc(theLength)); - strncpy(const_cast<char*>(value.stringValue.UTF8Characters), - iOther.value.stringValue.UTF8Characters, theLength); + this->pSetString( + sNPStringCharsConst(iOther.value.stringValue), + sNPStringLengthConst(iOther.value.stringValue)); break; } case NPVariantType_Object: @@ -120,9 +118,7 @@ } NPVariantH::NPVariantH() - { - type = NPVariantType_Void; - } + {} NPVariantH::NPVariantH(const NPVariant& iOther) { @@ -146,28 +142,20 @@ } NPVariantH::NPVariantH(bool iValue) - { - type = NPVariantType_Bool; - value.boolValue = iValue; - } +: NPVariantBase(iValue) + {} NPVariantH::NPVariantH(int32 iValue) - { - type = NPVariantType_Int32; - value.intValue = iValue; - } +: NPVariantBase(iValue) + {} NPVariantH::NPVariantH(double iValue) - { - type = NPVariantType_Double; - value.doubleValue = iValue; - } +: NPVariantBase(iValue) + {} -NPVariantH::NPVariantH(const std::string& iValue) - { - type = NPVariantType_Void; - this->SetString(iValue); - } +NPVariantH::NPVariantH(const string& iValue) +: NPVariantBase(iValue) + {} NPVariantH::NPVariantH(NPObjectH* iValue) { @@ -193,7 +181,7 @@ return *this; } -NPVariantH& NPVariantH::operator=(const std::string& iValue) +NPVariantH& NPVariantH::operator=(const string& iValue) { this->SetString(iValue); return *this; @@ -205,27 +193,6 @@ return *this; } -bool NPVariantH::IsVoid() const - { return type == NPVariantType_Void; } - -bool NPVariantH::IsNull() const - { return type == NPVariantType_Null; } - -bool NPVariantH::IsBool() const - { return type == NPVariantType_Bool; } - -bool NPVariantH::IsInt32() const - { return type == NPVariantType_Int32; } - -bool NPVariantH::IsDouble() const - { return type == NPVariantType_Double; } - -bool NPVariantH::IsString() const - { return type == NPVariantType_String; } - -bool NPVariantH::IsObject() const - { return type == NPVariantType_Object; } - void NPVariantH::SetVoid() { this->pRelease(); @@ -238,24 +205,6 @@ type = NPVariantType_Null; } -bool NPVariantH::GetBool() const - { return this->DGetBool(false); } - -bool NPVariantH::GetBool(bool& oValue) const - { - if (type != NPVariantType_Bool) - return false; - oValue = value.boolValue; - return true; - } - -bool NPVariantH::DGetBool(bool iDefault) const - { - if (type == NPVariantType_Bool) - return value.boolValue; - return iDefault; - } - void NPVariantH::SetBool(bool iValue) { this->pRelease(); @@ -263,24 +212,6 @@ value.boolValue = iValue; } -int32 NPVariantH::GetInt32() const - { return this->DGetInt32(0); } - -bool NPVariantH::GetInt32(int32& oValue) const - { - if (type != NPVariantType_Int32) - return false; - oValue = value.intValue; - return true; - } - -int32 NPVariantH::DGetInt32(int32 iDefault) const - { - if (type == NPVariantType_Int32) - return value.intValue; - return iDefault; - } - void NPVariantH::SetInt32(int32 iValue) { this->pRelease(); @@ -288,24 +219,6 @@ value.intValue = iValue; } -double NPVariantH::GetDouble() const - { return this->DGetDouble(0); } - -bool NPVariantH::GetDouble(double& oValue) const - { - if (type != NPVariantType_Double) - return false; - oValue = value.doubleValue; - return true; - } - -double NPVariantH::DGetDouble(double iDefault) const - { - if (type == NPVariantType_Double) - return value.doubleValue; - return iDefault; - } - void NPVariantH::SetDouble(double iValue) { this->pRelease(); @@ -313,31 +226,10 @@ value.doubleValue = iValue; } -std::string NPVariantH::GetString() const - { return this->DGetString(string()); } - -bool NPVariantH::GetString(std::string& oValue) const +void NPVariantH::SetString(const string& iValue) { - if (type != NPVariantType_String) - return false; - oValue = string(value.stringValue.UTF8Characters, value.stringValue.UTF8Length); - return true; - } - -std::string NPVariantH::DGetString(const std::string& iDefault) const - { - if (type != NPVariantType_String) - return iDefault; - return string(value.stringValue.UTF8Characters, value.stringValue.UTF8Length); - } - -void NPVariantH::SetString(const std::string& iValue) - { this->pRelease(); - size_t theLength = iValue.length(); - value.stringValue.UTF8Length = theLength; - value.stringValue.UTF8Characters = static_cast<char*>(malloc(theLength)); - strncpy(const_cast<char*>(value.stringValue.UTF8Characters), iValue.data(), theLength); + this->pSetString(iValue); type = NPVariantType_String; } @@ -602,8 +494,6 @@ oNPNF.memfree = sMemFree; oNPNF.memflush = sMemFlush; oNPNF.reloadplugins = sReloadPlugins; - oNPNF.getJavaEnv = sGetJavaEnv; - oNPNF.getJavaPeer = sGetJavaPeer; oNPNF.geturlnotify = sGetURLNotify; oNPNF.posturlnotify = sPostURLNotify; oNPNF.getvalue = sGetValue; @@ -617,8 +507,6 @@ oNPNF.getintidentifier = sGetIntIdentifier; oNPNF.identifierisstring = sIdentifierIsString; oNPNF.utf8fromidentifier = sUTF8FromIdentifier; - // AG. Need to do this cast because Mac headers are wrong. - oNPNF.intfromidentifier = (NPN_IntFromIdentifierProcPtr)sIntFromIdentifier; oNPNF.createobject = sCreateObject; oNPNF.retainobject = sRetainObject; oNPNF.releaseobject = sReleaseObject; @@ -632,6 +520,27 @@ oNPNF.hasmethod = sHasMethod; oNPNF.releasevariantvalue = sReleaseVariantValue; oNPNF.setexception = sSetException; + +// Doing these out of order because they're problematic in one way or another. + // AG. Need to do this cast because Mac headers are wrong. + + #if defined(NewNPN_IntFromIdentifierProc) + oNPNF.intfromidentifier = sIntFromIdentifier; + #else + oNPNF.intfromidentifier = (NPN_IntFromIdentifierProcPtr)sIntFromIdentifier; + #endif + + #if defined(NewNPN_GetJavaEnvProc) + oNPNF.getJavaEnv = (NPN_GetJavaEnvUPP)sGetJavaEnv; + #else + oNPNF.getJavaEnv = sGetJavaEnv; + #endif + + #if defined(NewNPN_GetJavaPeerProc) + oNPNF.getJavaPeer = (NPN_GetJavaPeerUPP)sGetJavaPeer; + #else + oNPNF.getJavaPeer = sGetJavaPeer; + #endif } HostMeister::HostMeister() @@ -770,12 +679,12 @@ { return sHostFromNPP(npp)->Host_CreateObject(npp, aClass); } bool HostMeister::sInvoke(NPP npp, - NPObject* obj, NPIdentifier methodName, const NPVariant* args, unsigned argCount, + NPObject* obj, NPIdentifier methodName, const NPVariant* args, uint32_t argCount, NPVariant* result) { return sHostFromNPP(npp)->Host_Invoke(npp, obj, methodName, args, argCount, result); } bool HostMeister::sInvokeDefault(NPP npp, - NPObject* obj, const NPVariant* args, unsigned argCount, NPVariant* result) + NPObject* obj, const NPVariant* args, uint32_t argCount, NPVariant* result) { return sHostFromNPP(npp)->Host_InvokeDefault(npp, obj, args, argCount, result); } bool HostMeister::sEvaluate(NPP npp, @@ -929,7 +838,7 @@ } else if (countPossible > 0) { - countPossible = std::min(countPossible, 64 * 1024); + countPossible = std::min(countPossible, int32(64 * 1024)); vector<uint8> buffer; buffer.resize(countPossible); @@ -1056,7 +965,7 @@ break; } - countPossible = std::min(countPossible, 1024 * 1024); + countPossible = std::min(countPossible, int32(1024 * 1024)); vector<uint8> buffer; buffer.resize(countPossible); Modified: trunk/zoolib/source/cxx/zoolib/ZNetscape_Host.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNetscape_Host.h 2008-11-25 03:56:31 UTC (rev 239) +++ trunk/zoolib/source/cxx/zoolib/ZNetscape_Host.h 2008-11-25 03:59:06 UTC (rev 240) @@ -22,17 +22,14 @@ #define __ZNetscape_Host__ 1 #include "zconfig.h" -#include <string> - -#include "zoolib/ZCompat_npapi.h" #include "zoolib/ZGeom.h" #include "zoolib/ZMemoryBlock.h" -#include "zoolib/ZRefCount.h" -#include "zoolib/ZStream.h" +#include "zoolib/ZNetscape.h" #include "zoolib/ZStreamer.h" #include "zoolib/ZThread.h" #include <list> +#include <string> namespace ZNetscape { @@ -48,7 +45,7 @@ #pragma mark - #pragma mark * NPVariantH -class NPVariantH : public NPVariant +class NPVariantH : public NPVariantBase { public: NPVariantH(); @@ -68,36 +65,11 @@ NPVariantH& operator=(const std::string& iValue); NPVariantH& operator=(NPObjectH* iValue); - bool IsVoid() const; - bool IsNull() const; - - bool IsBool() const; - bool IsInt32() const; - bool IsDouble() const; - bool IsString() const; - bool IsObject() const; - void SetVoid(); void SetNull(); - - bool GetBool() const; - bool GetBool(bool& oValue) const; - bool DGetBool(bool iDefault) const; void SetBool(bool iValue); - - int32 GetInt32() const; - bool GetInt32(int32& oValue) const; - int32 DGetInt32(int32 iDefault) const; void SetInt32(int32 iValue); - - double GetDouble() const; - bool GetDouble(double& oValue) const; - double DGetDouble(double iDefault) const; void SetDouble(double iValue); - - std::string GetString() const; - bool GetString(std::string& oValue) const; - std::string DGetString(const std::string& iDefault) const; void SetString(const std::string& iValue); NPObjectH* GetObject() const; @@ -304,11 +276,11 @@ static NPObject* sCreateObject(NPP npp, NPClass* aClass); static bool sInvoke(NPP npp, - NPObject* obj, NPIdentifier methodName, const NPVariant* args, unsigned argCount, + NPObject* obj, NPIdentifier methodName, const NPVariant* args, uint32_t argCount, NPVariant* result); static bool sInvokeDefault(NPP npp, - NPObject* obj, const NPVariant* args, unsigned argCount, NPVariant* result); + NPObject* obj, const NPVariant* args, uint32_t argCount, NPVariant* result); static bool sEvaluate(NPP npp, NPObject* obj, NPString* script, NPVariant* result); @@ -437,11 +409,11 @@ virtual NPObject* Host_CreateObject(NPP npp, NPClass* aClass) = 0; virtual bool Host_Invoke(NPP npp, - NPObject* obj, NPIdentifier methodName, const NPVariant* args, unsigned argCount, + NPObject* obj, NPIdentifier methodName, const NPVariant* args, uint32_t argCount, NPVariant* result) = 0; virtual bool Host_InvokeDefault(NPP npp, - NPObject* obj, const NPVariant* args, unsigned argCount, NPVariant* result) = 0; + NPObject* obj, const NPVariant* args, uint32_t argCount, NPVariant* result) = 0; virtual bool Host_Evaluate(NPP npp, NPObject* obj, NPString* script, NPVariant* result) = 0; Modified: trunk/zoolib/source/cxx/zoolib/ZNetscape_Host_Std.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNetscape_Host_Std.cpp 2008-11-25 03:56:31 UTC (rev 239) +++ trunk/zoolib/source/cxx/zoolib/ZNetscape_Host_Std.cpp 2008-11-25 03:59:06 UTC (rev 240) @@ -35,6 +35,8 @@ #include "zoolib/ZUtil_STL.h" #include "zoolib/ZUtil_Strim_Tuple.h" +#include "zoolib/ZCompat_string.h" // For strdup + using std::map; using std::pair; using std::string; @@ -160,9 +162,9 @@ } else if (variant->type == NPVariantType_String) { - free((void*)variant->value.stringValue.UTF8Characters); - variant->value.stringValue.UTF8Characters = 0; - variant->value.stringValue.UTF8Length = 0; + free((void*)sNPStringChars(variant->value.stringValue)); + sNPStringChars(variant->value.stringValue) = nil; + sNPStringLength(variant->value.stringValue) = 0; } variant->type = NPVariantType_Void; } @@ -212,7 +214,7 @@ static bool sHTTP(const ZStreamW& w, const ZStreamR& r, const string& iHost, const string& iPath, const ZMemoryBlock* iPOSTData, - int& oResponseCode, ZMemoryBlock& oRawHeaders, ZTuple& oHeaders, string& oMIME) + int32& oResponseCode, ZMemoryBlock& oRawHeaders, ZTuple& oHeaders, string& oMIME) { if (ZLOG(s, eDebug, "ZNetscape")) s << "sHTTP"; @@ -338,7 +340,7 @@ break; } - int theResponseCode; + int32 theResponseCode; ZTuple theHeaders; ZMemoryBlock theRawHeaders; string theMIME; @@ -506,8 +508,9 @@ if (URL == strstr(URL, "http:")) { + HTTPer* theG = new HTTPer(this, URL, nil, notifyData); + ZMutexLocker locker(fMutex); - HTTPer* theG = new HTTPer(this, URL, nil, notifyData); fHTTPers.push_back(theG); theG->Start(); return NPERR_NO_ERROR; @@ -527,6 +530,8 @@ { ZMemoryBlock theData(buf, len); HTTPer* theG = new HTTPer(this, URL, &theData, notifyData); + + ZMutexLocker locker(fMutex); fHTTPers.push_back(theG); theG->Start(); return NPERR_NO_ERROR; @@ -586,7 +591,7 @@ } bool Host_Std::Host_Invoke(NPP npp, - NPObject* obj, NPIdentifier methodName, const NPVariant* args, unsigned argCount, + NPObject* obj, NPIdentifier methodName, const NPVariant* args, uint32_t argCount, NPVariant* result) { if (ZLOG(s, eDebug, "Host_Std")) @@ -599,7 +604,7 @@ } bool Host_Std::Host_InvokeDefault(NPP npp, - NPObject* obj, const NPVariant* args, unsigned argCount, NPVariant* result) + NPObject* obj, const NPVariant* args, uint32_t argCount, NPVariant* result) { if (ZLOG(s, eDebug, "Host_Std")) s.Writef("InvokeDefault"); Modified: trunk/zoolib/source/cxx/zoolib/ZNetscape_Host_Std.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNetscape_Host_Std.h 2008-11-25 03:56:31 UTC (rev 239) +++ trunk/zoolib/source/cxx/zoolib/ZNetscape_Host_Std.h 2008-11-25 03:59:06 UTC (rev 240) @@ -135,11 +135,11 @@ virtual NPObject* Host_CreateObject(NPP npp, NPClass* aClass); virtual bool Host_Invoke(NPP npp, - NPObject* obj, NPIdentifier methodName, const NPVariant* args, unsigned argCount, + NPObject* obj, NPIdentifier methodName, const NPVariant* args, uint32_t argCount, NPVariant* result); virtual bool Host_InvokeDefault(NPP npp, - NPObject* obj, const NPVariant* args, unsigned argCount, NPVariant* result); + NPObject* obj, const NPVariant* args, uint32_t argCount, NPVariant* result); virtual bool Host_Evaluate(NPP npp, NPObject* obj, NPString* script, NPVariant* result); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-11-27 15:20:45
|
Revision: 241 http://zoolib.svn.sourceforge.net/zoolib/?rev=241&view=rev Author: agreen Date: 2008-11-27 15:20:36 +0000 (Thu, 27 Nov 2008) Log Message: ----------- Move the ZThreadSafe macros into their own header, so that use of ZRef doesn't pull in all the ZThread stuff. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZThread.cpp trunk/zoolib/source/cxx/zoolib/ZThread.h Added Paths: ----------- trunk/zoolib/source/cxx/zoolib/ZThreadSafe.h Modified: trunk/zoolib/source/cxx/zoolib/ZThread.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZThread.cpp 2008-11-25 03:59:06 UTC (rev 240) +++ trunk/zoolib/source/cxx/zoolib/ZThread.cpp 2008-11-27 15:20:36 UTC (rev 241) @@ -261,15 +261,16 @@ #elif ZCONFIG(API_Thread, Win32) fThreadHANDLE = (HANDLE) ::_beginthreadex(nil, 0, sThreadEntry_Win32, - this, fStarted ? 0 : CREATE_SUSPENDED, reinterpret_cast<unsigned int*>(&fThreadID)); + this, fStarted ? 0 : CREATE_SUSPENDED, reinterpret_cast<unsigned int*>(&fThreadID)); if (!fThreadHANDLE) throw bad_alloc(); #elif ZCONFIG(API_Thread, POSIX) - // Because there's no standard way to create a suspended thread we allocate a mutex/condlock combo, which - // will get fired by our Start method. If we used a mutex, then only the thread that creates this thread - // would be able to release it to allow this thread to start executing. + // Because there's no standard way to create a suspended thread we allocate a + // mutex/condlock combo, which will get fired by our Start method. If we used + // a mutex, then only the thread that creates this thread would be able to + // release it to allow this thread to start executing. ::pthread_mutex_init(&fMutex_Start, nil); ::pthread_cond_init(&fCond_Start, nil); @@ -310,8 +311,8 @@ #endif #if ZCONFIG(API_Thread, Win32) - // AG 2002-05-02. After examining MetroWerks' and Microsoft's runtime library sources - // it's clear that we have to close the thread handle iff we create the thread using beginthreadex. + // AG 2002-05-02. After examining MetroWerks' and Microsoft's runtime it's clear that we + // have to close the thread handle iff we create the thread using beginthreadex. if (HANDLE theThreadHANDLE = sCurrentThreadHANDLE()) ::CloseHandle(theThreadHANDLE); #endif @@ -457,7 +458,8 @@ FILETIME timeNow; ::GetSystemTimeAsFileTime(&timeNow); oRealTime = (*reinterpret_cast<int64*>(&timeNow)) / 10; - oCumulativeRunTime = (*reinterpret_cast<int64*>(&kernelTime) + *reinterpret_cast<int64*>(&userTime)) / 10; + oCumulativeRunTime = (*reinterpret_cast<int64*>(&kernelTime) + + *reinterpret_cast<int64*>(&userTime)) / 10; } else { @@ -842,7 +844,8 @@ if (theWaiter.fNext) { theWaiter.fNext->fSemaphoreDisposed = true; - while (theWaiter.fNext->fThreadHANDLE && ::ResumeThread(theWaiter.fNext->fThreadHANDLE) != 1) + while (theWaiter.fNext->fThreadHANDLE + && ::ResumeThread(theWaiter.fNext->fThreadHANDLE) != 1) {} } return ZThread::errorDisposed; @@ -851,7 +854,8 @@ ::sAcquireSpinlock(&fSpinlock); if (theWaiter.fNext) { - while (theWaiter.fNext->fThreadHANDLE && ::ResumeThread(theWaiter.fNext->fThreadHANDLE) != 1) + while (theWaiter.fNext->fThreadHANDLE + && ::ResumeThread(theWaiter.fNext->fThreadHANDLE) != 1) {} } @@ -1139,9 +1143,9 @@ #pragma mark - #pragma mark * ZMutexNR -// AG 2000-03-08. ZMutexNR is now a Benaphore. When acquiring, we increment fLock, and if it was already -// greater than zero, then we block on fSem. When releasing we decrement fLock, and if it was greater than one, -// then we release fSem. +// AG 2000-03-08. ZMutexNR is now a Benaphore. When acquiring, we increment fLock, and if it was +// already greater than zero, then we block on fSem. When releasing we decrement fLock, and if it +// was greater than one, then we release fSem. ZMutexNR::ZMutexNR(const char* iName) : fSem(0, iName) @@ -1202,8 +1206,9 @@ } else { - // AG 2000-07-12. We call ZDebugStop in a loop so that the message comes up over and over, - // so if I over-eagerly tell the debugger to start running again, we'll just drop back into the debugger. + // AG 2000-07-12. We call ZDebugStop in a loop so that the message comes up over + // and over, so if I over-eagerly tell the debugger to start running again, we'll + // just drop back into the debugger. for (;;) { ZDebugStopf(0, (result->c_str())); @@ -1232,7 +1237,7 @@ if (string* result = iOwnerThread->CheckForDeadlock(iAcquiringThread)) { *result += ZString::sFormat("mutex %08X (\"%s\"), owned by thread %08X ID %08X (\"%s\")\n", - this, this->fName, iOwnerThread, iOwnerThread->fThreadID, iOwnerThread->fName); + this, this->fName, iOwnerThread, iOwnerThread->fThreadID, iOwnerThread->fName); return result; } return nil; @@ -1281,7 +1286,8 @@ ZMutex::~ZMutex() { // It's only legal to destroy an unowned mutex, or one that is owned by the current thread - ZAssertStopf(kDebug_Thread, fThreadID_Owner == kThreadID_None || fThreadID_Owner == ZThread::sCurrentID(), ("Mutex name %s", (fName ? fName : "none"))); + ZAssertStopf(kDebug_Thread, fThreadID_Owner == kThreadID_None + || fThreadID_Owner == ZThread::sCurrentID(), ("Mutex name %s", (fName ? fName : "none"))); } ZThread::Error ZMutex::Acquire() @@ -1298,17 +1304,17 @@ ZThread::Error ZMutex::MutexAcquire(bigtime_t iMicroseconds) { - // This check of fThreadID_Owner is safe, even if it doesn't look it. fThreadID_Owner is going to have one of - // three values. It could be nil, in which case it won't match sCurrentID, or it could be - // the ID of some other thread, in which case it still won't match currentID. In both these - // cases we'll simply call Internal_Acquire, which will block on fSem. The third value it + // This check of fThreadID_Owner is safe, even if it doesn't look it. fThreadID_Owner is going + // to have one of three values. It could be nil, in which case it won't match sCurrentID, or it + // could be the ID of some other thread, in which case it still won't match currentID. In both + // these cases we'll simply call Internal_Acquire, which will block on fSem. The third value it // could have is sCurrentID, in which case we don't block on fSem, we just increment fCount. // In the first two cases some other thread could race us and change the value from nil to // some other ID, or vice versa -- which won't make any difference to us, we need to block - // anyway. The only way this could fuck up is if some other thread changes the value of fThreadID_Owner, - // and that change is not atomic -- so that at the point we read its value, fThreadID_Owner's bytes have - // taken on some value which isn't nil, and isn't the ID of the other thread, *and* which - // accidentally matches our ID. + // anyway. The only way this could fuck up is if some other thread changes the value of + // fThreadID_Owner, and that change is not atomic -- so that at the point we read its value, + // fThreadID_Owner's bytes have taken on some value which isn't nil, and isn't the ID of the + // other thread, *and* which accidentally matches our ID. if (fThreadID_Owner != ZThread::sCurrentID()) { ZThread::Error err = this->Internal_Acquire(iMicroseconds); @@ -1592,15 +1598,21 @@ fMutex_Structure.Acquire(); ZThread::ThreadID currentID = ZThread::sCurrentID(); - // Trip an assertion if this is a call on a lock we've already locked for reading, which means we're gonna deadlock. - ZAssertLogf(kDebug_Thread, find(fVector_CurrentReaders.begin(), fVector_CurrentReaders.end(), currentID) == fVector_CurrentReaders.end(), ("DEADLOCK")); + // Trip an assertion if this is a call on a lock we've already + // locked for reading, which means we're gonna deadlock. + ZAssertLogf(kDebug_Thread, + find(fVector_CurrentReaders.begin(), fVector_CurrentReaders.end(), currentID) + == fVector_CurrentReaders.end(), ("DEADLOCK")); if (fThreadID_CurrentWriter == currentID) { - // We're the current writer so this is a recursive acquisition and we can just increment the count. + // We're the current writer so this is a recursive + // acquisition and we can just increment the count. ++fCount_CurrentWriter; ZAssertStop(kDebug_Thread, fCount_CurrentReaders == 0); - ZDebugLogf(kDebug_RWLock, ("Thread %04X, Got it write recursive %d", ZThread::sCurrentID(), fCount_CurrentWriter)); + ZDebugLogf(kDebug_RWLock, + ("Thread %04X, Got it write recursive %d", ZThread::sCurrentID(), + fCount_CurrentWriter)); fMutex_Structure.Release(); return ZThread::errorNone; } @@ -1628,7 +1640,8 @@ // We're no longer waiting --fCount_WaitingWriters; - ZAssertStop(kDebug_Thread, fThreadID_CurrentWriter == kThreadID_None && fCount_CurrentWriter == 0); + ZAssertStop(kDebug_Thread, + fThreadID_CurrentWriter == kThreadID_None && fCount_CurrentWriter == 0); ZAssertStop(kDebug_Thread, fCount_CurrentReaders == 0); fThreadID_CurrentWriter = currentID; @@ -1655,9 +1668,9 @@ if (fThreadID_CurrentWriter == currentID) { - // We're the current writer, just reacquire the write lock (this is fair, cause we've already - // locked out other readers by the fact that we posess the write lock. And anyway, if we were - // to fail to acquire the read lock, we'd just deadlock the entire system) + // We're the current writer, just reacquire the write lock (this is fair, cause we've + // already locked out other readers by the fact that we posess the write lock. And anyway, + // if we were to fail to acquire the read lock, we'd just deadlock the entire system) ++fCount_CurrentWriter; } else @@ -1668,7 +1681,9 @@ // The following check on fCount_CurrentReaders short circuits the call to find(); if // fCount_CurrentReaders is zero then obviously we can't find ourselves in the vector. - if (fCount_CurrentReaders && find(fVector_CurrentReaders.begin(), fVector_CurrentReaders.end(), currentID) != fVector_CurrentReaders.end()) + if (fCount_CurrentReaders + && find(fVector_CurrentReaders.begin(), fVector_CurrentReaders.end(), currentID) + != fVector_CurrentReaders.end()) { // We're a current reader, so just stick ourselves on the list again. ++fCount_CurrentReaders; @@ -1678,13 +1693,16 @@ fVector_Thread_CurrentReaders.push_back(currentThread); #endif // ZCONFIG_Thread_DeadlockDetect - ZDebugLogf(kDebug_RWLock, ("Thread %04X, Got it read recursive, total: %d", ZThread::sCurrentID(), fCount_CurrentReaders)); + ZDebugLogf(kDebug_RWLock, + ("Thread %04X, Got it read recursive, total: %d", ZThread::sCurrentID(), + fCount_CurrentReaders)); } else { if (fCount_WaitingWriters != 0 || fCount_CurrentReaders == 0) { - // There are waiting writers, or there are no current readers, so we have to ensure the access lock is grabbed + // There are waiting writers, or there are no current + // readers, so we have to ensure the access lock is grabbed ++fCount_WaitingReaders; if (fCount_WaitingReaders == 1) { @@ -1705,8 +1723,11 @@ fMutex_Structure.Acquire(); ZDebugLogf(kDebug_RWLock, ("Thread %04X, Got it read", ZThread::sCurrentID())); - ZAssertStop(kDebug_Thread, fThreadID_CurrentWriter == 0 && fCount_CurrentWriter == 0); - ZDebugLogf(kDebug_RWLock, ("Thread %04X, Signal subs: %d", ZThread::sCurrentID(), fCount_WaitingReaders - 1)); + ZAssertStop(kDebug_Thread, + fThreadID_CurrentWriter == 0 && fCount_CurrentWriter == 0); + ZDebugLogf(kDebug_RWLock, + ("Thread %04X, Signal subs: %d", ZThread::sCurrentID(), + fCount_WaitingReaders - 1)); // We've acquired the access lock, so let the subsequent readers through. fSem_SubsequentReaders.Signal(fCount_WaitingReaders - 1); @@ -1721,7 +1742,8 @@ else { // We're a subsequent reader. Wait for the read barrier to be opened - ZDebugLogf(kDebug_RWLock, ("Thread %04X, Waiting subsequent", ZThread::sCurrentID())); + ZDebugLogf(kDebug_RWLock, + ("Thread %04X, Waiting subsequent", ZThread::sCurrentID())); fMutex_Structure.Release(); @@ -1737,8 +1759,11 @@ fMutex_Structure.Acquire(); - ZDebugLogf(kDebug_RWLock, ("Thread %04X, Got it subsequent, total: %d", ZThread::sCurrentID(), fCount_CurrentReaders)); - ZAssertStop(kDebug_Thread, fThreadID_CurrentWriter == 0 && fCount_CurrentWriter == 0); + ZDebugLogf(kDebug_RWLock, + ("Thread %04X, Got it subsequent, total: %d", + ZThread::sCurrentID(), fCount_CurrentReaders)); + ZAssertStop(kDebug_Thread, + fThreadID_CurrentWriter == 0 && fCount_CurrentWriter == 0); fVector_CurrentReaders.push_back(currentID); @@ -1750,7 +1775,8 @@ else { // There were no waiting writers and there are current readers. - ZAssertStop(kDebug_Thread, fThreadID_CurrentWriter == 0 && fCount_CurrentWriter == 0); + ZAssertStop(kDebug_Thread, + fThreadID_CurrentWriter == 0 && fCount_CurrentWriter == 0); ZDebugLogf(kDebug_RWLock, ("Thread %04X, Got it other", ZThread::sCurrentID())); ++fCount_CurrentReaders; @@ -1813,13 +1839,16 @@ // there can't be a current writer ZAssertStop(kDebug_Thread, fThreadID_CurrentWriter == kThreadID_None); - vector<ZThread::ThreadID>::iterator theIter = find(fVector_CurrentReaders.begin(), fVector_CurrentReaders.end(), currentID); + vector<ZThread::ThreadID>::iterator theIter + = find(fVector_CurrentReaders.begin(), fVector_CurrentReaders.end(), currentID); ZAssertStop(kDebug_Thread, theIter != fVector_CurrentReaders.end()); fVector_CurrentReaders.erase(theIter); #if ZCONFIG_Thread_DeadlockDetect ZThread* currentThread = ::sCurrent(); - vector<ZThread*>::iterator iterThread = find(fVector_Thread_CurrentReaders.begin(), fVector_Thread_CurrentReaders.end(), currentThread); + vector<ZThread*>::iterator iterThread + = find(fVector_Thread_CurrentReaders.begin(), fVector_Thread_CurrentReaders.end(), + currentThread); ZAssertStop(kDebug_Thread, iterThread != fVector_Thread_CurrentReaders.end()); fVector_Thread_CurrentReaders.erase(iterThread); #endif // ZCONFIG_Thread_DeadlockDetect @@ -1851,7 +1880,8 @@ return true; } - if (find(fVector_CurrentReaders.begin(), fVector_CurrentReaders.end(), currentID) != fVector_CurrentReaders.end()) + if (find(fVector_CurrentReaders.begin(), fVector_CurrentReaders.end(), currentID) + != fVector_CurrentReaders.end()) { // We're a current reader. fMutex_Structure.Release(); @@ -1892,7 +1922,8 @@ } else { - for (vector<ZThread*>::iterator i = fVector_Thread_CurrentReaders.begin(); i != fVector_Thread_CurrentReaders.end(); ++i) + for (vector<ZThread*>::iterator i = fVector_Thread_CurrentReaders.begin(); + i != fVector_Thread_CurrentReaders.end(); ++i) { if (string* result = iLock->CheckDeadlockThread(iAcquiringThread, *i)) return result; Modified: trunk/zoolib/source/cxx/zoolib/ZThread.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZThread.h 2008-11-25 03:59:06 UTC (rev 240) +++ trunk/zoolib/source/cxx/zoolib/ZThread.h 2008-11-27 15:20:36 UTC (rev 241) @@ -29,17 +29,16 @@ #include "zoolib/ZAtomic.h" #include "zoolib/ZCompat_NonCopyable.h" #include "zoolib/ZDebug.h" +#include "zoolib/ZThreadSafe.h" #include "zoolib/ZTypes.h" // For bigtime_t +// ================================================================================================= + #define ZCONFIG_API_Thread_Unknown 0 #define ZCONFIG_API_Thread_Win32 2 #define ZCONFIG_API_Thread_POSIX 4 #define ZCONFIG_API_Thread_Be 8 -// ================================================================================================= - -#include "zoolib/ZCONFIG_SPI.h" - #ifndef ZCONFIG_API_Thread # if 0 # elif ZCONFIG_SPI_Enabled(Win) @@ -53,7 +52,6 @@ # error "Don't know what thread API we're using" #endif - // ================================================================================================= #pragma mark - #pragma mark * ZThread Configuration @@ -75,7 +73,6 @@ # define ZCONFIG_Thread_UseCurrent 0 #endif -// ================================================== // Include appropriate headers for each platform, and set up ZCONFIG_Thread_Preemptive. // // ZCONFIG_Thread_Preemptive is 1 if threading is preemptive, that is if control can switch @@ -98,64 +95,12 @@ # define ZCONFIG_Thread_Preemptive 1 #endif -// ================================================== +// ================================================================================================= // A macro that has proven to be useful. #define ZAssertLocked(a, b) ZAssertStop(a, (b).IsLocked()) // ================================================================================================= #pragma mark - -#pragma mark * ZThreadSafe Macros -// "Safe" increment and decrement. In non-preemptive environments this will do cheap addition/subtraction, -// and in preemptive situations it will do slightly less efficient, but thread-safe operations. You need to use -// the ZThreadSafe_t type for variables that will manipulated by this. Right now it is a struct, but might -// degenerate into a simple integer at some point. ZThreadSafe_IncReturnNew and ZThreadSafe_DecReturnNew -// are used by windows COM objects' AddRef and Release methods. - -typedef ZAtomic_t ZThreadSafe_t; - -#if ZCONFIG_Thread_Preemptive - - #define ZThreadSafe_Get(x) ZAtomic_Get(&x) - #define ZThreadSafe_Set(x, y) ZAtomic_Set(&x, y) - #define ZThreadSafe_Swap(x, y) ZAtomic_Swap(&x, y) - - #define ZThreadSafe_Inc(x) ZAtomic_Inc(&x) - #define ZThreadSafe_Dec(x) ZAtomic_Dec(&x) - #define ZThreadSafe_DecAndTest(x) ZAtomic_DecAndTest(&x) - - #define ZThreadSafe_IncReturnNew(x) (ZAtomic_Add(&x, 1) + 1) - #define ZThreadSafe_DecReturnNew(x) (ZAtomic_Add(&x, -1) - 1) - - #define ZThreadSafe_IncReturnOld(x) (ZAtomic_Add(&x, 1)) - #define ZThreadSafe_DecReturnOld(x) (ZAtomic_Add(&x, -1)) - -#else // ZCONFIG_Thread_Preemptive - - inline int ZThreadSafe_SwapHelper(ZThreadSafe_t& inX, int inY) - { - int oldValue = inX.fValue; - inX.fValue = inY; - return oldValue; - } - #define ZThreadSafe_Swap(x, y) ZThreadSafe_SwapHelper(x, y) - - #define ZThreadSafe_Get(x) (x.fValue) - #define ZThreadSafe_Set(x, y) ((void)((x).fValue = y)) - - #define ZThreadSafe_Inc(x) ((void)(++(x).fValue)) - #define ZThreadSafe_Dec(x) ((void)(--(x).fValue)) - #define ZThreadSafe_DecAndTest(x) ((--(x).fValue) == 0) - - #define ZThreadSafe_IncReturnNew(x) (++(x).fValue) - #define ZThreadSafe_DecReturnNew(x) (--(x).fValue) - - #define ZThreadSafe_IncReturnOld(x) ((x).fValue++) - #define ZThreadSafe_DecReturnOld(x) ((x).fValue--) - -#endif // ZCONFIG_Thread_Preemptive - -// ================================================================================================= -#pragma mark - #pragma mark * ZThreadCurrentHelper #if ZCONFIG_Thread_UseCurrent @@ -346,14 +291,14 @@ #pragma mark * ZSemaphore // ZSemaphore is available for use by applications and provides the foundation for all the other -// synchronization facilities. ZFiber and BeOS provide exactly the behavior we want, but in the case -// of BeOS the system-wide limit on semaphores precludes their profligate use, which can be problematic. -// A call to Wait specifies a count and a timeout (the version without a timeout parameter has an effectively -// infinite timeout). Wait will return one of three results: ZThread::errorNone if all the signals were -// satisfied within the timeout, ZThread::errorTimeout if not all the signals could be satisified -// within the timeout and ZThread::errorDisposed if the semaphore was destroyed *whilst* Wait was blocked. -// If code is calling Wait whilst the destructor is being called the behavior is not well-defined -- any -// Waits have to be already blocked. +// synchronization facilities. ZFiber and BeOS provide exactly the behavior we want, but in the +// case of BeOS the system-wide limit on semaphores precludes their profligate use, which can be +// problematic. A call to Wait specifies a count and a timeout (the version without a timeout +// parameter has an effectively infinite timeout). Wait will return one of three results: +// ZThread::errorNone if all the signals were satisfied within the timeout, ZThread::errorTimeout +// if not all the signals could be satisified within the timeout and ZThread::errorDisposed if the +// semaphore was destroyed *whilst* Wait was blocked. If code is calling Wait whilst the destructor +// is being called the behavior is not well-defined -- any Waits have to be already blocked. class ZSemaphore : ZooLib::NonCopyable { @@ -679,8 +624,8 @@ ~ZLocker(); // Used to temporarily release, then (usually) reacquire the lock - ZThread::Error Acquire(); void Release(); + ZThread::Error Acquire(); bool IsOkay() { return fOkay; } @@ -701,8 +646,8 @@ ~ZMutexLocker(); // Used to temporarily release, then (usually) reacquire the lock - ZThread::Error Acquire(); void Release(); + ZThread::Error Acquire(); bool IsOkay() { return fOkay; } Added: trunk/zoolib/source/cxx/zoolib/ZThreadSafe.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZThreadSafe.h (rev 0) +++ trunk/zoolib/source/cxx/zoolib/ZThreadSafe.h 2008-11-27 15:20:36 UTC (rev 241) @@ -0,0 +1,81 @@ +/* ------------------------------------------------------------------------------------------------- +Copyright (c) 2008 Andrew Green +http://www.zoolib.org + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software +and associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +------------------------------------------------------------------------------------------------- */ + +#ifndef __ZThreadSafe__ +#define __ZThreadSafe__ 1 +#include "zconfig.h" + +#include "zoolib/ZAtomic.h" + +// ================================================================================================= +#pragma mark - +#pragma mark * ZThreadSafe Macros + +// "Safe" increment and decrement. In non-preemptive environments this will do cheap +// addition/subtraction, and in preemptive situations it will do slightly less efficient, but +// thread-safe operations. You need to use the ZThreadSafe_t type for variables that will +// manipulated by this. Right now it is a struct, but might // degenerate into a simple integer +// at some point. ZThreadSafe_IncReturnNew and ZThreadSafe_DecReturnNew are used by Windows +// COM objects' AddRef and Release methods. + +typedef ZAtomic_t ZThreadSafe_t; + +#if !defined(ZCONFIG_Thread_Preemptive) || !ZCONFIG_Thread_Preemptive + + #define ZThreadSafe_Get(x) ZAtomic_Get(&x) + #define ZThreadSafe_Set(x, y) ZAtomic_Set(&x, y) + #define ZThreadSafe_Swap(x, y) ZAtomic_Swap(&x, y) + + #define ZThreadSafe_Inc(x) ZAtomic_Inc(&x) + #define ZThreadSafe_Dec(x) ZAtomic_Dec(&x) + #define ZThreadSafe_DecAndTest(x) ZAtomic_DecAndTest(&x) + + #define ZThreadSafe_IncReturnNew(x) (ZAtomic_Add(&x, 1) + 1) + #define ZThreadSafe_DecReturnNew(x) (ZAtomic_Add(&x, -1) - 1) + + #define ZThreadSafe_IncReturnOld(x) (ZAtomic_Add(&x, 1)) + #define ZThreadSafe_DecReturnOld(x) (ZAtomic_Add(&x, -1)) + +#else // ZCONFIG_Thread_Preemptive + + inline int ZThreadSafe_SwapHelper(ZThreadSafe_t& inX, int inY) + { + int oldValue = inX.fValue; + inX.fValue = inY; + return oldValue; + } + #define ZThreadSafe_Swap(x, y) ZThreadSafe_SwapHelper(x, y) + + #define ZThreadSafe_Get(x) (x.fValue) + #define ZThreadSafe_Set(x, y) ((void)((x).fValue = y)) + + #define ZThreadSafe_Inc(x) ((void)(++(x).fValue)) + #define ZThreadSafe_Dec(x) ((void)(--(x).fValue)) + #define ZThreadSafe_DecAndTest(x) ((--(x).fValue) == 0) + + #define ZThreadSafe_IncReturnNew(x) (++(x).fValue) + #define ZThreadSafe_DecReturnNew(x) (--(x).fValue) + + #define ZThreadSafe_IncReturnOld(x) ((x).fValue++) + #define ZThreadSafe_DecReturnOld(x) ((x).fValue--) + +#endif // ZCONFIG_Thread_Preemptive + +#endif // __ZThreadSafe__ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-11-27 15:30:52
|
Revision: 245 http://zoolib.svn.sourceforge.net/zoolib/?rev=245&view=rev Author: agreen Date: 2008-11-27 15:30:42 +0000 (Thu, 27 Nov 2008) Log Message: ----------- Conform to header changes (no longer see ZThread.h, so we need to pull in stdexcept explicitly). Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZTuple.cpp trunk/zoolib/source/cxx/zoolib/ZTuple.h Modified: trunk/zoolib/source/cxx/zoolib/ZTuple.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZTuple.cpp 2008-11-27 15:29:39 UTC (rev 244) +++ trunk/zoolib/source/cxx/zoolib/ZTuple.cpp 2008-11-27 15:30:42 UTC (rev 245) @@ -22,8 +22,6 @@ #include "zoolib/ZMemory.h" #include "zoolib/ZMemoryBlock.h" -#include <stdexcept> // For runtime_error - using std::min; using std::pair; using std::runtime_error; Modified: trunk/zoolib/source/cxx/zoolib/ZTuple.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZTuple.h 2008-11-27 15:29:39 UTC (rev 244) +++ trunk/zoolib/source/cxx/zoolib/ZTuple.h 2008-11-27 15:30:42 UTC (rev 245) @@ -28,6 +28,7 @@ #include "zoolib/ZTName.h" #include "zoolib/ZTypes.h" +#include <stdexcept> // For runtime_error #include <string> #include <vector> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-12-04 03:25:01
|
Revision: 263 http://zoolib.svn.sourceforge.net/zoolib/?rev=263&view=rev Author: agreen Date: 2008-12-04 03:24:50 +0000 (Thu, 04 Dec 2008) Log Message: ----------- Include correct file. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZNetscape_GuestFactory_Mac.cpp trunk/zoolib/source/cxx/zoolib/ZNetscape_GuestFactory_Mac.h Modified: trunk/zoolib/source/cxx/zoolib/ZNetscape_GuestFactory_Mac.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNetscape_GuestFactory_Mac.cpp 2008-12-04 03:23:08 UTC (rev 262) +++ trunk/zoolib/source/cxx/zoolib/ZNetscape_GuestFactory_Mac.cpp 2008-12-04 03:24:50 UTC (rev 263) @@ -18,7 +18,7 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ------------------------------------------------------------------------------------------------- */ -#include "zoolib/ZNetscape_GuestFactory_MacPlugin.h" +#include "zoolib/ZNetscape_GuestFactory_Mac.h" #if ZCONFIG_SPI_Enabled(MacOSX) Modified: trunk/zoolib/source/cxx/zoolib/ZNetscape_GuestFactory_Mac.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZNetscape_GuestFactory_Mac.h 2008-12-04 03:23:08 UTC (rev 262) +++ trunk/zoolib/source/cxx/zoolib/ZNetscape_GuestFactory_Mac.h 2008-12-04 03:24:50 UTC (rev 263) @@ -18,8 +18,8 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ------------------------------------------------------------------------------------------------- */ -#ifndef __ZNetscape_GuestFactory_MacPlugin__ -#define __ZNetscape_GuestFactory_MacPlugin__ 1 +#ifndef __ZNetscape_GuestFactory_Mac__ +#define __ZNetscape_GuestFactory_Mac__ 1 #include "zconfig.h" #include "zoolib/ZCONFIG_SPI.h" @@ -55,4 +55,4 @@ #endif // ZCONFIG_SPI_Enabled(MacOSX) -#endif // __ZNetscape_GuestFactory_MacPlugin__ +#endif // __ZNetscape_GuestFactory_Mac__ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-12-12 22:22:27
|
Revision: 292 http://zoolib.svn.sourceforge.net/zoolib/?rev=292&view=rev Author: agreen Date: 2008-12-12 21:56:11 +0000 (Fri, 12 Dec 2008) Log Message: ----------- Use namespaces for non class-based stuff. ZThreadImp renames API-specific types to general names. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZThreadImp_MacMP.cpp trunk/zoolib/source/cxx/zoolib/ZThreadImp_MacMP.h trunk/zoolib/source/cxx/zoolib/ZThreadImp_Win.h trunk/zoolib/source/cxx/zoolib/ZThreadImp_boost.cpp trunk/zoolib/source/cxx/zoolib/ZThreadImp_boost.h trunk/zoolib/source/cxx/zoolib/ZThreadImp_pthread.cpp trunk/zoolib/source/cxx/zoolib/ZThreadImp_pthread.h Added Paths: ----------- trunk/zoolib/source/cxx/zoolib/ZThreadImp.cpp trunk/zoolib/source/cxx/zoolib/ZThreadImp.h Added: trunk/zoolib/source/cxx/zoolib/ZThreadImp.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZThreadImp.cpp (rev 0) +++ trunk/zoolib/source/cxx/zoolib/ZThreadImp.cpp 2008-12-12 21:56:11 UTC (rev 292) @@ -0,0 +1,21 @@ +/* ------------------------------------------------------------------------------------------------- +Copyright (c) 2008 Andrew Green +http://www.zoolib.org + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software +and associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +------------------------------------------------------------------------------------------------- */ + +#include "zoolib/ZThreadImp.h" Added: trunk/zoolib/source/cxx/zoolib/ZThreadImp.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZThreadImp.h (rev 0) +++ trunk/zoolib/source/cxx/zoolib/ZThreadImp.h 2008-12-12 21:56:11 UTC (rev 292) @@ -0,0 +1,71 @@ +/* ------------------------------------------------------------------------------------------------- +Copyright (c) 2008 Andrew Green +http://www.zoolib.org + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software +and associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +------------------------------------------------------------------------------------------------- */ + +#ifndef __ZThreadImp__ +#define __ZThreadImp__ 1 +#include "zconfig.h" + +#include "zoolib/ZThreadImp_boost.h" +#include "zoolib/ZThreadImp_MacMP.h" +#include "zoolib/ZThreadImp_pthread.h" +#include "zoolib/ZThreadImp_Win.h" + +namespace ZooLib { + +#if 0 + +#elif ZCONFIG_API_Enabled(ThreadImp_MacMP) + +namespace ZTSS = ZTSS_MacMP; +namespace ZThreadImp = ZThreadImp_MacMP; + +typedef ZMtx_MacMP ZMtx; +typedef ZCnd_MacMP ZCnd; +typedef ZSem_MacMP ZSem; + +#elif ZCONFIG_API_Enabled(ThreadImp_pthread) + +namespace ZTSS = ZTSS_pthread; +namespace ZThreadImp = ZThreadImp_pthread; + +typedef ZMtx_pthread ZMtx; +typedef ZCnd_pthread ZCnd; +typedef ZSem_pthread ZSem; + +#elif ZCONFIG_API_Enabled(ThreadImp_Win) + +namespace ZTSS = ZTSS_Win; +namespace ZThreadImp = ZThreadImp_Win; + +typedef ZMtx_Win ZMtx; +typedef ZCnd_Win ZCnd; +typedef ZSem_Win ZSem; + +#elif ZCONFIG_API_Enabled(ThreadImp_boost) + +typedef ZMtx_boost ZMtx; +typedef ZCnd_boost ZCnd; +typedef ZSem_boost ZSem; + +#endif + +} // namespace ZooLib + +#endif // __ZThreadImp__ Modified: trunk/zoolib/source/cxx/zoolib/ZThreadImp_MacMP.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZThreadImp_MacMP.cpp 2008-12-12 21:54:28 UTC (rev 291) +++ trunk/zoolib/source/cxx/zoolib/ZThreadImp_MacMP.cpp 2008-12-12 21:56:11 UTC (rev 292) @@ -48,18 +48,18 @@ // ================================================================================================= #pragma mark - -#pragma mark * ZSemTimeout_MacMP +#pragma mark * ZSem_MacMP -ZSemTimeout_MacMP::ZSemTimeout_MacMP() +ZSem_MacMP::ZSem_MacMP() { ::MPCreateSemaphore(0xFFFFFFFFU, 0, &fMPSemaphoreID); } -ZSemTimeout_MacMP::~ZSemTimeout_MacMP() +ZSem_MacMP::~ZSem_MacMP() { ::MPDeleteSemaphore(fMPSemaphoreID); } -void ZSemTimeout_MacMP::Wait() +void ZSem_MacMP::Wait() { ::MPWaitOnSemaphore(fMPSemaphoreID, kDurationForever); } -bool ZSemTimeout_MacMP::Wait(double iTimeout) +bool ZSem_MacMP::Wait(double iTimeout) { if (iTimeout <= 0) { @@ -77,7 +77,7 @@ } } -void ZSemTimeout_MacMP::Signal() +void ZSem_MacMP::Signal() { ::MPSignalSemaphore(fMPSemaphoreID); } // ================================================================================================= Modified: trunk/zoolib/source/cxx/zoolib/ZThreadImp_MacMP.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZThreadImp_MacMP.h 2008-12-12 21:54:28 UTC (rev 291) +++ trunk/zoolib/source/cxx/zoolib/ZThreadImp_MacMP.h 2008-12-12 21:56:11 UTC (rev 292) @@ -51,30 +51,29 @@ #pragma mark - #pragma mark * ZTSS_MacMP -class ZTSS_MacMP : NonCopyable - { - ZTSS_MacMP(); -public: - typedef TaskStorageIndex Key; - typedef TaskStorageValue Value; +namespace ZTSS_MacMP { - static Key sCreate(); - static void sFree(Key iKey); +typedef TaskStorageIndex Key; +typedef TaskStorageValue Value; - static void sSet(Key iKey, Value iValue); - static Value sGet(Key iKey); - }; +Key sCreate(); +void sFree(Key iKey); +void sSet(Key iKey, Value iValue); +Value sGet(Key iKey); + +} // namespace ZTSS_MacMP + // ================================================================================================= #pragma mark - -#pragma mark * ZSemTimeout_MacMP +#pragma mark * ZSem_MacMP -class ZSemTimeout_MacMP : NonCopyable +class ZSem_MacMP : NonCopyable { public: - ZSemTimeout_MacMP(); + ZSem_MacMP(); - ~ZSemTimeout_MacMP(); + ~ZSem_MacMP(); void Wait(); bool Wait(double iTimeout); @@ -105,7 +104,7 @@ #pragma mark - #pragma mark * ZCnd_MacMP -class ZCnd_MacMP : ZCnd_T<ZMtx_MacMP, ZSemTimeout_MacMP> +class ZCnd_MacMP : ZCnd_T<ZMtx_MacMP, ZSem_MacMP> { public: ZCnd_MacMP(); @@ -122,19 +121,16 @@ #pragma mark - #pragma mark * ZThreadImp_MacMP -class ZThreadImp_MacMP : NonCopyable - { -private: - ZThreadImp_MacMP(); +namespace ZThreadImp_MacMP { -public: - typedef TaskProc Proc_t; - typedef MPTaskID ID; +typedef TaskProc Proc_t; +typedef MPTaskID ID; - static ID sCreate(size_t iStackSize, Proc_t iProc, void* iParam); - static ID sID(); - }; +ID sCreate(size_t iStackSize, Proc_t iProc, void* iParam); +ID sID(); +} // namespace ZThreadImp_MacMP + } // namespace ZooLib Modified: trunk/zoolib/source/cxx/zoolib/ZThreadImp_Win.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZThreadImp_Win.h 2008-12-12 21:54:28 UTC (rev 291) +++ trunk/zoolib/source/cxx/zoolib/ZThreadImp_Win.h 2008-12-12 21:56:11 UTC (rev 292) @@ -50,20 +50,20 @@ #pragma mark - #pragma mark * ZTSS_Win -class ZTSS_Win : NonCopyable - { - ZTSS_Win(); -public: - typedef DWORD Key; - typedef LPVOID Value; +namespace ZTSS_Win { - static Key sCreate(); - static void sFree(Key iKey); +typedef DWORD Key; +typedef LPVOID Value; - static void sSet(Key iKey, Value iValue); - static Value sGet(Key iKey); - }; +#elif ZCONFIG_API_Enabled(ThreadImp_boost) +Key sCreate(); +static void sFree(Key iKey); + +void sSet(Key iKey, Value iValue); +Value sGet(Key iKey); +} // namespace ZTSS_Win + // ================================================================================================= #pragma mark - #pragma mark * ZSemTimeout_Win @@ -121,19 +121,16 @@ #pragma mark - #pragma mark * ZThreadImp_Win -class ZThreadImp_Win : NonCopyable - { -private: - ZThreadImp_Win(); +namespace ZThreadImp_Win { -public: - typedef unsigned (__stdcall* Proc_t)(void *); - typedef unsigned int ID; +typedef unsigned (__stdcall* Proc_t)(void *); +typedef unsigned int ID; - static ID sCreate(size_t iStackSize, Proc_t iProc, void* iParam); - static ID sID(); - }; +ID sCreate(size_t iStackSize, Proc_t iProc, void* iParam); +ID sID(); +} // namespace ZThreadImp_Win + } // namespace ZooLib #endif // ZCONFIG_API_Enabled(ThreadImp_Win) Modified: trunk/zoolib/source/cxx/zoolib/ZThreadImp_boost.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZThreadImp_boost.cpp 2008-12-12 21:54:28 UTC (rev 291) +++ trunk/zoolib/source/cxx/zoolib/ZThreadImp_boost.cpp 2008-12-12 21:56:11 UTC (rev 292) @@ -74,21 +74,21 @@ // ================================================================================================= #pragma mark - -#pragma mark * ZSemTimeout_boost +#pragma mark * ZSem_boost -ZSemTimeout_boost::ZSemTimeout_boost() +ZSem_boost::ZSem_boost() {} -ZSemTimeout_boost::~ZSemTimeout_boost() +ZSem_boost::~ZSem_boost() {} -void ZSemTimeout_boost::Wait() +void ZSem_boost::Wait() { this->Imp_Wait(1); } -bool ZSemTimeout_boost::Wait(double iTimeout) +bool ZSem_boost::Wait(double iTimeout) { return this->Imp_Wait(1, iTimeout); } -void ZSemTimeout_boost::Signal() +void ZSem_boost::Signal() { this->Imp_Signal(1); } } // namespace ZooLib Modified: trunk/zoolib/source/cxx/zoolib/ZThreadImp_boost.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZThreadImp_boost.h 2008-12-12 21:54:28 UTC (rev 291) +++ trunk/zoolib/source/cxx/zoolib/ZThreadImp_boost.h 2008-12-12 21:56:11 UTC (rev 292) @@ -87,13 +87,13 @@ // ================================================================================================= #pragma mark - -#pragma mark * ZSemTimeout_boost +#pragma mark * ZSem_boost -class ZSemTimeout_boost : ZSem_T<ZMtx_boost, ZCnd_boost> +class ZSem_boost : ZSem_T<ZMtx_boost, ZCnd_boost> { public: - ZSemTimeout_boost(); - ~ZSemTimeout_boost(); + ZSem_boost(); + ~ZSem_boost(); void Wait(); bool Wait(double iTimeout); Modified: trunk/zoolib/source/cxx/zoolib/ZThreadImp_pthread.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZThreadImp_pthread.cpp 2008-12-12 21:54:28 UTC (rev 291) +++ trunk/zoolib/source/cxx/zoolib/ZThreadImp_pthread.cpp 2008-12-12 21:56:11 UTC (rev 292) @@ -101,15 +101,15 @@ // ================================================================================================= #pragma mark - -#pragma mark * ZSem_pthread +#pragma mark * ZSemNoTimeout_pthread -ZSem_pthread::ZSem_pthread() +ZSemNoTimeout_pthread::ZSemNoTimeout_pthread() { ::sem_init(&fSem, 0, 0); } -ZSem_pthread::~ZSem_pthread() +ZSemNoTimeout_pthread::~ZSemNoTimeout_pthread() { ::sem_destroy(&fSem); } -void ZSem_pthread::Wait() +void ZSemNoTimeout_pthread::Wait() { for (;;) { @@ -123,10 +123,10 @@ } } -bool ZSem_pthread::TryWait() +bool ZSemNoTimeout_pthread::TryWait() { return 0 == ::sem_trywait(&fSem); } -void ZSem_pthread::Signal() +void ZSemNoTimeout_pthread::Signal() { ::sem_post(&fSem); } // ================================================================================================= Modified: trunk/zoolib/source/cxx/zoolib/ZThreadImp_pthread.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZThreadImp_pthread.h 2008-12-12 21:54:28 UTC (rev 291) +++ trunk/zoolib/source/cxx/zoolib/ZThreadImp_pthread.h 2008-12-12 21:56:11 UTC (rev 292) @@ -49,20 +49,19 @@ #pragma mark - #pragma mark * ZTSS_pthread -class ZTSS_pthread - { - ZTSS_pthread(); -public: - typedef pthread_key_t Key; - typedef void* Value; +namespace ZTSS_pthread { - static Key sCreate(); - static void sFree(Key iKey); +typedef pthread_key_t Key; +typedef void* Value; - static void sSet(Key iKey, Value iValue); - static Value sGet(Key iKey); - }; +Key sCreate(); +void sFree(Key iKey); +void sSet(Key iKey, Value iValue); +Value sGet(Key iKey); + +} + // ================================================================================================= #pragma mark - #pragma mark * ZMtx_pthread @@ -103,13 +102,13 @@ // ================================================================================================= #pragma mark - -#pragma mark * ZSem_pthread +#pragma mark * ZSemNoTimeout_pthread -class ZSem_pthread : NonCopyable +class ZSemNoTimeout_pthread : NonCopyable { public: - ZSem_pthread(); - ~ZSem_pthread(); + ZSemNoTimeout_pthread(); + ~ZSemNoTimeout_pthread(); void Wait(); bool TryWait(); @@ -123,19 +122,16 @@ #pragma mark - #pragma mark * ZThreadImp_pthread -class ZThreadImp_pthread : NonCopyable - { -private: - ZThreadImp_pthread(); +namespace ZThreadImp_pthread { -public: - typedef void* (*Proc_t)(void* iParam); - typedef pthread_t ID; +typedef void* (*Proc_t)(void* iParam); +typedef pthread_t ID; - static ID sCreate(size_t iStackSize, Proc_t iProc, void* iParam); - static ID sID(); - }; +ID sCreate(size_t iStackSize, Proc_t iProc, void* iParam); +ID sID(); +} // namespace ZThreadImp_pthread + } // namespace ZooLib #endif // ZCONFIG_API_Enabled(ThreadImp_pthread) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-12-12 22:22:45
|
Revision: 288 http://zoolib.svn.sourceforge.net/zoolib/?rev=288&view=rev Author: agreen Date: 2008-12-12 21:52:14 +0000 (Fri, 12 Dec 2008) Log Message: ----------- Use ZMutexNR rather than ZMutex. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZTxn.cpp trunk/zoolib/source/cxx/zoolib/ZTxn.h Modified: trunk/zoolib/source/cxx/zoolib/ZTxn.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZTxn.cpp 2008-12-12 21:51:45 UTC (rev 287) +++ trunk/zoolib/source/cxx/zoolib/ZTxn.cpp 2008-12-12 21:52:14 UTC (rev 288) @@ -30,7 +30,7 @@ #pragma mark - #pragma mark * ZTxn -ZThreadSafe_t sNextID = {1}; +ZThreadSafe_t sNextID(1); /** \class ZTxn Some more words about transactions. @@ -43,7 +43,7 @@ ZTxn::~ZTxn() { - ZMutexLocker locker(fMutex); + ZMutexNRLocker locker(fMutex); if (!fTargets.empty()) { try @@ -64,19 +64,19 @@ bool ZTxn::Commit() { - ZMutexLocker locker(fMutex); + ZMutexNRLocker locker(fMutex); return this->pCommit(); } void ZTxn::Abort() { - ZMutexLocker locker(fMutex); + ZMutexNRLocker locker(fMutex); this->pAbort(); } struct Waiter_Validate { - ZMutex* fMutex; + ZMutexNR* fMutex; ZCondition* fCondition; bool fCompleted; bool fOkay; @@ -84,14 +84,14 @@ struct Waiter_Commit { - ZMutex* fMutex; + ZMutexNR* fMutex; ZCondition* fCondition; bool fCompleted; }; bool ZTxn::pCommit() { - ZAssertStop(0, fMutex.IsLocked()); +// ZAssertStop(0, fMutex.IsLocked()); ZCondition theCondition; @@ -181,7 +181,7 @@ void ZTxn::pAbort() { - ZAssertStop(0, fMutex.IsLocked()); +// ZAssertStop(0, fMutex.IsLocked()); // Abort all targets. for (size_t x = 0; x < fTargets.size(); ++x) @@ -192,7 +192,7 @@ void ZTxn::pRegisterTarget(ZTxnTarget* iTarget) const { - ZMutexLocker locker(fMutex); + ZMutexNRLocker locker(fMutex); ZAssertStop(0, !ZUtil_STL::sContains(fTargets, iTarget)); fTargets.push_back(iTarget); } Modified: trunk/zoolib/source/cxx/zoolib/ZTxn.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZTxn.h 2008-12-12 21:51:45 UTC (rev 287) +++ trunk/zoolib/source/cxx/zoolib/ZTxn.h 2008-12-12 21:52:14 UTC (rev 288) @@ -57,7 +57,7 @@ int32 fID; - ZooLib::ZMutex fMutex; + ZooLib::ZMutexNR fMutex; mutable std::vector<ZTxnTarget*> fTargets; friend class ZTxnTarget; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-12-13 04:42:32
|
Revision: 296 http://zoolib.svn.sourceforge.net/zoolib/?rev=296&view=rev Author: agreen Date: 2008-12-13 04:42:28 +0000 (Sat, 13 Dec 2008) Log Message: ----------- Minor tweaks. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZThreadImp.h trunk/zoolib/source/cxx/zoolib/ZThreadImp_MacMP.cpp trunk/zoolib/source/cxx/zoolib/ZThreadImp_MacMP.h trunk/zoolib/source/cxx/zoolib/ZThreadImp_T.h trunk/zoolib/source/cxx/zoolib/ZThreadImp_Win.cpp trunk/zoolib/source/cxx/zoolib/ZThreadImp_Win.h trunk/zoolib/source/cxx/zoolib/ZThreadImp_boost.cpp trunk/zoolib/source/cxx/zoolib/ZThreadImp_boost.h trunk/zoolib/source/cxx/zoolib/ZThreadImp_pthread.cpp trunk/zoolib/source/cxx/zoolib/ZThreadImp_pthread.h Modified: trunk/zoolib/source/cxx/zoolib/ZThreadImp.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZThreadImp.h 2008-12-13 04:41:23 UTC (rev 295) +++ trunk/zoolib/source/cxx/zoolib/ZThreadImp.h 2008-12-13 04:42:28 UTC (rev 296) @@ -31,6 +31,16 @@ #if 0 +#elif ZCONFIG_API_Enabled(ThreadImp_pthread) + +namespace ZTSS = ZTSS_pthread; +namespace ZThreadImp = ZThreadImp_pthread; + +typedef ZMtx_pthread ZMtx; +typedef ZCnd_pthread ZCnd; +typedef ZSemNoTimeout_pthread ZSemNotimeout; +typedef ZSem_pthread ZSem; + #elif ZCONFIG_API_Enabled(ThreadImp_MacMP) namespace ZTSS = ZTSS_MacMP; @@ -40,15 +50,6 @@ typedef ZCnd_MacMP ZCnd; typedef ZSem_MacMP ZSem; -#elif ZCONFIG_API_Enabled(ThreadImp_pthread) - -namespace ZTSS = ZTSS_pthread; -namespace ZThreadImp = ZThreadImp_pthread; - -typedef ZMtx_pthread ZMtx; -typedef ZCnd_pthread ZCnd; -typedef ZSem_pthread ZSem; - #elif ZCONFIG_API_Enabled(ThreadImp_Win) namespace ZTSS = ZTSS_Win; Modified: trunk/zoolib/source/cxx/zoolib/ZThreadImp_MacMP.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZThreadImp_MacMP.cpp 2008-12-13 04:41:23 UTC (rev 295) +++ trunk/zoolib/source/cxx/zoolib/ZThreadImp_MacMP.cpp 2008-12-13 04:42:28 UTC (rev 296) @@ -24,6 +24,13 @@ #include <new> // for bad_alloc +// For UpTime etc +#if __MACH__ +//# include <CoreServices/CoreServices.h> +#else +# include <DriverServices.h> +#endif + namespace ZooLib { // ================================================================================================= @@ -136,6 +143,17 @@ ZThreadImp_MacMP::ID ZThreadImp_MacMP::sID() { return ::MPCurrentTaskID(); } +void ZThreadImp_MacMP::sSleep(double iDuration) + { + const Nanoseconds nowU = ::AbsoluteToNanoseconds(::UpTime()); + const double targetDouble + = double(*reinterpret_cast<const uint64*>(&nowU)) / 1e9 + iDuration; + const uint64 targetU = uint64(targetDouble * 1e9); + AbsoluteTime targetA + = ::NanosecondsToAbsolute(*reinterpret_cast<const Nanoseconds*>(&targetU)); + ::MPDelayUntil(&targetA); + } + } // namespace ZooLib #endif // ZCONFIG_API_Enabled(ThreadImp_MacMP) Modified: trunk/zoolib/source/cxx/zoolib/ZThreadImp_MacMP.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZThreadImp_MacMP.h 2008-12-13 04:41:23 UTC (rev 295) +++ trunk/zoolib/source/cxx/zoolib/ZThreadImp_MacMP.h 2008-12-13 04:42:28 UTC (rev 296) @@ -37,10 +37,15 @@ #include "zoolib/ZCompat_NonCopyable.h" #include "zoolib/ZThreadImp_T.h" -//#include "zoolib/ZTypes.h" #if __MACH__ -# include <CoreServices/CoreServices.h> +// This is tricky. We need Multiprocessing.h, but don't want to pull in other +// stuff like OpenTransport, which has conflicts with tcp.h. +# if __MWERKS__ +# include <CarbonCore/CarbonCore.h> +# else +# include <CoreServices/CoreServices.h> +# endif #else # include <Multiprocessing.h> #endif @@ -128,6 +133,7 @@ ID sCreate(size_t iStackSize, Proc_t iProc, void* iParam); ID sID(); +void sSleep(double iDuration); } // namespace ZThreadImp_MacMP Modified: trunk/zoolib/source/cxx/zoolib/ZThreadImp_T.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZThreadImp_T.h 2008-12-13 04:41:23 UTC (rev 295) +++ trunk/zoolib/source/cxx/zoolib/ZThreadImp_T.h 2008-12-13 04:42:28 UTC (rev 296) @@ -41,6 +41,10 @@ : fMtx(iMtx) { fMtx.Acquire(); } + ZGuard_T(const Mtx& iMtx) + : fMtx(const_cast<Mtx&>(iMtx)) + { fMtx.Acquire(); } + ~ZGuard_T() { fMtx.Release(); } @@ -50,6 +54,47 @@ // ================================================================================================= #pragma mark - +#pragma mark * ZGuardR_T + +template <class Mtx> +class ZGuardR_T : NonCopyable + { +public: + ZGuardR_T(Mtx& iMtx) + : fMtx(iMtx), + fCount(1) + { fMtx.Acquire(); } + + ZGuardR_T(const Mtx& iMtx) + : fMtx(const_cast<Mtx&>(iMtx)), + fCount(1) + { fMtx.Acquire(); } + + ~ZGuardR_T() + { + while (--fCount) + fMtx.Release(); + } + + void Release() + { + --fCount; + fMtx.Release(); + } + + void Acquire() + { + fMtx.Acquire(); + ++fCount; + } + +protected: + Mtx& fMtx; + int fCount; + }; + +// ================================================================================================= +#pragma mark - #pragma mark * ZSem_T template <class Mtx, class Cnd> @@ -121,17 +166,14 @@ Waiter theWaiter(iCount); fWaiters.PushBack(&theWaiter); - while (theWaiter.fCount > 0) - { - if (!fCnd.Wait(fMtx, expired - ZTime::sSystem())) - break; - } + while (theWaiter.fCount > 0 && expired > ZTime::sSystem()) + fCnd.Wait(fMtx, expired - ZTime::sSystem()); fWaiters.Remove(&theWaiter); - if (theWaiter.fCount > 0) + if (int acquired = iCount - theWaiter.fCount) { - this->Imp_Signal(iCount - theWaiter.fCount); + this->Imp_Signal(acquired); return false; } Modified: trunk/zoolib/source/cxx/zoolib/ZThreadImp_Win.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZThreadImp_Win.cpp 2008-12-13 04:41:23 UTC (rev 295) +++ trunk/zoolib/source/cxx/zoolib/ZThreadImp_Win.cpp 2008-12-13 04:42:28 UTC (rev 296) @@ -46,21 +46,21 @@ // ================================================================================================= #pragma mark - -#pragma mark * ZSemTimeout_Win +#pragma mark * ZSem_Win -ZSemTimeout_Win::ZSemTimeout_Win() +ZSem_Win::ZSem_Win() { fHANDLE = ::CreateSemaphore(nil, 0, 0x7FFFFFFF, nil); } -ZSemTimeout_Win::~ZSemTimeout_Win() +ZSem_Win::~ZSem_Win() { ::CloseHandle(fHANDLE); } -void ZSemTimeout_Win::Wait() +void ZSem_Win::Wait() { ::WaitForSingleObject(fHANDLE, INFINITE); } -bool ZSemTimeout_Win::Wait(double iTimeout) +bool ZSem_Win::Wait(double iTimeout) { return WAIT_OBJECT_0 == ::WaitForSingleObject(fHANDLE, iTimeout * 1e3); } -void ZSemTimeout_Win::Signal() +void ZSem_Win::Signal() { ::ReleaseSemaphore(fHANDLE, 1, nil); } // ================================================================================================= @@ -118,6 +118,9 @@ ZThreadImp_Win::ID ZThreadImp_Win::sID() { return ::GetCurrentThreadId(); } +void ZThreadImp_Win::sSleep(double iDuration) + { ::Sleep(iDuration * 1e3); } + } // namespace ZooLib #endif // ZCONFIG_API_Enabled(ThreadImp_Win) Modified: trunk/zoolib/source/cxx/zoolib/ZThreadImp_Win.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZThreadImp_Win.h 2008-12-13 04:41:23 UTC (rev 295) +++ trunk/zoolib/source/cxx/zoolib/ZThreadImp_Win.h 2008-12-13 04:42:28 UTC (rev 296) @@ -55,25 +55,24 @@ typedef DWORD Key; typedef LPVOID Value; -#elif ZCONFIG_API_Enabled(ThreadImp_boost) - Key sCreate(); static void sFree(Key iKey); void sSet(Key iKey, Value iValue); Value sGet(Key iKey); + } // namespace ZTSS_Win // ================================================================================================= #pragma mark - -#pragma mark * ZSemTimeout_Win +#pragma mark * ZSem_Win -class ZSemTimeout_Win : NonCopyable +class ZSem_Win : NonCopyable { public: - ZSemTimeout_Win(); + ZSem_Win(); - ~ZSemTimeout_Win(); + ~ZSem_Win(); void Wait(); bool Wait(double iTimeout); @@ -104,7 +103,7 @@ #pragma mark - #pragma mark * ZCnd_Win -class ZCnd_Win : ZCnd_T<ZMtx_Win, ZSemTimeout_Win> +class ZCnd_Win : ZCnd_T<ZMtx_Win, ZSem_Win> { public: ZCnd_Win(); @@ -128,6 +127,7 @@ ID sCreate(size_t iStackSize, Proc_t iProc, void* iParam); ID sID(); +void sSleep(double iDuration); } // namespace ZThreadImp_Win Modified: trunk/zoolib/source/cxx/zoolib/ZThreadImp_boost.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZThreadImp_boost.cpp 2008-12-13 04:41:23 UTC (rev 295) +++ trunk/zoolib/source/cxx/zoolib/ZThreadImp_boost.cpp 2008-12-13 04:42:28 UTC (rev 296) @@ -52,15 +52,15 @@ ZCnd_boost::~ZCnd_boost() {} -void ZCnd_boost::Wait(ZMtx_boost& iMtx) +void ZCnd_boost::Wait(boost::mutex& iMtx) { - ZMtx_boost::scoped_lock theLock(iMtx, boost::adopt_lock); + boost::mutex::scoped_lock theLock(iMtx, boost::adopt_lock); condition_variable::wait(theLock); } -bool ZCnd_boost::Wait(ZMtx_boost& iMtx, double iTimeout) +bool ZCnd_boost::Wait(boost::mutex& iMtx, double iTimeout) { - ZMtx_boost::scoped_lock theLock(iMtx, boost::adopt_lock); + boost::mutex::scoped_lock theLock(iMtx, boost::adopt_lock); return condition_variable::timed_wait( theLock, boost::posix_time::microseconds(iTimeout * 1e6)); Modified: trunk/zoolib/source/cxx/zoolib/ZThreadImp_boost.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZThreadImp_boost.h 2008-12-13 04:41:23 UTC (rev 295) +++ trunk/zoolib/source/cxx/zoolib/ZThreadImp_boost.h 2008-12-13 04:42:28 UTC (rev 296) @@ -78,8 +78,8 @@ ZCnd_boost(); ~ZCnd_boost(); - void Wait(ZMtx_boost& iMtx); - bool Wait(ZMtx_boost& iMtx, double iTimeout); + void Wait(boost::mutex& iMtx); + bool Wait(boost::mutex& iMtx, double iTimeout); void Signal(); void Broadcast(); Modified: trunk/zoolib/source/cxx/zoolib/ZThreadImp_pthread.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZThreadImp_pthread.cpp 2008-12-13 04:41:23 UTC (rev 295) +++ trunk/zoolib/source/cxx/zoolib/ZThreadImp_pthread.cpp 2008-12-13 04:42:28 UTC (rev 296) @@ -25,7 +25,9 @@ #include "zoolib/ZCompat_cmath.h" // for fmod #include "zoolib/ZDebug.h" +#include <errno.h> // For errno #include <sys/time.h> // For gettimeofday +#include <unistd.h> // For usleep #include <new> // for std::bad_alloc @@ -131,6 +133,25 @@ // ================================================================================================= #pragma mark - +#pragma mark * ZSem_pthread + +ZSem_pthread::ZSem_pthread() + {} + +ZSem_pthread::~ZSem_pthread() + {} + +void ZSem_pthread::Wait() + { this->Imp_Wait(1); } + +bool ZSem_pthread::Wait(double iTimeout) + { return this->Imp_Wait(1, iTimeout); } + +void ZSem_pthread::Signal() + { this->Imp_Signal(1); } + +// ================================================================================================= +#pragma mark - #pragma mark * ZThreadImp_pthread ZThreadImp_pthread::ID ZThreadImp_pthread::sCreate(size_t iStackSize, Proc_t iProc, void* iParam) @@ -162,6 +183,9 @@ ZThreadImp_pthread::ID ZThreadImp_pthread::sID() { return ::pthread_self(); } +void ZThreadImp_pthread::sSleep(double iDuration) + { ::usleep(iDuration * 1e6); } + } // namespace ZooLib #endif // ZCONFIG_API_Enabled(ThreadImp_pthread) Modified: trunk/zoolib/source/cxx/zoolib/ZThreadImp_pthread.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZThreadImp_pthread.h 2008-12-13 04:41:23 UTC (rev 295) +++ trunk/zoolib/source/cxx/zoolib/ZThreadImp_pthread.h 2008-12-13 04:42:28 UTC (rev 296) @@ -36,7 +36,7 @@ #if ZCONFIG_API_Enabled(ThreadImp_pthread) #include "zoolib/ZCompat_NonCopyable.h" -//#include "zoolib/ZTypes.h" +#include "zoolib/ZThreadImp_T.h" #include <pthread.h> #include <semaphore.h> @@ -120,6 +120,21 @@ // ================================================================================================= #pragma mark - +#pragma mark * ZSem_pthread + +class ZSem_pthread : ZSem_T<ZMtx_pthread, ZCnd_pthread> + { +public: + ZSem_pthread(); + ~ZSem_pthread(); + + void Wait(); + bool Wait(double iTimeout); + void Signal(); + }; + +// ================================================================================================= +#pragma mark - #pragma mark * ZThreadImp_pthread namespace ZThreadImp_pthread { @@ -129,6 +144,7 @@ ID sCreate(size_t iStackSize, Proc_t iProc, void* iParam); ID sID(); +void sSleep(double iDuration); } // namespace ZThreadImp_pthread This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |