|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "satsajnitools.h" |
|
21 #include <e32base.h> |
|
22 |
|
23 void STSSetJavaErrorCode(JNIEnv* aJniEnv, jintArray aErrorTo, |
|
24 const TInt& aErrorFrom) |
|
25 { |
|
26 jint javaError[1] = |
|
27 { aErrorFrom }; |
|
28 aJniEnv->SetIntArrayRegion(aErrorTo, 0, 1, javaError); |
|
29 } |
|
30 |
|
31 CDesCArrayFlat* STSCreateNativeStringArrayL(JNIEnv* aJniEnv, |
|
32 jobjectArray aJavaArray) |
|
33 { |
|
34 const TInt numElems = aJniEnv->GetArrayLength(aJavaArray); |
|
35 |
|
36 CDesCArrayFlat* nativeArray = new(ELeave) CDesCArrayFlat(numElems + 1); // ensure granularity of at least 1 (panics if 0) |
|
37 |
|
38 CleanupStack::PushL(nativeArray); |
|
39 |
|
40 for (TInt elemIndex = 0; elemIndex < numElems; elemIndex++) |
|
41 { |
|
42 // Creates a new local reference |
|
43 jobject javaElemObject = aJniEnv->GetObjectArrayElement(aJavaArray, |
|
44 elemIndex); |
|
45 |
|
46 jstring javaElem = static_cast<jstring>(javaElemObject); |
|
47 |
|
48 // Guarded with blocks to delete RJString before deleting local |
|
49 // reference |
|
50 { |
|
51 RJString nativeElem(*aJniEnv, javaElem); |
|
52 nativeArray->AppendL(nativeElem); |
|
53 } |
|
54 // The VM runs out of temporary local references, unless the |
|
55 // elements are released here |
|
56 aJniEnv->DeleteLocalRef(javaElemObject); |
|
57 } |
|
58 |
|
59 CleanupStack::Pop(nativeArray); |
|
60 return nativeArray; |
|
61 } |