diff -r 2a9601315dfc -r 98ccebc37403 javauis/mmapi_qt/utils/src/mmapiutils.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/javauis/mmapi_qt/utils/src/mmapiutils.cpp Fri May 14 15:47:24 2010 +0300 @@ -0,0 +1,75 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ +#include "mmapiutils.h" +#include "s60commonutils.h" +using namespace java::util; + +enum TJavaArrayPanic +{ + EBadOffsetIntoJavaArray, + EWritingOverEndOfJavaArray, + EBadOffsetIntoJavaArrayForRead, + EReadingOverEndOfJavaArray, +}; + + +/** + * Copies data from the native to the Java array. + * @return The number of bytes copied. + */ +TInt MMAPIUtils::CopyToJava(JNIEnv& aJni, const TDesC8& aNativeBuffer, + jbyteArray aJavaBuffer, TInt aOffset, TInt aLength) +{ + __ASSERT_DEBUG(aOffset <= aJni.GetArrayLength(aJavaBuffer), + User::Panic(_L("ArrayUtils"), EBadOffsetIntoJavaArray)); + __ASSERT_DEBUG(aLength <= aJni.GetArrayLength(aJavaBuffer) - aOffset, + User::Panic(_L("ArrayUtils"), EWritingOverEndOfJavaArray)); + + TInt nativeBufferLength = aNativeBuffer.Length(); + TInt length = (nativeBufferLength < aLength) ? nativeBufferLength : aLength; + TUint8* nativeBufferPtr = const_cast(aNativeBuffer.Ptr()); + jbyte* jNativeBufferPtr = reinterpret_cast(nativeBufferPtr); + aJni.SetByteArrayRegion(aJavaBuffer, aOffset, length, jNativeBufferPtr); + return length; +} + +jobjectArray MMAPIUtils::CopyToNewJavaStringArrayL(JNIEnv& aJni, const CDesCArray& aNativeArray) +{ + jclass stringClass = aJni.FindClass("java/lang/String"); + User::LeaveIfNull(stringClass); + // + jobjectArray result = aJni.NewObjectArray(aNativeArray.Count(), stringClass, NULL); + if (result != NULL) + { + TPtrC item; + for (int i=0; i