2 * //******************************************************************
4 * // Copyright 2015 Intel Corporation.
6 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
8 * // Licensed under the Apache License, Version 2.0 (the "License");
9 * // you may not use this file except in compliance with the License.
10 * // You may obtain a copy of the License at
12 * // http://www.apache.org/licenses/LICENSE-2.0
14 * // Unless required by applicable law or agreed to in writing, software
15 * // distributed under the License is distributed on an "AS IS" BASIS,
16 * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * // See the License for the specific language governing permissions and
18 * // limitations under the License.
20 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
23 #include "JniOcResource.h"
24 #include "JniOcRepresentation.h"
27 JniOcResource::JniOcResource(std::shared_ptr<OCResource> resource)
28 : m_sharedResource(resource)
32 JniOcResource::~JniOcResource()
34 LOGD("~JniOcResource()");
36 m_sharedResource = nullptr;
38 jint envRet = JNI_ERR;
39 JNIEnv *env = GetJNIEnv(envRet);
45 m_onGetManager.removeAllListeners(env);
46 m_onPutManager.removeAllListeners(env);
47 m_onPostManager.removeAllListeners(env);
48 m_onDeleteManager.removeAllListeners(env);
49 m_onObserveManager.removeAllListeners(env);
51 m_onFoundTopicResourceManager.removeAllListeners(env);
52 m_onSubcribeTopicManager.removeAllListeners(env);
55 if (JNI_EDETACHED == envRet)
57 g_jvm->DetachCurrentThread();
61 OCStackResult JniOcResource::get(JNIEnv* env, const QueryParamsMap &queryParametersMap, jobject jListener)
63 JniOnGetListener *onGetListener = addOnGetListener(env, jListener);
65 GetCallback getCallback = [onGetListener](
66 const HeaderOptions& opts,
67 const OCRepresentation& rep,
70 onGetListener->onGetCallback(opts, rep, eCode);
73 return m_sharedResource->get(queryParametersMap, getCallback);
76 OCStackResult JniOcResource::get(JNIEnv* env, const QueryParamsMap &queryParametersMap, jobject jListener,
79 JniOnGetListener *onGetListener = addOnGetListener(env, jListener);
81 GetCallback getCallback = [onGetListener](const HeaderOptions& opts, const OCRepresentation& rep,
84 onGetListener->onGetCallback(opts, rep, eCode);
87 return m_sharedResource->get(queryParametersMap, getCallback, QoS);
90 OCStackResult JniOcResource::get(
92 const std::string &resourceType,
93 const std::string &resourceInterface,
94 const QueryParamsMap &queryParametersMap,
97 JniOnGetListener *onGetListener = addOnGetListener(env, jListener);
99 GetCallback getCallback = [onGetListener](const HeaderOptions& opts,
100 const OCRepresentation& rep, const int eCode)
102 onGetListener->onGetCallback(opts, rep, eCode);
105 return m_sharedResource->get(resourceType, resourceInterface, queryParametersMap,
109 OCStackResult JniOcResource::get(JNIEnv* env, const std::string &resourceType,
110 const std::string &resourceInterface, const QueryParamsMap &queryParametersMap,
111 jobject jListener, QualityOfService QoS)
113 JniOnGetListener *onGetListener = addOnGetListener(env, jListener);
115 GetCallback getCallback = [onGetListener](const HeaderOptions& opts,
116 const OCRepresentation& rep, const int eCode)
118 onGetListener->onGetCallback(opts, rep, eCode);
121 return m_sharedResource->get(resourceType, resourceInterface, queryParametersMap,
125 OCStackResult JniOcResource::put(JNIEnv* env, const OCRepresentation &representation,
126 const QueryParamsMap &queryParametersMap, jobject jListener)
128 JniOnPutListener *onPutListener = addOnPutListener(env, jListener);
130 PutCallback putCallback = [onPutListener](const HeaderOptions& opts,
131 const OCRepresentation& rep, const int eCode)
133 onPutListener->onPutCallback(opts, rep, eCode);
136 return m_sharedResource->put(representation, queryParametersMap, putCallback);
139 OCStackResult JniOcResource::put(JNIEnv* env, const OCRepresentation &representation,
140 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
142 JniOnPutListener *onPutListener = addOnPutListener(env, jListener);
144 PutCallback putCallback = [onPutListener](const HeaderOptions& opts,
145 const OCRepresentation& rep, const int eCode)
147 onPutListener->onPutCallback(opts, rep, eCode);
150 return m_sharedResource->put(representation, queryParametersMap, putCallback, QoS);
153 OCStackResult JniOcResource::put(JNIEnv* env, const std::string &resourceType,
154 const std::string &resourceInterface, const OCRepresentation &representation,
155 const QueryParamsMap &queryParametersMap, jobject jListener)
157 JniOnPutListener *onPutListener = addOnPutListener(env, jListener);
159 PutCallback putCallback = [onPutListener](const HeaderOptions& opts,
160 const OCRepresentation& rep, const int eCode)
162 onPutListener->onPutCallback(opts, rep, eCode);
165 return m_sharedResource->put(resourceType, resourceInterface, representation,
166 queryParametersMap, putCallback);
169 OCStackResult JniOcResource::put(JNIEnv* env, const std::string &resourceType,
170 const std::string &resourceInterface, const OCRepresentation &representation,
171 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
173 JniOnPutListener *onPutListener = addOnPutListener(env, jListener);
175 PutCallback putCallback = [onPutListener](const HeaderOptions& opts,
176 const OCRepresentation& rep, const int eCode)
178 onPutListener->onPutCallback(opts, rep, eCode);
181 return m_sharedResource->put(resourceType, resourceInterface, representation,
182 queryParametersMap, putCallback, QoS);
185 OCStackResult JniOcResource::post(JNIEnv* env, const OCRepresentation &representation,
186 const QueryParamsMap &queryParametersMap, jobject jListener)
188 JniOnPostListener *onPostListener = addOnPostListener(env, jListener);
190 PostCallback postCallback = [onPostListener](const HeaderOptions& opts,
191 const OCRepresentation& rep, const int eCode)
193 onPostListener->onPostCallback(opts, rep, eCode);
196 return m_sharedResource->post(representation, queryParametersMap, postCallback);
199 OCStackResult JniOcResource::post(JNIEnv* env, const OCRepresentation &representation,
200 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
202 JniOnPostListener *onPostListener = addOnPostListener(env, jListener);
204 PostCallback postCallback = [onPostListener](const HeaderOptions& opts,
205 const OCRepresentation& rep, const int eCode)
207 onPostListener->onPostCallback(opts, rep, eCode);
210 return m_sharedResource->post(representation, queryParametersMap, postCallback, QoS);
213 OCStackResult JniOcResource::post(JNIEnv* env, const std::string &resourceType,
214 const std::string &resourceInterface, const OCRepresentation &representation,
215 const QueryParamsMap &queryParametersMap, jobject jListener)
217 JniOnPostListener *onPostListener = addOnPostListener(env, jListener);
219 PostCallback postCallback = [onPostListener](const HeaderOptions& opts,
220 const OCRepresentation& rep, const int eCode)
222 onPostListener->onPostCallback(opts, rep, eCode);
225 return m_sharedResource->post(resourceType, resourceInterface, representation,
226 queryParametersMap, postCallback);
229 OCStackResult JniOcResource::post(JNIEnv* env, const std::string &resourceType,
230 const std::string &resourceInterface, const OCRepresentation &representation,
231 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
233 JniOnPostListener *onPostListener = addOnPostListener(env, jListener);
235 PostCallback postCallback = [onPostListener](const HeaderOptions& opts,
236 const OCRepresentation& rep, const int eCode)
238 onPostListener->onPostCallback(opts, rep, eCode);
241 return m_sharedResource->post(resourceType, resourceInterface, representation,
242 queryParametersMap, postCallback, QoS);
245 OCStackResult JniOcResource::deleteResource(JNIEnv* env, jobject jListener)
247 JniOnDeleteListener *onDeleteListener = addOnDeleteListener(env, jListener);
249 DeleteCallback deleteCallback = [onDeleteListener](const HeaderOptions& opts,
252 onDeleteListener->onDeleteCallback(opts, eCode);
255 return m_sharedResource->deleteResource(deleteCallback);
258 OCStackResult JniOcResource::deleteResource(JNIEnv* env, jobject jListener, QualityOfService QoS)
260 JniOnDeleteListener *onDeleteListener = addOnDeleteListener(env, jListener);
262 DeleteCallback deleteCallback = [onDeleteListener](const HeaderOptions& opts, const int eCode)
264 onDeleteListener->onDeleteCallback(opts, eCode);
267 return m_sharedResource->deleteResource(deleteCallback, QoS);
270 OCStackResult JniOcResource::observe(JNIEnv* env, ObserveType observeType,
271 const QueryParamsMap &queryParametersMap, jobject jListener)
273 JniOnObserveListener *onObserveListener = addOnObserveListener(env, jListener);
275 ObserveCallback observeCallback = [onObserveListener](const HeaderOptions& opts,
276 const OCRepresentation& rep, const int& eCode, const int& sequenceNumber)
278 onObserveListener->onObserveCallback(opts, rep, eCode, sequenceNumber);
281 return m_sharedResource->observe(observeType, queryParametersMap, observeCallback);
284 OCStackResult JniOcResource::observe(JNIEnv* env, ObserveType observeType,
285 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
287 JniOnObserveListener *onObserveListener = addOnObserveListener(env, jListener);
289 ObserveCallback observeCallback = [onObserveListener](const HeaderOptions& opts,
290 const OCRepresentation& rep, const int& eCode, const int& sequenceNumber)
292 onObserveListener->onObserveCallback(opts, rep, eCode, sequenceNumber);
295 return m_sharedResource->observe(observeType, queryParametersMap, observeCallback, QoS);
298 OCStackResult JniOcResource::cancelObserve(JNIEnv* env, QualityOfService qos)
300 // In Low case, after delete the callback and send empty message when client receive the notify.
301 // But TCP does not support EMPTY message.
302 if ((CT_ADAPTER_IP & connectivityType()) && QualityOfService::HighQos != qos)
304 this->m_onObserveManager.removeAllListeners(env);
306 return m_sharedResource->cancelObserve(qos);
309 void JniOcResource::setHeaderOptions(const HeaderOptions &headerOptions)
311 m_sharedResource->setHeaderOptions(headerOptions);
314 void JniOcResource::unsetHeaderOptions()
316 m_sharedResource->unsetHeaderOptions();
319 std::string JniOcResource::host()
321 return m_sharedResource->host();
324 std::string JniOcResource::uri()
326 return m_sharedResource->uri();
329 OCConnectivityType JniOcResource::connectivityType() const
331 return m_sharedResource->connectivityType();
334 bool JniOcResource::isObservable()
336 return m_sharedResource->isObservable();
339 std::vector< std::string > JniOcResource::getResourceTypes() const
341 return m_sharedResource->getResourceTypes();
344 std::vector< std::string > JniOcResource::getResourceInterfaces(void) const
346 return m_sharedResource->getResourceInterfaces();
349 OCResourceIdentifier JniOcResource::uniqueIdentifier() const
351 return m_sharedResource->uniqueIdentifier();
354 std::string JniOcResource::sid() const
356 return m_sharedResource->sid();
359 std::string JniOcResource::deviceName() const
361 return m_sharedResource->deviceName();
364 JniOnGetListener* JniOcResource::addOnGetListener(JNIEnv* env, jobject jListener)
366 return this->m_onGetManager.addListener(env, jListener, this);
369 JniOnPutListener* JniOcResource::addOnPutListener(JNIEnv* env, jobject jListener)
371 return this->m_onPutManager.addListener(env, jListener, this);
374 JniOnPostListener* JniOcResource::addOnPostListener(JNIEnv* env, jobject jListener)
376 return this->m_onPostManager.addListener(env, jListener, this);
379 JniOnDeleteListener* JniOcResource::addOnDeleteListener(JNIEnv* env, jobject jListener)
381 return this->m_onDeleteManager.addListener(env, jListener, this);
384 JniOnObserveListener* JniOcResource::addOnObserveListener(JNIEnv* env, jobject jListener)
386 return this->m_onObserveManager.addListener(env, jListener, this);
389 void JniOcResource::removeOnGetListener(JNIEnv* env, jobject jListener)
391 this->m_onGetManager.removeListener(env, jListener);
394 void JniOcResource::removeOnPutListener(JNIEnv* env, jobject jListener)
396 this->m_onPutManager.removeListener(env, jListener);
399 void JniOcResource::removeOnPostListener(JNIEnv* env, jobject jListener)
401 this->m_onPostManager.removeListener(env, jListener);
404 void JniOcResource::removeOnDeleteListener(JNIEnv* env, jobject jListener)
406 this->m_onDeleteManager.removeListener(env, jListener);
409 void JniOcResource::removeOnObserveListener(JNIEnv* env, jobject jListener)
411 this->m_onObserveManager.removeListener(env, jListener);
415 JniOnMQTopicFoundListener* JniOcResource::addOnTopicFoundListener(JNIEnv* env, jobject jListener)
417 return this->m_onFoundTopicResourceManager.addListener(env, jListener, this);
420 void JniOcResource::removeOnTopicFoundListener(JNIEnv* env, jobject jListener)
422 this->m_onFoundTopicResourceManager.removeListener(env, jListener);
425 JniOnMQSubscribeListener* JniOcResource::addOnMQTopicSubscribeListener(JNIEnv* env, jobject jListener)
427 return this->m_onSubcribeTopicManager.addListener(env, jListener, this);
430 void JniOcResource::removeOnMQTopicSubscribeListener(JNIEnv* env, jobject jListener)
432 this->m_onSubcribeTopicManager.removeListener(env, jListener);
436 std::shared_ptr<OCResource> JniOcResource::getOCResource()
438 return this->m_sharedResource;
441 JniOcResource* JniOcResource::getJniOcResourcePtr(JNIEnv *env, jobject thiz)
443 JniOcResource *resource = GetHandle<JniOcResource>(env, thiz);
444 if (env->ExceptionCheck())
446 LOGE("Failed to get native handle from OcResource");
450 ThrowOcException(JNI_NO_NATIVE_POINTER, "");
456 OCStackResult JniOcResource::discoveryMQTopics(JNIEnv* env,
457 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
459 JniOnMQTopicFoundListener *onTopicFoundListener = addOnTopicFoundListener(env, jListener);
461 MQTopicCallback findCallback = [onTopicFoundListener](const int& eCode,
462 const std::string& uri, std::shared_ptr<OCResource> resource)
464 onTopicFoundListener->foundTopicCallback(eCode, uri, resource);
467 return m_sharedResource->discoveryMQTopics(queryParametersMap, findCallback, QoS);
470 OCStackResult JniOcResource::createMQTopic(JNIEnv* env,
471 const OCRepresentation &representation, const std::string &targetUri,
472 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
474 JniOnMQTopicFoundListener *onTopicCreatedListener = addOnTopicFoundListener(env, jListener);
476 MQTopicCallback createCallback = [onTopicCreatedListener](const int& eCode,
477 const std::string& uri, std::shared_ptr<OCResource> resource)
479 onTopicCreatedListener->createdTopicCallback(eCode, uri, resource);
482 return m_sharedResource->createMQTopic(representation, targetUri,
484 createCallback, QoS);
488 OCStackResult JniOcResource::subscribeMQTopic(JNIEnv* env,
489 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
491 JniOnMQSubscribeListener *onSubscribeListener = addOnMQTopicSubscribeListener(env, jListener);
493 ObserveCallback subscribeCallback = [onSubscribeListener](const HeaderOptions& opts,
494 const OCRepresentation& rep, const int& eCode, const int& sequenceNumber)
496 onSubscribeListener->onSubscribeCallback(opts, rep, eCode, sequenceNumber);
499 return m_sharedResource->subscribeMQTopic(ObserveType::Observe, queryParametersMap,
500 subscribeCallback, QoS);
503 OCStackResult JniOcResource::unsubscribeMQTopic(QualityOfService QoS)
505 return m_sharedResource->unsubscribeMQTopic(QoS);
508 OCStackResult JniOcResource::requestMQPublish(JNIEnv* env,
509 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
511 JniOnPostListener *onPostListener = addOnPostListener(env, jListener);
513 PostCallback postCallback = [onPostListener](const HeaderOptions& opts,
514 const OCRepresentation& rep, const int eCode)
516 onPostListener->onPostCallback(opts, rep, eCode);
519 return m_sharedResource->requestMQPublish(queryParametersMap, postCallback, QoS);
523 OCStackResult JniOcResource::publishMQTopic(JNIEnv* env, const OCRepresentation &representation,
524 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
526 JniOnPostListener *onPostListener = addOnPostListener(env, jListener);
528 PostCallback postCallback = [onPostListener](const HeaderOptions& opts,
529 const OCRepresentation& rep, const int eCode)
531 onPostListener->onPostCallback(opts, rep, eCode);
534 return m_sharedResource->publishMQTopic(representation, queryParametersMap,
540 * Class: org_iotivity_base_OcResource
542 * Signature: (Ljava/util/Map;Lorg/iotivity/base/OcResource/OnGetListener;)V
544 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_get
545 (JNIEnv *env, jobject thiz, jobject jQueryParamsMap, jobject jListener)
547 LOGD("OcResource_get");
548 if (!jQueryParamsMap)
550 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
555 ThrowOcException(OC_STACK_INVALID_PARAM, "onGetListener cannot be null");
558 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
565 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
569 OCStackResult result = resource->get(
574 if (OC_STACK_OK != result)
576 ThrowOcException(result, "OcResource_get");
579 catch (OCException& e)
581 LOGE("%s", e.reason().c_str());
582 ThrowOcException(e.code(), e.reason().c_str());
587 * Class: org_iotivity_base_OcResource
589 * Signature: (Ljava/util/Map;Lorg/iotivity/base/OcResource/OnGetListener;I)V
591 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_get1
592 (JNIEnv *env, jobject thiz, jobject jQueryParamsMap, jobject jListener, jint jQoS)
594 LOGD("OcResource_get");
595 if (!jQueryParamsMap)
597 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
602 ThrowOcException(OC_STACK_INVALID_PARAM, "onGetListener cannot be null");
605 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
612 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
616 OCStackResult result = resource->get(
620 JniUtils::getQOS(env, static_cast<int>(jQoS)));
622 if (OC_STACK_OK != result)
624 ThrowOcException(result, "OcResource_get");
627 catch (OCException& e)
629 LOGE("%s", e.reason().c_str());
630 ThrowOcException(e.code(), e.reason().c_str());
635 * Class: org_iotivity_base_OcResource
637 * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;
638 Lorg/iotivity/base/OcResource/OnGetListener;)V
640 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_get2
641 (JNIEnv *env, jobject thiz, jstring jResourceType, jstring jResourceInterface,
642 jobject jQueryParamsMap, jobject jListener)
644 LOGD("OcResource_get");
645 std::string resourceType;
648 resourceType = env->GetStringUTFChars(jResourceType, nullptr);
650 std::string resourceInterface;
651 if (jResourceInterface)
653 resourceInterface = env->GetStringUTFChars(jResourceInterface, nullptr);
655 if (!jQueryParamsMap)
657 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
662 ThrowOcException(OC_STACK_INVALID_PARAM, "onGetListener cannot be null");
665 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
672 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
675 OCStackResult result = resource->get(
682 if (OC_STACK_OK != result)
684 ThrowOcException(result, "OcResource_get");
687 catch (OCException& e)
689 LOGE("%s", e.reason().c_str());
690 ThrowOcException(e.code(), e.reason().c_str());
695 * Class: org_iotivity_base_OcResource
697 * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;
698 Lorg/iotivity/base/OcResource/OnGetListener;I)V
700 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_get3
701 (JNIEnv *env, jobject thiz, jstring jResourceType, jstring jResourceInterface,
702 jobject jQueryParamsMap, jobject jListener, jint jQoS)
704 LOGD("OcResource_get");
705 if (!jQueryParamsMap)
707 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
712 ThrowOcException(OC_STACK_INVALID_PARAM, "onGetListener cannot be null");
715 std::string resourceType;
718 resourceType = env->GetStringUTFChars(jResourceType, nullptr);
720 std::string resourceInterface;
721 if (jResourceInterface)
723 resourceInterface = env->GetStringUTFChars(jResourceInterface, nullptr);
725 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
732 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
736 OCStackResult result = resource->get(
742 JniUtils::getQOS(env, static_cast<int>(jQoS)));
744 if (OC_STACK_OK != result)
746 ThrowOcException(result, "OcResource_get");
749 catch (OCException& e)
751 LOGE("%s", e.reason().c_str());
752 ThrowOcException(e.code(), e.reason().c_str());
757 * Class: org_iotivity_base_OcResource
759 * Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/Map;
760 Lorg/iotivity/base/OcResource/OnPutListener;)V
762 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_put
763 (JNIEnv *env, jobject thiz, jobject jRepresentation, jobject jQueryParamsMap, jobject jListener)
765 LOGD("OcResource_put");
766 if (!jRepresentation)
768 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
771 if (!jQueryParamsMap)
773 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
778 ThrowOcException(OC_STACK_INVALID_PARAM, "onPutListener cannot be null");
781 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
787 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
794 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
798 OCStackResult result = resource->put(
804 if (OC_STACK_OK != result)
806 ThrowOcException(result, "OcResource_put");
809 catch (OCException& e)
811 LOGE("%s", e.reason().c_str());
812 ThrowOcException(e.code(), e.reason().c_str());
817 * Class: org_iotivity_base_OcResource
819 * Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/Map;
820 Lorg/iotivity/base/OcResource/OnPutListener;I)V
822 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_put1
823 (JNIEnv *env, jobject thiz, jobject jRepresentation, jobject jQueryParamsMap,
824 jobject jListener, jint jQoS)
826 LOGD("OcResource_put");
827 if (!jRepresentation)
829 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
832 if (!jQueryParamsMap)
834 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
839 ThrowOcException(OC_STACK_INVALID_PARAM, "onPutListener cannot be null");
842 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
848 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
855 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
859 OCStackResult result = resource->put(
864 JniUtils::getQOS(env, static_cast<int>(jQoS)));
866 if (OC_STACK_OK != result)
868 ThrowOcException(result, "OcResource_put");
871 catch (OCException& e)
873 LOGE("%s", e.reason().c_str());
874 ThrowOcException(e.code(), e.reason().c_str());
879 * Class: org_iotivity_base_OcResource
881 * Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcRepresentation;
882 Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPutListener;)V
884 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_put2
885 (JNIEnv *env, jobject thiz, jstring jResourceType, jstring jResourceInterface,
886 jobject jRepresentation, jobject jQueryParamsMap, jobject jListener)
888 LOGD("OcResource_put");
889 std::string resourceType;
892 resourceType = env->GetStringUTFChars(jResourceType, nullptr);
894 std::string resourceInterface;
895 if (jResourceInterface)
897 resourceInterface = env->GetStringUTFChars(jResourceInterface, nullptr);
899 if (!jRepresentation)
901 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
904 if (!jQueryParamsMap)
906 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
911 ThrowOcException(OC_STACK_INVALID_PARAM, "onPutListener cannot be null");
914 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
920 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
927 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
931 OCStackResult result = resource->put(
939 if (OC_STACK_OK != result)
941 ThrowOcException(result, "OcResource_put");
944 catch (OCException& e)
946 LOGE("%s", e.reason().c_str());
947 ThrowOcException(e.code(), e.reason().c_str());
952 * Class: org_iotivity_base_OcResource
954 * Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcRepresentation;
955 Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPutListener;I)V
957 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_put3
958 (JNIEnv *env, jobject thiz, jstring jResourceType, jstring jResourceInterface, jobject jRepresentation,
959 jobject jQueryParamsMap, jobject jListener, jint jQoS)
961 LOGD("OcResource_put");
962 if (!jRepresentation)
964 ThrowOcException(OC_STACK_INVALID_PARAM, "representation cannot be null");
967 if (!jQueryParamsMap)
969 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
974 ThrowOcException(OC_STACK_INVALID_PARAM, "onPutListener cannot be null");
977 std::string resourceType;
980 resourceType = env->GetStringUTFChars(jResourceType, nullptr);
982 std::string resourceInterface;
983 if (jResourceInterface)
985 resourceInterface = env->GetStringUTFChars(jResourceInterface, nullptr);
988 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
994 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
1001 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1005 OCStackResult result = resource->put(
1012 JniUtils::getQOS(env, static_cast<int>(jQoS)));
1014 if (OC_STACK_OK != result)
1016 ThrowOcException(result, "OcResource_put");
1019 catch (OCException& e)
1021 LOGE("%s", e.reason().c_str());
1022 ThrowOcException(e.code(), e.reason().c_str());
1027 * Class: org_iotivity_base_OcResource
1029 * Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPostListener;)V
1031 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_post
1032 (JNIEnv *env, jobject thiz, jobject jRepresentation, jobject jQueryParamsMap, jobject jListener)
1034 LOGD("OcResource_post");
1035 if (!jRepresentation)
1037 ThrowOcException(OC_STACK_INVALID_PARAM, "representation cannot be null");
1040 if (!jQueryParamsMap)
1042 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1047 ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null");
1050 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1056 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
1057 if (!representation)
1063 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1067 OCStackResult result = resource->post(
1073 if (OC_STACK_OK != result)
1075 ThrowOcException(result, "OcResource_post");
1078 catch (OCException& e)
1080 LOGE("%s", e.reason().c_str());
1081 ThrowOcException(e.code(), e.reason().c_str());
1086 * Class: org_iotivity_base_OcResource
1088 * Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPostListener;I)V
1090 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_post1
1091 (JNIEnv *env, jobject thiz, jobject jRepresentation, jobject jQueryParamsMap, jobject jListener, jint jQoS)
1093 LOGD("OcResource_post");
1094 if (!jRepresentation)
1096 ThrowOcException(OC_STACK_INVALID_PARAM, "representation cannot be null");
1099 if (!jQueryParamsMap)
1101 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1106 ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null");
1109 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1115 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
1116 if (!representation)
1122 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1126 OCStackResult result = resource->post(
1131 JniUtils::getQOS(env, static_cast<int>(jQoS)));
1133 if (OC_STACK_OK != result)
1135 ThrowOcException(result, "OcResource_post");
1138 catch (OCException& e)
1140 LOGE("%s", e.reason().c_str());
1141 ThrowOcException(e.code(), e.reason().c_str());
1146 * Class: org_iotivity_base_OcResource
1148 * Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcRepresentation;
1149 Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPostListener;)V
1151 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_post2
1152 (JNIEnv *env, jobject thiz, jstring jResourceType, jstring jResourceInterface,
1153 jobject jRepresentation, jobject jQueryParamsMap, jobject jListener)
1155 LOGD("OcResource_post");
1156 if (!jRepresentation)
1158 ThrowOcException(OC_STACK_INVALID_PARAM, "representation cannot be null");
1161 if (!jQueryParamsMap)
1163 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1168 ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null");
1171 std::string resourceType;
1174 resourceType = env->GetStringUTFChars(jResourceType, nullptr);
1176 std::string resourceInterface;
1177 if (jResourceInterface)
1179 resourceInterface = env->GetStringUTFChars(jResourceInterface, nullptr);
1182 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1188 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
1189 if (!representation)
1195 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1199 OCStackResult result = resource->post(
1207 if (OC_STACK_OK != result)
1209 ThrowOcException(result, "OcResource_post");
1212 catch (OCException& e)
1214 LOGE("%s", e.reason().c_str());
1215 ThrowOcException(e.code(), e.reason().c_str());
1220 * Class: org_iotivity_base_OcResource
1222 * Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcRepresentation;
1223 Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPostListener;I)V
1225 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_post3
1226 (JNIEnv *env, jobject thiz, jstring jResourceType, jstring jResourceInterface,
1227 jobject jRepresentation, jobject jQueryParamsMap, jobject jListener, jint jQoS)
1229 LOGD("OcResource_post");
1230 if (!jRepresentation)
1232 ThrowOcException(OC_STACK_INVALID_PARAM, "representation cannot be null");
1235 if (!jQueryParamsMap)
1237 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1242 ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null");
1245 std::string resourceType;
1248 resourceType = env->GetStringUTFChars(jResourceType, nullptr);
1250 std::string resourceInterface;
1251 if (jResourceInterface)
1253 resourceInterface = env->GetStringUTFChars(jResourceInterface, nullptr);
1256 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1262 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
1263 if (!representation)
1269 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1273 OCStackResult result = resource->post(
1280 JniUtils::getQOS(env, static_cast<int>(jQoS)));
1282 if (OC_STACK_OK != result)
1284 ThrowOcException(result, "OcResource_post");
1287 catch (OCException& e)
1289 LOGE("%s", e.reason().c_str());
1290 ThrowOcException(e.code(), e.reason().c_str());
1295 * Class: org_iotivity_base_OcResource
1296 * Method: deleteResource
1297 * Signature: (Lorg/iotivity/base/OcResource/OnDeleteListener;)V
1299 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_deleteResource
1300 (JNIEnv *env, jobject thiz, jobject jListener)
1302 LOGD("OcResource_deleteResource");
1305 ThrowOcException(OC_STACK_INVALID_PARAM, "onDeleteListener cannot be null");
1308 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1316 OCStackResult result = resource->deleteResource(
1320 if (OC_STACK_OK != result)
1322 ThrowOcException(result, "OcResource_deleteResource");
1325 catch (OCException& e)
1327 LOGE("%s", e.reason().c_str());
1328 ThrowOcException(e.code(), e.reason().c_str());
1333 * Class: org_iotivity_base_OcResource
1334 * Method: deleteResource1
1335 * Signature: (Lorg/iotivity/base/OcResource/OnDeleteListener;I)V
1337 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_deleteResource1
1338 (JNIEnv *env, jobject thiz, jobject jListener, jint jQoS)
1340 LOGD("OcResource_deleteResource");
1343 ThrowOcException(OC_STACK_INVALID_PARAM, "onDeleteListener cannot be null");
1346 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1354 OCStackResult result = resource->deleteResource(
1357 JniUtils::getQOS(env, static_cast<int>(jQoS)));
1359 if (OC_STACK_OK != result)
1361 ThrowOcException(result, "OcResource_deleteResource");
1364 catch (OCException& e)
1366 LOGE("%s", e.reason().c_str());
1367 ThrowOcException(e.code(), e.reason().c_str());
1372 * Class: org_iotivity_base_OcResource
1374 * Signature: (Lorg/iotivity/base/ObserveType;Ljava/util/Map;
1375 Lorg/iotivity/base/OcResource/OnObserveListener;)V
1377 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_observe
1378 (JNIEnv *env, jobject thiz, jint observeType, jobject jQueryParamsMap, jobject jListener)
1380 LOGD("OcResource_observe");
1381 if (!jQueryParamsMap)
1383 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1388 ThrowOcException(OC_STACK_INVALID_PARAM, "onObserveListener cannot be null");
1391 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1398 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1402 OCStackResult result = resource->observe(
1404 JniUtils::getObserveType(env, static_cast<int>(observeType)),
1408 if (OC_STACK_OK != result)
1410 ThrowOcException(result, "OcResource_observe");
1413 catch (OCException& e)
1415 LOGE("%s", e.reason().c_str());
1416 ThrowOcException(e.code(), e.reason().c_str());
1421 * Class: org_iotivity_base_OcResource
1423 * Signature: (Lorg/iotivity/base/ObserveType;Ljava/util/Map;
1424 Lorg/iotivity/base/OcResource/OnObserveListener;I)V
1426 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_observe1
1427 (JNIEnv *env, jobject thiz, jint observeType, jobject jQueryParamsMap,
1428 jobject jListener, jint jQoS)
1430 LOGD("OcResource_observe");
1431 if (!jQueryParamsMap)
1433 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1438 ThrowOcException(OC_STACK_INVALID_PARAM, "onObserveListener cannot be null");
1441 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1448 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1452 OCStackResult result = resource->observe(
1454 JniUtils::getObserveType(env, static_cast<int>(observeType)),
1457 JniUtils::getQOS(env, static_cast<int>(jQoS)));
1459 if (OC_STACK_OK != result)
1461 ThrowOcException(result, "OcResource_observe");
1464 catch (OCException& e)
1466 LOGE("%s", e.reason().c_str());
1467 ThrowOcException(e.code(), e.reason().c_str());
1472 * Class: org_iotivity_base_OcResource
1473 * Method: cancelObserve1
1476 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_cancelObserve1
1477 (JNIEnv *env, jobject thiz, jint jQoS)
1479 LOGD("OcResource_cancelObserve1");
1480 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1488 OCStackResult result = resource->cancelObserve(
1490 JniUtils::getQOS(env, static_cast<int>(jQoS)));
1492 if (OC_STACK_OK != result)
1494 ThrowOcException(result, "OcResource_cancelObserve");
1497 catch (OCException& e)
1499 LOGE("%s", e.reason().c_str());
1500 ThrowOcException(e.code(), e.reason().c_str());
1505 * Class: org_iotivity_base_OcResource
1506 * Method: setHeaderOptions
1507 * Signature: ([Lorg/iotivity/OcHeaderOption;)V
1509 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_setHeaderOptions
1510 (JNIEnv *env, jobject thiz, jobjectArray jheaderOptionArr)
1512 LOGD("OcResource_setHeaderOptions");
1513 if (!jheaderOptionArr)
1515 ThrowOcException(OC_STACK_INVALID_PARAM, "headerOptionList cannot be null");
1518 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1524 HeaderOptions headerOptions;
1525 JniUtils::convertJavaHeaderOptionsArrToVector(env, jheaderOptionArr, headerOptions);
1527 resource->setHeaderOptions(headerOptions);
1531 * Class: org_iotivity_base_OcResource
1532 * Method: unsetHeaderOptions
1535 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_unsetHeaderOptions
1536 (JNIEnv *env, jobject thiz)
1538 LOGD("OcResource_unsetHeaderOptions");
1539 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1545 resource->unsetHeaderOptions();
1549 * Class: org_iotivity_base_OcResource
1551 * Signature: ()Ljava/lang/String;
1553 JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcResource_getHost
1554 (JNIEnv *env, jobject thiz)
1556 LOGD("OcResource_getHost");
1557 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1563 return env->NewStringUTF(resource->host().c_str());
1567 * Class: org_iotivity_base_OcResource
1569 * Signature: ()Ljava/lang/String;
1571 JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcResource_getUri
1572 (JNIEnv *env, jobject thiz)
1574 LOGD("OcResource_getUri");
1575 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1581 return env->NewStringUTF(resource->uri().c_str());
1585 * Class: org_iotivity_base_OcResource
1586 * Method: getConnectivityTypeN
1589 JNIEXPORT jint JNICALL Java_org_iotivity_base_OcResource_getConnectivityTypeN
1590 (JNIEnv *env, jobject thiz)
1592 LOGD("OcResource_getConnectivityType");
1593 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1599 OCConnectivityType connectivityType = resource->connectivityType();
1600 return static_cast<jint>(connectivityType);
1604 * Class: org_iotivity_base_OcResource
1605 * Method: isObservable
1608 JNIEXPORT jboolean JNICALL Java_org_iotivity_base_OcResource_isObservable
1609 (JNIEnv *env, jobject thiz)
1611 LOGD("OcResource_isObservable");
1612 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1618 return (jboolean)resource->isObservable();
1622 * Class: org_iotivity_base_OcResource
1623 * Method: getResourceTypes
1624 * Signature: ()Ljava/util/List;
1626 JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcResource_getResourceTypes
1627 (JNIEnv *env, jobject thiz)
1629 LOGD("OcResource_getResourceTypes");
1630 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1636 std::vector<std::string> resourceTypes = resource->getResourceTypes();
1638 return JniUtils::convertStrVectorToJavaStrList(env, resourceTypes);
1642 * Class: org_iotivity_base_OcResource
1643 * Method: getResourceInterfaces
1644 * Signature: ()Ljava/util/List;
1646 JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcResource_getResourceInterfaces
1647 (JNIEnv *env, jobject thiz)
1649 LOGD("OcResource_getResourceInterfaces");
1650 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1656 std::vector<std::string> resourceInterfaces = resource->getResourceInterfaces();
1658 return JniUtils::convertStrVectorToJavaStrList(env, resourceInterfaces);
1662 * Class: org_iotivity_base_OcResource
1663 * Method: getUniqueIdentifier
1664 * Signature: ()Lorg/iotivity/base/OcResourceIdentifier;
1666 JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcResource_getUniqueIdentifier
1667 (JNIEnv *env, jobject thiz)
1669 LOGD("OcResource_getUniqueIdentifier");
1670 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1676 JniOcResourceIdentifier *jniResourceIdentifier =
1677 new JniOcResourceIdentifier(resource->uniqueIdentifier());
1678 if (!jniResourceIdentifier)
1683 jlong handle = reinterpret_cast<jlong>(jniResourceIdentifier);
1684 jobject jResourceIdentifier = env->NewObject(g_cls_OcResourceIdentifier,
1685 g_mid_OcResourceIdentifier_N_ctor, handle);
1686 if (!jResourceIdentifier)
1688 delete jniResourceIdentifier;
1690 return jResourceIdentifier;
1694 * Class: org_iotivity_base_OcResource
1695 * Method: getServerId
1696 * Signature: ()Ljava/lang/String;
1698 JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcResource_getServerId
1699 (JNIEnv *env, jobject thiz)
1701 LOGD("OcResource_getServerId");
1702 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1708 return env->NewStringUTF(resource->sid().c_str());
1712 * Class: org_iotivity_base_OcResource
1713 * Method: getDeviceName
1714 * Signature: ()Ljava/lang/String;
1716 JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcResource_getDeviceName
1717 (JNIEnv *env, jobject thiz)
1719 LOGD("OcResource_getDeviceName");
1720 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1726 return env->NewStringUTF(resource->deviceName().c_str());
1730 * Class: org_iotivity_base_OcResource
1734 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_dispose
1735 (JNIEnv *env, jobject thiz)
1737 LOGD("OcResource_dispose");
1738 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1743 * Class: org_iotivity_base_OcResource
1744 * Method: discoveryMQTopicsImpl
1745 * Signature: (Ljava/util/Map;Lorg/iotivity/base/OcPlatform/OnResourceFoundListener;I)V
1747 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_discoveryMQTopicsImpl
1748 (JNIEnv *env, jobject thiz, jobject jQueryParamsMap, jobject jListener, jint jQoS)
1750 LOGD("OcResource_discoveryMQTopicsImpl");
1753 if (!jQueryParamsMap)
1755 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1761 ThrowOcException(OC_STACK_INVALID_PARAM, "listener cannot be null");
1765 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1772 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1776 OCStackResult result = resource->discoveryMQTopics(
1780 JniUtils::getQOS(env, static_cast<int>(jQoS)));
1782 if (OC_STACK_OK != result)
1784 ThrowOcException(result, "OcResource_discoveryMQTopicsImpl");
1787 catch (OCException& e)
1789 LOGE("%s", e.reason().c_str());
1790 ThrowOcException(e.code(), e.reason().c_str());
1793 ThrowOcException(JNI_NO_SUPPORT, "not support");
1798 * Class: org_iotivity_base_OcResource
1799 * Method: createMQTopicImpl
1800 * Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/String;Ljava/util/Map
1801 * ;Lorg/iotivity/base/OcPlatform/OnMQTopicCreatedListener;I)V
1803 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_createMQTopicImpl
1804 (JNIEnv *env, jobject thiz, jobject jRepresentation, jstring jUri,
1805 jobject jQueryParamsMap, jobject jListener, jint jQoS)
1807 LOGD("OcResource_createMQTopicImpl");
1810 if (!jQueryParamsMap)
1812 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1818 ThrowOcException(OC_STACK_INVALID_PARAM, "listener cannot be null");
1822 if (!jRepresentation)
1824 ThrowOcException(OC_STACK_INVALID_PARAM, "representation null");
1828 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1834 std::string targetUri;
1837 targetUri = env->GetStringUTFChars(jUri, nullptr);
1840 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env,
1842 if (!representation)
1848 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1852 OCStackResult result = resource->createMQTopic(
1858 JniUtils::getQOS(env, static_cast<int>(jQoS)));
1860 if (OC_STACK_OK != result)
1862 ThrowOcException(result, "OcResource_createMQTopicImpl");
1865 catch (OCException& e)
1867 LOGE("%s", e.reason().c_str());
1868 ThrowOcException(e.code(), e.reason().c_str());
1871 ThrowOcException(JNI_NO_SUPPORT, "not support");
1876 * Class: org_iotivity_base_OcResource
1877 * Method: subscribeMQTopic
1878 * Signature: (Ljava/util/Map;Lorg/iotivity/base/OcResource/OnObserveListener;I)V
1880 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_subscribeMQTopicImpl
1881 (JNIEnv *env, jobject thiz, jobject jQueryParamsMap, jobject jListener, jint jQoS)
1883 LOGD("OcResource_subscribeMQTopicImpl");
1884 #ifdef MQ_SUBSCRIBER
1885 if (!jQueryParamsMap)
1887 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1892 ThrowOcException(OC_STACK_INVALID_PARAM, "onObserveListener cannot be null");
1895 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1902 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1906 OCStackResult result = resource->subscribeMQTopic(
1910 JniUtils::getQOS(env, static_cast<int>(jQoS)));
1912 if (OC_STACK_OK != result)
1914 ThrowOcException(result, "OcResource_subscribeMQTopicImpl");
1917 catch (OCException& e)
1919 LOGE("%s", e.reason().c_str());
1920 ThrowOcException(e.code(), e.reason().c_str());
1923 ThrowOcException(JNI_NO_SUPPORT, "not support");
1928 * Class: org_iotivity_base_OcResource
1929 * Method: unsubscribeMQTopicImpl
1932 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_unsubscribeMQTopicImpl
1933 (JNIEnv *env, jobject thiz, jint jQoS)
1935 LOGD("OcResource_unsubscribeMQTopicImpl");
1936 #ifdef MQ_SUBSCRIBER
1937 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1945 OCStackResult result = resource->unsubscribeMQTopic(
1946 JniUtils::getQOS(env, static_cast<int>(jQoS)));
1947 if (OC_STACK_OK != result)
1949 ThrowOcException(result, "OcResource_unsubscribeMQTopicImpl");
1952 catch (OCException& e)
1954 LOGE("%s", e.reason().c_str());
1955 ThrowOcException(e.code(), e.reason().c_str());
1958 ThrowOcException(JNI_NO_SUPPORT, "not support");
1963 * Class: org_iotivity_base_OcResource
1964 * Method: requestMQPublishImpl
1965 * Signature: (Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPostListener;I)V
1967 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_requestMQPublishImpl
1968 (JNIEnv *env, jobject thiz, jobject jQueryParamsMap, jobject jListener, jint jQoS)
1970 LOGD("OcResource_requestMQPublishImpl");
1971 #ifdef MQ_SUBSCRIBER
1972 if (!jQueryParamsMap)
1974 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1979 ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null");
1983 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1990 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1994 OCStackResult result = resource->requestMQPublish(
1998 JniUtils::getQOS(env, static_cast<int>(jQoS)));
2000 if (OC_STACK_OK != result)
2002 ThrowOcException(result, "OcResource_requestMQPublishImpl");
2005 catch (OCException& e)
2007 LOGE("%s", e.reason().c_str());
2008 ThrowOcException(e.code(), e.reason().c_str());
2011 ThrowOcException(JNI_NO_SUPPORT, "not support");
2016 * Class: org_iotivity_base_OcResource
2017 * Method: publishMQTopicImpl
2018 * Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/Map;
2019 * Lorg/iotivity/base/OcResource/OnPostListener;I)V
2021 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_publishMQTopicImpl
2022 (JNIEnv *env, jobject thiz, jobject jRepresentation, jobject jQueryParamsMap,
2023 jobject jListener, jint jQoS)
2025 LOGD("OcResource_publishMQTopicImpl");
2027 if (!jRepresentation)
2029 ThrowOcException(OC_STACK_INVALID_PARAM, "representation cannot be null");
2033 if (!jQueryParamsMap)
2035 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
2041 ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null");
2045 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
2051 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env,
2053 if (!representation)
2059 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
2063 OCStackResult result = resource->publishMQTopic(
2068 JniUtils::getQOS(env, static_cast<int>(jQoS)));
2070 if (OC_STACK_OK != result)
2072 ThrowOcException(result, "OcResource_publishMQTopicImpl");
2075 catch (OCException& e)
2077 LOGE("%s", e.reason().c_str());
2078 ThrowOcException(e.code(), e.reason().c_str());
2081 ThrowOcException(JNI_NO_SUPPORT, "not support");