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;
554 NS_LOGD ("Created OCRepresentation Object from Native");
556 jfieldID fid_extraInfo = env->GetFieldID(cls_message, "mExtraInfo",
557 "Lorg/iotivity/base/OcRepresentation;");
560 NS_LOGE ("Failed to get mExtraInfo for Message");
561 delete ocRepresentation;
564 NS_LOGD ("setting extraInfo field");
565 env->SetObjectField(obj_message, fid_extraInfo, jRepresentation);
567 env->DeleteLocalRef(cls_message);
568 NS_LOGD ("JNIProviderService: getJavaMessage - OUT");
572 jobject getJavaTopicState(JNIEnv *env, OIC::Service::NSTopic::NSTopicState nsState)
574 NS_LOGD ("JNIProviderService: getJavaTopicState - IN");
577 jclass cls_topicState = (jclass) (env->NewLocalRef(g_cls_TopicState));
580 NS_LOGE ("Failed to Get ObjectClass for TopicState Type");
583 jobject topicState = NULL;
587 case OIC::Service::NSTopic::NSTopicState::UNSUBSCRIBED:
589 static jfieldID fieldID = env->GetStaticFieldID(cls_topicState,
590 "UNSUBSCRIBED", "Lorg/iotivity/service/ns/common/Topic$TopicState;");
591 topicState = env->GetStaticObjectField(cls_topicState, fieldID);
594 case OIC::Service::NSTopic::NSTopicState::SUBSCRIBED:
596 static jfieldID fieldID = env->GetStaticFieldID(cls_topicState,
597 "SUBSCRIBED", "Lorg/iotivity/service/ns/common/Topic$TopicState;");
598 topicState = env->GetStaticObjectField(cls_topicState, fieldID);
608 NS_LOGD ("JNIProviderService: getJavaTopicState - OUT");
612 jobject getJavaTopicsList(JNIEnv *env, std::shared_ptr<OIC::Service::NSTopicsList> topicList)
614 NS_LOGD ("JNIProviderService: getJavaTopicsList - IN");
615 jclass cls_topicList = (jclass) (env->NewLocalRef(g_cls_TopicsList));
618 NS_LOGE ("Failed to Get ObjectClass for TopicsList");
621 jmethodID mid_topicList = env->GetMethodID(cls_topicList, "<init>", "()V");
624 NS_LOGE ("Failed to Get MethodID for TopicsList<init>");
627 jobject obj_topicList = env->NewObject(cls_topicList, mid_topicList);
630 NS_LOGE ("Failed to Get object for TopicsList");
633 jmethodID mid_addTopic = env->GetMethodID(cls_topicList, "addTopic",
634 "(Ljava/lang/String;Lorg/iotivity/service/ns/common/Topic$TopicState;)V");
637 NS_LOGE ("Failed to Get MethodID for addTopic");
640 for (auto it : topicList->getTopicsList())
642 jobject jState = getJavaTopicState(env, it.getState());
643 std::string topicName = it.getTopicName();
644 jstring jTopicName = env->NewStringUTF(topicName.c_str());
645 env->CallVoidMethod(obj_topicList, mid_addTopic, jTopicName, jState);
647 env->DeleteLocalRef(cls_topicList);
648 NS_LOGD ("JNIProviderService: getJavaTopicsList - OUT");
649 return obj_topicList;
652 jobject getJavaSyncType(JNIEnv *env, OIC::Service::NSSyncInfo::NSSyncType nsType)
654 NS_LOGD ("JNIProviderService: getJavaSyncType - IN");
657 jclass cls_SyncType = (jclass) (env->NewLocalRef(g_cls_SyncType));
660 NS_LOGE ("Failed to Get ObjectClass for SyncType");
663 jobject syncType = NULL;
666 case OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_UNREAD:
668 static jfieldID fieldID = env->GetStaticFieldID(cls_SyncType,
669 "UNREAD", "Lorg/iotivity/service/ns/common/SyncInfo$SyncType;");
670 syncType = env->GetStaticObjectField(cls_SyncType, fieldID);
673 case OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_READ :
675 static jfieldID fieldID = env->GetStaticFieldID(cls_SyncType,
676 "READ", "Lorg/iotivity/service/ns/common/SyncInfo$SyncType;");
677 syncType = env->GetStaticObjectField(cls_SyncType, fieldID);
680 case OIC::Service::NSSyncInfo::NSSyncType::NS_SYNC_DELETED :
682 static jfieldID fieldID = env->GetStaticFieldID(cls_SyncType,
683 "DELETED", "Lorg/iotivity/service/ns/common/SyncInfo$SyncType;");
684 syncType = env->GetStaticObjectField(cls_SyncType, fieldID);
694 NS_LOGD ("JNIProviderService: getJavaSyncType - OUT");
699 void onSubscribeListenerCb(std::shared_ptr<OIC::Service::NSConsumer> consumer)
701 NS_LOGD ("JNIProviderService_onSubscribeListenerCb - IN");
704 JNIEnv *env = GetJNIEnv(&envRet);
710 jobject jSubscriptionListener = (jobject) env->NewLocalRef(g_obj_subscriptionListener);
711 if (!jSubscriptionListener)
713 NS_LOGE ("Failed to Get jSubscriptionListener");
714 if (JNI_EDETACHED == envRet)
716 g_jvm_provider->DetachCurrentThread();
721 NS_LOGD ("consumer ID : %s\n", consumer->getConsumerId().c_str());
723 jstring jConsumerId = env->NewStringUTF( consumer->getConsumerId().c_str());
725 jclass cls_consumer = (jclass) (env->NewLocalRef(g_cls_Consumer));
728 NS_LOGE ("Failed to Get ObjectClass for Consumer");
729 if (JNI_EDETACHED == envRet)
731 g_jvm_provider->DetachCurrentThread();
736 jmethodID mid_consumer = env->GetMethodID(
739 "(Ljava/lang/String;)V");
742 NS_LOGE ("Failed to Get MethodID for Consumer<init>");
743 if (JNI_EDETACHED == envRet)
745 g_jvm_provider->DetachCurrentThread();
749 jobject obj_consumer = env->NewObject( cls_consumer, mid_consumer, jConsumerId);
751 jclass cls = env->GetObjectClass( jSubscriptionListener);
754 NS_LOGE ("Failed to Get ObjectClass of jSubscriptionListener");
755 if (JNI_EDETACHED == envRet)
757 g_jvm_provider->DetachCurrentThread();
761 jmethodID mid = env->GetMethodID(
763 "onConsumerSubscribed",
764 "(Lorg/iotivity/service/ns/provider/Consumer;)V");
767 NS_LOGE ("Failed to Get MethodID of onConsumerSubscribed");
768 if (JNI_EDETACHED == envRet)
770 g_jvm_provider->DetachCurrentThread();
775 env->CallVoidMethod( jSubscriptionListener, mid, obj_consumer);
776 env->DeleteLocalRef(jSubscriptionListener);
777 env->DeleteLocalRef(cls_consumer);
778 if (JNI_EDETACHED == envRet)
780 g_jvm_provider->DetachCurrentThread();
782 NS_LOGD ("JNIProviderService_onSubscribeListenerCb - OUT");
786 void onSyncInfoListenerCb(OIC::Service::NSSyncInfo sync)
788 NS_LOGD ("JNIProviderService_onSyncInfoListenerCb - IN");
791 JNIEnv *env = GetJNIEnv(&envRet);
797 jobject jSyncListener = (jobject) env->NewLocalRef(g_obj_syncListener);
800 NS_LOGE ("Failed to Get jSyncListener");
801 if (JNI_EDETACHED == envRet)
803 g_jvm_provider->DetachCurrentThread();
808 NS_LOGD ("Sync ID : %ld\n", (long) sync.getMessageId());
809 NS_LOGD ("Sync STATE : %d\n", (int) sync.getState());
811 jlong jMessageId = (long) sync.getMessageId();
812 jstring jProviderId = env->NewStringUTF(sync.getProviderId().c_str());
813 jobject syncType = getJavaSyncType(env, sync.getState());
816 NS_LOGE ("Failed to Get syncType for SyncInfo");
817 if (JNI_EDETACHED == envRet)
819 g_jvm_provider->DetachCurrentThread();
823 jclass cls_SyncInfo = (jclass) (env->NewLocalRef(g_cls_SyncInfo));
826 NS_LOGE ("Failed to Get ObjectClass for SyncInfo");
827 if (JNI_EDETACHED == envRet)
829 g_jvm_provider->DetachCurrentThread();
833 jmethodID mid_syncInfo = env->GetMethodID(
836 "(JLjava/lang/String;Lorg/iotivity/service/ns/common/SyncInfo$SyncType;)V");
839 NS_LOGE ("Failed to Get MethodID for SyncInfo");
840 if (JNI_EDETACHED == envRet)
842 g_jvm_provider->DetachCurrentThread();
847 jobject obj_syncInfo = env->NewObject( cls_SyncInfo, mid_syncInfo,
848 jMessageId, jProviderId, syncType);
851 NS_LOGE ("Failed to Get Object for SyncInfo");
852 if (JNI_EDETACHED == envRet)
854 g_jvm_provider->DetachCurrentThread();
859 jclass cls = env->GetObjectClass( jSyncListener);
862 NS_LOGE ("Failed to Get ObjectClass");
863 if (JNI_EDETACHED == envRet)
865 g_jvm_provider->DetachCurrentThread();
869 jmethodID mid = env->GetMethodID(
871 "onMessageSynchronized",
872 "(Lorg/iotivity/service/ns/common/SyncInfo;)V");
875 NS_LOGE ("Failed to Get MethodID");
876 if (JNI_EDETACHED == envRet)
878 g_jvm_provider->DetachCurrentThread();
882 env->CallVoidMethod( jSyncListener, mid, obj_syncInfo);
884 env->DeleteLocalRef(jSyncListener);
885 env->DeleteLocalRef(cls_SyncInfo);
886 if (JNI_EDETACHED == envRet)
888 g_jvm_provider->DetachCurrentThread();
890 NS_LOGD ("JNIProviderService: OnSyncInfoListenerCb - OUT");
895 JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeStart
896 (JNIEnv *env, jobject jObj, jobject jSubscriptionListener, jobject jSyncListener,
897 jboolean jPolicy, jstring jUserInfo, jboolean jResourceSecurity)
899 NS_LOGD ("JNIProviderService: nativeStart - IN");
900 if (!jSubscriptionListener || !jSyncListener)
902 ThrowNSException(JNI_INVALID_VALUE, "Listener cannot be null");
906 if (g_obj_subscriptionListener != NULL)
908 env->DeleteGlobalRef(g_obj_subscriptionListener);
910 if (g_obj_syncListener != NULL)
912 env->DeleteGlobalRef(g_obj_syncListener);
915 g_obj_subscriptionListener = (jobject) env->NewGlobalRef(jSubscriptionListener);
916 g_obj_syncListener = (jobject) env->NewGlobalRef(jSyncListener);
918 // check access policy
920 OIC::Service::NSProviderService::ProviderConfig cfg;
921 cfg.m_subscribeRequestCb = onSubscribeListenerCb;
922 cfg.m_syncInfoCb = onSyncInfoListenerCb;
923 cfg.subControllability = (bool) jPolicy;
926 const char *info = env->GetStringUTFChars( jUserInfo, NULL);
927 std::string userInfo(info);
928 cfg.userInfo = userInfo;
930 cfg.resourceSecurity = (bool) jResourceSecurity;
932 OIC::Service::NSResult result = OIC::Service::NSProviderService::getInstance()->start(cfg);
933 if (result != OIC::Service::NSResult::OK)
935 ThrowNSException((int) result, "Fail to start NSProviderService");
939 NS_LOGD ("JNIProviderService: nativeStart - OUT");
943 JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeStop
944 (JNIEnv *env, jobject jObj)
946 NS_LOGD ("JNIProviderService: nativeStop - IN");
948 OIC::Service::NSResult result = OIC::Service::NSProviderService::getInstance()->stop();
949 if (result != OIC::Service::NSResult::OK)
951 ThrowNSException((int) result, "Fail to stop NSProviderService");
955 env->DeleteGlobalRef( g_obj_subscriptionListener);
956 env->DeleteGlobalRef( g_obj_syncListener);
957 g_obj_subscriptionListener = NULL;
958 g_obj_syncListener = NULL;
960 NS_LOGD ("JNIProviderService: nativeStop - OUT");
964 JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeSendMessage
965 (JNIEnv *env, jobject jObj, jobject jMsg)
967 NS_LOGD ("JNIProviderService: nativeSendMessage - IN");
970 ThrowNSException(JNI_INVALID_VALUE, "Message cannot be null");
973 OIC::Service::NSMessage nsMsg = getNativeMessage(env, jMsg);
975 OIC::Service::NSResult result = OIC::Service::NSProviderService::getInstance()->sendMessage(nsMsg);
976 if (result != OIC::Service::NSResult::OK)
978 ThrowNSException((int) result, "Fail to send NSProvider Message");
981 NS_LOGD ("JNIProviderService: nativeSendMessage - OUT");
985 JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeSendSyncInfo
986 (JNIEnv *env, jobject jObj, jlong messageId , jint syncState)
988 NS_LOGD ("JNIProviderService: nativeSendSyncInfo - IN");
989 OIC::Service::NSResult result = OIC::Service::NSProviderService::getInstance()->sendSyncInfo(
991 (OIC::Service::NSSyncInfo::NSSyncType) syncState);
992 if (result != OIC::Service::NSResult::OK)
994 ThrowNSException((int) result, "Fail to send NSProvider SendSyncInfo");
997 NS_LOGD ("JNIProviderService: nativeSendSyncInfo - OUT");
1001 JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeCreateMessage
1002 (JNIEnv *env, jobject jObj)
1004 NS_LOGD ("JNIProviderService: nativeCreateMessage - IN");
1005 OIC::Service::NSMessage message =
1006 OIC::Service::NSProviderService::getInstance()->createMessage();
1007 jobject jMsg = getJavaMessage(env, message);
1010 ThrowNSException(JNI_INVALID_VALUE, "Couldn't create Java Message");
1013 NS_LOGD ("JNIProviderService: nativeCreateMessage - OUT");
1017 JNIEXPORT void JNICALL
1018 Java_org_iotivity_service_ns_provider_ProviderService_nativeEnableRemoteService
1019 (JNIEnv *env, jobject jObj, jstring jstr)
1021 NS_LOGD ("JNIProviderService: nativeEnableRemoteService - IN");
1024 ThrowNSException(JNI_INVALID_VALUE, "Server Address Can't be NULL");
1028 const char *address = env->GetStringUTFChars( jstr, NULL);
1029 std::string servAddress(address);
1030 OIC::Service::NSResult result =
1031 OIC::Service::NSProviderService::getInstance()->enableRemoteService(
1033 if (result != OIC::Service::NSResult::OK)
1035 ThrowNSException((int) result, "Fail to Enable Remote Service");
1038 env->ReleaseStringUTFChars(jstr, address);
1039 NS_LOGD ("JNIProviderService: nativeEnableRemoteService - OUT");
1043 JNIEXPORT void JNICALL
1044 Java_org_iotivity_service_ns_provider_ProviderService_nativeDisableRemoteService
1045 (JNIEnv *env, jobject jObj, jstring jstr)
1047 NS_LOGD ("JNIProviderService: nativeDisableRemoteService - IN");
1050 ThrowNSException(JNI_INVALID_VALUE, "Server Address Can't be NULL");
1054 const char *address = env->GetStringUTFChars( jstr, NULL);
1055 std::string servAddress(address);
1056 OIC::Service::NSResult result =
1057 OIC::Service::NSProviderService::getInstance()->disableRemoteService(
1059 if (result != OIC::Service::NSResult::OK)
1061 ThrowNSException((int) result, "Fail to Disable Remote Service");
1064 env->ReleaseStringUTFChars(jstr, address);
1065 NS_LOGD ("JNIProviderService: nativeDisableRemoteService - OUT");
1069 JNIEXPORT void JNICALL
1070 Java_org_iotivity_service_ns_provider_ProviderService_nativeSubscribeMQService
1071 (JNIEnv *env, jobject jObj, jstring jserverAddress, jstring jTopicName)
1073 NS_LOGD ("JNIProviderService: nativeSubscribeMQService - IN");
1074 if (!jserverAddress)
1076 ThrowNSException(JNI_INVALID_VALUE, "Server Address Can't be NULL");
1081 ThrowNSException(JNI_INVALID_VALUE, "TopicName Can't be NULL");
1085 const char *address = env->GetStringUTFChars( jserverAddress, NULL);
1086 std::string servAddress(address);
1087 const char *topic = env->GetStringUTFChars( jTopicName, NULL);
1088 std::string topicName(topic);
1090 OIC::Service::NSResult result =
1091 OIC::Service::NSProviderService::getInstance()->subscribeMQService(
1092 servAddress, topicName);
1093 if (result != OIC::Service::NSResult::OK)
1095 ThrowNSException((int) result, "Fail to Subscribe to MQ Service");
1098 env->ReleaseStringUTFChars(jserverAddress, address);
1099 env->ReleaseStringUTFChars(jTopicName, topic);
1100 NS_LOGD ("JNIProviderService: nativeSubscribeMQService - OUT");
1104 JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeRegisterTopic
1105 (JNIEnv *env, jobject jObj, jstring jTopicName)
1107 NS_LOGD ("JNIProviderService: nativeRegisterTopic - IN");
1110 ThrowNSException(JNI_INVALID_VALUE, "Topic Name Can't be NULL");
1113 const char *name = env->GetStringUTFChars( jTopicName, NULL);
1114 std::string topicName(name);
1115 OIC::Service::NSResult result = OIC::Service::NSProviderService::getInstance()->registerTopic(
1117 if (result != OIC::Service::NSResult::OK)
1119 ThrowNSException((int) result, "Fail to Register Topic");
1122 env->ReleaseStringUTFChars(jTopicName, name);
1123 NS_LOGD ("JNIProviderService: nativeRegisterTopic - OUT");
1126 JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_ProviderService_nativeUnregisterTopic
1127 (JNIEnv *env, jobject jObj, jstring jTopicName)
1129 NS_LOGD ("JNIProviderService: nativeUnregisterTopic - IN");
1132 ThrowNSException(JNI_INVALID_VALUE, "Topic Name Can't be NULL");
1135 const char *name = env->GetStringUTFChars( jTopicName, NULL);
1136 std::string topicName(name);
1137 OIC::Service::NSResult result = OIC::Service::NSProviderService::getInstance()->unregisterTopic(
1139 if (result != OIC::Service::NSResult::OK)
1141 ThrowNSException((int) result, "Fail to Unregister Topic");
1144 env->ReleaseStringUTFChars(jTopicName, name);
1145 NS_LOGD ("JNIProviderService: nativeUnregisterTopic - OUT");
1149 JNIEXPORT jobject JNICALL
1150 Java_org_iotivity_service_ns_provider_ProviderService_nativeGetRegisteredTopicList
1151 (JNIEnv *env, jobject jObj)
1153 NS_LOGD ("JNIProviderService: nativeGetRegisteredTopicList - IN");
1155 std::shared_ptr<OIC::Service::NSTopicsList> topicList =
1156 OIC::Service::NSProviderService::getInstance()->getRegisteredTopicList();
1157 if (topicList == nullptr)
1159 ThrowNSException(JNI_INVALID_VALUE, "Topic List doesn't exist");
1163 jobject obj_topicList = getJavaTopicsList(env, topicList);
1165 NS_LOGD ("JNIProviderService: nativeGetRegisteredTopicList - OUT");
1166 return obj_topicList;
1169 JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeAcceptSubscription
1170 (JNIEnv *env, jobject jObj, jstring jConsumerId, jboolean jAccepted)
1172 NS_LOGD ("JNIProviderService: nativeAcceptSubscription - IN");
1175 ThrowNSException(JNI_INVALID_VALUE, "ConsumerId Can't be NULL");
1178 const char *id = env->GetStringUTFChars( jConsumerId, NULL);
1179 std::string consumerId(id);
1180 NS_LOGD ("Consumer ID: %s\n", consumerId.c_str());
1182 std::shared_ptr<OIC::Service::NSConsumer> consumer =
1183 OIC::Service::NSProviderService::getInstance()->getConsumer(consumerId);
1186 OIC::Service::NSResult result = OIC::Service::NSResult::ERROR;
1189 result = consumer->acceptSubscription((bool)jAccepted);
1191 catch (OIC::Service::NSException ex)
1193 ThrowNSException(NATIVE_EXCEPTION, ex.what());
1196 if (result != OIC::Service::NSResult::OK)
1198 ThrowNSException((int) result, "Fail to acceptSubscription");
1204 NS_LOGE ("Couldn't find consumer");
1205 ThrowNSException(JNI_NO_NATIVE_POINTER, "Fail to find native consumer");
1209 JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeSetConsumerTopic
1210 (JNIEnv *env, jobject jObj, jstring jConsumerId, jstring jTopicName)
1212 NS_LOGD ("JNIProviderService: nativeSetConsumerTopic - IN");
1213 if (!jConsumerId || !jTopicName)
1215 ThrowNSException(JNI_INVALID_VALUE, "Topic Name or ConsumerId Can't be NULL");
1218 const char *name = env->GetStringUTFChars( jTopicName, NULL);
1219 const char *id = env->GetStringUTFChars( jConsumerId, NULL);
1220 std::string topicName(name);
1221 std::string consumerId(id);
1222 std::shared_ptr<OIC::Service::NSConsumer> nsConsumer =
1223 OIC::Service::NSProviderService::getInstance()->getConsumer(consumerId);
1226 ThrowNSException(JNI_NO_NATIVE_POINTER, "Consumer does exists");
1229 OIC::Service::NSResult result = OIC::Service::NSResult::ERROR;
1232 result = nsConsumer->setTopic(topicName);
1234 catch (OIC::Service::NSException ex)
1236 ThrowNSException(NATIVE_EXCEPTION, ex.what());
1240 if (result != OIC::Service::NSResult::OK)
1242 ThrowNSException((int) result, "Fail to Select Topic");
1245 env->ReleaseStringUTFChars(jTopicName, name);
1246 env->ReleaseStringUTFChars(jConsumerId, id);
1247 NS_LOGD ("JNIProviderService: nativeSetConsumerTopic - OUT");
1250 JNIEXPORT void JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeUnsetConsumerTopic
1251 (JNIEnv *env, jobject jObj, jstring jConsumerId, jstring jTopicName)
1253 NS_LOGD ("JNIProviderService: nativeUnsetConsumerTopic - IN");
1254 if (!jConsumerId || !jTopicName)
1256 ThrowNSException(JNI_INVALID_VALUE, "Topic Name or ConsumerId Can't be NULL");
1259 const char *name = env->GetStringUTFChars( jTopicName, NULL);
1260 const char *id = env->GetStringUTFChars( jConsumerId, NULL);
1261 std::string topicName(name);
1262 std::string consumerId(id);
1263 std::shared_ptr<OIC::Service::NSConsumer> nsConsumer =
1264 OIC::Service::NSProviderService::getInstance()->getConsumer(consumerId);
1267 ThrowNSException(JNI_NO_NATIVE_POINTER, "Consumer does exists");
1270 OIC::Service::NSResult result = OIC::Service::NSResult::ERROR;
1273 result = nsConsumer->unsetTopic(topicName);
1275 catch (OIC::Service::NSException ex)
1277 ThrowNSException(NATIVE_EXCEPTION, ex.what());
1281 if (result != OIC::Service::NSResult::OK)
1283 ThrowNSException((int) result, "Fail to Unselect Topic");
1286 env->ReleaseStringUTFChars(jTopicName, name);
1287 env->ReleaseStringUTFChars(jConsumerId, id);
1288 NS_LOGD ("JNIProviderService: nativeUnsetConsumerTopic - OUT");
1292 JNIEXPORT jobject JNICALL Java_org_iotivity_service_ns_provider_Consumer_nativeGetConsumerTopicList
1293 (JNIEnv *env, jobject jObj, jstring jConsumerId)
1295 NS_LOGD ("JNIProviderService: nativeGetConsumerTopicList - IN");
1298 ThrowNSException(JNI_INVALID_VALUE, "Topic Name or ConsumerId Can't be NULL");
1301 const char *id = env->GetStringUTFChars( jConsumerId, NULL);
1302 std::string consumerId(id);
1303 std::shared_ptr<OIC::Service::NSConsumer> nsConsumer =
1304 OIC::Service::NSProviderService::getInstance()->getConsumer(consumerId);
1307 ThrowNSException(JNI_NO_NATIVE_POINTER, "Consumer does exists");
1310 env->ReleaseStringUTFChars(jConsumerId, id);
1311 std::shared_ptr<OIC::Service::NSTopicsList> topicList = nullptr;
1314 topicList = nsConsumer->getConsumerTopicList();
1316 catch (OIC::Service::NSException ex)
1318 ThrowNSException(NATIVE_EXCEPTION, ex.what());
1321 if (topicList == nullptr)
1323 ThrowNSException(JNI_NO_NATIVE_POINTER, "Topic List doesn't exist");
1326 jobject obj_topicList = getJavaTopicsList(env, topicList);
1328 NS_LOGD ("JNIProviderService: nativeGetConsumerTopicList - OUT");
1329 return obj_topicList;
1333 JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved)
1335 NS_LOGD ("ProviderService_JNI_OnLoad");
1336 g_jvm_provider = jvm;
1339 if (jvm->GetEnv((void **)&env, JNI_CURRENT_VERSION) != JNI_OK)
1341 NS_LOGE ("Failed to get the environment using GetEnv()");
1345 jclass localMessage = env->FindClass(
1346 "org/iotivity/service/ns/common/Message");
1349 NS_LOGE ("Failed to get local Message class");
1352 g_cls_Message = (jclass) (env->NewGlobalRef(localMessage));
1355 NS_LOGE ("Failed to set Global Message reference");
1359 jclass localMessageType = env->FindClass(
1360 "org/iotivity/service/ns/common/Message$MessageType");
1361 if (!localMessageType)
1363 NS_LOGE ("Failed to get local Message Type class");
1366 g_cls_Message_Type = (jclass) (env->NewGlobalRef(localMessageType));
1367 if (!g_cls_Message_Type)
1369 NS_LOGE ("Failed to set Global Message Type reference");
1373 jclass localConsumer = env->FindClass(
1374 "org/iotivity/service/ns/provider/Consumer");
1377 NS_LOGE ("Failed to get local Provider class");
1380 g_cls_Consumer = (jclass) (env->NewGlobalRef(localConsumer));
1381 if (!g_cls_Consumer)
1383 NS_LOGE ("Failed to set Global Provider reference");
1387 jclass localSyncInfo = env->FindClass(
1388 "org/iotivity/service/ns/common/SyncInfo");
1391 NS_LOGE ("Failed to get local SyncInfo class");
1394 g_cls_SyncInfo = (jclass) (env->NewGlobalRef(localSyncInfo));
1395 if (!g_cls_SyncInfo)
1397 NS_LOGE ("Failed to set Global SyncInfo reference");
1401 jclass localSyncType = env->FindClass(
1402 "org/iotivity/service/ns/common/SyncInfo$SyncType");
1405 NS_LOGE ("Failed to get local SyncType enum");
1408 g_cls_SyncType = (jclass) (env->NewGlobalRef(localSyncType));
1409 if (!g_cls_SyncType)
1411 NS_LOGE ("Failed to set Global SyncType reference");
1415 jclass localMediaContents = env->FindClass(
1416 "org/iotivity/service/ns/common/MediaContents");
1417 if (!localMediaContents)
1419 NS_LOGE ("Failed to get local MediaContents class");
1422 g_cls_MediaContents = (jclass) (env->NewGlobalRef(localMediaContents));
1423 if (!g_cls_MediaContents)
1425 NS_LOGE ("Failed to set Global MediaContents reference");
1429 jclass localTopic = env->FindClass(
1430 "org/iotivity/service/ns/common/Topic");
1433 NS_LOGE ("Failed to get local Topic class");
1436 g_cls_Topic = (jclass) (env->NewGlobalRef(localTopic));
1439 NS_LOGE ("Failed to set Global Topic reference");
1443 jclass localTopicsList = env->FindClass(
1444 "org/iotivity/service/ns/common/TopicsList");
1445 if (!localTopicsList)
1447 NS_LOGE ("Failed to get local Topic class");
1450 g_cls_TopicsList = (jclass) (env->NewGlobalRef(localTopicsList));
1451 if (!g_cls_TopicsList)
1453 NS_LOGE ("Failed to set Global TopicsList reference");
1457 jclass localTopicState = env->FindClass(
1458 "org/iotivity/service/ns/common/Topic$TopicState");
1459 if (!localTopicState)
1461 NS_LOGE ("Failed to get local TopicState enum");
1464 g_cls_TopicState = (jclass) (env->NewGlobalRef(localTopicState));
1465 if (!g_cls_TopicState)
1467 NS_LOGE ("Failed to set Global TopicState reference");
1472 jclass localOcRepresentation = env->FindClass("org/iotivity/base/OcRepresentation");
1473 if (!localOcRepresentation)
1475 NS_LOGE ("Failed to get local OcRepresentation class");
1478 g_cls_OcRepresentation = (jclass) env->NewGlobalRef(localOcRepresentation);
1479 if (!g_cls_OcRepresentation)
1481 NS_LOGE ("Failed to set Global OcRepresentation reference");
1485 g_mid_OcRepresentation_N_ctor_bool = env->GetMethodID(g_cls_OcRepresentation, "<init>", "(JZ)V");
1486 if (!g_mid_OcRepresentation_N_ctor_bool)
1488 NS_LOGE ("Failed to get Global OcRepresentation Constructor reference");
1492 env->DeleteLocalRef(localMessage);
1493 env->DeleteLocalRef(localMessageType);
1494 env->DeleteLocalRef(localConsumer);
1495 env->DeleteLocalRef(localSyncInfo);
1496 env->DeleteLocalRef(localSyncType);
1497 env->DeleteLocalRef(localMediaContents);
1498 env->DeleteLocalRef(localTopic);
1499 env->DeleteLocalRef(localTopicsList);
1500 env->DeleteLocalRef(localTopicState);
1501 env->DeleteLocalRef(localOcRepresentation);
1503 return NSExceptionInit(env);
1506 JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *jvm, void *reserved)
1508 NS_LOGD ("ProviderService_JNI_OnUnload");
1511 if (jvm->GetEnv((void **)&env, JNI_CURRENT_VERSION) != JNI_OK)
1513 NS_LOGE ("Failed to get the environment using GetEnv()");
1517 env->DeleteGlobalRef(g_cls_Message);
1518 env->DeleteGlobalRef(g_cls_Consumer);
1519 env->DeleteGlobalRef(g_cls_SyncInfo);
1520 env->DeleteGlobalRef(g_cls_SyncType);
1521 env->DeleteGlobalRef(g_cls_MediaContents);
1522 env->DeleteGlobalRef(g_cls_Message_Type);
1523 env->DeleteGlobalRef(g_cls_Topic);
1524 env->DeleteGlobalRef(g_cls_TopicsList);
1525 env->DeleteGlobalRef(g_cls_TopicState);
1526 env->DeleteGlobalRef(g_cls_OcRepresentation);