|
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 "com_nokia_mj_impl_properties_satsa_SmartCardSlots.h" |
|
20 |
|
21 #include "javaapduconnection.h" |
|
22 #include "cstsconnection.h" |
|
23 |
|
24 #include "cstsresphandler.h" |
|
25 #include "fs_methodcall.h" |
|
26 #include "logger.h" |
|
27 #include "javajniutils.h" |
|
28 #include "s60commonutils.h" |
|
29 |
|
30 using namespace java::satsa; |
|
31 |
|
32 /** |
|
33 * JNI function. |
|
34 */ |
|
35 JNIEXPORT jstring JNICALL Java_com_nokia_mj_impl_properties_satsa_SmartCardSlots__1getSlots( |
|
36 JNIEnv* aJni, jclass /*aPeer*/, jint aHandle, |
|
37 jintArray aErrArray) |
|
38 { |
|
39 LOG(ESATSA, EInfo,"+ entering the __1getSlots JNI"); |
|
40 |
|
41 TPtr respPtr(NULL, 0); |
|
42 jstring retSlots = NULL; |
|
43 |
|
44 JavaApduConnection* apduConn = reinterpret_cast<JavaApduConnection *>(aHandle); |
|
45 |
|
46 std::wstring slotString(L""); |
|
47 TRAPD(err, slotString = apduConn->GetSlot()); |
|
48 if (KErrNone != err) |
|
49 { |
|
50 return NULL; |
|
51 } |
|
52 |
|
53 if (slotString.length()> 0) |
|
54 { |
|
55 retSlots = |
|
56 java::util::JniUtils::wstringToJstring(aJni, slotString); |
|
57 } |
|
58 else |
|
59 { |
|
60 std::wstring str(L""); |
|
61 return java::util::JniUtils::wstringToJstring(aJni, str); |
|
62 } |
|
63 |
|
64 jint javaError[ 1 ] = |
|
65 { err}; |
|
66 aJni->SetIntArrayRegion(aErrArray, 0, 1, javaError); |
|
67 LOG(ESATSA, EInfo, "-- returning from __1getSlots JNI"); |
|
68 return retSlots; |
|
69 |
|
70 } |
|
71 |
|
72 /** |
|
73 * JNI function. |
|
74 */ |
|
75 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_properties_satsa_SmartCardSlots__1create |
|
76 (JNIEnv* aJni, jobject aPeer) |
|
77 { |
|
78 LOG(ESATSA, EInfo, "+ entering the __1create slots JNI"); |
|
79 |
|
80 jobject connectionObject = aJni->NewWeakGlobalRef(aPeer); |
|
81 |
|
82 TInt handle = KErrNoMemory; |
|
83 JavaApduConnection *apduConn = NULL; |
|
84 try |
|
85 { |
|
86 apduConn = JavaApduConnection::getInstance(); |
|
87 } |
|
88 catch (int err) |
|
89 { |
|
90 ELOG1(ESATSA,"Caught an Exception --Value is:%d",err); |
|
91 delete apduConn; |
|
92 apduConn=NULL; |
|
93 } |
|
94 |
|
95 TInt connectionHandle = reinterpret_cast<TInt>(apduConn); |
|
96 handle = connectionHandle; |
|
97 |
|
98 TInt err = apduConn->CreateSlot(*aJni, connectionObject); |
|
99 if (err != KErrNone) |
|
100 { |
|
101 // Set error code to handle which is returned to Java |
|
102 ELOG(ESATSA,"__1create slots JNI:"); |
|
103 return err; |
|
104 } |
|
105 LOG1(ESATSA, EInfo, "APDUConnectionImpl.cpp::create return value %d", err); |
|
106 LOG(ESATSA, EInfo, "-- returning from the __1create slots JNI"); |
|
107 // return handle to new connection object or error code |
|
108 return handle; |
|
109 } |
|
110 |