From: <ag...@us...> - 2009-10-08 11:37:21
|
Revision: 1008 http://zoolib.svn.sourceforge.net/zoolib/?rev=1008&view=rev Author: agreen Date: 2009-10-08 11:37:12 +0000 (Thu, 08 Oct 2009) Log Message: ----------- Move ZStream_JNI to old, and remove the config macro from ZCONFIG_SPI. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZCONFIG_SPI.h Added Paths: ----------- trunk/zoolib/source/cxx/old/zoolib/ZStream_JNI.cpp trunk/zoolib/source/cxx/old/zoolib/ZStream_JNI.h Removed Paths: ------------- trunk/zoolib/source/cxx/zoolib/ZStream_JNI.cpp trunk/zoolib/source/cxx/zoolib/ZStream_JNI.h Copied: trunk/zoolib/source/cxx/old/zoolib/ZStream_JNI.cpp (from rev 1004, trunk/zoolib/source/cxx/zoolib/ZStream_JNI.cpp) =================================================================== --- trunk/zoolib/source/cxx/old/zoolib/ZStream_JNI.cpp (rev 0) +++ trunk/zoolib/source/cxx/old/zoolib/ZStream_JNI.cpp 2009-10-08 11:37:12 UTC (rev 1008) @@ -0,0 +1,93 @@ +/* ------------------------------------------------------------------------------------------------- +Copyright (c) 2003 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/ZStream_JNI.h" + +#if ZCONFIG_SPI_Enabled(JNI) + +#include "zoolib/ZMemory.h" + +NAMESPACE_ZOOLIB_BEGIN + +// ================================================================================================= +#pragma mark - +#pragma mark * ZStreamR_JNI + +ZStreamR_JNI::ZStreamR_JNI(JNIEnv* iEnv, jobject iJavaStream) + { + fEnv = iEnv; + fJavaStream = iJavaStream; + } + +ZStreamR_JNI::~ZStreamR_JNI() + {} + +void ZStreamR_JNI::Imp_Read(void* iDest, size_t iCount, size_t* oCountRead) + { + if (oCountRead) + *oCountRead = 0; + + if (!fEnv || !fJavaStream) + return; + + jclass class_Stream = fEnv->GetObjectClass(fJavaStream); + if (!class_Stream) + return; + + jmethodID mid_read = fEnv->GetMethodID(class_Stream, "read", "([BII)I"); + if (!mid_read) + return; + + size_t theBufferSize = min(size_t(4096), iCount); + jbyteArray theBufferArray = fEnv->NewByteArray(theBufferSize); + + uint8* localDest = reinterpret_cast<uint8*>(iDest); + size_t countRemaining = iCount; + while (countRemaining > 0) + { + size_t countToRead = min(countRemaining, theBufferSize); + jint countRead = fEnv->CallIntMethod(fJavaStream, mid_read, theBufferArray, 0, countToRead); + if (countRead <= 0) + break; + jboolean isCopy; + jbyte* elems = static_cast<jbyte*>(fEnv->GetPrimitiveArrayCritical(theBufferArray, &isCopy)); + ZBlockCopy(elems, localDest, countRead); + fEnv->ReleasePrimitiveArrayCritical(theBufferArray, elems, JNI_ABORT); + localDest += countRead; + countRemaining -= countRead; + if (oCountRead) + *oCountRead += countRead; + } + fEnv->DeleteLocalRef(theBufferArray); + } + +size_t ZStreamR_JNI::Imp_CountReadable() + { + if (jclass class_Stream = fEnv->GetObjectClass(fJavaStream)) + { + if (jmethodID mid_available = fEnv->GetMethodID(class_Stream, "available", "()I")) + return fEnv->CallIntMethod(fJavaStream, mid_available); + } + return 0; + } + +NAMESPACE_ZOOLIB_END + +#endif // ZCONFIG_SPI_Enabled(JNI) Copied: trunk/zoolib/source/cxx/old/zoolib/ZStream_JNI.h (from rev 1004, trunk/zoolib/source/cxx/zoolib/ZStream_JNI.h) =================================================================== --- trunk/zoolib/source/cxx/old/zoolib/ZStream_JNI.h (rev 0) +++ trunk/zoolib/source/cxx/old/zoolib/ZStream_JNI.h 2009-10-08 11:37:12 UTC (rev 1008) @@ -0,0 +1,58 @@ +/* ------------------------------------------------------------------------------------------------- +Copyright (c) 2003 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 __ZStream_JNI__ +#define __ZStream_JNI__ 1 +#include "zoolib/ZCONFIG_SPI.h" + +#include "zoolib/ZStream.h" + +#if ZCONFIG_SPI_Enabled(JNI) + +#include <jni.h> + +NAMESPACE_ZOOLIB_BEGIN + +// ================================================================================================= +#pragma mark - +#pragma mark * ZStreamR_JNI + +/// A read stream that sources data from a java.io.InputStream. + +class ZStreamR_JNI : public ZStreamR + { +public: + ZStreamR_JNI(JNIEnv* iEnv, jobject iJavaStream); + ~ZStreamR_JNI(); + +// From ZStreamR + virtual void Imp_Read(void* iDest, size_t iCount, size_t* oCountRead); + virtual size_t Imp_CountReadable(); + +private: + jobject fJavaStream; + JNIEnv* fEnv; + }; + +NAMESPACE_ZOOLIB_END + +#endif // ZCONFIG_SPI_Enabled(JNI) + +#endif // __ZStream_JNI__ Modified: trunk/zoolib/source/cxx/zoolib/ZCONFIG_SPI.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZCONFIG_SPI.h 2009-10-08 11:36:10 UTC (rev 1007) +++ trunk/zoolib/source/cxx/zoolib/ZCONFIG_SPI.h 2009-10-08 11:37:12 UTC (rev 1008) @@ -311,17 +311,6 @@ // ================================================================================================= -#pragma mark JNI -#ifndef ZCONFIG_SPI_Avail__JNI -# define ZCONFIG_SPI_Avail__JNI 0 -#endif - -#ifndef ZCONFIG_SPI_Desired__JNI -# define ZCONFIG_SPI_Desired__JNI 1 -#endif - - -// ================================================================================================= #pragma mark libpng #ifndef ZCONFIG_SPI_Avail__libpng # define ZCONFIG_SPI_Avail__libpng 0 Deleted: trunk/zoolib/source/cxx/zoolib/ZStream_JNI.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZStream_JNI.cpp 2009-10-08 11:36:10 UTC (rev 1007) +++ trunk/zoolib/source/cxx/zoolib/ZStream_JNI.cpp 2009-10-08 11:37:12 UTC (rev 1008) @@ -1,93 +0,0 @@ -/* ------------------------------------------------------------------------------------------------- -Copyright (c) 2003 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/ZStream_JNI.h" - -#if ZCONFIG_SPI_Enabled(JNI) - -#include "zoolib/ZMemory.h" - -NAMESPACE_ZOOLIB_BEGIN - -// ================================================================================================= -#pragma mark - -#pragma mark * ZStreamR_JNI - -ZStreamR_JNI::ZStreamR_JNI(JNIEnv* iEnv, jobject iJavaStream) - { - fEnv = iEnv; - fJavaStream = iJavaStream; - } - -ZStreamR_JNI::~ZStreamR_JNI() - {} - -void ZStreamR_JNI::Imp_Read(void* iDest, size_t iCount, size_t* oCountRead) - { - if (oCountRead) - *oCountRead = 0; - - if (!fEnv || !fJavaStream) - return; - - jclass class_Stream = fEnv->GetObjectClass(fJavaStream); - if (!class_Stream) - return; - - jmethodID mid_read = fEnv->GetMethodID(class_Stream, "read", "([BII)I"); - if (!mid_read) - return; - - size_t theBufferSize = min(size_t(4096), iCount); - jbyteArray theBufferArray = fEnv->NewByteArray(theBufferSize); - - uint8* localDest = reinterpret_cast<uint8*>(iDest); - size_t countRemaining = iCount; - while (countRemaining > 0) - { - size_t countToRead = min(countRemaining, theBufferSize); - jint countRead = fEnv->CallIntMethod(fJavaStream, mid_read, theBufferArray, 0, countToRead); - if (countRead <= 0) - break; - jboolean isCopy; - jbyte* elems = static_cast<jbyte*>(fEnv->GetPrimitiveArrayCritical(theBufferArray, &isCopy)); - ZBlockCopy(elems, localDest, countRead); - fEnv->ReleasePrimitiveArrayCritical(theBufferArray, elems, JNI_ABORT); - localDest += countRead; - countRemaining -= countRead; - if (oCountRead) - *oCountRead += countRead; - } - fEnv->DeleteLocalRef(theBufferArray); - } - -size_t ZStreamR_JNI::Imp_CountReadable() - { - if (jclass class_Stream = fEnv->GetObjectClass(fJavaStream)) - { - if (jmethodID mid_available = fEnv->GetMethodID(class_Stream, "available", "()I")) - return fEnv->CallIntMethod(fJavaStream, mid_available); - } - return 0; - } - -NAMESPACE_ZOOLIB_END - -#endif // ZCONFIG_SPI_Enabled(JNI) Deleted: trunk/zoolib/source/cxx/zoolib/ZStream_JNI.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZStream_JNI.h 2009-10-08 11:36:10 UTC (rev 1007) +++ trunk/zoolib/source/cxx/zoolib/ZStream_JNI.h 2009-10-08 11:37:12 UTC (rev 1008) @@ -1,58 +0,0 @@ -/* ------------------------------------------------------------------------------------------------- -Copyright (c) 2003 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 __ZStream_JNI__ -#define __ZStream_JNI__ 1 -#include "zoolib/ZCONFIG_SPI.h" - -#include "zoolib/ZStream.h" - -#if ZCONFIG_SPI_Enabled(JNI) - -#include <jni.h> - -NAMESPACE_ZOOLIB_BEGIN - -// ================================================================================================= -#pragma mark - -#pragma mark * ZStreamR_JNI - -/// A read stream that sources data from a java.io.InputStream. - -class ZStreamR_JNI : public ZStreamR - { -public: - ZStreamR_JNI(JNIEnv* iEnv, jobject iJavaStream); - ~ZStreamR_JNI(); - -// From ZStreamR - virtual void Imp_Read(void* iDest, size_t iCount, size_t* oCountRead); - virtual size_t Imp_CountReadable(); - -private: - jobject fJavaStream; - JNIEnv* fEnv; - }; - -NAMESPACE_ZOOLIB_END - -#endif // ZCONFIG_SPI_Enabled(JNI) - -#endif // __ZStream_JNI__ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |