67
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 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 |
#include <centralrepository.h> // KMaxUnicodeStringLength
|
|
19 |
|
|
20 |
#include "com_nokia_mj_impl_cenrep_CentralRepositoryImpl.h"
|
|
21 |
#include "cjavacentralrepository.h"
|
|
22 |
#include "centrepfunctionserver.h"
|
|
23 |
#include "javajniutils.h"
|
|
24 |
#include "jstringutils.h"
|
|
25 |
#include "s60commonutils.h"
|
|
26 |
#include "logger.h"
|
|
27 |
#include "fs_methodcall.h"
|
|
28 |
|
|
29 |
using namespace java::util;
|
|
30 |
/*
|
|
31 |
* Class: com_nokia_mj_impl_cenrep_CentralRepositoryImpl
|
|
32 |
* Method: _createFunctionSource
|
|
33 |
* Signature: ()I
|
|
34 |
*/
|
|
35 |
JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_cenrep_CentralRepositoryImpl__1createFunctionSource
|
|
36 |
(JNIEnv *aJni, jobject /*aPeer*/)
|
|
37 |
{
|
|
38 |
JELOG2(EJavaCentrep);
|
|
39 |
java::centrep::CentrepFunctionServer* mFunctionServer;
|
|
40 |
mFunctionServer = new java::centrep::CentrepFunctionServer();
|
|
41 |
TInt handle = reinterpret_cast<jint>(mFunctionServer);
|
|
42 |
if (handle < KErrNone)
|
|
43 |
{
|
|
44 |
JniUtils::throwNewException(aJni, "com/nokia/mid/cenrep/CentralRepositoryException" ,
|
|
45 |
JavaCommonUtils::intToString(handle));
|
|
46 |
}
|
|
47 |
return handle;
|
|
48 |
}
|
|
49 |
|
|
50 |
/**
|
|
51 |
* CreateCentralRepositoryL
|
|
52 |
*/
|
|
53 |
void CreateCentralRepositoryL(CJavaCentralRepository*& aCenRep,
|
|
54 |
TUid aRepositoryId)
|
|
55 |
{
|
|
56 |
CJavaCentralRepository* cenrep =
|
|
57 |
CJavaCentralRepository::NewL(aRepositoryId);
|
|
58 |
aCenRep = cenrep;
|
|
59 |
}
|
|
60 |
|
|
61 |
/*
|
|
62 |
* Class: com_nokia_mj_impl_cenrep_CentralRepositoryImpl
|
|
63 |
* Method: _createNativePeer
|
|
64 |
* Signature: (II)I
|
|
65 |
*/
|
|
66 |
JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_cenrep_CentralRepositoryImpl__1createNativePeer
|
|
67 |
(JNIEnv *aJni, jobject, jint aFunctionSourceHandle, jint aRepositoryId)
|
|
68 |
{
|
|
69 |
java::centrep::CentrepFunctionServer* mFunctionServer =
|
|
70 |
reinterpret_cast< java::centrep::CentrepFunctionServer*>(aFunctionSourceHandle);
|
|
71 |
|
|
72 |
CJavaCentralRepository* cenrep = NULL;
|
|
73 |
|
|
74 |
TUid uid = TUid::Uid(aRepositoryId);
|
|
75 |
TRAPD(err,CallMethodL(CreateCentralRepositoryL, cenrep, uid, mFunctionServer));
|
|
76 |
|
|
77 |
if (err != KErrNone)
|
|
78 |
{
|
|
79 |
JniUtils::throwNewException(aJni, "com/nokia/mid/cenrep/CentralRepositoryException" ,
|
|
80 |
JavaCommonUtils::intToString(err));
|
|
81 |
}
|
|
82 |
return reinterpret_cast<jint>(cenrep);
|
|
83 |
}
|
|
84 |
|
|
85 |
/**
|
|
86 |
* Close
|
|
87 |
*/
|
|
88 |
void CloseCentralRepository(CJavaCentralRepository* aCenRep)
|
|
89 |
{
|
|
90 |
aCenRep->Close();
|
|
91 |
}
|
|
92 |
|
|
93 |
/*
|
|
94 |
* Class: com_nokia_mj_impl_cenrep_CentralRepositoryImpl
|
|
95 |
* Method: _close
|
|
96 |
* Signature: (II)I
|
|
97 |
*/
|
|
98 |
JNIEXPORT void JNICALL Java_com_nokia_mj_impl_cenrep_CentralRepositoryImpl__1close
|
|
99 |
(JNIEnv *, jobject, jint aFunctionSourceHandle, jint aCenrepHandle)
|
|
100 |
{
|
|
101 |
java::centrep::CentrepFunctionServer* mFunctionServer =
|
|
102 |
reinterpret_cast< java::centrep::CentrepFunctionServer*>(
|
|
103 |
aFunctionSourceHandle);
|
|
104 |
|
|
105 |
CJavaCentralRepository* cenrep =
|
|
106 |
reinterpret_cast<CJavaCentralRepository *>(aCenrepHandle);
|
|
107 |
|
|
108 |
CallMethod(CloseCentralRepository, cenrep, mFunctionServer);
|
|
109 |
}
|
|
110 |
|
|
111 |
/**
|
|
112 |
* Dispose
|
|
113 |
*/
|
|
114 |
void Dispose(CJavaCentralRepository* aCenRep)
|
|
115 |
{
|
|
116 |
delete aCenRep;
|
|
117 |
aCenRep = NULL;
|
|
118 |
}
|
|
119 |
|
|
120 |
/*
|
|
121 |
* Class: com_nokia_mj_impl_cenrep_CentralRepositoryImpl
|
|
122 |
* Method: _dispose
|
|
123 |
* Signature: (II)V
|
|
124 |
*/
|
|
125 |
JNIEXPORT void JNICALL Java_com_nokia_mj_impl_cenrep_CentralRepositoryImpl__1dispose
|
|
126 |
(JNIEnv *, jobject, jint aFunctionSourceHandle, jint aCenrepHandle)
|
|
127 |
{
|
|
128 |
java::centrep::CentrepFunctionServer* mFunctionServer =
|
|
129 |
reinterpret_cast< java::centrep::CentrepFunctionServer*>(
|
|
130 |
aFunctionSourceHandle);
|
|
131 |
|
|
132 |
CJavaCentralRepository* cenrep =
|
|
133 |
reinterpret_cast<CJavaCentralRepository *>(aCenrepHandle);
|
|
134 |
|
|
135 |
CallMethod(Dispose, cenrep, mFunctionServer);
|
|
136 |
delete mFunctionServer;
|
|
137 |
}
|
|
138 |
|
|
139 |
/*
|
|
140 |
* Class: com_nokia_mj_impl_cenrep_CentralRepositoryImpl
|
|
141 |
* Method: _getString
|
|
142 |
* Signature: (IIJLcom/nokia/mj/impl/cenrep/CentralRepositoryImpl$StringValue;)I
|
|
143 |
*/
|
|
144 |
JNIEXPORT jstring JNICALL Java_com_nokia_mj_impl_cenrep_CentralRepositoryImpl__1getString
|
|
145 |
(JNIEnv * aJni, jobject, jint aFunctionSourceHandle, jint aCenrepHandle,
|
|
146 |
jlong aKey)
|
|
147 |
{
|
|
148 |
java::centrep::CentrepFunctionServer* mFunctionServer =
|
|
149 |
reinterpret_cast< java::centrep::CentrepFunctionServer*>(
|
|
150 |
aFunctionSourceHandle);
|
|
151 |
|
|
152 |
CJavaCentralRepository* cenrep =
|
|
153 |
reinterpret_cast<CJavaCentralRepository *>(aCenrepHandle);
|
|
154 |
|
|
155 |
HBufC* buf = NULL;
|
|
156 |
|
|
157 |
TUint32 key = (TUint32)aKey;
|
|
158 |
TRAPD(err, CallMethodL(buf, cenrep, &CJavaCentralRepository::GetStringL, key, mFunctionServer));
|
|
159 |
|
|
160 |
jstring val = NULL;
|
|
161 |
if (err == KErrNone && buf)
|
|
162 |
{
|
|
163 |
val = java::util::S60CommonUtils::NativeToJavaString(*aJni, *buf);
|
|
164 |
}
|
|
165 |
else
|
|
166 |
{
|
|
167 |
JniUtils::throwNewException(aJni, "com/nokia/mid/cenrep/CentralRepositoryException" ,
|
|
168 |
JavaCommonUtils::intToString(err));
|
|
169 |
}
|
|
170 |
|
|
171 |
delete buf;
|
|
172 |
return val;
|
|
173 |
}
|
|
174 |
|
|
175 |
|
|
176 |
/*
|
|
177 |
* Class: com_nokia_mj_impl_cenrep_CentralRepositoryImpl
|
|
178 |
* Method: _getInt
|
|
179 |
* Signature: (IIJLcom/nokia/mj/impl/cenrep/CentralRepositoryImpl$IntValue;)I
|
|
180 |
*/
|
|
181 |
JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_cenrep_CentralRepositoryImpl__1getInt
|
|
182 |
(JNIEnv * aJni, jobject, jint aFunctionSourceHandle, jint aCenrepHandle,
|
|
183 |
jlong aKey)
|
|
184 |
{
|
|
185 |
java::centrep::CentrepFunctionServer* mFunctionServer =
|
|
186 |
reinterpret_cast< java::centrep::CentrepFunctionServer*>(
|
|
187 |
aFunctionSourceHandle);
|
|
188 |
|
|
189 |
CJavaCentralRepository* cenrep =
|
|
190 |
reinterpret_cast<CJavaCentralRepository *>(aCenrepHandle);
|
|
191 |
|
|
192 |
TInt val = 0;
|
|
193 |
TUint32 key = (TUint32)aKey;
|
|
194 |
|
|
195 |
TRAPD(err, CallMethodL(val, cenrep, &CJavaCentralRepository::GetIntL, key, mFunctionServer));
|
|
196 |
|
|
197 |
if (err != KErrNone)
|
|
198 |
{
|
|
199 |
JniUtils::throwNewException(aJni, "com/nokia/mid/cenrep/CentralRepositoryException" ,
|
|
200 |
JavaCommonUtils::intToString(err));
|
|
201 |
}
|
|
202 |
return val;
|
|
203 |
}
|
|
204 |
|
|
205 |
/**
|
|
206 |
* SetStringL
|
|
207 |
*/
|
|
208 |
void SetStringL(CJavaCentralRepository* aCenRep, TUint32 aKey, TDesC* aValue)
|
|
209 |
{
|
|
210 |
aCenRep->SetL(aKey, *aValue);
|
|
211 |
}
|
|
212 |
|
|
213 |
/*
|
|
214 |
* Class: com_nokia_mj_impl_cenrep_CentralRepositoryImpl
|
|
215 |
* Method: _setString
|
|
216 |
* Signature: (IIJLjava/lang/String;)I
|
|
217 |
*/
|
|
218 |
JNIEXPORT void JNICALL Java_com_nokia_mj_impl_cenrep_CentralRepositoryImpl__1setString
|
|
219 |
(JNIEnv *aJni, jobject, jint aFunctionSourceHandle, jint aCenrepHandle,
|
|
220 |
jlong aKey, jstring aValue)
|
|
221 |
{
|
|
222 |
java::centrep::CentrepFunctionServer* mFunctionServer =
|
|
223 |
reinterpret_cast< java::centrep::CentrepFunctionServer*>(
|
|
224 |
aFunctionSourceHandle);
|
|
225 |
|
|
226 |
CJavaCentralRepository* cenrep =
|
|
227 |
reinterpret_cast<CJavaCentralRepository *>(aCenrepHandle);
|
|
228 |
|
|
229 |
JStringUtils string(*aJni, aValue);
|
|
230 |
TUint32 key = (TUint32)aKey;
|
|
231 |
|
|
232 |
TDesC* tstring = (TDesC*) &string;
|
|
233 |
TRAPD(err, CallMethodL(SetStringL, cenrep, key, tstring, mFunctionServer));
|
|
234 |
|
|
235 |
if (err != KErrNone)
|
|
236 |
{
|
|
237 |
JniUtils::throwNewException(aJni, "com/nokia/mid/cenrep/CentralRepositoryException" ,
|
|
238 |
JavaCommonUtils::intToString(err));
|
|
239 |
}
|
|
240 |
}
|
|
241 |
|
|
242 |
/**
|
|
243 |
* SetIntL
|
|
244 |
*/
|
|
245 |
void SetIntL(CJavaCentralRepository* aCenRep, TUint32 aKey, TInt aValue)
|
|
246 |
{
|
|
247 |
aCenRep->SetL(aKey, aValue);
|
|
248 |
}
|
|
249 |
|
|
250 |
/*
|
|
251 |
* Class: com_nokia_mj_impl_cenrep_CentralRepositoryImpl
|
|
252 |
* Method: _setInt
|
|
253 |
* Signature: (IIJI)I
|
|
254 |
*/
|
|
255 |
JNIEXPORT void JNICALL Java_com_nokia_mj_impl_cenrep_CentralRepositoryImpl__1setInt
|
|
256 |
(JNIEnv *aJni, jobject, jint aFunctionSourceHandle, jint aCenrepHandle,
|
|
257 |
jlong aKey, jint aValue)
|
|
258 |
{
|
|
259 |
java::centrep::CentrepFunctionServer* mFunctionServer =
|
|
260 |
reinterpret_cast< java::centrep::CentrepFunctionServer*>(
|
|
261 |
aFunctionSourceHandle);
|
|
262 |
|
|
263 |
CJavaCentralRepository* cenrep =
|
|
264 |
reinterpret_cast<CJavaCentralRepository *>(aCenrepHandle);
|
|
265 |
|
|
266 |
TUint32 key = (TUint32)aKey;
|
|
267 |
TInt value = (TInt)aValue;
|
|
268 |
|
|
269 |
TRAPD(err, CallMethodL(SetIntL, cenrep, key, value, mFunctionServer));
|
|
270 |
if (err != KErrNone)
|
|
271 |
{
|
|
272 |
JniUtils::throwNewException(aJni, "com/nokia/mid/cenrep/CentralRepositoryException" ,
|
|
273 |
JavaCommonUtils::intToString(err));
|
|
274 |
}
|
|
275 |
}
|
|
276 |
|
|
277 |
|