|
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_push_PushRegistryImpl.h" |
|
20 #include "logger.h" |
|
21 #include "pushregistry.h" |
|
22 #include "pushexception.h" |
|
23 #include "javajniutils.h" |
|
24 #include "javacommonutils.h" |
|
25 #include "pusherrorcodes.h" |
|
26 #include "libraryloaderexception.h" |
|
27 #include "dynamiclibloader.h" |
|
28 #include "pushcontrollerstarter.h" |
|
29 #include "pushcontrollerstarterimpl.h" |
|
30 |
|
31 using namespace java::push; |
|
32 using namespace java::runtime; |
|
33 using namespace java::util; |
|
34 |
|
35 class StaticImplObjContainer |
|
36 { |
|
37 public: |
|
38 StaticImplObjContainer():mImpl(0) {} |
|
39 |
|
40 ~StaticImplObjContainer() {} |
|
41 |
|
42 PushRegistry* mImpl; |
|
43 }; |
|
44 |
|
45 #if defined(__SYMBIAN32__) && defined(__WINSCW__) |
|
46 #include <pls.h> |
|
47 #else |
|
48 static StaticImplObjContainer* sImpObjContainer = 0; |
|
49 #endif |
|
50 |
|
51 #ifdef __SYMBIAN32__ |
|
52 PushRegistry& getPushRegistryInstance() |
|
53 #else |
|
54 extern "C" PushRegistry& getPushRegistryInstance() |
|
55 #endif |
|
56 { |
|
57 JELOG2(EJavaPush); |
|
58 StaticImplObjContainer* container = 0; |
|
59 #if defined(__SYMBIAN32__) && defined(__WINSCW__) |
|
60 TUid uid = TUid::Uid(0xE0000020); |
|
61 container = Pls<StaticImplObjContainer>(uid); |
|
62 #else |
|
63 if (sImpObjContainer == 0) |
|
64 { |
|
65 sImpObjContainer = new StaticImplObjContainer(); |
|
66 } |
|
67 container = sImpObjContainer; |
|
68 #endif |
|
69 |
|
70 if (0 == container->mImpl) |
|
71 { |
|
72 std::auto_ptr<java::util::DynamicLibLoader> loader(NULL); |
|
73 PushControllerStarter& starter = PushControllerStarter::getPushControllerStarter(loader); |
|
74 //We have to leave this object to memory leak because we does not have correct place |
|
75 //to store DynamicLibLoader object. This just means that |
|
76 //pushcontroller dll is never unloaded from the runtime process. |
|
77 loader.release(); |
|
78 PushRegistry* retObj = static_cast<PushControllerStarterImpl*>(&starter); |
|
79 container->mImpl = retObj; |
|
80 return *retObj; |
|
81 } |
|
82 return *container->mImpl; |
|
83 } |
|
84 |
|
85 JNIEXPORT jstring JNICALL Java_com_nokia_mj_impl_push_PushRegistryImpl_getFilter0 |
|
86 (JNIEnv* aEnv, jclass, jstring aUri, jstring aSuiteUid) |
|
87 { |
|
88 JELOG2(EJavaPush); |
|
89 try |
|
90 { |
|
91 Uid suiteUid(JniUtils::jstringToWstring(aEnv,aSuiteUid)); |
|
92 std::wstring uriAsWStr = JniUtils::jstringToWstring(aEnv,aUri); |
|
93 PushRegistry& pushRegistry = getPushRegistryInstance(); |
|
94 std::wstring filterStr = pushRegistry.getFilter(uriAsWStr,suiteUid); |
|
95 jstring filter = JniUtils::wstringToJstring(aEnv,filterStr); |
|
96 return filter; |
|
97 } |
|
98 catch (PushException& ex) |
|
99 { |
|
100 ELOG1(EJavaPush,"ERROR!!! PushException caught: %s",ex.toString().c_str()); |
|
101 return NULL; |
|
102 } |
|
103 catch (...) |
|
104 { |
|
105 ELOG(EJavaPush,"ERROR!!! Unexpected exception was caught"); |
|
106 return NULL; |
|
107 } |
|
108 } |
|
109 |
|
110 JNIEXPORT jstring JNICALL Java_com_nokia_mj_impl_push_PushRegistryImpl_getMIDlet0 |
|
111 (JNIEnv* aEnv, jclass, jstring aUri, jstring aSuiteUid) |
|
112 { |
|
113 JELOG2(EJavaPush); |
|
114 try |
|
115 { |
|
116 Uid suiteUid(JniUtils::jstringToWstring(aEnv,aSuiteUid)); |
|
117 std::wstring uriAsWStr = JniUtils::jstringToWstring(aEnv,aUri); |
|
118 PushRegistry& pushRegistry = getPushRegistryInstance(); |
|
119 std::wstring filterStr = pushRegistry.getClassNameOfMidlet(uriAsWStr,suiteUid); |
|
120 jstring filter = JniUtils::wstringToJstring(aEnv,filterStr); |
|
121 return filter; |
|
122 } |
|
123 catch (PushException& ex) |
|
124 { |
|
125 ELOG1(EJavaPush,"ERROR!!! PushException caught: %s",ex.toString().c_str()); |
|
126 return NULL; |
|
127 } |
|
128 catch (...) |
|
129 { |
|
130 ELOG(EJavaPush,"ERROR!!! Unexpected exception was caught"); |
|
131 return NULL; |
|
132 } |
|
133 } |
|
134 |
|
135 |
|
136 JNIEXPORT jboolean JNICALL Java_com_nokia_mj_impl_push_PushRegistryImpl_isPushConnection0 |
|
137 (JNIEnv* aEnv, jclass, jstring aUri, jstring aAppUid) |
|
138 { |
|
139 JELOG2(EJavaPush); |
|
140 try |
|
141 { |
|
142 Uid appUid(JniUtils::jstringToWstring(aEnv,aAppUid)); |
|
143 std::wstring uriAsWStr = JniUtils::jstringToWstring(aEnv,aUri); |
|
144 PushRegistry& pushRegistry = getPushRegistryInstance(); |
|
145 bool isPushConn = pushRegistry.isPushConnection(uriAsWStr,appUid); |
|
146 if (isPushConn) |
|
147 return JNI_TRUE; |
|
148 return JNI_FALSE; |
|
149 } |
|
150 catch (PushException& ex) |
|
151 { |
|
152 ELOG1(EJavaPush,"ERROR!!! PushException caught: %s",ex.toString().c_str()); |
|
153 return JNI_FALSE; |
|
154 } |
|
155 catch (...) |
|
156 { |
|
157 ELOG(EJavaPush,"ERROR!!! Unexpected exception was caught"); |
|
158 return JNI_FALSE; |
|
159 } |
|
160 } |
|
161 |
|
162 JNIEXPORT jobjectArray JNICALL Java_com_nokia_mj_impl_push_PushRegistryImpl_listConnections0 |
|
163 (JNIEnv* aEnv, jclass, jboolean aAvailable, jstring aAppUid) |
|
164 { |
|
165 JELOG2(EJavaPush); |
|
166 try |
|
167 { |
|
168 bool available = false; |
|
169 if (JNI_TRUE == aAvailable) |
|
170 available = true; |
|
171 |
|
172 PushRegistry& pushRegistry = getPushRegistryInstance(); |
|
173 Uid appUid(JniUtils::jstringToWstring(aEnv,aAppUid)); |
|
174 std::list<std::wstring> uriList; |
|
175 pushRegistry.listConnections(available,appUid,uriList); |
|
176 if (0 == uriList.size()) |
|
177 return NULL; |
|
178 |
|
179 jobjectArray array = |
|
180 (jobjectArray)aEnv->NewObjectArray(uriList.size(), |
|
181 aEnv->FindClass("java/lang/String"), |
|
182 aEnv->NewStringUTF("")); |
|
183 std::list<std::wstring>::iterator iter; |
|
184 int i = 0; |
|
185 for (iter = uriList.begin(); iter != uriList.end(); ++iter) |
|
186 { |
|
187 char* dynamicChr = JavaCommonUtils::wstringToUtf8((*iter)); |
|
188 aEnv->SetObjectArrayElement(array,i,aEnv->NewStringUTF(dynamicChr)); |
|
189 i++; |
|
190 delete [] dynamicChr; |
|
191 }//end for |
|
192 return array; |
|
193 } |
|
194 catch (PushException& ex) |
|
195 { |
|
196 ELOG1(EJavaPush,"ERROR!!! PushException caught: %s",ex.toString().c_str()); |
|
197 return NULL; |
|
198 } |
|
199 catch (...) |
|
200 { |
|
201 ELOG(EJavaPush,"ERROR!!! Unexpected exception was caught"); |
|
202 return NULL; |
|
203 } |
|
204 } |
|
205 |
|
206 JNIEXPORT jlong JNICALL Java_com_nokia_mj_impl_push_PushRegistryImpl_registerAlarm0 |
|
207 (JNIEnv* aEnv, jclass,jlong aTimeInMilliSecs, jstring aSuiteUid, |
|
208 jstring aMIDletClassName, jboolean aIsUidOfThisMidlet) |
|
209 { |
|
210 JELOG2(EJavaPush); |
|
211 try |
|
212 { |
|
213 PushRegistry& pushRegistry = getPushRegistryInstance(); |
|
214 Uid suiteUid(JniUtils::jstringToWstring(aEnv,aSuiteUid)); |
|
215 std::wstring classNameWStr = JniUtils::jstringToWstring(aEnv,aMIDletClassName); |
|
216 bool isUidOfThisMidlet = false; |
|
217 if (JNI_TRUE == aIsUidOfThisMidlet) |
|
218 isUidOfThisMidlet = true; |
|
219 long long retValue = pushRegistry.registerAlarm(aTimeInMilliSecs,suiteUid, |
|
220 classNameWStr,isUidOfThisMidlet); |
|
221 return retValue; |
|
222 } |
|
223 catch (PushException& ex) |
|
224 { |
|
225 ELOG1(EJavaPush,"ERROR!!! PushException caught: %s",ex.toString().c_str()); |
|
226 if (INVALID_ALARM_TIME == ex.mErrCode) |
|
227 { |
|
228 JniUtils::throwNewException(aEnv,"java/lang/IllegalArgumentException",ex.toString()); |
|
229 } |
|
230 //else if(INCORRECT_APP_DATA == ex.mErrCode) |
|
231 else if (std::string::npos != ex.toString().find("-11052")) |
|
232 { |
|
233 JniUtils::throwNewException(aEnv,"java/lang/ClassNotFoundException",ex.toString()); |
|
234 } |
|
235 else |
|
236 { |
|
237 //We have to return 0 because IOException cannot be thrown. |
|
238 return 0; |
|
239 } |
|
240 } |
|
241 catch (...) |
|
242 { |
|
243 ELOG(EJavaPush,"ERROR!!! Unexpected exception was caught"); |
|
244 } |
|
245 return 0; |
|
246 } |
|
247 |
|
248 JNIEXPORT void JNICALL Java_com_nokia_mj_impl_push_PushRegistryImpl_registerConnection0 |
|
249 (JNIEnv* aEnv, jclass, jstring aUri, jstring aMIDletClassName, jstring aFilter, |
|
250 jstring aAppUid,jboolean aIsUidOfThisMidlet) |
|
251 { |
|
252 JELOG2(EJavaPush); |
|
253 try |
|
254 { |
|
255 PushRegistry& pushRegistry = getPushRegistryInstance(); |
|
256 std::wstring uriAsWStr = JniUtils::jstringToWstring(aEnv,aUri); |
|
257 std::wstring midletClassAsWStr = JniUtils::jstringToWstring(aEnv,aMIDletClassName); |
|
258 std::wstring filterAsWStr = JniUtils::jstringToWstring(aEnv,aFilter); |
|
259 Uid appUid(JniUtils::jstringToWstring(aEnv,aAppUid)); |
|
260 bool isUidOfThisMidlet = false; |
|
261 if (JNI_TRUE == aIsUidOfThisMidlet) |
|
262 isUidOfThisMidlet = true; |
|
263 pushRegistry.registerDynamicPushConn(uriAsWStr,midletClassAsWStr,filterAsWStr,appUid, |
|
264 isUidOfThisMidlet); |
|
265 } |
|
266 catch (PushException& ex) |
|
267 { |
|
268 ELOG1(EJavaPush,"ERROR!!! registerConnection0(): PushException: %s",ex.toString().c_str()); |
|
269 if (INVALID_URI == ex.mErrCode) |
|
270 { |
|
271 JniUtils::throwNewException(aEnv,"java/lang/IllegalArgumentException",ex.toString()); |
|
272 } |
|
273 //else if(PUSH_CONNECTION_ALREADY_EXISTS == ex.mErrCode){ |
|
274 // JniUtils::throwNewException(aEnv,"java/io/IOException",ex.toString()); |
|
275 //} |
|
276 else |
|
277 { |
|
278 JniUtils::throwNewException(aEnv,"java/io/IOException",ex.toString()); |
|
279 } |
|
280 } |
|
281 catch (java::util::LibraryLoaderException& ex) |
|
282 { |
|
283 if (java::util::OPENING_LIBRARY_FAILED == ex.mErrCode) |
|
284 { |
|
285 JniUtils::throwNewException |
|
286 (aEnv,"javax/microedition/io/ConnectionNotFoundException",ex.toString()); |
|
287 } |
|
288 else |
|
289 { |
|
290 JniUtils::throwNewException(aEnv,"java/io/IOException",ex.toString()); |
|
291 } |
|
292 } |
|
293 catch (...) |
|
294 { |
|
295 ELOG(EJavaPush,"ERROR!!! Unexpected exception was caught"); |
|
296 JniUtils::throwNewException(aEnv,"java/io/IOException","Unexpected error occurred"); |
|
297 } |
|
298 } |
|
299 JNIEXPORT jboolean JNICALL Java_com_nokia_mj_impl_push_PushRegistryImpl_unregisterConnection0 |
|
300 (JNIEnv* aEnv, jclass, jstring aUri, jstring aAppUid,jboolean aIsUidOfThisMidlet) |
|
301 { |
|
302 JELOG2(EJavaPush); |
|
303 try |
|
304 { |
|
305 PushRegistry& pushRegistry = getPushRegistryInstance(); |
|
306 std::wstring uriAsWStr = JniUtils::jstringToWstring(aEnv,aUri); |
|
307 Uid appUid(JniUtils::jstringToWstring(aEnv,aAppUid)); |
|
308 bool isUidOfThisMidlet = false; |
|
309 if (JNI_TRUE == aIsUidOfThisMidlet) |
|
310 isUidOfThisMidlet = true; |
|
311 pushRegistry.unregisterDynamicPushConn(uriAsWStr,appUid,isUidOfThisMidlet); |
|
312 return true; |
|
313 } |
|
314 catch (...) |
|
315 { |
|
316 ELOG(EJavaPush,"ERROR!!! Unexpected exception was caught in the unregisterConnection0 operation"); |
|
317 return false; |
|
318 } |
|
319 } |