1 //******************************************************************
3 // Copyright 2016 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include "JniNotificationProvider.h"
22 #include "NSProviderService.h"
23 #include "NSException.h"
24 #include "JniOcRepresentation.h"
26 static JavaVM *g_jvm_provider = NULL;
28 static jobject g_obj_subscriptionListener = NULL;
29 static jobject g_obj_syncListener = NULL;
32 jclass g_cls_Message_Type;
33 jclass g_cls_Consumer;
34 jclass g_cls_SyncInfo;
35 jclass g_cls_SyncType;
36 jclass g_cls_MediaContents;
38 jclass g_cls_TopicsList;
39 jclass g_cls_TopicState;
40 jclass g_cls_OcRepresentation;
41 jmethodID g_mid_OcRepresentation_N_ctor_bool = NULL;
43 static JNIEnv *GetJNIEnv(jint *ret)
47 *ret = g_jvm_provider->GetEnv((void **) &env, JNI_CURRENT_VERSION);
53 if (g_jvm_provider->AttachCurrentThread(&env, NULL) != JNI_OK)
55 NS_LOGE ("Failed to get the environment");
63 NS_LOGE ("JNI version is not supported");
66 NS_LOGE ("Failed to get the environment");
71 OIC::Service::NSMessage getNativeMessage(JNIEnv *env, jobject jMsg)
73 NS_LOGD ("JNIProviderService: getMessage - IN");
75 jclass cls = env->GetObjectClass( jMsg);
78 jclass cls_messageType = (jclass) (env->NewLocalRef(g_cls_Message_Type));
81 ThrowNSException(JNI_INVALID_VALUE, "Failed to Get ObjectClass for Message Type");
84 jmethodID mid = env->GetMethodID(cls_messageType, "ordinal", "()I");
85 jfieldID fid_type = env->GetFieldID( cls, "mType",
86 "Lorg/iotivity/service/ns/common/Message$MessageType;");
89 ThrowNSException(JNI_INVALID_VALUE, "Error: jfieldID for message type is null");
92 jobject jobj = env->GetObjectField( jMsg, fid_type);
95 ThrowNSException(JNI_INVALID_VALUE, "Error: object of field Message Type is null");
98 jint jtype = env->CallIntMethod(jobj, mid);
99 OIC::Service::NSMessage::NSMessageType type = (OIC::Service::NSMessage::NSMessageType) jtype;
101 NS_LOGD ("Message Type: %ld\n", (long )type);
104 jfieldID fid_tm = env->GetFieldID( cls, "mTime", "Ljava/lang/String;");
107 ThrowNSException(JNI_INVALID_VALUE, "Error: jfieldID for message time is null");
110 jstring jtime = (jstring)env->GetObjectField( jMsg, fid_tm);
111 const char *time = "";
114 time = env->GetStringUTFChars( jtime, NULL);
118 NS_LOGD ("Info: messageTitle is null");
120 NS_LOGD ("Message Time: %s\n", time);
123 jfieldID fid_ttl = env->GetFieldID( cls, "mTTL", "J");
126 ThrowNSException(JNI_INVALID_VALUE, "Error: jfieldID for message ttl is null");
130 jlong jttl = (jlong) env->GetLongField( jMsg, fid_ttl);
132 NS_LOGD ("TTL: %lld\n", ttl);
135 jfieldID fid_title = env->GetFieldID( cls, "mTitle", "Ljava/lang/String;");
136 if (fid_title == NULL)
138 ThrowNSException(JNI_INVALID_VALUE, "Error: jfieldID for message title is null");
141 jstring jmsgTitle = (jstring)env->GetObjectField( jMsg, fid_title);
142 const char *messageTitle = "";
145 messageTitle = env->GetStringUTFChars( jmsgTitle, NULL);
149 NS_LOGD ("Info: messageTitle is null");
151 NS_LOGD ("Message Title: %s\n", messageTitle);
153 // Message Content Text
154 jfieldID fid_body = env->GetFieldID( cls, "mContentText", "Ljava/lang/String;");
155 if (fid_body == NULL)
157 ThrowNSException(JNI_INVALID_VALUE, "Error: jfieldID for message context Text is null");
160 jstring jmsgBody = (jstring)env->GetObjectField( jMsg, fid_body);
161 const char *messageBody = "";
164 messageBody = env->GetStringUTFChars( jmsgBody, NULL);
168 NS_LOGD ("Info: messageBody is null");
170 NS_LOGD ("Message Body: %s\n", messageBody);
173 jfieldID fid_source = env->GetFieldID( cls, "mSourceName", "Ljava/lang/String;");
174 if (fid_source == NULL)
176 ThrowNSException(JNI_INVALID_VALUE, "Error: jfieldID for message source is null");
179 jstring jmsgSource = (jstring)env->GetObjectField( jMsg, fid_source);
180 const char *messageSource = "";
183 messageSource = env->GetStringUTFChars( jmsgSource, NULL);
187 NS_LOGD ("Info: messageSource is null");
189 NS_LOGD ("Message Source: %s\n", messageSource);
192 jfieldID fid_topic = env->GetFieldID( cls, "mTopic", "Ljava/lang/String;");
193 if (fid_topic == NULL)
195 ThrowNSException(JNI_INVALID_VALUE, "Error: jfieldID for topic is null");
198 jstring jtopic = (jstring)env->GetObjectField( jMsg, fid_topic);
199 const char *topic = "";
202 topic = env->GetStringUTFChars( jtopic, NULL);
206 NS_LOGD ("Info: topic is null");
208 NS_LOGD ("Topic : %s\n", topic);
210 // Message MediaContents
211 jfieldID fid_media = env->GetFieldID( cls, "mMediaContents",
212 "Lorg/iotivity/service/ns/common/MediaContents;");
213 if (fid_media == NULL)
215 ThrowNSException(JNI_INVALID_VALUE, "Error: jfieldID for MediaContents is null");
218 jobject jmedia = env->GetObjectField( jMsg, fid_media);
219 OIC::Service::NSMediaContents *media = nullptr;
222 NS_LOGD ("Info: jmedia object of MediaContents inside Message is null");
226 jclass cls_MediaContents = (jclass) (env->NewLocalRef(g_cls_MediaContents));
227 if (!cls_MediaContents)
229 ThrowNSException(JNI_INVALID_VALUE, "Failed to Get ObjectClass for class MediaContents");
232 jfieldID fid_icon = env->GetFieldID( cls_MediaContents, "mIconImage", "Ljava/lang/String;");
233 if (fid_icon == NULL)
235 ThrowNSException(JNI_INVALID_VALUE, "Error: jfieldID for iconImage is null");
238 jstring jiconImage = (jstring)env->GetObjectField( jmedia, fid_icon);
239 const char *iconImage = "";
242 iconImage = env->GetStringUTFChars( jiconImage, NULL);
243 media = new OIC::Service::NSMediaContents(std::string(iconImage));
244 env->ReleaseStringUTFChars(jiconImage, iconImage);
248 NS_LOGD ("Info: iconImage is null");
250 env->DeleteLocalRef(cls_MediaContents);
251 NS_LOGD ("iconImage: %s\n", iconImage);
255 jfieldID fid_extraInfo = env->GetFieldID( cls, "mExtraInfo",
256 "Lorg/iotivity/base/OcRepresentation;");
257 if (fid_extraInfo == NULL)
259 ThrowNSException(JNI_INVALID_VALUE, "Error: jfieldID for mExtraInfo is null");
262 jobject jExtraInfo = env->GetObjectField( jMsg, fid_extraInfo);
263 OC::OCRepresentation *representation = nullptr;
264 if (jExtraInfo == NULL)
266 NS_LOGE ("Error: jExtraInfo object of Message is null");
270 representation = GetHandle<OC::OCRepresentation>(env, jExtraInfo);
271 if (env->ExceptionCheck())
273 NS_LOGE ("Failed to get native handle from OcRepresentation");
277 NS_LOGE ("Failed to get native object OcRepresentation");
282 jfieldID fid_mid = env->GetFieldID( cls, "mMessageId", "J");
285 ThrowNSException(JNI_INVALID_VALUE, "Error: jfieldID for message mMessageId is null");
289 jlong jId = (jlong) env->GetLongField( jMsg, fid_mid);
291 NS_LOGD ("Message Id: %lld\n", jmId);
294 jfieldID fid_pid = env->GetFieldID( cls, "mProviderId", "Ljava/lang/String;");
297 ThrowNSException(JNI_INVALID_VALUE, "Error: jfieldID for message mProviderId is null");
300 jstring jProId = (jstring)env->GetObjectField( jMsg, fid_pid);
301 const char *jpId = "";
304 jpId = env->GetStringUTFChars( jProId, NULL);
308 NS_LOGD ("Info: messageSource is null");
310 NS_LOGD ("Provider Id : %s\n", jpId);
313 NSMessage *mesg = new NSMessage;
314 mesg->messageId = jmId;
315 mesg->providerId[0] = '\0';
316 strncat(mesg->providerId, jpId, NS_UTILS_UUID_STRING_SIZE - 1);
318 mesg->dateTime = nullptr;
319 mesg->title = nullptr;
320 mesg->contentText = nullptr;
321 mesg->sourceName = nullptr;
322 mesg->mediaContents = nullptr;
323 mesg->topic = nullptr;
324 mesg->extraInfo = nullptr;
326 OIC::Service::NSMessage nsMsg(mesg);
327 NS_LOGD ("Created NSMessage");
330 nsMsg.setTime(std::string(time));
332 nsMsg.setTitle(std::string(messageTitle));
333 nsMsg.setContentText(std::string(messageBody));
334 nsMsg.setSourceName(std::string(messageSource));
335 if (media != nullptr)
337 nsMsg.setMediaContents(media);
339 nsMsg.setTopic(std::string(topic));
340 if (representation != nullptr)
342 nsMsg.setExtraInfo(*representation);
345 env->DeleteLocalRef(cls_messageType);
349 env->ReleaseStringUTFChars(jtime, time);
353 env->ReleaseStringUTFChars(jmsgTitle, messageTitle);
357 env->ReleaseStringUTFChars(jmsgBody, messageBody);
361 env->ReleaseStringUTFChars(jmsgSource, messageSource);
365 env->ReleaseStringUTFChars(jtopic, topic);
368 NS_LOGD ("JNIProviderService: getMessage - OUT");
373 jobject getJavaMessageType(JNIEnv *env, OIC::Service::NSMessage::NSMessageType type)
375 NS_LOGD ("JNIProviderService: getJavaMessageType - IN");
376 jobject messageType = NULL;
379 case OIC::Service::NSMessage::NSMessageType::NS_MESSAGE_ALERT:
381 static jfieldID fieldID = env->GetStaticFieldID(g_cls_Message_Type,
382 "ALERT", "Lorg/iotivity/service/ns/common/Message$MessageType;");
383 messageType = env->GetStaticObjectField(g_cls_Message_Type, fieldID);
386 case OIC::Service::NSMessage::NSMessageType::NS_MESSAGE_NOTICE:
388 static jfieldID fieldID = env->GetStaticFieldID(g_cls_Message_Type,
389 "NOTICE", "Lorg/iotivity/service/ns/common/Message$MessageType;");
390 messageType = env->GetStaticObjectField(g_cls_Message_Type, fieldID);
393 case OIC::Service::NSMessage::NSMessageType::NS_MESSAGE_EVENT:
395 static jfieldID fieldID = env->GetStaticFieldID(g_cls_Message_Type,
396 "EVENT", "Lorg/iotivity/service/ns/common/Message$MessageType;");
397 messageType = env->GetStaticObjectField(g_cls_Message_Type, fieldID);
400 case OIC::Service::NSMessage::NSMessageType::NS_MESSAGE_INFO:
402 static jfieldID fieldID = env->GetStaticFieldID(g_cls_Message_Type,
403 "INFO", "Lorg/iotivity/service/ns/common/Message$MessageType;");
404 messageType = env->GetStaticObjectField(g_cls_Message_Type, fieldID);
413 NS_LOGD ("JNIProviderService: getJavaMessageType - OUT");
417 jobject getJavaMessage(JNIEnv *env, OIC::Service::NSMessage message)
419 NS_LOGD ("JNIProviderService: getJavaMessage - IN");
421 NS_LOGD ("id : %llu\n", message.getMessageId());
422 NS_LOGD ("title : %s\n", message.getTitle().c_str());
423 NS_LOGD ("content : %s\n", message.getContentText().c_str());
424 NS_LOGD ("source : %s\n", message.getSourceName().c_str());
426 jlong jMessageId = (jlong) message.getMessageId();
427 jstring jProviderId = env->NewStringUTF(message.getProviderId().c_str());
428 jstring jTitle = env->NewStringUTF(message.getTitle().c_str());
429 jstring jContentText = env->NewStringUTF(message.getContentText().c_str());
430 jstring jSourceName = env->NewStringUTF(message.getSourceName().c_str());
431 jstring jTopic = env->NewStringUTF(message.getTopic().c_str());
433 jstring jTime = env->NewStringUTF(message.getTime().c_str());
434 jlong jTTL = (jlong) message.getTTL();
436 jclass cls_message = (jclass) (env->NewLocalRef(g_cls_Message));
439 NS_LOGE ("Failed to Get ObjectClass for Message");
442 jmethodID mid_message = env->GetMethodID(
443 cls_message, "<init>",
444 "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
447 NS_LOGE ("Failed to Get MethodID for Message<init>");
450 jobject obj_message = env->NewObject(cls_message, mid_message,
451 jTitle, jContentText, jSourceName);
454 NS_LOGE ("Failed to Get Java Object for Message");
458 jfieldID fid_messageId = env->GetFieldID(cls_message, "mMessageId", "J");
461 NS_LOGE ("Failed to get field MessageID for Message");
464 env->SetLongField(obj_message, fid_messageId, jMessageId);
466 jfieldID fid_providerId = env->GetFieldID(cls_message, "mProviderId", "Ljava/lang/String;");
469 NS_LOGE ("Failed to get field ProviderID for Message");
472 env->SetObjectField(obj_message, fid_providerId, jProviderId);
474 jfieldID fid_time = env->GetFieldID(cls_message, "mTime", "Ljava/lang/String;");
477 NS_LOGE ("Failed to get field Time for Message");
480 env->SetObjectField(obj_message, fid_time, jTime);
482 jfieldID fid_ttl = env->GetFieldID(cls_message, "mTTL", "J");
485 NS_LOGE ("Failed to get field TTL for Message");
488 env->SetLongField(obj_message, fid_ttl, jTTL);
490 jfieldID fid_topic = env->GetFieldID(cls_message, "mTopic", "Ljava/lang/String;");
493 NS_LOGE ("Failed to get mTopic for Message");
496 env->SetObjectField(obj_message, fid_topic, jTopic);
498 OIC::Service::NSMediaContents *mediaCont = message.getMediaContents();
499 if (mediaCont != nullptr)
501 jstring jIconImage = env->NewStringUTF(mediaCont->getIconImage().c_str());
502 jclass cls_mediaContents = (jclass) (env->NewLocalRef(g_cls_MediaContents));
503 if (!cls_mediaContents)
505 NS_LOGE ("Failed to Get ObjectClass for MediaContents");
508 jmethodID mid_mediaContents = env->GetMethodID(
509 cls_mediaContents, "<init>", "(Ljava/lang/String;)V");
510 if (!mid_mediaContents)
512 NS_LOGE ("Failed to Get MethodID for MediaContents<init>");
515 jobject obj_mediaContents = env->NewObject(cls_mediaContents, mid_mediaContents,
518 jfieldID fid_mediaContents = env->GetFieldID(cls_message, "mMediaContents",
519 "Lorg/iotivity/service/ns/common/MediaContents;");
520 if (!fid_mediaContents)
522 NS_LOGE ("Failed to get field mediaContents for Message");
525 env->SetObjectField(obj_message, fid_mediaContents, obj_mediaContents);
529 jobject jType = getJavaMessageType(env, message.getType());
532 jfieldID fid_type = env->GetFieldID(cls_message, "mType",
533 "Lorg/iotivity/service/ns/common/Message$MessageType;");
536 NS_LOGE ("Failed to get field Type for Message");
539 env->SetObjectField(obj_message, fid_type, jType);
542 NS_LOGD ("Reading OCRepresentation Object from Native");
543 OC::OCRepresentation *ocRepresentation = new OC::OCRepresentation(message.getExtraInfo());
544 jlong handle = reinterpret_cast<jlong>(ocRepresentation);
545 jobject jRepresentation = env->NewObject(g_cls_OcRepresentation, g_mid_OcRepresentation_N_ctor_bool,
547 if (!jRepresentation)
549 NS_LOGE ("Failed to create OcRepresentation");
550 delete ocRepresentation;
555 NS_LOGD ("Created OCRepresentation Object from Native");
557 jfieldID fid_extraInfo = env->GetFieldID(cls_message, "mExtraInfo",
558 "Lorg/iotivity/base/OcRepresentation;");
561 NS_LOGE ("Failed to get mExtraInfo for Message");
562 delete ocRepresentation;
565 NS_LOGD ("setting extraInfo field");
566 env->SetObjectField(obj_message, fid_extraInfo, jRepresentation);
568 env->DeleteLocalRef(cls_message);
569 NS_LOGD ("JNIProviderService: getJavaMessage - OUT");
573 jobject getJavaTopicState(JNIEnv *env, OIC::Service::NSTopic::NSTopicState nsState)
575 NS_LOGD ("JNIProviderService: getJavaTopicState - IN");
578 jclass cls_topicState = (jclass) (env->NewLocalRef(g_cls_TopicState));
581 NS_LOGE ("Failed to Get ObjectClass for TopicState Type");
584 jobject topicState = NULL;
588 case OIC::Service::NSTopic::NSTopicState::UNSUBSCRIBED:
590 static jfieldID fieldID = env->GetStaticFieldID(cls_topicState,
591 "UNSUBSCRIBED", "Lorg/iotivity/service/ns/common/Topic$TopicState;");
592 topicState = env->GetStaticObjectField(cls_topicState, fieldID);
595 case OIC::Service::NSTopic::NSTopicState::SUBSCRIBED:
597 static jfieldID fieldID = env->GetStaticFieldID(cls_topicState,
598 "SUBSCRIBED", "Lorg/iotivity/service/ns/common/Topic$TopicState;");
599 topicState = env->GetStaticObjectField(cls_topicState, fieldID);
609 NS_LOGD ("JNIProviderService: getJavaTopicState - OUT");
613 jobject getJavaTopicsList(JNIEnv *env, std::shared_ptr<OIC::Service::NSTopicsList> topicList)
615 NS_LOGD ("JNIProviderService: getJavaTopicsList - IN");
616 jclass cls_topicList = (jclass) (env->NewLocalRef(g_cls_TopicsList));
619 NS_LOGE ("Failed to Get ObjectClass for TopicsList");
622 jmethodID mid_topicList = env->GetMethodID(cls_topicList, "<init>", "()V");
625 NS_LOGE ("Failed to Get MethodID for TopicsList<init>");
628 jobject obj_topicList = env->NewObject(cls_topicList, mid_topicList);
631 NS_LOGE ("Failed to Get object for TopicsList");
634 jmethodID mid_addTopic = env->GetMethodID(cls_topicList, "addTopic",
635 "(Ljava/lang/String;Lorg/iotivity/service/ns/common/Topic$TopicState;)V");
638 NS_LOGE ("Failed to Get MethodID for addTopic");
641 for (auto it : topicList->getTopicsList())
643 jobject jState = getJavaTopicState(env, it.getState());
644 std::string topicName = it.getTopicName();
645 jstring jTopicName = env->NewStringUTF(topicName.c_str());
646 env->CallVoidMethod(obj_topicList, mid_addTopic, jTopicName, jState);
648 env->DeleteLocalRef(cls_topicList);
649 NS_LOGD ("JNIProviderService: getJavaTopicsList - OUT");
650 return obj_topicList;
653 jobject getJavaSyncType(JNIEnv *env, OIC::Service::NSSyncInfo::NSSyncType nsType)
655 NS_LOGD ("JNIProviderService: getJavaSyncType - IN");
658 jclass cls_SyncType = (jclass) (env->NewLocalRef(g_cls_SyncType));
661 NS_LOGE ("Failed to Get ObjectClass for SyncType");
664 jobject syncType = NULL;
667 case OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_UNREAD:
669 static jfieldID fieldID = env->GetStaticFieldID(cls_SyncType,
670 "UNREAD", "Lorg/iotivity/service/ns/common/SyncInfo$SyncType;");
671 syncType = env->GetStaticObjectField(cls_SyncType, fieldID);
674 case OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ :
676 static jfieldID fieldID = env->GetStaticFieldID(cls_SyncType,
677 "READ", "Lorg/iotivity/service/ns/common/SyncInfo$SyncType;");
678 syncType = env->GetStaticObjectField(cls_SyncType, fieldID);
681 case OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED :
683 static jfieldID fieldID = env->GetStaticFieldID(cls_SyncType,
684 "DELETED", "Lorg/iotivity/service/ns/common/SyncInfo$SyncType;");
685 syncType = env->GetStaticObjectField(cls_SyncType, fieldID);
695 NS_LOGD ("JNIProviderService: getJavaSyncType - OUT");
700 void onSubscribeListenerCb(std::shared_ptr<OIC::Service::NSConsumer> consumer)
702 NS_LOGD ("JNIProviderService_onSubscribeListenerCb - IN");
705 JNIEnv *env = GetJNIEnv(&envRet);
711 jobject jSubscriptionListener = (jobject) env->NewLocalRef(g_obj_subscriptionListener);
712 if (!jSubscriptionListener)
714 NS_LOGE ("Failed to Get jSubscriptionListener");
715 if (JNI_EDETACHED == envRet)
717 g_jvm_provider->DetachCurrentThread();
722 NS_LOGD ("consumer ID : %s\n", consumer->getConsumerId().c_str());
724 jstring jConsumerId = env->NewStringUTF( consumer->getConsumerId().c_str());
726 jclass cls_consumer = (jclass) (env->NewLocalRef(g_cls_Consumer));
729 NS_LOGE ("Failed to Get ObjectClass for Consumer");
730 if (JNI_EDETACHED == envRet)
732 g_jvm_provider->DetachCurrentThread();
737 jmethodID mid_consumer = env->GetMethodID(
740 "(Ljava/lang/String;)V");
743 NS_LOGE ("Failed to Get MethodID for Consumer<init>");
744 if (JNI_EDETACHED == envRet)
746 g_jvm_provider->DetachCurrentThread();
750 jobject obj_consumer = env->NewObject( cls_consumer, mid_consumer, jConsumerId);
752 jclass cls = env->GetObjectClass( jSubscriptionListener);
755 NS_LOGE ("Failed to Get ObjectClass of jSubscriptionListener");
756 if (JNI_EDETACHED == envRet)
758 g_jvm_provider->DetachCurrentThread();
762 jmethodID mid = env->GetMethodID(
764 "onConsumerSubscribed",
765 "(Lorg/iotivity/service/ns/provider/Consumer;)V");
768 NS_LOGE ("Failed to Get MethodID of onConsumerSubscribed");
769 if (JNI_EDETACHED == envRet)
771 g_jvm_provider->DetachCurrentThread();
776 env->CallVoidMethod( jSubscriptionListener, mid, obj_consumer);
777 env->DeleteLocalRef(jSubscriptionListener);
778 env->DeleteLocalRef(cls_consumer);
779 if (JNI_EDETACHED == envRet)
781 g_jvm_provider->DetachCurrentThread();
783 NS_LOGD ("JNIProviderService_onSubscribeListenerCb - OUT");
787 void onSyncInfoListenerCb(OIC::Service::NSSyncInfo sync)
789 NS_LOGD ("JNIProviderService_onSyncInfoListenerCb - IN");
792 JNIEnv *env = GetJNIEnv(&envRet);
798 jobject jSyncListener = (jobject) env->NewLocalRef(g_obj_syncListener);
801 NS_LOGE ("Failed to Get jSyncListener");
802 if (JNI_EDETACHED == envRet)
804 g_jvm_provider->DetachCurrentThread();
809 NS_LOGD ("Sync ID : %ld\n", (long) sync.getMessageId());
810 NS_LOGD ("Sync STATE : %d\n", (int) sync.getState());
812 jlong jMessageId = (long) sync.getMessageId();
813 jstring jProviderId = env->NewStringUTF(sync.getProviderId().c_str());
814 jobject syncType = getJavaSyncType(env, sync.getState());
817 NS_LOGE ("Failed to Get syncType for SyncInfo");
818 if (JNI_EDETACHED == envRet)
820 g_jvm_provider->DetachCurrentThread();
824 jclass cls_SyncInfo = (jclass) (env->NewLocalRef(g_cls_SyncInfo));
827 NS_LOGE ("Failed to Get ObjectClass for SyncInfo");
828 if (JNI_EDETACHED == envRet)
830 g_jvm_provider->DetachCurrentThread();
834 jmethodID mid_syncInfo = env->GetMethodID(
837 "(JLjava/lang/String;Lorg/iotivity/service/ns/common/SyncInfo$SyncType;)V");
840 NS_LOGE ("Failed to Get MethodID for SyncInfo");
841 if (JNI_EDETACHED == envRet)
843 g_jvm_provider->DetachCurrentThread();
848 jobject obj_syncInfo = env->NewObject( cls_SyncInfo, mid_syncInfo,
849 jMessageId, jProviderId, syncType);
852 NS_LOGE ("Failed to Get Object for SyncInfo");
853 if (JNI_EDETACHED == envRet)
855 g_jvm_provider->DetachCurrentThread();
860 jclass cls = env->GetObjectClass( jSyncListener);
863 NS_LOGE ("Failed to Get ObjectClass");
864 if (JNI_EDETACHED == envRet)
866 g_jvm_provider->DetachCurrentThread();
870 jmethodID mid = env->GetMethodID(
872 "onMessageSynchronized",
873 "(Lorg/iotivity/service/ns/common/SyncInfo;)V");
876 NS_LOGE ("Failed to Get MethodID");
877 if (JNI_EDETACHED == envRet)
879 g_jvm_provider->DetachCurrentThread();
883 env->CallVoidMethod( jSyncListener, mid, obj_syncInfo);
885 env->DeleteLocalRef(jSyncListener);
886 env->DeleteLocalRef(cls_SyncInfo);
887 if (JNI_EDETACHED == envRet)
889 g_jvm_provider->DetachCurrentThread();
891 NS_LOGD ("JNIProviderService: OnSyncInfoListenerCb - OUT");
896 JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeStart
897 (JNIEnv *env, jobject jObj, jobject jSubscriptionListener, jobject jSyncListener,
898 jboolean jPolicy, jstring jUserInfo, jboolean jResourceSecurity)
900 NS_LOGD ("JNIProviderService: nativeStart - IN");
901 if (!jSubscriptionListener || !jSyncListener)
903 ThrowNSException(JNI_INVALID_VALUE, "Listener cannot be null");
907 if (g_obj_subscriptionListener != NULL)
909 env->DeleteGlobalRef(g_obj_subscriptionListener);
911 if (g_obj_syncListener != NULL)
913 env->DeleteGlobalRef(g_obj_syncListener);
916 g_obj_subscriptionListener = (jobject) env->NewGlobalRef(jSubscriptionListener);
917 g_obj_syncListener = (jobject) env->NewGlobalRef(jSyncListener);
919 // check access policy
921 OIC::Service::NSProviderService::ProviderConfig cfg;
922 cfg.m_subscribeRequestCb = onSubscribeListenerCb;
923 cfg.m_syncInfoCb = onSyncInfoListenerCb;
924 cfg.subControllability = (bool) jPolicy;
927 const char *info = env->GetStringUTFChars( jUserInfo, NULL);
928 std::string userInfo(info);
929 cfg.userInfo = userInfo;
931 cfg.resourceSecurity = (bool) jResourceSecurity;
933 OIC::Service::NSResult result = OIC::Service::NSProviderService::getInstance()->start(cfg);
934 if (result != OIC::Service::NSResult::OK)
936 ThrowNSException((int) result, "Fail to start NSProviderService");
940 NS_LOGD ("JNIProviderService: nativeStart - OUT");
944 JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeStop
945 (JNIEnv *env, jobject jObj)
947 NS_LOGD ("JNIProviderService: nativeStop - IN");
949 OIC::Service::NSResult result = OIC::Service::NSProviderService::getInstance()->stop();
950 if (result != OIC::Service::NSResult::OK)
952 ThrowNSException((int) result, "Fail to stop NSProviderService");
956 env->DeleteGlobalRef( g_obj_subscriptionListener);
957 env->DeleteGlobalRef( g_obj_syncListener);
958 g_obj_subscriptionListener = NULL;
959 g_obj_syncListener = NULL;
961 NS_LOGD ("JNIProviderService: nativeStop - OUT");
965 JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeSendMessage
966 (JNIEnv *env, jobject jObj, jobject jMsg)
968 NS_LOGD ("JNIProviderService: nativeSendMessage - IN");
971 ThrowNSException(JNI_INVALID_VALUE, "Message cannot be null");
974 OIC::Service::NSMessage nsMsg = getNativeMessage(env, jMsg);
976 OIC::Service::NSResult result = OIC::Service::NSProviderService::getInstance()->sendMessage(nsMsg);
977 if (result != OIC::Service::NSResult::OK)
979 ThrowNSException((int) result, "Fail to send NSProvider Message");
982 NS_LOGD ("JNIProviderService: nativeSendMessage - OUT");
986 JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeSendSyncInfo
987 (JNIEnv *env, jobject jObj, jlong messageId , jint syncState)
989 NS_LOGD ("JNIProviderService: nativeSendSyncInfo - IN");
990 OIC::Service::NSResult result = OIC::Service::NSProviderService::getInstance()->sendSyncInfo(
992 (OIC::Service::NSSyncInfo::NSSyncType) syncState);
993 if (result != OIC::Service::NSResult::OK)
995 ThrowNSException((int) result, "Fail to send NSProvider SendSyncInfo");
998 NS_LOGD ("JNIProviderService: nativeSendSyncInfo - OUT");
1002 JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeCreateMessage
1003 (JNIEnv *env, jobject jObj)
1005 NS_LOGD ("JNIProviderService: nativeCreateMessage - IN");
1006 OIC::Service::NSMessage message =
1007 OIC::Service::NSProviderService::getInstance()->createMessage();
1008 jobject jMsg = getJavaMessage(env, message);
1011 ThrowNSException(JNI_INVALID_VALUE, "Couldn't create Java Message");
1014 NS_LOGD ("JNIProviderService: nativeCreateMessage - OUT");
1018 JNIEXPORT void JNICALL
1019 Java_org_iotivity_service_ns_provider_ProviderService_nativeEnableRemoteService
1020 (JNIEnv *env, jobject jObj, jstring jstr)
1022 NS_LOGD ("JNIProviderService: nativeEnableRemoteService - IN");
1025 ThrowNSException(JNI_INVALID_VALUE, "Server Address Can't be NULL");
1029 const char *address = env->GetStringUTFChars( jstr, NULL);
1030 std::string servAddress(address);
1031 OIC::Service::NSResult result =
1032 OIC::Service::NSProviderService::getInstance()->enableRemoteService(
1034 if (result != OIC::Service::NSResult::OK)
1036 ThrowNSException((int) result, "Fail to Enable Remote Service");
1039 env->ReleaseStringUTFChars(jstr, address);
1040 NS_LOGD ("JNIProviderService: nativeEnableRemoteService - OUT");
1044 JNIEXPORT void JNICALL
1045 Java_org_iotivity_service_ns_provider_ProviderService_nativeDisableRemoteService
1046 (JNIEnv *env, jobject jObj, jstring jstr)
1048 NS_LOGD ("JNIProviderService: nativeDisableRemoteService - IN");
1051 ThrowNSException(JNI_INVALID_VALUE, "Server Address Can't be NULL");
1055 const char *address = env->GetStringUTFChars( jstr, NULL);
1056 std::string servAddress(address);
1057 OIC::Service::NSResult result =
1058 OIC::Service::NSProviderService::getInstance()->disableRemoteService(
1060 if (result != OIC::Service::NSResult::OK)
1062 ThrowNSException((int) result, "Fail to Disable Remote Service");
1065 env->ReleaseStringUTFChars(jstr, address);
1066 NS_LOGD ("JNIProviderService: nativeDisableRemoteService - OUT");
1070 JNIEXPORT void JNICALL
1071 Java_org_iotivity_service_ns_provider_ProviderService_nativeSubscribeMQService
1072 (JNIEnv *env, jobject jObj, jstring jserverAddress, jstring jTopicName)
1074 NS_LOGD ("JNIProviderService: nativeSubscribeMQService - IN");
1075 if (!jserverAddress)
1077 ThrowNSException(JNI_INVALID_VALUE, "Server Address Can't be NULL");
1082 ThrowNSException(JNI_INVALID_VALUE, "TopicName Can't be NULL");
1086 const char *address = env->GetStringUTFChars( jserverAddress, NULL);
1087 std::string servAddress(address);
1088 const char *topic = env->GetStringUTFChars( jTopicName, NULL);
1089 std::string topicName(topic);
1091 OIC::Service::NSResult result =
1092 OIC::Service::NSProviderService::getInstance()->subscribeMQService(
1093 servAddress, topicName);
1094 if (result != OIC::Service::NSResult::OK)
1096 ThrowNSException((int) result, "Fail to Subscribe to MQ Service");
1099 env->ReleaseStringUTFChars(jserverAddress, address);
1100 env->ReleaseStringUTFChars(jTopicName, topic);
1101 NS_LOGD ("JNIProviderService: nativeSubscribeMQService - OUT");
1105 JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeRegisterTopic
1106 (JNIEnv *env, jobject jObj, jstring jTopicName)
1108 NS_LOGD ("JNIProviderService: nativeRegisterTopic - IN");
1111 ThrowNSException(JNI_INVALID_VALUE, "Topic Name Can't be NULL");
1114 const char *name = env->GetStringUTFChars( jTopicName, NULL);
1115 std::string topicName(name);
1116 OIC::Service::NSResult result = OIC::Service::NSProviderService::getInstance()->registerTopic(
1118 if (result != OIC::Service::NSResult::OK)
1120 ThrowNSException((int) result, "Fail to Register Topic");
1123 env->ReleaseStringUTFChars(jTopicName, name);
1124 NS_LOGD ("JNIProviderService: nativeRegisterTopic - OUT");
1127 JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeUnregisterTopic
1128 (JNIEnv *env, jobject jObj, jstring jTopicName)
1130 NS_LOGD ("JNIProviderService: nativeUnregisterTopic - IN");
1133 ThrowNSException(JNI_INVALID_VALUE, "Topic Name Can't be NULL");
1136 const char *name = env->GetStringUTFChars( jTopicName, NULL);
1137 std::string topicName(name);
1138 OIC::Service::NSResult result = OIC::Service::NSProviderService::getInstance()->unregisterTopic(
1140 if (result != OIC::Service::NSResult::OK)
1142 ThrowNSException((int) result, "Fail to Unregister Topic");
1145 env->ReleaseStringUTFChars(jTopicName, name);
1146 NS_LOGD ("JNIProviderService: nativeUnregisterTopic - OUT");
1150 JNIEXPORT jobject JNICALL
1151 Java_org_iotivity_service_ns_provider_ProviderService_nativeGetRegisteredTopicList
1152 (JNIEnv *env, jobject jObj)
1154 NS_LOGD ("JNIProviderService: nativeGetRegisteredTopicList - IN");
1156 std::shared_ptr<OIC::Service::NSTopicsList> topicList =
1157 OIC::Service::NSProviderService::getInstance()->getRegisteredTopicList();
1158 if (topicList == nullptr)
1160 ThrowNSException(JNI_INVALID_VALUE, "Topic List doesn't exist");
1164 jobject obj_topicList = getJavaTopicsList(env, topicList);
1166 NS_LOGD ("JNIProviderService: nativeGetRegisteredTopicList - OUT");
1167 return obj_topicList;
1170 JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeAcceptSubscription
1171 (JNIEnv *env, jobject jObj, jstring jConsumerId, jboolean jAccepted)
1173 NS_LOGD ("JNIProviderService: nativeAcceptSubscription - IN");
1176 ThrowNSException(JNI_INVALID_VALUE, "ConsumerId Can't be NULL");
1179 const char *id = env->GetStringUTFChars( jConsumerId, NULL);
1180 std::string consumerId(id);
1181 NS_LOGD ("Consumer ID: %s\n", consumerId.c_str());
1183 std::shared_ptr<OIC::Service::NSConsumer> consumer =
1184 OIC::Service::NSProviderService::getInstance()->getConsumer(consumerId);
1187 OIC::Service::NSResult result = OIC::Service::NSResult::ERROR;
1190 result = consumer->acceptSubscription((bool)jAccepted);
1192 catch (OIC::Service::NSException ex)
1194 ThrowNSException(NATIVE_EXCEPTION, ex.what());
1197 if (result != OIC::Service::NSResult::OK)
1199 ThrowNSException((int) result, "Fail to acceptSubscription");
1205 NS_LOGE ("Couldn't find consumer");
1206 ThrowNSException(JNI_NO_NATIVE_POINTER, "Fail to find native consumer");
1210 JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeSetConsumerTopic
1211 (JNIEnv *env, jobject jObj, jstring jConsumerId, jstring jTopicName)
1213 NS_LOGD ("JNIProviderService: nativeSetConsumerTopic - IN");
1214 if (!jConsumerId || !jTopicName)
1216 ThrowNSException(JNI_INVALID_VALUE, "Topic Name or ConsumerId Can't be NULL");
1219 const char *name = env->GetStringUTFChars( jTopicName, NULL);
1220 const char *id = env->GetStringUTFChars( jConsumerId, NULL);
1221 std::string topicName(name);
1222 std::string consumerId(id);
1223 std::shared_ptr<OIC::Service::NSConsumer> nsConsumer =
1224 OIC::Service::NSProviderService::getInstance()->getConsumer(consumerId);
1227 ThrowNSException(JNI_NO_NATIVE_POINTER, "Consumer does exists");
1230 OIC::Service::NSResult result = OIC::Service::NSResult::ERROR;
1233 result = nsConsumer->setTopic(topicName);
1235 catch (OIC::Service::NSException ex)
1237 ThrowNSException(NATIVE_EXCEPTION, ex.what());
1241 if (result != OIC::Service::NSResult::OK)
1243 ThrowNSException((int) result, "Fail to Select Topic");
1246 env->ReleaseStringUTFChars(jTopicName, name);
1247 env->ReleaseStringUTFChars(jConsumerId, id);
1248 NS_LOGD ("JNIProviderService: nativeSetConsumerTopic - OUT");
1251 JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeUnsetConsumerTopic
1252 (JNIEnv *env, jobject jObj, jstring jConsumerId, jstring jTopicName)
1254 NS_LOGD ("JNIProviderService: nativeUnsetConsumerTopic - IN");
1255 if (!jConsumerId || !jTopicName)
1257 ThrowNSException(JNI_INVALID_VALUE, "Topic Name or ConsumerId Can't be NULL");
1260 const char *name = env->GetStringUTFChars( jTopicName, NULL);
1261 const char *id = env->GetStringUTFChars( jConsumerId, NULL);
1262 std::string topicName(name);
1263 std::string consumerId(id);
1264 std::shared_ptr<OIC::Service::NSConsumer> nsConsumer =
1265 OIC::Service::NSProviderService::getInstance()->getConsumer(consumerId);
1268 ThrowNSException(JNI_NO_NATIVE_POINTER, "Consumer does exists");
1271 OIC::Service::NSResult result = OIC::Service::NSResult::ERROR;
1274 result = nsConsumer->unsetTopic(topicName);
1276 catch (OIC::Service::NSException ex)
1278 ThrowNSException(NATIVE_EXCEPTION, ex.what());
1282 if (result != OIC::Service::NSResult::OK)
1284 ThrowNSException((int) result, "Fail to Unselect Topic");
1287 env->ReleaseStringUTFChars(jTopicName, name);
1288 env->ReleaseStringUTFChars(jConsumerId, id);
1289 NS_LOGD ("JNIProviderService: nativeUnsetConsumerTopic - OUT");
1293 JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeGetConsumerTopicList
1294 (JNIEnv *env, jobject jObj, jstring jConsumerId)
1296 NS_LOGD ("JNIProviderService: nativeGetConsumerTopicList - IN");
1299 ThrowNSException(JNI_INVALID_VALUE, "Topic Name or ConsumerId Can't be NULL");
1302 const char *id = env->GetStringUTFChars( jConsumerId, NULL);
1303 std::string consumerId(id);
1304 std::shared_ptr<OIC::Service::NSConsumer> nsConsumer =
1305 OIC::Service::NSProviderService::getInstance()->getConsumer(consumerId);
1308 ThrowNSException(JNI_NO_NATIVE_POINTER, "Consumer does exists");
1311 env->ReleaseStringUTFChars(jConsumerId, id);
1312 std::shared_ptr<OIC::Service::NSTopicsList> topicList = nullptr;
1315 topicList = nsConsumer->getConsumerTopicList();
1317 catch (OIC::Service::NSException ex)
1319 ThrowNSException(NATIVE_EXCEPTION, ex.what());
1322 if (topicList == nullptr)
1324 ThrowNSException(JNI_NO_NATIVE_POINTER, "Topic List doesn't exist");
1327 jobject obj_topicList = getJavaTopicsList(env, topicList);
1329 NS_LOGD ("JNIProviderService: nativeGetConsumerTopicList - OUT");
1330 return obj_topicList;
1334 JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved)
1336 NS_LOGD ("ProviderService_JNI_OnLoad");
1337 g_jvm_provider = jvm;
1340 if (jvm->GetEnv((void **)&env, JNI_CURRENT_VERSION) != JNI_OK)
1342 NS_LOGE ("Failed to get the environment using GetEnv()");
1346 jclass localMessage = env->FindClass(
1347 "org/iotivity/service/ns/common/Message");
1350 NS_LOGE ("Failed to get local Message class");
1353 g_cls_Message = (jclass) (env->NewGlobalRef(localMessage));
1356 NS_LOGE ("Failed to set Global Message reference");
1360 jclass localMessageType = env->FindClass(
1361 "org/iotivity/service/ns/common/Message$MessageType");
1362 if (!localMessageType)
1364 NS_LOGE ("Failed to get local Message Type class");
1367 g_cls_Message_Type = (jclass) (env->NewGlobalRef(localMessageType));
1368 if (!g_cls_Message_Type)
1370 NS_LOGE ("Failed to set Global Message Type reference");
1374 jclass localConsumer = env->FindClass(
1375 "org/iotivity/service/ns/provider/Consumer");
1378 NS_LOGE ("Failed to get local Provider class");
1381 g_cls_Consumer = (jclass) (env->NewGlobalRef(localConsumer));
1382 if (!g_cls_Consumer)
1384 NS_LOGE ("Failed to set Global Provider reference");
1388 jclass localSyncInfo = env->FindClass(
1389 "org/iotivity/service/ns/common/SyncInfo");
1392 NS_LOGE ("Failed to get local SyncInfo class");
1395 g_cls_SyncInfo = (jclass) (env->NewGlobalRef(localSyncInfo));
1396 if (!g_cls_SyncInfo)
1398 NS_LOGE ("Failed to set Global SyncInfo reference");
1402 jclass localSyncType = env->FindClass(
1403 "org/iotivity/service/ns/common/SyncInfo$SyncType");
1406 NS_LOGE ("Failed to get local SyncType enum");
1409 g_cls_SyncType = (jclass) (env->NewGlobalRef(localSyncType));
1410 if (!g_cls_SyncType)
1412 NS_LOGE ("Failed to set Global SyncType reference");
1416 jclass localMediaContents = env->FindClass(
1417 "org/iotivity/service/ns/common/MediaContents");
1418 if (!localMediaContents)
1420 NS_LOGE ("Failed to get local MediaContents class");
1423 g_cls_MediaContents = (jclass) (env->NewGlobalRef(localMediaContents));
1424 if (!g_cls_MediaContents)
1426 NS_LOGE ("Failed to set Global MediaContents reference");
1430 jclass localTopic = env->FindClass(
1431 "org/iotivity/service/ns/common/Topic");
1434 NS_LOGE ("Failed to get local Topic class");
1437 g_cls_Topic = (jclass) (env->NewGlobalRef(localTopic));
1440 NS_LOGE ("Failed to set Global Topic reference");
1444 jclass localTopicsList = env->FindClass(
1445 "org/iotivity/service/ns/common/TopicsList");
1446 if (!localTopicsList)
1448 NS_LOGE ("Failed to get local Topic class");
1451 g_cls_TopicsList = (jclass) (env->NewGlobalRef(localTopicsList));
1452 if (!g_cls_TopicsList)
1454 NS_LOGE ("Failed to set Global TopicsList reference");
1458 jclass localTopicState = env->FindClass(
1459 "org/iotivity/service/ns/common/Topic$TopicState");
1460 if (!localTopicState)
1462 NS_LOGE ("Failed to get local TopicState enum");
1465 g_cls_TopicState = (jclass) (env->NewGlobalRef(localTopicState));
1466 if (!g_cls_TopicState)
1468 NS_LOGE ("Failed to set Global TopicState reference");
1473 jclass localOcRepresentation = env->FindClass("org/iotivity/base/OcRepresentation");
1474 if (!localOcRepresentation)
1476 NS_LOGE ("Failed to get local OcRepresentation class");
1479 g_cls_OcRepresentation = (jclass) env->NewGlobalRef(localOcRepresentation);
1480 if (!g_cls_OcRepresentation)
1482 NS_LOGE ("Failed to set Global OcRepresentation reference");
1486 g_mid_OcRepresentation_N_ctor_bool = env->GetMethodID(g_cls_OcRepresentation, "<init>", "(JZ)V");
1487 if (!g_mid_OcRepresentation_N_ctor_bool)
1489 NS_LOGE ("Failed to get Global OcRepresentation Constructor reference");
1493 env->DeleteLocalRef(localMessage);
1494 env->DeleteLocalRef(localMessageType);
1495 env->DeleteLocalRef(localConsumer);
1496 env->DeleteLocalRef(localSyncInfo);
1497 env->DeleteLocalRef(localSyncType);
1498 env->DeleteLocalRef(localMediaContents);
1499 env->DeleteLocalRef(localTopic);
1500 env->DeleteLocalRef(localTopicsList);
1501 env->DeleteLocalRef(localTopicState);
1502 env->DeleteLocalRef(localOcRepresentation);
1504 return NSExceptionInit(env);
1507 JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *jvm, void *reserved)
1509 NS_LOGD ("ProviderService_JNI_OnUnload");
1512 if (jvm->GetEnv((void **)&env, JNI_CURRENT_VERSION) != JNI_OK)
1514 NS_LOGE ("Failed to get the environment using GetEnv()");
1518 env->DeleteGlobalRef(g_cls_Message);
1519 env->DeleteGlobalRef(g_cls_Consumer);
1520 env->DeleteGlobalRef(g_cls_SyncInfo);
1521 env->DeleteGlobalRef(g_cls_SyncType);
1522 env->DeleteGlobalRef(g_cls_MediaContents);
1523 env->DeleteGlobalRef(g_cls_Message_Type);
1524 env->DeleteGlobalRef(g_cls_Topic);
1525 env->DeleteGlobalRef(g_cls_TopicsList);
1526 env->DeleteGlobalRef(g_cls_TopicState);
1527 env->DeleteGlobalRef(g_cls_OcRepresentation);