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 JniOnGetListener* JniOcResource::addOnGetListener(JNIEnv* env, jobject jListener)
361 return this->m_onGetManager.addListener(env, jListener, this);
364 JniOnPutListener* JniOcResource::addOnPutListener(JNIEnv* env, jobject jListener)
366 return this->m_onPutManager.addListener(env, jListener, this);
369 JniOnPostListener* JniOcResource::addOnPostListener(JNIEnv* env, jobject jListener)
371 return this->m_onPostManager.addListener(env, jListener, this);
374 JniOnDeleteListener* JniOcResource::addOnDeleteListener(JNIEnv* env, jobject jListener)
376 return this->m_onDeleteManager.addListener(env, jListener, this);
379 JniOnObserveListener* JniOcResource::addOnObserveListener(JNIEnv* env, jobject jListener)
381 return this->m_onObserveManager.addListener(env, jListener, this);
384 void JniOcResource::removeOnGetListener(JNIEnv* env, jobject jListener)
386 this->m_onGetManager.removeListener(env, jListener);
389 void JniOcResource::removeOnPutListener(JNIEnv* env, jobject jListener)
391 this->m_onPutManager.removeListener(env, jListener);
394 void JniOcResource::removeOnPostListener(JNIEnv* env, jobject jListener)
396 this->m_onPostManager.removeListener(env, jListener);
399 void JniOcResource::removeOnDeleteListener(JNIEnv* env, jobject jListener)
401 this->m_onDeleteManager.removeListener(env, jListener);
404 void JniOcResource::removeOnObserveListener(JNIEnv* env, jobject jListener)
406 this->m_onObserveManager.removeListener(env, jListener);
410 JniOnMQTopicFoundListener* JniOcResource::addOnTopicFoundListener(JNIEnv* env, jobject jListener)
412 return this->m_onFoundTopicResourceManager.addListener(env, jListener, this);
415 void JniOcResource::removeOnTopicFoundListener(JNIEnv* env, jobject jListener)
417 this->m_onFoundTopicResourceManager.removeListener(env, jListener);
420 JniOnMQSubscribeListener* JniOcResource::addOnMQTopicSubscribeListener(JNIEnv* env, jobject jListener)
422 return this->m_onSubcribeTopicManager.addListener(env, jListener, this);
425 void JniOcResource::removeOnMQTopicSubscribeListener(JNIEnv* env, jobject jListener)
427 this->m_onSubcribeTopicManager.removeListener(env, jListener);
431 std::shared_ptr<OCResource> JniOcResource::getOCResource()
433 return this->m_sharedResource;
436 JniOcResource* JniOcResource::getJniOcResourcePtr(JNIEnv *env, jobject thiz)
438 JniOcResource *resource = GetHandle<JniOcResource>(env, thiz);
439 if (env->ExceptionCheck())
441 LOGE("Failed to get native handle from OcResource");
445 ThrowOcException(JNI_NO_NATIVE_POINTER, "");
451 OCStackResult JniOcResource::discoveryMQTopics(JNIEnv* env,
452 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
454 JniOnMQTopicFoundListener *onTopicFoundListener = addOnTopicFoundListener(env, jListener);
456 MQTopicCallback findCallback = [onTopicFoundListener](const int& eCode,
457 const std::string& uri, std::shared_ptr<OCResource> resource)
459 onTopicFoundListener->foundTopicCallback(eCode, uri, resource);
462 return m_sharedResource->discoveryMQTopics(queryParametersMap, findCallback, QoS);
465 OCStackResult JniOcResource::createMQTopic(JNIEnv* env,
466 const OCRepresentation &representation, const std::string &targetUri,
467 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
469 JniOnMQTopicFoundListener *onTopicCreatedListener = addOnTopicFoundListener(env, jListener);
471 MQTopicCallback createCallback = [onTopicCreatedListener](const int& eCode,
472 const std::string& uri, std::shared_ptr<OCResource> resource)
474 onTopicCreatedListener->createdTopicCallback(eCode, uri, resource);
477 return m_sharedResource->createMQTopic(representation, targetUri,
479 createCallback, QoS);
483 OCStackResult JniOcResource::subscribeMQTopic(JNIEnv* env,
484 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
486 JniOnMQSubscribeListener *onSubscribeListener = addOnMQTopicSubscribeListener(env, jListener);
488 ObserveCallback subscribeCallback = [onSubscribeListener](const HeaderOptions& opts,
489 const OCRepresentation& rep, const int& eCode, const int& sequenceNumber)
491 onSubscribeListener->onSubscribeCallback(opts, rep, eCode, sequenceNumber);
494 return m_sharedResource->subscribeMQTopic(ObserveType::Observe, queryParametersMap,
495 subscribeCallback, QoS);
498 OCStackResult JniOcResource::unsubscribeMQTopic(QualityOfService QoS)
500 return m_sharedResource->unsubscribeMQTopic(QoS);
503 OCStackResult JniOcResource::requestMQPublish(JNIEnv* env,
504 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
506 JniOnPostListener *onPostListener = addOnPostListener(env, jListener);
508 PostCallback postCallback = [onPostListener](const HeaderOptions& opts,
509 const OCRepresentation& rep, const int eCode)
511 onPostListener->onPostCallback(opts, rep, eCode);
514 return m_sharedResource->requestMQPublish(queryParametersMap, postCallback, QoS);
518 OCStackResult JniOcResource::publishMQTopic(JNIEnv* env, const OCRepresentation &representation,
519 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
521 JniOnPostListener *onPostListener = addOnPostListener(env, jListener);
523 PostCallback postCallback = [onPostListener](const HeaderOptions& opts,
524 const OCRepresentation& rep, const int eCode)
526 onPostListener->onPostCallback(opts, rep, eCode);
529 return m_sharedResource->publishMQTopic(representation, queryParametersMap,
535 * Class: org_iotivity_base_OcResource
537 * Signature: (Ljava/util/Map;Lorg/iotivity/base/OcResource/OnGetListener;)V
539 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_get
540 (JNIEnv *env, jobject thiz, jobject jQueryParamsMap, jobject jListener)
542 LOGD("OcResource_get");
543 if (!jQueryParamsMap)
545 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
550 ThrowOcException(OC_STACK_INVALID_PARAM, "onGetListener cannot be null");
553 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
560 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
564 OCStackResult result = resource->get(
569 if (OC_STACK_OK != result)
571 ThrowOcException(result, "OcResource_get");
574 catch (OCException& e)
576 LOGE("%s", e.reason().c_str());
577 ThrowOcException(e.code(), e.reason().c_str());
582 * Class: org_iotivity_base_OcResource
584 * Signature: (Ljava/util/Map;Lorg/iotivity/base/OcResource/OnGetListener;I)V
586 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_get1
587 (JNIEnv *env, jobject thiz, jobject jQueryParamsMap, jobject jListener, jint jQoS)
589 LOGD("OcResource_get");
590 if (!jQueryParamsMap)
592 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
597 ThrowOcException(OC_STACK_INVALID_PARAM, "onGetListener cannot be null");
600 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
607 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
611 OCStackResult result = resource->get(
615 JniUtils::getQOS(env, static_cast<int>(jQoS)));
617 if (OC_STACK_OK != result)
619 ThrowOcException(result, "OcResource_get");
622 catch (OCException& e)
624 LOGE("%s", e.reason().c_str());
625 ThrowOcException(e.code(), e.reason().c_str());
630 * Class: org_iotivity_base_OcResource
632 * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;
633 Lorg/iotivity/base/OcResource/OnGetListener;)V
635 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_get2
636 (JNIEnv *env, jobject thiz, jstring jResourceType, jstring jResourceInterface,
637 jobject jQueryParamsMap, jobject jListener)
639 LOGD("OcResource_get");
640 std::string resourceType;
643 resourceType = env->GetStringUTFChars(jResourceType, nullptr);
645 std::string resourceInterface;
646 if (jResourceInterface)
648 resourceInterface = env->GetStringUTFChars(jResourceInterface, nullptr);
650 if (!jQueryParamsMap)
652 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
657 ThrowOcException(OC_STACK_INVALID_PARAM, "onGetListener cannot be null");
660 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
667 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
670 OCStackResult result = resource->get(
677 if (OC_STACK_OK != result)
679 ThrowOcException(result, "OcResource_get");
682 catch (OCException& e)
684 LOGE("%s", e.reason().c_str());
685 ThrowOcException(e.code(), e.reason().c_str());
690 * Class: org_iotivity_base_OcResource
692 * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;
693 Lorg/iotivity/base/OcResource/OnGetListener;I)V
695 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_get3
696 (JNIEnv *env, jobject thiz, jstring jResourceType, jstring jResourceInterface,
697 jobject jQueryParamsMap, jobject jListener, jint jQoS)
699 LOGD("OcResource_get");
700 if (!jQueryParamsMap)
702 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
707 ThrowOcException(OC_STACK_INVALID_PARAM, "onGetListener cannot be null");
710 std::string resourceType;
713 resourceType = env->GetStringUTFChars(jResourceType, nullptr);
715 std::string resourceInterface;
716 if (jResourceInterface)
718 resourceInterface = env->GetStringUTFChars(jResourceInterface, nullptr);
720 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
727 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
731 OCStackResult result = resource->get(
737 JniUtils::getQOS(env, static_cast<int>(jQoS)));
739 if (OC_STACK_OK != result)
741 ThrowOcException(result, "OcResource_get");
744 catch (OCException& e)
746 LOGE("%s", e.reason().c_str());
747 ThrowOcException(e.code(), e.reason().c_str());
752 * Class: org_iotivity_base_OcResource
754 * Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/Map;
755 Lorg/iotivity/base/OcResource/OnPutListener;)V
757 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_put
758 (JNIEnv *env, jobject thiz, jobject jRepresentation, jobject jQueryParamsMap, jobject jListener)
760 LOGD("OcResource_put");
761 if (!jRepresentation)
763 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
766 if (!jQueryParamsMap)
768 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
773 ThrowOcException(OC_STACK_INVALID_PARAM, "onPutListener cannot be null");
776 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
782 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
789 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
793 OCStackResult result = resource->put(
799 if (OC_STACK_OK != result)
801 ThrowOcException(result, "OcResource_put");
804 catch (OCException& e)
806 LOGE("%s", e.reason().c_str());
807 ThrowOcException(e.code(), e.reason().c_str());
812 * Class: org_iotivity_base_OcResource
814 * Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/Map;
815 Lorg/iotivity/base/OcResource/OnPutListener;I)V
817 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_put1
818 (JNIEnv *env, jobject thiz, jobject jRepresentation, jobject jQueryParamsMap,
819 jobject jListener, jint jQoS)
821 LOGD("OcResource_put");
822 if (!jRepresentation)
824 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
827 if (!jQueryParamsMap)
829 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
834 ThrowOcException(OC_STACK_INVALID_PARAM, "onPutListener cannot be null");
837 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
843 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
850 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
854 OCStackResult result = resource->put(
859 JniUtils::getQOS(env, static_cast<int>(jQoS)));
861 if (OC_STACK_OK != result)
863 ThrowOcException(result, "OcResource_put");
866 catch (OCException& e)
868 LOGE("%s", e.reason().c_str());
869 ThrowOcException(e.code(), e.reason().c_str());
874 * Class: org_iotivity_base_OcResource
876 * Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcRepresentation;
877 Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPutListener;)V
879 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_put2
880 (JNIEnv *env, jobject thiz, jstring jResourceType, jstring jResourceInterface,
881 jobject jRepresentation, jobject jQueryParamsMap, jobject jListener)
883 LOGD("OcResource_put");
884 std::string resourceType;
887 resourceType = env->GetStringUTFChars(jResourceType, nullptr);
889 std::string resourceInterface;
890 if (jResourceInterface)
892 resourceInterface = env->GetStringUTFChars(jResourceInterface, nullptr);
894 if (!jRepresentation)
896 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
899 if (!jQueryParamsMap)
901 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
906 ThrowOcException(OC_STACK_INVALID_PARAM, "onPutListener cannot be null");
909 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
915 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
922 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
926 OCStackResult result = resource->put(
934 if (OC_STACK_OK != result)
936 ThrowOcException(result, "OcResource_put");
939 catch (OCException& e)
941 LOGE("%s", e.reason().c_str());
942 ThrowOcException(e.code(), e.reason().c_str());
947 * Class: org_iotivity_base_OcResource
949 * Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcRepresentation;
950 Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPutListener;I)V
952 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_put3
953 (JNIEnv *env, jobject thiz, jstring jResourceType, jstring jResourceInterface, jobject jRepresentation,
954 jobject jQueryParamsMap, jobject jListener, jint jQoS)
956 LOGD("OcResource_put");
957 if (!jRepresentation)
959 ThrowOcException(OC_STACK_INVALID_PARAM, "representation cannot be null");
962 if (!jQueryParamsMap)
964 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
969 ThrowOcException(OC_STACK_INVALID_PARAM, "onPutListener cannot be null");
972 std::string resourceType;
975 resourceType = env->GetStringUTFChars(jResourceType, nullptr);
977 std::string resourceInterface;
978 if (jResourceInterface)
980 resourceInterface = env->GetStringUTFChars(jResourceInterface, nullptr);
983 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
989 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
996 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1000 OCStackResult result = resource->put(
1007 JniUtils::getQOS(env, static_cast<int>(jQoS)));
1009 if (OC_STACK_OK != result)
1011 ThrowOcException(result, "OcResource_put");
1014 catch (OCException& e)
1016 LOGE("%s", e.reason().c_str());
1017 ThrowOcException(e.code(), e.reason().c_str());
1022 * Class: org_iotivity_base_OcResource
1024 * Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPostListener;)V
1026 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_post
1027 (JNIEnv *env, jobject thiz, jobject jRepresentation, jobject jQueryParamsMap, jobject jListener)
1029 LOGD("OcResource_post");
1030 if (!jRepresentation)
1032 ThrowOcException(OC_STACK_INVALID_PARAM, "representation cannot be null");
1035 if (!jQueryParamsMap)
1037 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1042 ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null");
1045 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1051 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
1052 if (!representation)
1058 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1062 OCStackResult result = resource->post(
1068 if (OC_STACK_OK != result)
1070 ThrowOcException(result, "OcResource_post");
1073 catch (OCException& e)
1075 LOGE("%s", e.reason().c_str());
1076 ThrowOcException(e.code(), e.reason().c_str());
1081 * Class: org_iotivity_base_OcResource
1083 * Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPostListener;I)V
1085 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_post1
1086 (JNIEnv *env, jobject thiz, jobject jRepresentation, jobject jQueryParamsMap, jobject jListener, jint jQoS)
1088 LOGD("OcResource_post");
1089 if (!jRepresentation)
1091 ThrowOcException(OC_STACK_INVALID_PARAM, "representation cannot be null");
1094 if (!jQueryParamsMap)
1096 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1101 ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null");
1104 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1110 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
1111 if (!representation)
1117 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1121 OCStackResult result = resource->post(
1126 JniUtils::getQOS(env, static_cast<int>(jQoS)));
1128 if (OC_STACK_OK != result)
1130 ThrowOcException(result, "OcResource_post");
1133 catch (OCException& e)
1135 LOGE("%s", e.reason().c_str());
1136 ThrowOcException(e.code(), e.reason().c_str());
1141 * Class: org_iotivity_base_OcResource
1143 * Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcRepresentation;
1144 Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPostListener;)V
1146 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_post2
1147 (JNIEnv *env, jobject thiz, jstring jResourceType, jstring jResourceInterface,
1148 jobject jRepresentation, jobject jQueryParamsMap, jobject jListener)
1150 LOGD("OcResource_post");
1151 if (!jRepresentation)
1153 ThrowOcException(OC_STACK_INVALID_PARAM, "representation cannot be null");
1156 if (!jQueryParamsMap)
1158 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1163 ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null");
1166 std::string resourceType;
1169 resourceType = env->GetStringUTFChars(jResourceType, nullptr);
1171 std::string resourceInterface;
1172 if (jResourceInterface)
1174 resourceInterface = env->GetStringUTFChars(jResourceInterface, nullptr);
1177 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1183 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
1184 if (!representation)
1190 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1194 OCStackResult result = resource->post(
1202 if (OC_STACK_OK != result)
1204 ThrowOcException(result, "OcResource_post");
1207 catch (OCException& e)
1209 LOGE("%s", e.reason().c_str());
1210 ThrowOcException(e.code(), e.reason().c_str());
1215 * Class: org_iotivity_base_OcResource
1217 * Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcRepresentation;
1218 Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPostListener;I)V
1220 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_post3
1221 (JNIEnv *env, jobject thiz, jstring jResourceType, jstring jResourceInterface,
1222 jobject jRepresentation, jobject jQueryParamsMap, jobject jListener, jint jQoS)
1224 LOGD("OcResource_post");
1225 if (!jRepresentation)
1227 ThrowOcException(OC_STACK_INVALID_PARAM, "representation cannot be null");
1230 if (!jQueryParamsMap)
1232 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1237 ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null");
1240 std::string resourceType;
1243 resourceType = env->GetStringUTFChars(jResourceType, nullptr);
1245 std::string resourceInterface;
1246 if (jResourceInterface)
1248 resourceInterface = env->GetStringUTFChars(jResourceInterface, nullptr);
1251 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1257 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
1258 if (!representation)
1264 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1268 OCStackResult result = resource->post(
1275 JniUtils::getQOS(env, static_cast<int>(jQoS)));
1277 if (OC_STACK_OK != result)
1279 ThrowOcException(result, "OcResource_post");
1282 catch (OCException& e)
1284 LOGE("%s", e.reason().c_str());
1285 ThrowOcException(e.code(), e.reason().c_str());
1290 * Class: org_iotivity_base_OcResource
1291 * Method: deleteResource
1292 * Signature: (Lorg/iotivity/base/OcResource/OnDeleteListener;)V
1294 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_deleteResource
1295 (JNIEnv *env, jobject thiz, jobject jListener)
1297 LOGD("OcResource_deleteResource");
1300 ThrowOcException(OC_STACK_INVALID_PARAM, "onDeleteListener cannot be null");
1303 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1311 OCStackResult result = resource->deleteResource(
1315 if (OC_STACK_OK != result)
1317 ThrowOcException(result, "OcResource_deleteResource");
1320 catch (OCException& e)
1322 LOGE("%s", e.reason().c_str());
1323 ThrowOcException(e.code(), e.reason().c_str());
1328 * Class: org_iotivity_base_OcResource
1329 * Method: deleteResource1
1330 * Signature: (Lorg/iotivity/base/OcResource/OnDeleteListener;I)V
1332 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_deleteResource1
1333 (JNIEnv *env, jobject thiz, jobject jListener, jint jQoS)
1335 LOGD("OcResource_deleteResource");
1338 ThrowOcException(OC_STACK_INVALID_PARAM, "onDeleteListener cannot be null");
1341 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1349 OCStackResult result = resource->deleteResource(
1352 JniUtils::getQOS(env, static_cast<int>(jQoS)));
1354 if (OC_STACK_OK != result)
1356 ThrowOcException(result, "OcResource_deleteResource");
1359 catch (OCException& e)
1361 LOGE("%s", e.reason().c_str());
1362 ThrowOcException(e.code(), e.reason().c_str());
1367 * Class: org_iotivity_base_OcResource
1369 * Signature: (Lorg/iotivity/base/ObserveType;Ljava/util/Map;
1370 Lorg/iotivity/base/OcResource/OnObserveListener;)V
1372 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_observe
1373 (JNIEnv *env, jobject thiz, jint observeType, jobject jQueryParamsMap, jobject jListener)
1375 LOGD("OcResource_observe");
1376 if (!jQueryParamsMap)
1378 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1383 ThrowOcException(OC_STACK_INVALID_PARAM, "onObserveListener cannot be null");
1386 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1393 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1397 OCStackResult result = resource->observe(
1399 JniUtils::getObserveType(env, static_cast<int>(observeType)),
1403 if (OC_STACK_OK != result)
1405 ThrowOcException(result, "OcResource_observe");
1408 catch (OCException& e)
1410 LOGE("%s", e.reason().c_str());
1411 ThrowOcException(e.code(), e.reason().c_str());
1416 * Class: org_iotivity_base_OcResource
1418 * Signature: (Lorg/iotivity/base/ObserveType;Ljava/util/Map;
1419 Lorg/iotivity/base/OcResource/OnObserveListener;I)V
1421 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_observe1
1422 (JNIEnv *env, jobject thiz, jint observeType, jobject jQueryParamsMap,
1423 jobject jListener, jint jQoS)
1425 LOGD("OcResource_observe");
1426 if (!jQueryParamsMap)
1428 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1433 ThrowOcException(OC_STACK_INVALID_PARAM, "onObserveListener cannot be null");
1436 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1443 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1447 OCStackResult result = resource->observe(
1449 JniUtils::getObserveType(env, static_cast<int>(observeType)),
1452 JniUtils::getQOS(env, static_cast<int>(jQoS)));
1454 if (OC_STACK_OK != result)
1456 ThrowOcException(result, "OcResource_observe");
1459 catch (OCException& e)
1461 LOGE("%s", e.reason().c_str());
1462 ThrowOcException(e.code(), e.reason().c_str());
1467 * Class: org_iotivity_base_OcResource
1468 * Method: cancelObserve1
1471 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_cancelObserve1
1472 (JNIEnv *env, jobject thiz, jint jQoS)
1474 LOGD("OcResource_cancelObserve1");
1475 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1483 OCStackResult result = resource->cancelObserve(
1485 JniUtils::getQOS(env, static_cast<int>(jQoS)));
1487 if (OC_STACK_OK != result)
1489 ThrowOcException(result, "OcResource_cancelObserve");
1492 catch (OCException& e)
1494 LOGE("%s", e.reason().c_str());
1495 ThrowOcException(e.code(), e.reason().c_str());
1500 * Class: org_iotivity_base_OcResource
1501 * Method: setHeaderOptions
1502 * Signature: ([Lorg/iotivity/OcHeaderOption;)V
1504 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_setHeaderOptions
1505 (JNIEnv *env, jobject thiz, jobjectArray jheaderOptionArr)
1507 LOGD("OcResource_setHeaderOptions");
1508 if (!jheaderOptionArr)
1510 ThrowOcException(OC_STACK_INVALID_PARAM, "headerOptionList cannot be null");
1513 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1519 HeaderOptions headerOptions;
1520 JniUtils::convertJavaHeaderOptionsArrToVector(env, jheaderOptionArr, headerOptions);
1522 resource->setHeaderOptions(headerOptions);
1526 * Class: org_iotivity_base_OcResource
1527 * Method: unsetHeaderOptions
1530 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_unsetHeaderOptions
1531 (JNIEnv *env, jobject thiz)
1533 LOGD("OcResource_unsetHeaderOptions");
1534 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1540 resource->unsetHeaderOptions();
1544 * Class: org_iotivity_base_OcResource
1546 * Signature: ()Ljava/lang/String;
1548 JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcResource_getHost
1549 (JNIEnv *env, jobject thiz)
1551 LOGD("OcResource_getHost");
1552 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1558 return env->NewStringUTF(resource->host().c_str());
1562 * Class: org_iotivity_base_OcResource
1564 * Signature: ()Ljava/lang/String;
1566 JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcResource_getUri
1567 (JNIEnv *env, jobject thiz)
1569 LOGD("OcResource_getUri");
1570 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1576 return env->NewStringUTF(resource->uri().c_str());
1580 * Class: org_iotivity_base_OcResource
1581 * Method: getConnectivityTypeN
1584 JNIEXPORT jint JNICALL Java_org_iotivity_base_OcResource_getConnectivityTypeN
1585 (JNIEnv *env, jobject thiz)
1587 LOGD("OcResource_getConnectivityType");
1588 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1594 OCConnectivityType connectivityType = resource->connectivityType();
1595 return static_cast<jint>(connectivityType);
1599 * Class: org_iotivity_base_OcResource
1600 * Method: isObservable
1603 JNIEXPORT jboolean JNICALL Java_org_iotivity_base_OcResource_isObservable
1604 (JNIEnv *env, jobject thiz)
1606 LOGD("OcResource_isObservable");
1607 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1613 return (jboolean)resource->isObservable();
1617 * Class: org_iotivity_base_OcResource
1618 * Method: getResourceTypes
1619 * Signature: ()Ljava/util/List;
1621 JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcResource_getResourceTypes
1622 (JNIEnv *env, jobject thiz)
1624 LOGD("OcResource_getResourceTypes");
1625 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1631 std::vector<std::string> resourceTypes = resource->getResourceTypes();
1633 return JniUtils::convertStrVectorToJavaStrList(env, resourceTypes);
1637 * Class: org_iotivity_base_OcResource
1638 * Method: getResourceInterfaces
1639 * Signature: ()Ljava/util/List;
1641 JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcResource_getResourceInterfaces
1642 (JNIEnv *env, jobject thiz)
1644 LOGD("OcResource_getResourceInterfaces");
1645 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1651 std::vector<std::string> resourceInterfaces = resource->getResourceInterfaces();
1653 return JniUtils::convertStrVectorToJavaStrList(env, resourceInterfaces);
1657 * Class: org_iotivity_base_OcResource
1658 * Method: getUniqueIdentifier
1659 * Signature: ()Lorg/iotivity/base/OcResourceIdentifier;
1661 JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcResource_getUniqueIdentifier
1662 (JNIEnv *env, jobject thiz)
1664 LOGD("OcResource_getUniqueIdentifier");
1665 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1671 JniOcResourceIdentifier *jniResourceIdentifier =
1672 new JniOcResourceIdentifier(resource->uniqueIdentifier());
1673 if (!jniResourceIdentifier)
1678 jlong handle = reinterpret_cast<jlong>(jniResourceIdentifier);
1679 jobject jResourceIdentifier = env->NewObject(g_cls_OcResourceIdentifier,
1680 g_mid_OcResourceIdentifier_N_ctor, handle);
1681 if (!jResourceIdentifier)
1683 delete jniResourceIdentifier;
1685 return jResourceIdentifier;
1689 * Class: org_iotivity_base_OcResource
1690 * Method: getServerId
1691 * Signature: ()Ljava/lang/String;
1693 JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcResource_getServerId
1694 (JNIEnv *env, jobject thiz)
1696 LOGD("OcResource_getServerId");
1697 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1703 return env->NewStringUTF(resource->sid().c_str());
1707 * Class: org_iotivity_base_OcResource
1711 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_dispose
1712 (JNIEnv *env, jobject thiz)
1714 LOGD("OcResource_dispose");
1715 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1720 * Class: org_iotivity_base_OcResource
1721 * Method: discoveryMQTopicsImpl
1722 * Signature: (Ljava/util/Map;Lorg/iotivity/base/OcPlatform/OnResourceFoundListener;I)V
1724 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_discoveryMQTopicsImpl
1725 (JNIEnv *env, jobject thiz, jobject jQueryParamsMap, jobject jListener, jint jQoS)
1727 LOGD("OcResource_discoveryMQTopicsImpl");
1730 if (!jQueryParamsMap)
1732 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1738 ThrowOcException(OC_STACK_INVALID_PARAM, "listener cannot be null");
1742 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1749 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1753 OCStackResult result = resource->discoveryMQTopics(
1757 JniUtils::getQOS(env, static_cast<int>(jQoS)));
1759 if (OC_STACK_OK != result)
1761 ThrowOcException(result, "OcResource_discoveryMQTopicsImpl");
1764 catch (OCException& e)
1766 LOGE("%s", e.reason().c_str());
1767 ThrowOcException(e.code(), e.reason().c_str());
1770 ThrowOcException(JNI_NO_SUPPORT, "not support");
1775 * Class: org_iotivity_base_OcResource
1776 * Method: createMQTopicImpl
1777 * Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/String;Ljava/util/Map
1778 * ;Lorg/iotivity/base/OcPlatform/OnMQTopicCreatedListener;I)V
1780 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_createMQTopicImpl
1781 (JNIEnv *env, jobject thiz, jobject jRepresentation, jstring jUri,
1782 jobject jQueryParamsMap, jobject jListener, jint jQoS)
1784 LOGD("OcResource_createMQTopicImpl");
1787 if (!jQueryParamsMap)
1789 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1795 ThrowOcException(OC_STACK_INVALID_PARAM, "listener cannot be null");
1799 if (!jRepresentation)
1801 ThrowOcException(OC_STACK_INVALID_PARAM, "representation null");
1805 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1811 std::string targetUri;
1814 targetUri = env->GetStringUTFChars(jUri, nullptr);
1817 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env,
1819 if (!representation)
1825 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1829 OCStackResult result = resource->createMQTopic(
1835 JniUtils::getQOS(env, static_cast<int>(jQoS)));
1837 if (OC_STACK_OK != result)
1839 ThrowOcException(result, "OcResource_createMQTopicImpl");
1842 catch (OCException& e)
1844 LOGE("%s", e.reason().c_str());
1845 ThrowOcException(e.code(), e.reason().c_str());
1848 ThrowOcException(JNI_NO_SUPPORT, "not support");
1853 * Class: org_iotivity_base_OcResource
1854 * Method: subscribeMQTopic
1855 * Signature: (Ljava/util/Map;Lorg/iotivity/base/OcResource/OnObserveListener;I)V
1857 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_subscribeMQTopicImpl
1858 (JNIEnv *env, jobject thiz, jobject jQueryParamsMap, jobject jListener, jint jQoS)
1860 LOGD("OcResource_subscribeMQTopicImpl");
1861 #ifdef MQ_SUBSCRIBER
1862 if (!jQueryParamsMap)
1864 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1869 ThrowOcException(OC_STACK_INVALID_PARAM, "onObserveListener cannot be null");
1872 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1879 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1883 OCStackResult result = resource->subscribeMQTopic(
1887 JniUtils::getQOS(env, static_cast<int>(jQoS)));
1889 if (OC_STACK_OK != result)
1891 ThrowOcException(result, "OcResource_subscribeMQTopicImpl");
1894 catch (OCException& e)
1896 LOGE("%s", e.reason().c_str());
1897 ThrowOcException(e.code(), e.reason().c_str());
1900 ThrowOcException(JNI_NO_SUPPORT, "not support");
1905 * Class: org_iotivity_base_OcResource
1906 * Method: unsubscribeMQTopicImpl
1909 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_unsubscribeMQTopicImpl
1910 (JNIEnv *env, jobject thiz, jint jQoS)
1912 LOGD("OcResource_unsubscribeMQTopicImpl");
1913 #ifdef MQ_SUBSCRIBER
1914 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1922 OCStackResult result = resource->unsubscribeMQTopic(
1923 JniUtils::getQOS(env, static_cast<int>(jQoS)));
1924 if (OC_STACK_OK != result)
1926 ThrowOcException(result, "OcResource_unsubscribeMQTopicImpl");
1929 catch (OCException& e)
1931 LOGE("%s", e.reason().c_str());
1932 ThrowOcException(e.code(), e.reason().c_str());
1935 ThrowOcException(JNI_NO_SUPPORT, "not support");
1940 * Class: org_iotivity_base_OcResource
1941 * Method: requestMQPublishImpl
1942 * Signature: (Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPostListener;I)V
1944 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_requestMQPublishImpl
1945 (JNIEnv *env, jobject thiz, jobject jQueryParamsMap, jobject jListener, jint jQoS)
1947 LOGD("OcResource_requestMQPublishImpl");
1948 #ifdef MQ_SUBSCRIBER
1949 if (!jQueryParamsMap)
1951 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1956 ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null");
1960 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1967 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1971 OCStackResult result = resource->requestMQPublish(
1975 JniUtils::getQOS(env, static_cast<int>(jQoS)));
1977 if (OC_STACK_OK != result)
1979 ThrowOcException(result, "OcResource_requestMQPublishImpl");
1982 catch (OCException& e)
1984 LOGE("%s", e.reason().c_str());
1985 ThrowOcException(e.code(), e.reason().c_str());
1988 ThrowOcException(JNI_NO_SUPPORT, "not support");
1993 * Class: org_iotivity_base_OcResource
1994 * Method: publishMQTopicImpl
1995 * Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/Map;
1996 * Lorg/iotivity/base/OcResource/OnPostListener;I)V
1998 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_publishMQTopicImpl
1999 (JNIEnv *env, jobject thiz, jobject jRepresentation, jobject jQueryParamsMap,
2000 jobject jListener, jint jQoS)
2002 LOGD("OcResource_publishMQTopicImpl");
2004 if (!jRepresentation)
2006 ThrowOcException(OC_STACK_INVALID_PARAM, "representation cannot be null");
2010 if (!jQueryParamsMap)
2012 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
2018 ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null");
2022 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
2028 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env,
2030 if (!representation)
2036 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
2040 OCStackResult result = resource->publishMQTopic(
2045 JniUtils::getQOS(env, static_cast<int>(jQoS)));
2047 if (OC_STACK_OK != result)
2049 ThrowOcException(result, "OcResource_publishMQTopicImpl");
2052 catch (OCException& e)
2054 LOGE("%s", e.reason().c_str());
2055 ThrowOcException(e.code(), e.reason().c_str());
2058 ThrowOcException(JNI_NO_SUPPORT, "not support");