1 //******************************************************************
\r
3 // Copyright 2016 Samsung Electronics All Rights Reserved.
\r
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\r
7 // Licensed under the Apache License, Version 2.0 (the "License");
\r
8 // you may not use this file except in compliance with the License.
\r
9 // You may obtain a copy of the License at
\r
11 // http://www.apache.org/licenses/LICENSE-2.0
\r
13 // Unless required by applicable law or agreed to in writing, software
\r
14 // distributed under the License is distributed on an "AS IS" BASIS,
\r
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 // See the License for the specific language governing permissions and
\r
17 // limitations under the License.
\r
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\r
21 #include "JniNotificationConsumer.h"
\r
22 #include "NSConsumerService.h"
\r
24 static JavaVM *g_jvm = NULL;
\r
26 static jobject g_obj_postListener = NULL;
\r
27 static jobject g_obj_discoverListener = NULL;
\r
28 static jobject g_obj_syncListener = NULL;
\r
29 static jobject g_obj_acceptListener = NULL;
\r
31 jclass g_cls_Message;
\r
32 jclass g_cls_Provider;
\r
33 jclass g_cls_SyncInfo;
\r
34 jclass g_cls_SyncType;
\r
35 jclass g_cls_MediaContents;
\r
36 jclass g_cls_TopicState;
\r
37 jclass g_cls_Message_Type;
\r
38 jclass g_cls_Response;
\r
40 jclass g_cls_TopicsList;
\r
42 static JNIEnv *GetJNIEnv(jint *ret)
\r
46 *ret = g_jvm->GetEnv((void **) &env, JNI_CURRENT_VERSION);
\r
52 if (g_jvm->AttachCurrentThread(&env, NULL) != JNI_OK)
\r
54 LOGE ("Failed to get the environment");
\r
62 LOGE ("JNI version is not supported");
\r
64 LOGE ("Failed to get the environment");
\r
69 jobject getJavaResponse(JNIEnv *env, OIC::Service::NSResponse response)
\r
71 LOGD ("ConsumerService_getJavaResponse - IN");
\r
74 case OIC::Service::NSResponse::ALLOW:
\r
76 static jfieldID fieldID = env->GetStaticFieldID(g_cls_Response,
\r
77 "ALLOW", "Lorg/iotivity/service/ns/consumer/ConsumerService$Response;");
\r
78 return env->GetStaticObjectField(g_cls_Response, fieldID);
\r
80 case OIC::Service::NSResponse::DENY:
\r
82 static jfieldID fieldID = env->GetStaticFieldID(g_cls_Response,
\r
83 "DENY", "Lorg/iotivity/service/ns/consumer/ConsumerService$Response;");
\r
84 return env->GetStaticObjectField(g_cls_Response, fieldID);
\r
86 case OIC::Service::NSResponse::TOPIC:
\r
88 static jfieldID fieldID = env->GetStaticFieldID(g_cls_Response,
\r
89 "TOPIC", "Lorg/iotivity/service/ns/consumer/ConsumerService$Response;");
\r
90 return env->GetStaticObjectField(g_cls_Response, fieldID);
\r
95 LOGD ("ConsumerService_getJavaResponse - OUT");
\r
99 jobject getJavaSyncType(JNIEnv *env, OIC::Service::NSSyncInfo::NSSyncType nsType)
\r
101 LOGD ("ConsumerService_getJavaSyncType - IN");
\r
104 jclass cls_SyncType = (jclass) (env->NewLocalRef(g_cls_SyncType));
\r
107 LOGE ("Failed to Get ObjectClass for SyncType");
\r
113 case OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_UNREAD:
\r
115 static jfieldID fieldID = env->GetStaticFieldID(cls_SyncType,
\r
116 "UNREAD", "Lorg/iotivity/service/ns/common/SyncInfo$SyncType;");
\r
117 syncType = env->GetStaticObjectField(cls_SyncType, fieldID);
\r
119 case OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ :
\r
121 static jfieldID fieldID = env->GetStaticFieldID(cls_SyncType,
\r
122 "READ", "Lorg/iotivity/service/ns/common/SyncInfo$SyncType;");
\r
123 syncType = env->GetStaticObjectField(cls_SyncType, fieldID);
\r
125 case OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED :
\r
127 static jfieldID fieldID = env->GetStaticFieldID(cls_SyncType,
\r
128 "DELETED", "Lorg/iotivity/service/ns/common/SyncInfo$SyncType;");
\r
129 syncType = env->GetStaticObjectField(cls_SyncType, fieldID);
\r
134 if (syncType == NULL)
\r
136 LOGD("Error: object of field Synctype is null");
\r
139 env->DeleteLocalRef(cls_SyncType);
\r
140 LOGD ("ConsumerService_getJavaSyncType - OUT");
\r
144 jobject getJavaTopicState(JNIEnv *env, OIC::Service::NSTopic::NSTopicState nsState)
\r
146 LOGD ("ConsumerService_getJavaTopicState - IN");
\r
149 jclass cls_topicState = (jclass) (env->NewLocalRef(g_cls_TopicState));
\r
150 if (!cls_topicState)
\r
152 LOGE ("Failed to Get ObjectClass for TopicState Type");
\r
156 jobject obj_topicState;
\r
159 case OIC::Service::NSTopic::NSTopicState::UNSUBSCRIBED:
\r
161 static jfieldID fieldID = env->GetStaticFieldID(cls_topicState,
\r
162 "UNSUBSCRIBED", "Lorg/iotivity/service/ns/common/Topic$TopicState;");
\r
163 obj_topicState = env->GetStaticObjectField(cls_topicState, fieldID);
\r
165 case OIC::Service::NSTopic::NSTopicState::SUBSCRIBED:
\r
167 static jfieldID fieldID = env->GetStaticFieldID(cls_topicState,
\r
168 "SUBSCRIBED", "Lorg/iotivity/service/ns/common/Topic$TopicState;");
\r
169 obj_topicState = env->GetStaticObjectField(cls_topicState, fieldID);
\r
173 if (obj_topicState == NULL)
\r
175 LOGD("Error: object of field TopicState is null");
\r
178 env->DeleteLocalRef(cls_topicState);
\r
179 LOGD ("ConsumerService_getJavaTopicState - OUT");
\r
180 return obj_topicState;
\r
183 jobject getJavaTopicsList(JNIEnv *env, OIC::Service::NSTopicsList *topicList)
\r
185 LOGD ("ConsumerService_getJavaTopicsList - IN");
\r
186 jclass cls_topicList = (jclass) (env->NewLocalRef(g_cls_TopicsList));
\r
187 if (!cls_topicList)
\r
189 LOGE ("Failed to Get ObjectClass for TopicsList");
\r
192 jmethodID mid_topicList = env->GetMethodID(cls_topicList, "<init>", "()V");
\r
193 if (!mid_topicList)
\r
195 LOGE ("Failed to Get MethodID for TopicsList<init>");
\r
198 jobject obj_topicList = env->NewObject(cls_topicList, mid_topicList);
\r
199 if (!obj_topicList)
\r
201 LOGE ("Failed to Get object for TopicsList");
\r
204 jmethodID mid_addTopic = env->GetMethodID(cls_topicList, "addTopic",
\r
205 "(Ljava/lang/String;Lorg/iotivity/service/ns/common/Topic$TopicState;)V");
\r
208 LOGE ("Failed to Get MethodID for addTopic");
\r
211 for (auto it : topicList->getTopicsList())
\r
213 jobject jState = getJavaTopicState(env, it->getState());
\r
214 std::string topicName = it->getTopicName();
\r
215 jstring jTopicName = env->NewStringUTF(topicName.c_str());
\r
216 env->CallVoidMethod(obj_topicList, mid_addTopic, jTopicName, jState);
\r
218 env->DeleteLocalRef(cls_topicList);
\r
219 LOGD ("ConsumerService_getJavaTopicsList - OUT");
\r
220 return obj_topicList;
\r
223 bool getNativeTopicState(JNIEnv *env, jobject jTopic , OIC::Service::NSTopic::NSTopicState &state )
\r
225 LOGD ("ConsumerService_getNativeTopicState - IN");
\r
227 jclass cls_topic = env->GetObjectClass( jTopic);
\r
229 jclass cls_TopicState = (jclass) (env->NewLocalRef(g_cls_TopicState));
\r
230 if (!cls_TopicState)
\r
232 LOGE ("Failed to Get ObjectClass for cls_TopicState Type");
\r
235 jmethodID mid = env->GetMethodID(cls_TopicState, "ordinal", "()I");
\r
236 jfieldID fid_state = env->GetFieldID( cls_topic, "mState",
\r
237 "Lorg/iotivity/service/ns/common/Topic$TopicState;");
\r
238 if (fid_state == NULL)
\r
240 LOGE("Error: jfieldID for state type is null");
\r
243 jobject jobj = env->GetObjectField( jTopic, fid_state);
\r
246 LOGE("Error: object of field state Type is null");
\r
249 jint jState = env->CallIntMethod(jobj, mid);
\r
250 state = (OIC::Service::NSTopic::NSTopicState) jState;
\r
251 LOGD ("ConsumerService_getNativeTopicState - OUT");
\r
256 const char *getNativeTopicName(JNIEnv *env, jobject jTopic)
\r
258 LOGD ("ConsumerService_getNativeTopicName - IN");
\r
259 jclass cls_topic = env->GetObjectClass( jTopic);
\r
260 if (cls_topic == NULL)
\r
262 LOGE("Error: Class for Topic is null");
\r
265 jfieldID fid_name = env->GetFieldID( cls_topic, "mTopicName", "Ljava/lang/String;");
\r
266 if (fid_name == NULL)
\r
268 LOGE("Error: jfieldID for Topic Name is null");
\r
271 jstring jTopicName = (jstring) env->GetObjectField( jTopic, fid_name);
\r
272 const char *topicName;
\r
275 topicName = env->GetStringUTFChars( jTopicName, NULL);
\r
279 LOGI("Info: topicName is null");
\r
281 LOGD ("ConsumerService_getNativeTopicName - OUT");
\r
286 OIC::Service::NSTopicsList *getNativeTopicsList(JNIEnv *env, jobject jTopicList)
\r
288 LOGD ("ConsumerService_getNativeTopicsList - IN");
\r
290 jclass cls_topicList = env->GetObjectClass( jTopicList);
\r
291 if (cls_topicList == NULL)
\r
293 LOGE("Error: Class for Topic List is null");
\r
296 jfieldID fid_list = env->GetFieldID( cls_topicList, "mTopicsList", "Ljava/util/Vector;");
\r
297 if (fid_list == NULL)
\r
299 LOGE("Error: jfieldID for Topic List is null");
\r
302 jobject jobj = env->GetObjectField( jTopicList, fid_list);
\r
305 LOGE("Error: object of field Topic List is null");
\r
308 jclass cls_vec = env->FindClass("java/util/Vector");
\r
309 if (cls_vec == NULL)
\r
311 LOGE("Error: Class for Vector not found");
\r
314 jmethodID sizeMethod = env->GetMethodID(cls_vec, "size", "()I");
\r
315 if (sizeMethod == NULL)
\r
317 LOGE("Error: MethodId for Vector Size not found");
\r
320 int size = env->CallIntMethod(jobj, sizeMethod);
\r
321 jmethodID getMethod = env->GetMethodID(cls_vec, "get", "(I)Ljava/lang/Object;");
\r
322 if (getMethod == NULL)
\r
324 LOGE("Error: MethodId for Vector get not found");
\r
327 OIC::Service::NSTopicsList *nsTopicList = new OIC::Service::NSTopicsList();
\r
328 for (int index = 0; index < size; index++)
\r
330 jobject topicObj = env->CallObjectMethod(jobj, getMethod, index);
\r
331 if (topicObj == NULL)
\r
333 LOGE("Error: object of field Topic is null");
\r
336 const char *name = getNativeTopicName(env, topicObj);
\r
337 if (name == nullptr)
\r
339 LOGE("Error: Couldn't find topic Name");
\r
342 std::string topicName(name);
\r
343 OIC::Service::NSTopic::NSTopicState state;
\r
344 if (!getNativeTopicState(env, topicObj, state))
\r
348 nsTopicList->addTopic(topicName, state);
\r
351 env->DeleteLocalRef(cls_vec);
\r
352 env->DeleteLocalRef(cls_topicList);
\r
353 LOGD ("ConsumerService_getNativeTopicsList - OUT");
\r
354 return nsTopicList;
\r
357 OIC::Service::NSProvider *getNativeProvider(JNIEnv *env, jobject jObj)
\r
359 LOGD ("ConsumerService_getNativeProvider - IN");
\r
360 jclass providerClass = env->GetObjectClass(jObj);
\r
361 if (!providerClass)
\r
363 ThrowNSException(NS_ERROR, "Failed to Get ObjectClass for Provider");
\r
366 jfieldID jproviderId = env->GetFieldID(providerClass, "mProviderId", "Ljava/lang/String;");
\r
369 ThrowNSException(NS_ERROR, "Failed to get providerId for Provider");
\r
372 jstring jprovider_id = (jstring) env->GetObjectField(jObj, jproviderId);
\r
375 ThrowNSException(NS_ERROR, "ProviderId cannot be null");
\r
379 const char *providerId = env->GetStringUTFChars(jprovider_id, 0);
\r
380 LOGD ("ProviderId : %s\n", providerId);
\r
382 OIC::Service::NSProvider *provider =
\r
383 OIC::Service::NSConsumerService::getInstance()->getProvider(std::string(providerId));
\r
384 if (provider == nullptr)
\r
386 ThrowNSException(NS_ERROR, "Provider with Given Id doesn't exist");
\r
389 env->ReleaseStringUTFChars(jprovider_id, providerId);
\r
390 LOGD ("ConsumerService_getNativeProvider - OUT");
\r
394 jobject getJavaProvider(JNIEnv *env, OIC::Service::NSProvider *provider)
\r
396 LOGD ("ConsumerService_getJavaProvider - IN");
\r
397 LOGD ("ProviderId : %s\n", provider->getProviderId().c_str());
\r
399 jstring jProviderId = env->NewStringUTF(provider->getProviderId().c_str());
\r
400 jlong pProvider = (long)provider;
\r
402 jclass cls_provider = (jclass) (env->NewLocalRef(g_cls_Provider));
\r
405 LOGE ("Failed to Get ObjectClass for Provider");
\r
408 jmethodID mid_provider = env->GetMethodID(
\r
409 cls_provider, "<init>", "(Ljava/lang/String;)V");
\r
412 LOGE ("Failed to Get MethodID for Provider<init>");
\r
415 jobject obj_provider = env->NewObject(cls_provider, mid_provider, jProviderId);
\r
418 LOGE("Failed to create new Object for Provider");
\r
422 jfieldID nativeHandle = env->GetFieldID(cls_provider, "mNativeHandle", "J");
\r
425 LOGE("Failed to get nativeHandle for Provider");
\r
428 env->SetLongField(obj_provider, nativeHandle, pProvider);
\r
430 jfieldID fid_topic = env->GetFieldID(cls_provider, "mTopicsList",
\r
431 "Lorg/iotivity/service/ns/common/TopicsList;");
\r
434 LOGE("Failed to get TopicList for Provider");
\r
437 jobject topicList = getJavaTopicsList(env, provider->getTopicList());
\r
438 env->SetObjectField(obj_provider, fid_topic, topicList);
\r
439 env->DeleteLocalRef(cls_provider);
\r
440 LOGD ("ConsumerService_getJavaProvider - OUT");
\r
441 return obj_provider;
\r
444 jobject getJavaMessageType(JNIEnv *env, OIC::Service::NSMessage::NSMessageType type)
\r
446 LOGD ("ConsumerService_getJavaMessageType - IN");
\r
449 case OIC::Service::NSMessage::NSMessageType::NS_MESSAGE_ALERT:
\r
451 static jfieldID fieldID = env->GetStaticFieldID(g_cls_Message_Type,
\r
452 "ALERT", "Lorg/iotivity/service/ns/common/Message$MessageType;");
\r
453 return env->GetStaticObjectField(g_cls_Message_Type, fieldID);
\r
455 case OIC::Service::NSMessage::NSMessageType::NS_MESSAGE_NOTICE:
\r
457 static jfieldID fieldID = env->GetStaticFieldID(g_cls_Message_Type,
\r
458 "NOTICE", "Lorg/iotivity/service/ns/common/Message$MessageType;");
\r
459 return env->GetStaticObjectField(g_cls_Message_Type, fieldID);
\r
461 case OIC::Service::NSMessage::NSMessageType::NS_MESSAGE_EVENT:
\r
463 static jfieldID fieldID = env->GetStaticFieldID(g_cls_Message_Type,
\r
464 "EVENT", "Lorg/iotivity/service/ns/common/Message$MessageType;");
\r
465 return env->GetStaticObjectField(g_cls_Message_Type, fieldID);
\r
467 case OIC::Service::NSMessage::NSMessageType::NS_MESSAGE_INFO:
\r
469 static jfieldID fieldID = env->GetStaticFieldID(g_cls_Message_Type,
\r
470 "INFO", "Lorg/iotivity/service/ns/common/Message$MessageType;");
\r
471 return env->GetStaticObjectField(g_cls_Message_Type, fieldID);
\r
476 LOGD ("ConsumerService_getJavaMessageType - OUT");
\r
480 jobject getJavaMessage(JNIEnv *env, OIC::Service::NSMessage *message)
\r
482 LOGD ("ConsumerService_getJavaMessage - IN");
\r
484 LOGD ("id : %llu\n", message->getMessageId());
\r
485 LOGD ("title : %s\n", message->getTitle().c_str());
\r
486 LOGD ("content : %s\n", message->getContentText().c_str());
\r
487 LOGD ("source : %s\n", message->getSourceName().c_str());
\r
489 jlong jMessageId = (jlong) message->getMessageId();
\r
490 jstring jProviderId = env->NewStringUTF(message->getProviderId().c_str());
\r
491 jstring jTitle = env->NewStringUTF(message->getTitle().c_str());
\r
492 jstring jContentText = env->NewStringUTF(message->getContentText().c_str());
\r
493 jstring jSourceName = env->NewStringUTF(message->getSourceName().c_str());
\r
494 jstring jTopic = env->NewStringUTF(message->getTopic().c_str());
\r
496 jstring jTime = env->NewStringUTF(message->getTime().c_str());
\r
497 jlong jTTL = (jlong) message->getTTL();
\r
499 jlong pMessage = (long) message;
\r
501 jclass cls_message = (jclass) (env->NewLocalRef(g_cls_Message));
\r
504 LOGE ("Failed to Get ObjectClass for Message");
\r
507 jmethodID mid_message = env->GetMethodID(
\r
508 cls_message, "<init>",
\r
509 "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
\r
512 LOGE ("Failed to Get MethodID for Message<init>");
\r
515 jobject obj_message = env->NewObject(cls_message, mid_message,
\r
516 jTitle, jContentText, jSourceName);
\r
519 LOGE ("Failed to Get Java Object for Message");
\r
522 jfieldID fid_nativeHandle = env->GetFieldID(cls_message, "mNativeHandle", "J");
\r
523 if (!fid_nativeHandle)
\r
525 LOGE("Failed to get nativeHandle for Message");
\r
528 env->SetLongField(obj_message, fid_nativeHandle, pMessage);
\r
530 jfieldID fid_messageId = env->GetFieldID(cls_message, "mMessageId", "J");
\r
531 if (!fid_messageId)
\r
533 LOGE("Failed to get field MessageID for Message");
\r
536 env->SetLongField(obj_message, fid_messageId, jMessageId);
\r
538 jfieldID fid_providerId = env->GetFieldID(cls_message, "mProviderId", "Ljava/lang/String;");
\r
539 if (!fid_providerId)
\r
541 LOGE("Failed to get field ProviderID for Message");
\r
544 env->SetObjectField(obj_message, fid_providerId, jProviderId);
\r
546 jfieldID fid_time = env->GetFieldID(cls_message, "mTime", "Ljava/lang/String;");
\r
549 LOGE("Failed to get field Time for Message");
\r
552 env->SetObjectField(obj_message, fid_time, jTime);
\r
554 jfieldID fid_ttl = env->GetFieldID(cls_message, "mTTL", "J");
\r
557 LOGE("Failed to get field TTL for Message");
\r
560 env->SetLongField(obj_message, fid_ttl, jTTL);
\r
562 jfieldID fid_topic = env->GetFieldID(cls_message, "mTopic", "Ljava/lang/String;");
\r
565 LOGE("Failed to get mTopic for Message");
\r
568 env->SetObjectField(obj_message, fid_topic, jTopic);
\r
570 OIC::Service::NSMediaContents *mediaCont = message->getMediaContents();
\r
571 if (mediaCont != nullptr)
\r
573 jstring jIconImage = env->NewStringUTF(mediaCont->getIconImage().c_str());
\r
574 jclass cls_mediaContents = (jclass) (env->NewLocalRef(g_cls_MediaContents));
\r
575 if (!cls_mediaContents)
\r
577 LOGE ("Failed to Get ObjectClass for MediaContents");
\r
580 jmethodID mid_mediaContents = env->GetMethodID(
\r
581 cls_mediaContents, "<init>", "(Ljava/lang/String;)V");
\r
582 if (!mid_mediaContents)
\r
584 LOGE ("Failed to Get MethodID for MediaContents<init>");
\r
587 jobject obj_mediaContents = env->NewObject(cls_mediaContents, mid_mediaContents,
\r
590 jfieldID fid_mediaContents = env->GetFieldID(cls_message, "mMediaContents",
\r
591 "Lorg/iotivity/service/ns/common/MediaContents;");
\r
592 if (!fid_mediaContents)
\r
594 LOGE("Failed to get field mediaContents for Message");
\r
597 env->SetObjectField(obj_message, fid_mediaContents, obj_mediaContents);
\r
601 jobject jType = getJavaMessageType(env, message->getType());
\r
604 jfieldID fid_type = env->GetFieldID(cls_message, "mType",
\r
605 "Lorg/iotivity/service/ns/common/Message$MessageType;");
\r
608 LOGE("Failed to get field Type for Message");
\r
611 env->SetObjectField(obj_message, fid_type, jType);
\r
614 env->DeleteLocalRef(cls_message);
\r
615 LOGD ("ConsumerService_getJavaMessage - OUT");
\r
616 return obj_message;
\r
619 void onDiscoverProvider(OIC::Service::NSProvider *provider)
\r
621 LOGD ("ConsumerService_onDiscoverProvider - IN");
\r
624 JNIEnv *env = GetJNIEnv(&envRet);
\r
625 if (NULL == env) return ;
\r
627 jobject jDiscoverListener = (jobject) env->NewLocalRef(g_obj_discoverListener);
\r
628 if (!jDiscoverListener)
\r
630 LOGE ("Failed to Get jDiscoverListener");
\r
631 if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
\r
635 jobject obj_provider = getJavaProvider(env, provider);
\r
638 LOGE ("Failed to Get Provider Object");
\r
639 if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
\r
643 jclass cls = env->GetObjectClass(jDiscoverListener);
\r
646 LOGE ("Failed to Get ObjectClass for jDiscoverListener");
\r
647 if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
\r
650 jmethodID mid = env->GetMethodID(
\r
652 "onProviderDiscovered",
\r
653 "(Lorg/iotivity/service/ns/consumer/Provider;)V");
\r
656 LOGE ("Failed to Get MethodID for onProviderDiscovered");
\r
657 if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
\r
661 env->CallVoidMethod(jDiscoverListener, mid, obj_provider);
\r
663 env->DeleteLocalRef(jDiscoverListener);
\r
664 if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
\r
665 LOGD ("ConsumerService_onDiscoverProvider - OUT");
\r
669 void onProviderChanged(OIC::Service::NSProvider *provider, OIC::Service::NSResponse response)
\r
671 LOGD ("ConsumerService_onProviderChanged -IN");
\r
674 JNIEnv *env = GetJNIEnv(&envRet);
\r
675 if (NULL == env) return ;
\r
677 jobject jAcceptListener = (jobject) env->NewLocalRef(g_obj_acceptListener);
\r
678 if (!jAcceptListener)
\r
680 LOGE ("Failed to Get jAcceptListener");
\r
681 if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
\r
684 jobject obj_provider = getJavaProvider(env, provider);
\r
687 LOGE ("Failed to Get Provider Object");
\r
688 if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
\r
692 jclass cls = env->GetObjectClass(jAcceptListener);
\r
695 LOGE ("Failed to Get ObjectClass for jAcceptListener");
\r
696 if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
\r
699 jmethodID mid = env->GetMethodID(
\r
701 "onProviderChanged",
\r
702 "(Lorg/iotivity/service/ns/consumer/Provider;Lorg/iotivity/service/ns/consumer/ConsumerService$Response;)V");
\r
705 LOGE ("Failed to Get MethodID for onProviderChanged");
\r
706 if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
\r
709 jobject obj_response = getJavaResponse(env, response);
\r
710 env->CallVoidMethod(jAcceptListener, mid, obj_provider, obj_response);
\r
712 env->DeleteLocalRef(jAcceptListener);
\r
713 if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
\r
714 LOGD ("ConsumerService_onProviderChanged -OUT");
\r
719 void onMessagePosted(OIC::Service::NSMessage *message)
\r
721 LOGD ("ConsumerService_onMessagePosted -IN");
\r
724 JNIEnv *env = GetJNIEnv(&envRet);
\r
725 if (NULL == env) return ;
\r
727 jobject jPostListener = (jobject) env->NewLocalRef(g_obj_postListener);
\r
728 if (!jPostListener)
\r
730 LOGE ("Failed to Get jPostListener");
\r
731 if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
\r
735 jobject obj_message = getJavaMessage( env, message);
\r
738 LOGE ("Failed to Get Message Object");
\r
739 if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
\r
742 jclass cls = env->GetObjectClass(jPostListener);
\r
745 LOGE ("Failed to Get ObjectClass for jPostListener");
\r
746 if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
\r
749 jmethodID mid = env->GetMethodID(
\r
751 "onMessageReceived",
\r
752 "(Lorg/iotivity/service/ns/common/Message;)V");
\r
755 LOGE ("Failed to Get MethodID for onMessageReceived");
\r
756 if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
\r
760 env->CallVoidMethod(jPostListener, mid, obj_message);
\r
762 env->DeleteLocalRef(jPostListener);
\r
763 if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
\r
764 LOGD ("ConsumerService_onMessagePosted -OUT");
\r
768 void onSyncInfoReceived(OIC::Service::NSSyncInfo *sync)
\r
770 LOGD ("ConsumerService_onSyncInfoReceived - IN");
\r
773 JNIEnv *env = GetJNIEnv(&envRet);
\r
774 if (NULL == env) return ;
\r
776 jobject jSyncListener = (jobject) env->NewLocalRef(g_obj_syncListener);
\r
777 if (!jSyncListener)
\r
779 LOGE ("Failed to Get jSyncListener");
\r
780 if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
\r
784 LOGD ("Sync ID : %llu\n", sync->getMessageId());
\r
785 LOGD ("Sync ProviderId : %s\n", sync->getProviderId().c_str());
\r
786 LOGD ("Sync STATE : %d\n", (int) sync->getState());
\r
788 jlong jMessageId = (jlong) sync->getMessageId();
\r
789 jstring jProviderId = env->NewStringUTF(sync->getProviderId().c_str());
\r
790 jobject syncType = getJavaSyncType(env, sync->getState());
\r
793 LOGE ("Failed to Get syncType for SyncInfo");
\r
794 if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
\r
797 jclass cls_SyncInfo = (jclass) (env->NewLocalRef(g_cls_SyncInfo));
\r
800 LOGE ("Failed to Get ObjectClass for SyncInfo");
\r
801 if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
\r
804 jmethodID mid_syncInfo = env->GetMethodID(
\r
807 "(JLjava/lang/String;Lorg/iotivity/service/ns/common/SyncInfo$SyncType;)V");
\r
810 LOGE ("Failed to Get MethodID for SyncInfo");
\r
811 if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
\r
815 jobject obj_syncInfo = env->NewObject( cls_SyncInfo, mid_syncInfo,
\r
816 jMessageId, jProviderId, syncType);
\r
819 LOGE ("Failed to Get Object for SyncInfo");
\r
820 if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
\r
824 jclass cls = env->GetObjectClass(jSyncListener);
\r
827 LOGE ("Failed to Get ObjectClass for jSyncListener");
\r
828 if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
\r
831 jmethodID mid = env->GetMethodID(
\r
833 "onSyncInfoReceived",
\r
834 "(Lorg/iotivity/service/ns/common/SyncInfo;)V");
\r
837 LOGE ("Failed to Get MethodID for onSyncInfoReceived");
\r
838 if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
\r
842 env->CallVoidMethod(jSyncListener, mid, obj_syncInfo);
\r
844 env->DeleteLocalRef(jSyncListener);
\r
845 env->DeleteLocalRef(cls_SyncInfo);
\r
846 if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread();
\r
847 LOGD ("ConsumerService_onSyncInfoReceived - OUT");
\r
851 JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_nativeStart
\r
852 (JNIEnv *env, jobject jObj, jobject jDiscoverListener, jobject jAccpetListener)
\r
854 LOGD ("ConsumerService_StartConsumer - IN");
\r
855 if (!jDiscoverListener || !jAccpetListener)
\r
857 ThrowNSException(NS_ERROR, "Listener cannot be null");
\r
861 if (g_obj_discoverListener != NULL)
\r
863 env->DeleteGlobalRef(g_obj_discoverListener);
\r
865 if (g_obj_acceptListener != NULL)
\r
867 env->DeleteGlobalRef(g_obj_acceptListener);
\r
870 g_obj_discoverListener = (jobject) env->NewGlobalRef(jDiscoverListener);
\r
871 g_obj_acceptListener = (jobject) env->NewGlobalRef(jAccpetListener);
\r
873 OIC::Service::NSConsumerService::ConsumerConfig cfg;
\r
874 cfg.m_discoverCb = onDiscoverProvider;
\r
875 cfg.m_changedCb = onProviderChanged;
\r
877 OIC::Service::NSConsumerService::getInstance()->Start(cfg);
\r
878 LOGD ("ConsumerService_StartConsumer - OUT");
\r
883 JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_nativeStop
\r
884 (JNIEnv *env, jobject jObj)
\r
886 LOGD ("ConsumerService_StopConsumer - IN");
\r
888 env->DeleteGlobalRef(g_obj_postListener);
\r
889 env->DeleteGlobalRef(g_obj_discoverListener);
\r
890 env->DeleteGlobalRef(g_obj_syncListener);
\r
891 env->DeleteGlobalRef(g_obj_acceptListener);
\r
892 g_obj_postListener = NULL;
\r
893 g_obj_discoverListener = NULL;
\r
894 g_obj_syncListener = NULL;
\r
895 g_obj_acceptListener = NULL;
\r
896 OIC::Service::NSConsumerService::getInstance()->Stop();
\r
897 LOGD ("ConsumerService_StopConsumer - OUT");
\r
901 JNIEXPORT jint JNICALL
\r
902 Java_org_iotivity_service_ns_consumer_ConsumerService_nativeEnableRemoteService
\r
903 (JNIEnv *env, jobject jObj, jstring jServerAddress)
\r
905 LOGD ("ConsumerService_EnableRemoteService - IN");
\r
906 if (!jServerAddress)
\r
908 ThrowNSException(NS_ERROR, "EnableRemoteService server address NULL");
\r
909 return (jint) OIC::Service::NSResult::ERROR;
\r
911 const char *serverAddress = env->GetStringUTFChars(jServerAddress, 0);
\r
912 OIC::Service::NSResult res =
\r
913 OIC::Service::NSConsumerService::getInstance()->EnableRemoteService(std::string(serverAddress));
\r
914 env->ReleaseStringUTFChars(jServerAddress, serverAddress);
\r
915 LOGD ("ConsumerService_EnableRemoteService - OUT");
\r
919 JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_nativeRescanProvider
\r
920 (JNIEnv *env, jobject jObj)
\r
922 LOGD ("ConsumerService_RescanProvider - IN");
\r
923 OIC::Service::NSConsumerService::getInstance()->RescanProvider();
\r
924 LOGD ("ConsumerService_RescanProvider - OUT");
\r
929 JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_nativeGetProvider
\r
930 (JNIEnv *env, jobject jObj, jstring jProviderId)
\r
932 LOGD ("ConsumerService_GetProvider - IN");
\r
935 ThrowNSException(NS_ERROR, "ProviderId cannot be null");
\r
939 const char *providerId = env->GetStringUTFChars(jProviderId, 0);
\r
940 LOGD ("java_ProviderId : %s\n", providerId);
\r
942 OIC::Service::NSProvider *provider =
\r
943 OIC::Service::NSConsumerService::getInstance()->getProvider(std::string(providerId));
\r
944 if (provider == nullptr)
\r
946 ThrowNSException(NS_ERROR, "Provider with Given Id doesn't exist");
\r
949 LOGD ("native_ProviderId : %s\n", provider->getProviderId().c_str());
\r
951 jProviderId = env->NewStringUTF(provider->getProviderId().c_str());
\r
952 jlong pProvider = (long)provider;
\r
954 jclass cls_provider = (jclass) (env->NewLocalRef(g_cls_Provider));
\r
957 LOGE ("Failed to Get ObjectClass for Provider");
\r
958 ThrowNSException(NS_ERROR, "Couldn't find objectClass for Provider");
\r
961 jmethodID mid_provider = env->GetMethodID(
\r
962 cls_provider, "<init>", "(Ljava/lang/String;)V");
\r
965 LOGE ("Failed to Get MethodID for Provider<init>");
\r
966 ThrowNSException(NS_ERROR, "Couldn't find MethodID for Provider<init>");
\r
969 jobject obj_provider = env->NewObject(cls_provider, mid_provider,
\r
972 jfieldID nativeHandle = env->GetFieldID(cls_provider, "mNativeHandle", "J");
\r
975 ThrowNSException(NS_ERROR, "Failed to get nativeHandle for Provider");
\r
978 env->SetLongField(obj_provider, nativeHandle, pProvider);
\r
980 env->DeleteLocalRef(cls_provider);
\r
981 env->ReleaseStringUTFChars(jProviderId, providerId);
\r
982 LOGD ("ConsumerService_GetProvider - OUT");
\r
983 return obj_provider;
\r
986 JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_consumer_ConsumerService_nativeGetMessage
\r
987 (JNIEnv *env, jobject jObj, jlong jMsgId)
\r
989 LOGI("JNIConsumerService: nativeGetMessage - IN");
\r
991 OIC::Service::NSMessage *msg =
\r
992 OIC::Service::NSConsumerService::getInstance()->getMessage((uint64_t)jMsgId);
\r
993 if (msg == nullptr)
\r
995 ThrowNSException(NS_ERROR, "Message doesn't exist");
\r
999 jobject obj_msg = getJavaMessage(env, msg);
\r
1001 LOGI("JNIConsumerService: nativeGetMessage - OUT");
\r
1004 JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeSubscribe
\r
1005 (JNIEnv *env, jobject jObj)
\r
1007 LOGD ("Provider_Subscribe -IN");
\r
1008 jclass providerClass = env->GetObjectClass(jObj);
\r
1009 if (!providerClass)
\r
1011 ThrowNSException(NS_ERROR, "Failed to Get ObjectClass for Provider");
\r
1015 jfieldID nativeHandle = env->GetFieldID(providerClass, "mNativeHandle", "J");
\r
1016 if (!nativeHandle)
\r
1018 ThrowNSException(NS_ERROR, "Failed to get nativeHandle for Provider");
\r
1021 jlong jProvider = env->GetLongField(jObj, nativeHandle);
\r
1024 LOGD ("calling subscribe on mNativeHandle");
\r
1025 OIC::Service::NSProvider *provider = (OIC::Service::NSProvider *) (jProvider);
\r
1026 provider->subscribe();
\r
1030 OIC::Service::NSProvider *provider = getNativeProvider(env, jObj);
\r
1031 if (provider == nullptr)
\r
1033 ThrowNSException(NS_ERROR, "Provider with Given Id doesn't exist");
\r
1036 LOGD ("calling subscribe on ProviderID");
\r
1037 provider->subscribe();
\r
1039 LOGD ("Provider_Subscribe -OUT");
\r
1043 JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeUnsubscribe
\r
1044 (JNIEnv *env, jobject jObj)
\r
1046 LOGD ("Provider_Unsubscribe - IN");
\r
1048 jclass providerClass = env->GetObjectClass(jObj);
\r
1049 if (!providerClass)
\r
1051 ThrowNSException(NS_ERROR, "Failed to Get ObjectClass for Provider");
\r
1055 jfieldID nativeHandle = env->GetFieldID(providerClass, "mNativeHandle", "J");
\r
1056 if (!nativeHandle)
\r
1058 ThrowNSException(NS_ERROR, "Failed to get nativeHandle for Provider");
\r
1061 jlong jProvider = env->GetLongField(jObj, nativeHandle);
\r
1064 LOGD ("calling unSubscribe on mNativeHandle");
\r
1065 OIC::Service::NSProvider *provider = (OIC::Service::NSProvider *) (jProvider);
\r
1066 provider->unSubscribe();
\r
1070 OIC::Service::NSProvider *provider = getNativeProvider(env, jObj);
\r
1071 if (provider == nullptr)
\r
1073 ThrowNSException(NS_ERROR, "Provider with Given Id doesn't exist");
\r
1076 LOGD ("calling unSubscribe on ProviderID");
\r
1077 provider->unSubscribe();
\r
1079 LOGD ("Provider_Unsubscribe - IN");
\r
1083 JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeSendSyncInfo
\r
1084 (JNIEnv *env, jobject jObj, jlong jMessageId, jint jSyncType)
\r
1086 LOGD ("Provider_SendSyncInfo - IN");
\r
1089 ThrowNSException(NS_ERROR, "MessageId cannot be 0");
\r
1093 jclass providerClass = env->GetObjectClass(jObj);
\r
1094 if (!providerClass)
\r
1096 ThrowNSException(NS_ERROR, "Failed to Get ObjectClass for Provider");
\r
1100 jfieldID nativeHandle = env->GetFieldID(providerClass, "mNativeHandle", "J");
\r
1101 if (!nativeHandle)
\r
1103 ThrowNSException(NS_ERROR, "Failed to get nativeHandle for Provider");
\r
1106 uint64_t messageId = (uint64_t) jMessageId;
\r
1108 LOGD("!!!!!!jMessageId: %lld", jMessageId);
\r
1109 LOGD("!!!!!!messageId: %lld", messageId);
\r
1111 jlong jProvider = env->GetLongField(jObj, nativeHandle);
\r
1114 LOGD ("calling SendSyncInfo on mNativeHandle");
\r
1115 OIC::Service::NSProvider *provider = (OIC::Service::NSProvider *) (jProvider);
\r
1116 provider->SendSyncInfo(messageId, (OIC::Service::NSSyncInfo::NSSyncType)jSyncType);
\r
1120 OIC::Service::NSProvider *provider = getNativeProvider(env, jObj);
\r
1121 if (provider == nullptr)
\r
1123 ThrowNSException(NS_ERROR, "Provider with Given Id doesn't exist");
\r
1126 LOGD ("calling SendSyncInfo on ProviderID");
\r
1127 provider->SendSyncInfo(messageId, (OIC::Service::NSSyncInfo::NSSyncType)jSyncType);
\r
1129 LOGD ("Provider_SendSyncInfo - OUT");
\r
1134 JNIEXPORT void JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeSetListener
\r
1135 (JNIEnv *env, jobject jObj, jobject jPostListener, jobject jSyncListener)
\r
1137 LOGD ("Provider_SetListener - IN");
\r
1138 if (!jPostListener || !jSyncListener)
\r
1140 ThrowNSException(NS_ERROR, "Listener cannot be null");
\r
1144 jclass providerClass = env->GetObjectClass(jObj);
\r
1145 if (!providerClass)
\r
1147 ThrowNSException(NS_ERROR, "Failed to Get ObjectClass for Provider");
\r
1151 jfieldID nativeHandle = env->GetFieldID(providerClass, "mNativeHandle", "J");
\r
1152 if (!nativeHandle)
\r
1154 ThrowNSException(NS_ERROR, "Failed to get nativeHandle for Provider");
\r
1157 jlong jProvider = env->GetLongField(jObj, nativeHandle);
\r
1160 LOGD ("calling SetListener on mNativeHandle");
\r
1161 if (g_obj_postListener != NULL)
\r
1163 env->DeleteGlobalRef(g_obj_postListener);
\r
1165 if (g_obj_syncListener != NULL)
\r
1167 env->DeleteGlobalRef(g_obj_syncListener);
\r
1169 g_obj_postListener = (jobject) env->NewGlobalRef(jPostListener);
\r
1170 g_obj_syncListener = (jobject) env->NewGlobalRef(jSyncListener);
\r
1172 OIC::Service::NSProvider *provider = (OIC::Service::NSProvider *) (jProvider);
\r
1173 provider->setListener(onMessagePosted, onSyncInfoReceived);
\r
1177 OIC::Service::NSProvider *provider = getNativeProvider(env, jObj);
\r
1178 if (provider == nullptr)
\r
1180 ThrowNSException(NS_ERROR, "Provider with Given Id doesn't exist");
\r
1183 LOGD ("calling SetListener on ProviderID");
\r
1184 if (g_obj_postListener != NULL)
\r
1186 env->DeleteGlobalRef(g_obj_postListener);
\r
1188 if (g_obj_syncListener != NULL)
\r
1190 env->DeleteGlobalRef(g_obj_syncListener);
\r
1192 g_obj_postListener = (jobject) env->NewGlobalRef(jPostListener);
\r
1193 g_obj_syncListener = (jobject) env->NewGlobalRef(jSyncListener);
\r
1195 provider->setListener(onMessagePosted, onSyncInfoReceived);
\r
1197 LOGD ("Provider_SetListener - OUT");
\r
1201 JNIEXPORT jint JNICALL Java_org_iotivity_service_ns_consumer_Provider_nativeSelectInterestTopics
\r
1202 (JNIEnv *env, jobject jObj, jobject jTopicsList)
\r
1204 LOGD("Provider_SelectInterestTopics -IN");
\r
1207 LOGI("Fail to select Interest Topics - Topic List is null");
\r
1208 ThrowNSException(NS_ERROR, "TopicList cannot be null");
\r
1209 return (jint) OIC::Service::NSResult::ERROR;
\r
1211 OIC::Service::NSTopicsList *nsTopicsList = getNativeTopicsList(env, jTopicsList);
\r
1212 if (nsTopicsList == nullptr)
\r
1214 ThrowNSException(NS_ERROR, "NSTopicList cannot be created ");
\r
1215 return (jint) OIC::Service::NSResult::ERROR;
\r
1218 jclass providerClass = env->GetObjectClass(jObj);
\r
1219 if (!providerClass)
\r
1221 ThrowNSException(NS_ERROR, "Failed to Get ObjectClass for Provider");
\r
1222 return (jint) OIC::Service::NSResult::ERROR;
\r
1225 jfieldID nativeHandle = env->GetFieldID(providerClass, "mNativeHandle", "J");
\r
1226 if (!nativeHandle)
\r
1228 ThrowNSException(NS_ERROR, "Failed to get nativeHandle for Provider");
\r
1229 return (jint) OIC::Service::NSResult::ERROR;
\r
1231 jlong jProvider = env->GetLongField(jObj, nativeHandle);
\r
1232 OIC::Service::NSResult result;
\r
1235 LOGD ("calling subscribe on mNativeHandle");
\r
1236 OIC::Service::NSProvider *provider = (OIC::Service::NSProvider *) (jProvider);
\r
1237 result = provider->selectInterestTopics(nsTopicsList);
\r
1241 OIC::Service::NSProvider *provider = getNativeProvider(env, jObj);
\r
1242 if (provider == nullptr)
\r
1244 ThrowNSException(NS_ERROR, "Provider with Given Id doesn't exist");
\r
1245 return (jint) OIC::Service::NSResult::ERROR;
\r
1247 LOGD ("calling subscribe on ProviderID");
\r
1248 result = provider->selectInterestTopics(nsTopicsList);
\r
1250 if (result != OIC::Service::NSResult::OK)
\r
1252 LOGI("Fail to select Interest Topics");
\r
1254 LOGD("Provider_SelectInterestTopics -OUT");
\r
1255 return (jint) result;
\r
1258 JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved)
\r
1260 LOGD("ConsumerService_JNI_OnLoad");
\r
1264 if (jvm->GetEnv((void **)&env, JNI_CURRENT_VERSION) != JNI_OK)
\r
1266 LOGE("Failed to get the environment using GetEnv()");
\r
1270 jclass localMessage = env->FindClass(
\r
1271 "org/iotivity/service/ns/common/Message");
\r
1272 if (!localMessage)
\r
1274 LOGE("Failed to get local Message class");
\r
1277 g_cls_Message = (jclass) (env->NewGlobalRef(localMessage));
\r
1278 if (!g_cls_Message)
\r
1280 LOGE("Failed to set Global Message reference");
\r
1284 jclass localProvider = env->FindClass(
\r
1285 "org/iotivity/service/ns/consumer/Provider");
\r
1286 if (!localProvider)
\r
1288 LOGE("Failed to get local Provider class");
\r
1291 g_cls_Provider = (jclass) (env->NewGlobalRef(localProvider));
\r
1292 if (!g_cls_Provider)
\r
1294 LOGE("Failed to set Global Provider reference");
\r
1298 jclass localSyncInfo = env->FindClass(
\r
1299 "org/iotivity/service/ns/common/SyncInfo");
\r
1300 if (!localSyncInfo)
\r
1302 LOGE("Failed to get local SyncInfo class");
\r
1305 g_cls_SyncInfo = (jclass) (env->NewGlobalRef(localSyncInfo));
\r
1306 if (!g_cls_SyncInfo)
\r
1308 LOGE("Failed to set Global NSSyncInfo reference");
\r
1312 jclass localSyncType = env->FindClass(
\r
1313 "org/iotivity/service/ns/common/SyncInfo$SyncType");
\r
1314 if (!localSyncType)
\r
1316 LOGE("Failed to get local SyncType enum");
\r
1319 g_cls_SyncType = (jclass) (env->NewGlobalRef(localSyncType));
\r
1320 if (!g_cls_SyncType)
\r
1322 LOGE("Failed to set Global SyncType reference");
\r
1326 jclass localMediaContents = env->FindClass(
\r
1327 "org/iotivity/service/ns/common/MediaContents");
\r
1328 if (!localMediaContents)
\r
1330 LOGE("Failed to get local MediaContents class");
\r
1333 g_cls_MediaContents = (jclass) (env->NewGlobalRef(localMediaContents));
\r
1334 if (!g_cls_MediaContents)
\r
1336 LOGE("Failed to set Global MediaContents reference");
\r
1339 jclass localTopicState = env->FindClass(
\r
1340 "org/iotivity/service/ns/common/Topic$TopicState");
\r
1341 if (!localTopicState)
\r
1343 LOGE("Failed to get local TopicState enum");
\r
1346 g_cls_TopicState = (jclass) (env->NewGlobalRef(localTopicState));
\r
1347 if (!g_cls_TopicState)
\r
1349 LOGE("Failed to set Global TopicState reference");
\r
1353 jclass localTopic = env->FindClass(
\r
1354 "org/iotivity/service/ns/common/Topic");
\r
1357 LOGE("Failed to get local TopicState enum");
\r
1360 g_cls_Topic = (jclass) (env->NewGlobalRef(localTopic));
\r
1363 LOGE("Failed to set Global Topic reference");
\r
1367 jclass localMessageType = env->FindClass(
\r
1368 "org/iotivity/service/ns/common/Message$MessageType");
\r
1369 if (!localMessageType)
\r
1371 LOGE("Failed to get local Message Type class");
\r
1374 g_cls_Message_Type = (jclass) (env->NewGlobalRef(localMessageType));
\r
1375 if (!g_cls_Message_Type)
\r
1377 LOGE("Failed to set Global Message Type reference");
\r
1381 jclass localResponse = env->FindClass(
\r
1382 "org/iotivity/service/ns/consumer/ConsumerService$Response");
\r
1383 if (!localResponse)
\r
1385 LOGE("Failed to get localResponse Type class");
\r
1388 g_cls_Response = (jclass) (env->NewGlobalRef(localResponse));
\r
1389 if (!g_cls_Response)
\r
1391 LOGE("Failed to set Global Response Type reference");
\r
1395 jclass localTopicsList = env->FindClass(
\r
1396 "org/iotivity/service/ns/common/TopicsList");
\r
1397 if (!localTopicsList)
\r
1399 LOGE("Failed to get local Topic class");
\r
1402 g_cls_TopicsList = (jclass) (env->NewGlobalRef(localTopicsList));
\r
1403 if (!g_cls_TopicsList)
\r
1405 LOGE("Failed to set Global TopicsList reference");
\r
1408 env->DeleteLocalRef(localMessage);
\r
1409 env->DeleteLocalRef(localProvider);
\r
1410 env->DeleteLocalRef(localSyncInfo);
\r
1411 env->DeleteLocalRef(localSyncType);
\r
1412 env->DeleteLocalRef(localMediaContents);
\r
1413 env->DeleteLocalRef(localTopicState);
\r
1414 env->DeleteLocalRef(localMessageType);
\r
1415 env->DeleteLocalRef(localResponse);
\r
1416 env->DeleteLocalRef(localTopic);
\r
1417 env->DeleteLocalRef(localTopicsList);
\r
1419 return NSExceptionInit(env);
\r
1422 JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *jvm, void *reserved)
\r
1424 LOGI("ConsumerService_JNI_OnUnload");
\r
1427 if (jvm->GetEnv((void **)&env, JNI_CURRENT_VERSION) != JNI_OK)
\r
1429 LOGE("Failed to get the environment using GetEnv()");
\r
1433 env->DeleteGlobalRef(g_cls_Message);
\r
1434 env->DeleteGlobalRef(g_cls_Provider);
\r
1435 env->DeleteGlobalRef(g_cls_SyncInfo);
\r
1436 env->DeleteGlobalRef(g_cls_SyncType);
\r
1437 env->DeleteGlobalRef(g_cls_MediaContents);
\r
1438 env->DeleteGlobalRef(g_cls_TopicState);
\r
1439 env->DeleteGlobalRef(g_cls_Message_Type);
\r
1440 env->DeleteGlobalRef(g_cls_Response);
\r
1441 env->DeleteGlobalRef(g_cls_Topic);
\r
1442 env->DeleteGlobalRef(g_cls_TopicsList);
\r