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::Ptr onGetListener = addOnGetListener(env, jListener);
65 GetCallback getCallback = std::bind([](
66 const HeaderOptions& opts,
67 const OCRepresentation& rep,
69 std::weak_ptr<JniOnGetListener> weak_ref)
71 auto listener = weak_ref.lock();
74 listener->onGetCallback(opts, rep, eCode);
76 }, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, onGetListener);
78 return m_sharedResource->get(queryParametersMap, getCallback);
81 OCStackResult JniOcResource::get(JNIEnv* env, const QueryParamsMap &queryParametersMap, jobject jListener,
84 JniOnGetListener::Ptr onGetListener = addOnGetListener(env, jListener);
86 GetCallback getCallback = std::bind([](
87 const HeaderOptions& opts,
88 const OCRepresentation& rep,
90 std::weak_ptr<JniOnGetListener> weak_ref)
92 auto listener = weak_ref.lock();
95 listener->onGetCallback(opts, rep, eCode);
97 }, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, onGetListener);
99 return m_sharedResource->get(queryParametersMap, getCallback, QoS);
102 OCStackResult JniOcResource::get(
104 const std::string &resourceType,
105 const std::string &resourceInterface,
106 const QueryParamsMap &queryParametersMap,
109 JniOnGetListener::Ptr onGetListener = addOnGetListener(env, jListener);
111 GetCallback getCallback = std::bind([](
112 const HeaderOptions& opts,
113 const OCRepresentation& rep,
115 std::weak_ptr<JniOnGetListener> weak_ref)
117 auto listener = weak_ref.lock();
120 listener->onGetCallback(opts, rep, eCode);
122 }, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, onGetListener);
124 return m_sharedResource->get(resourceType, resourceInterface, queryParametersMap, getCallback);
127 OCStackResult JniOcResource::get(JNIEnv* env, const std::string &resourceType,
128 const std::string &resourceInterface, const QueryParamsMap &queryParametersMap,
129 jobject jListener, QualityOfService QoS)
131 JniOnGetListener::Ptr onGetListener = addOnGetListener(env, jListener);
133 GetCallback getCallback = std::bind([](
134 const HeaderOptions& opts,
135 const OCRepresentation& rep,
137 std::weak_ptr<JniOnGetListener> weak_ref)
139 auto listener = weak_ref.lock();
142 listener->onGetCallback(opts, rep, eCode);
144 }, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, onGetListener);
146 return m_sharedResource->get(resourceType, resourceInterface, queryParametersMap, getCallback, QoS);
149 OCStackResult JniOcResource::put(JNIEnv* env, const OCRepresentation &representation,
150 const QueryParamsMap &queryParametersMap, jobject jListener)
152 JniOnPutListener::Ptr onPutListener = addOnPutListener(env, jListener);
154 PutCallback putCallback = std::bind([](
155 const HeaderOptions& opts,
156 const OCRepresentation& rep,
158 std::weak_ptr<JniOnPutListener> weak_ref)
160 auto listener = weak_ref.lock();
163 listener->onPutCallback(opts, rep, eCode);
165 }, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, onPutListener);
167 return m_sharedResource->put(representation, queryParametersMap, putCallback);
170 OCStackResult JniOcResource::put(JNIEnv* env, const OCRepresentation &representation,
171 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
173 JniOnPutListener::Ptr onPutListener = addOnPutListener(env, jListener);
175 PutCallback putCallback = std::bind([](
176 const HeaderOptions& opts,
177 const OCRepresentation& rep,
179 std::weak_ptr<JniOnPutListener> weak_ref)
181 auto listener = weak_ref.lock();
184 listener->onPutCallback(opts, rep, eCode);
186 }, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, onPutListener);
188 return m_sharedResource->put(representation, queryParametersMap, putCallback, QoS);
191 OCStackResult JniOcResource::put(JNIEnv* env, const std::string &resourceType,
192 const std::string &resourceInterface, const OCRepresentation &representation,
193 const QueryParamsMap &queryParametersMap, jobject jListener)
195 JniOnPutListener::Ptr onPutListener = addOnPutListener(env, jListener);
197 PutCallback putCallback = std::bind([](
198 const HeaderOptions& opts,
199 const OCRepresentation& rep,
201 std::weak_ptr<JniOnPutListener> weak_ref)
203 auto listener = weak_ref.lock();
206 listener->onPutCallback(opts, rep, eCode);
208 }, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, onPutListener);
210 return m_sharedResource->put(resourceType, resourceInterface, representation,
211 queryParametersMap, putCallback);
214 OCStackResult JniOcResource::put(JNIEnv* env, const std::string &resourceType,
215 const std::string &resourceInterface, const OCRepresentation &representation,
216 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
218 JniOnPutListener::Ptr onPutListener = addOnPutListener(env, jListener);
220 PutCallback putCallback = std::bind( [](
221 const HeaderOptions& opts,
222 const OCRepresentation& rep,
224 std::weak_ptr<JniOnPutListener> weak_ref)
226 auto listener = weak_ref.lock();
229 listener->onPutCallback(opts, rep, eCode);
231 }, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, onPutListener);
233 return m_sharedResource->put(resourceType, resourceInterface, representation,
234 queryParametersMap, putCallback, QoS);
237 OCStackResult JniOcResource::post(JNIEnv* env, const OCRepresentation &representation,
238 const QueryParamsMap &queryParametersMap, jobject jListener)
240 JniOnPostListener::Ptr onPostListener = addOnPostListener(env, jListener);
242 PostCallback postCallback = std::bind([](
243 const HeaderOptions& opts,
244 const OCRepresentation& rep,
246 std::weak_ptr<JniOnPostListener> weak_ref)
248 auto listener = weak_ref.lock();
251 listener->onPostCallback(opts, rep, eCode);
253 }, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, onPostListener);
255 return m_sharedResource->post(representation, queryParametersMap, postCallback);
258 OCStackResult JniOcResource::post(JNIEnv* env, const OCRepresentation &representation,
259 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
261 JniOnPostListener::Ptr onPostListener = addOnPostListener(env, jListener);
263 PostCallback postCallback = std::bind([](
264 const HeaderOptions& opts,
265 const OCRepresentation& rep,
267 std::weak_ptr<JniOnPostListener> weak_ref)
269 auto listener = weak_ref.lock();
272 listener->onPostCallback(opts, rep, eCode);
274 }, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, onPostListener);
276 return m_sharedResource->post(representation, queryParametersMap, postCallback, QoS);
279 OCStackResult JniOcResource::post(JNIEnv* env, const std::string &resourceType,
280 const std::string &resourceInterface, const OCRepresentation &representation,
281 const QueryParamsMap &queryParametersMap, jobject jListener)
283 JniOnPostListener::Ptr onPostListener = addOnPostListener(env, jListener);
285 PostCallback postCallback = std::bind([](
286 const HeaderOptions& opts,
287 const OCRepresentation& rep,
289 std::weak_ptr<JniOnPostListener> weak_ref)
291 auto listener = weak_ref.lock();
294 listener->onPostCallback(opts, rep, eCode);
296 }, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, onPostListener);
298 return m_sharedResource->post(resourceType, resourceInterface, representation,
299 queryParametersMap, postCallback);
302 OCStackResult JniOcResource::post(JNIEnv* env, const std::string &resourceType,
303 const std::string &resourceInterface, const OCRepresentation &representation,
304 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
306 JniOnPostListener::Ptr onPostListener = addOnPostListener(env, jListener);
308 PostCallback postCallback = std::bind([](
309 const HeaderOptions& opts,
310 const OCRepresentation& rep,
312 std::weak_ptr<JniOnPostListener> weak_ref)
314 auto listener = weak_ref.lock();
317 listener->onPostCallback(opts, rep, eCode);
319 }, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, onPostListener);
321 return m_sharedResource->post(resourceType, resourceInterface, representation,
322 queryParametersMap, postCallback, QoS);
325 OCStackResult JniOcResource::deleteResource(JNIEnv* env, jobject jListener)
327 JniOnDeleteListener::Ptr onDeleteListener = addOnDeleteListener(env, jListener);
329 DeleteCallback deleteCallback = std::bind([](
330 const HeaderOptions& opts,
332 std::weak_ptr<JniOnDeleteListener> weak_ref)
334 auto listener = weak_ref.lock();
337 listener->onDeleteCallback(opts, eCode);
339 }, std::placeholders::_1, std::placeholders::_2, onDeleteListener);
341 return m_sharedResource->deleteResource(deleteCallback);
344 OCStackResult JniOcResource::deleteResource(JNIEnv* env, jobject jListener, QualityOfService QoS)
346 JniOnDeleteListener::Ptr onDeleteListener = addOnDeleteListener(env, jListener);
348 DeleteCallback deleteCallback = std::bind([](
349 const HeaderOptions& opts,
351 std::weak_ptr<JniOnDeleteListener> weak_ref)
353 auto listener = weak_ref.lock();
356 listener->onDeleteCallback(opts, eCode);
358 }, std::placeholders::_1, std::placeholders::_2, onDeleteListener);
360 return m_sharedResource->deleteResource(deleteCallback, QoS);
363 OCStackResult JniOcResource::observe(JNIEnv* env, ObserveType observeType,
364 const QueryParamsMap &queryParametersMap, jobject jListener)
366 JniOnObserveListener::Ptr onObserveListener = addOnObserveListener(env, jListener);
368 ObserveCallback observeCallback = std::bind([](
369 const HeaderOptions& opts,
370 const OCRepresentation& rep,
372 const int& sequenceNumber,
373 std::weak_ptr<JniOnObserveListener> weak_ref)
375 auto listener = weak_ref.lock();
378 listener->onObserveCallback(opts, rep, eCode, sequenceNumber);
380 }, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
381 std::placeholders::_4, onObserveListener);
383 return m_sharedResource->observe(observeType, queryParametersMap, observeCallback);
386 OCStackResult JniOcResource::observe(JNIEnv* env, ObserveType observeType,
387 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
389 JniOnObserveListener::Ptr onObserveListener = addOnObserveListener(env, jListener);
391 ObserveCallback observeCallback = std::bind([](
392 const HeaderOptions& opts,
393 const OCRepresentation& rep,
395 const int& sequenceNumber,
396 std::weak_ptr<JniOnObserveListener> weak_ref)
398 auto listener = weak_ref.lock();
401 listener->onObserveCallback(opts, rep, eCode, sequenceNumber);
403 }, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
404 std::placeholders::_4, onObserveListener);
406 return m_sharedResource->observe(observeType, queryParametersMap, observeCallback, QoS);
409 OCStackResult JniOcResource::cancelObserve(JNIEnv* env, QualityOfService qos)
411 // In Low case, after delete the callback and send empty message when client receive the notify.
412 // But TCP does not support EMPTY message.
413 if ((CT_ADAPTER_IP & connectivityType()) && QualityOfService::HighQos != qos)
415 this->m_onObserveManager.removeAllListeners(env);
417 return m_sharedResource->cancelObserve(qos);
420 void JniOcResource::setHeaderOptions(const HeaderOptions &headerOptions)
422 m_sharedResource->setHeaderOptions(headerOptions);
425 void JniOcResource::unsetHeaderOptions()
427 m_sharedResource->unsetHeaderOptions();
430 std::string JniOcResource::host()
432 return m_sharedResource->host();
435 std::string JniOcResource::uri()
437 return m_sharedResource->uri();
440 OCConnectivityType JniOcResource::connectivityType() const
442 return m_sharedResource->connectivityType();
445 bool JniOcResource::isObservable()
447 return m_sharedResource->isObservable();
450 std::vector< std::string > JniOcResource::getResourceTypes() const
452 return m_sharedResource->getResourceTypes();
455 std::vector< std::string > JniOcResource::getResourceInterfaces(void) const
457 return m_sharedResource->getResourceInterfaces();
460 OCResourceIdentifier JniOcResource::uniqueIdentifier() const
462 return m_sharedResource->uniqueIdentifier();
465 std::string JniOcResource::sid() const
467 return m_sharedResource->sid();
470 std::string JniOcResource::deviceName() const
472 return m_sharedResource->deviceName();
475 JniOnGetListener::Ptr JniOcResource::addOnGetListener(JNIEnv* env, jobject jListener)
477 return this->m_onGetManager.addListener(env, jListener, this);
480 JniOnPutListener::Ptr JniOcResource::addOnPutListener(JNIEnv* env, jobject jListener)
482 return this->m_onPutManager.addListener(env, jListener, this);
485 JniOnPostListener::Ptr JniOcResource::addOnPostListener(JNIEnv* env, jobject jListener)
487 return this->m_onPostManager.addListener(env, jListener, this);
490 JniOnDeleteListener::Ptr JniOcResource::addOnDeleteListener(JNIEnv* env, jobject jListener)
492 return this->m_onDeleteManager.addListener(env, jListener, this);
495 JniOnObserveListener::Ptr JniOcResource::addOnObserveListener(JNIEnv* env, jobject jListener)
497 return this->m_onObserveManager.addListener(env, jListener, this);
500 void JniOcResource::removeOnGetListener(JNIEnv* env, jobject jListener)
502 this->m_onGetManager.removeListener(env, jListener);
505 void JniOcResource::removeOnPutListener(JNIEnv* env, jobject jListener)
507 this->m_onPutManager.removeListener(env, jListener);
510 void JniOcResource::removeOnPostListener(JNIEnv* env, jobject jListener)
512 this->m_onPostManager.removeListener(env, jListener);
515 void JniOcResource::removeOnDeleteListener(JNIEnv* env, jobject jListener)
517 this->m_onDeleteManager.removeListener(env, jListener);
520 void JniOcResource::removeOnObserveListener(JNIEnv* env, jobject jListener)
522 this->m_onObserveManager.removeListener(env, jListener);
526 std::shared_ptr<JniOnMQTopicFoundListener> JniOcResource::addOnTopicFoundListener(JNIEnv* env, jobject jListener)
528 return this->m_onFoundTopicResourceManager.addListener(env, jListener, this);
531 void JniOcResource::removeOnTopicFoundListener(JNIEnv* env, jobject jListener)
533 this->m_onFoundTopicResourceManager.removeListener(env, jListener);
536 std::shared_ptr<JniOnMQSubscribeListener> JniOcResource::addOnMQTopicSubscribeListener(JNIEnv* env, jobject jListener)
538 return this->m_onSubcribeTopicManager.addListener(env, jListener, this);
541 void JniOcResource::removeOnMQTopicSubscribeListener(JNIEnv* env, jobject jListener)
543 this->m_onSubcribeTopicManager.removeListener(env, jListener);
547 std::shared_ptr<OCResource> JniOcResource::getOCResource()
549 return this->m_sharedResource;
552 JniOcResource* JniOcResource::getJniOcResourcePtr(JNIEnv *env, jobject thiz)
554 JniOcResource *resource = GetHandle<JniOcResource>(env, thiz);
555 if (env->ExceptionCheck())
557 LOGE("Failed to get native handle from OcResource");
561 ThrowOcException(JNI_NO_NATIVE_POINTER, "");
567 OCStackResult JniOcResource::discoveryMQTopics(JNIEnv* env,
568 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
570 std::shared_ptr<JniOnMQTopicFoundListener> onTopicFoundListener = addOnTopicFoundListener(env, jListener);
572 MQTopicCallback findCallback = std::bind([](const int& eCode,
573 const std::string& uri,
574 std::shared_ptr<OCResource> resource
575 std::weak_ptr<JniOnMQTopicFoundListener> weak_ref)
577 auto listener = weak_ref.lock();
580 listener->foundTopicCallback(eCode, uri, resource);
582 }, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, onTopicFoundListener);
584 return m_sharedResource->discoveryMQTopics(queryParametersMap, findCallback, QoS);
587 OCStackResult JniOcResource::createMQTopic(JNIEnv* env,
588 const OCRepresentation &representation, const std::string &targetUri,
589 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
591 std::shared_ptr<JniOnMQTopicFoundListener> onTopicCreatedListener = addOnTopicFoundListener(env, jListener);
593 MQTopicCallback createCallback = std::bind([](const int& eCode,
594 const std::string& uri,
595 std::shared_ptr<OCResource> resource,
596 std::weak_ptr<JniOnMQTopicFoundListener> weak_ref)
598 auto listener = weak_ref.lock();
601 listener->createdTopicCallback(eCode, uri, resource);
603 }, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, onTopicCreatedListener);
605 return m_sharedResource->createMQTopic(representation, targetUri,
607 createCallback, QoS);
611 OCStackResult JniOcResource::subscribeMQTopic(JNIEnv* env,
612 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
614 std::shared_ptr<JniOnMQSubscribeListener> onSubscribeListener = addOnMQTopicSubscribeListener(env, jListener);
616 ObserveCallback subscribeCallback = std::bind([](const HeaderOptions& opts,
617 const OCRepresentation& rep,
619 const int& sequenceNumber,
620 std::weak_ptr<JniOnMQSubscribeListener> weak_ref)
622 auto listener = weak_ref.lock();
625 listener->onSubscribeCallback(opts, rep, eCode, sequenceNumber);
627 }, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
628 std::placeholders::_4, onSubscribeListener);
630 return m_sharedResource->subscribeMQTopic(ObserveType::Observe, queryParametersMap,
631 subscribeCallback, QoS);
634 OCStackResult JniOcResource::unsubscribeMQTopic(QualityOfService QoS)
636 return m_sharedResource->unsubscribeMQTopic(QoS);
639 OCStackResult JniOcResource::requestMQPublish(JNIEnv* env,
640 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
642 JniOnPostListener::Ptr onPostListener = addOnPostListener(env, jListener);
644 PostCallback postCallback = std::bind([](const HeaderOptions& opts,
645 const OCRepresentation& rep,
647 std::weak_ptr<JniOnPostListener> weak_ref)
649 auto listener = weak_ref.lock();
652 listener->onPostCallback(opts, rep, eCode);
654 }, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, onPostListener);
656 return m_sharedResource->requestMQPublish(queryParametersMap, postCallback, QoS);
660 OCStackResult JniOcResource::publishMQTopic(JNIEnv* env, const OCRepresentation &representation,
661 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
663 JniOnPostListener::Ptr onPostListener = addOnPostListener(env, jListener);
665 PostCallback postCallback = std::bind([](const HeaderOptions& opts,
666 const OCRepresentation& rep,
668 std::weak_ptr<JniOnPostListener> weak_ref)
670 auto listener = weak_ref.lock();
673 onPostListener->onPostCallback(opts, rep, eCode);
675 }, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, onPostListener);
677 return m_sharedResource->publishMQTopic(representation, queryParametersMap,
683 * Class: org_iotivity_base_OcResource
685 * Signature: (Ljava/util/Map;Lorg/iotivity/base/OcResource/OnGetListener;)V
687 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_get
688 (JNIEnv *env, jobject thiz, jobject jQueryParamsMap, jobject jListener)
690 LOGD("OcResource_get");
691 if (!jQueryParamsMap)
693 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
698 ThrowOcException(OC_STACK_INVALID_PARAM, "onGetListener cannot be null");
701 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
708 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
712 OCStackResult result = resource->get(
717 if (OC_STACK_OK != result)
719 ThrowOcException(result, "OcResource_get");
722 catch (OCException& e)
724 LOGE("%s", e.reason().c_str());
725 ThrowOcException(e.code(), e.reason().c_str());
730 * Class: org_iotivity_base_OcResource
732 * Signature: (Ljava/util/Map;Lorg/iotivity/base/OcResource/OnGetListener;I)V
734 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_get1
735 (JNIEnv *env, jobject thiz, jobject jQueryParamsMap, jobject jListener, jint jQoS)
737 LOGD("OcResource_get");
738 if (!jQueryParamsMap)
740 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
745 ThrowOcException(OC_STACK_INVALID_PARAM, "onGetListener cannot be null");
748 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
755 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
759 OCStackResult result = resource->get(
763 JniUtils::getQOS(env, static_cast<int>(jQoS)));
765 if (OC_STACK_OK != result)
767 ThrowOcException(result, "OcResource_get");
770 catch (OCException& e)
772 LOGE("%s", e.reason().c_str());
773 ThrowOcException(e.code(), e.reason().c_str());
778 * Class: org_iotivity_base_OcResource
780 * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;
781 Lorg/iotivity/base/OcResource/OnGetListener;)V
783 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_get2
784 (JNIEnv *env, jobject thiz, jstring jResourceType, jstring jResourceInterface,
785 jobject jQueryParamsMap, jobject jListener)
787 LOGD("OcResource_get");
788 std::string resourceType;
791 resourceType = env->GetStringUTFChars(jResourceType, nullptr);
793 std::string resourceInterface;
794 if (jResourceInterface)
796 resourceInterface = env->GetStringUTFChars(jResourceInterface, nullptr);
798 if (!jQueryParamsMap)
800 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
805 ThrowOcException(OC_STACK_INVALID_PARAM, "onGetListener cannot be null");
808 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
815 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
818 OCStackResult result = resource->get(
825 if (OC_STACK_OK != result)
827 ThrowOcException(result, "OcResource_get");
830 catch (OCException& e)
832 LOGE("%s", e.reason().c_str());
833 ThrowOcException(e.code(), e.reason().c_str());
838 * Class: org_iotivity_base_OcResource
840 * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;
841 Lorg/iotivity/base/OcResource/OnGetListener;I)V
843 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_get3
844 (JNIEnv *env, jobject thiz, jstring jResourceType, jstring jResourceInterface,
845 jobject jQueryParamsMap, jobject jListener, jint jQoS)
847 LOGD("OcResource_get");
848 if (!jQueryParamsMap)
850 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
855 ThrowOcException(OC_STACK_INVALID_PARAM, "onGetListener cannot be null");
858 std::string resourceType;
861 resourceType = env->GetStringUTFChars(jResourceType, nullptr);
863 std::string resourceInterface;
864 if (jResourceInterface)
866 resourceInterface = env->GetStringUTFChars(jResourceInterface, nullptr);
868 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
875 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
879 OCStackResult result = resource->get(
885 JniUtils::getQOS(env, static_cast<int>(jQoS)));
887 if (OC_STACK_OK != result)
889 ThrowOcException(result, "OcResource_get");
892 catch (OCException& e)
894 LOGE("%s", e.reason().c_str());
895 ThrowOcException(e.code(), e.reason().c_str());
900 * Class: org_iotivity_base_OcResource
902 * Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/Map;
903 Lorg/iotivity/base/OcResource/OnPutListener;)V
905 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_put
906 (JNIEnv *env, jobject thiz, jobject jRepresentation, jobject jQueryParamsMap, jobject jListener)
908 LOGD("OcResource_put");
909 if (!jRepresentation)
911 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
914 if (!jQueryParamsMap)
916 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
921 ThrowOcException(OC_STACK_INVALID_PARAM, "onPutListener cannot be null");
924 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
930 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
937 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
941 OCStackResult result = resource->put(
947 if (OC_STACK_OK != result)
949 ThrowOcException(result, "OcResource_put");
952 catch (OCException& e)
954 LOGE("%s", e.reason().c_str());
955 ThrowOcException(e.code(), e.reason().c_str());
960 * Class: org_iotivity_base_OcResource
962 * Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/Map;
963 Lorg/iotivity/base/OcResource/OnPutListener;I)V
965 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_put1
966 (JNIEnv *env, jobject thiz, jobject jRepresentation, jobject jQueryParamsMap,
967 jobject jListener, jint jQoS)
969 LOGD("OcResource_put");
970 if (!jRepresentation)
972 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
975 if (!jQueryParamsMap)
977 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
982 ThrowOcException(OC_STACK_INVALID_PARAM, "onPutListener cannot be null");
985 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
991 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
998 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1002 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: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcRepresentation;
1025 Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPutListener;)V
1027 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_put2
1028 (JNIEnv *env, jobject thiz, jstring jResourceType, jstring jResourceInterface,
1029 jobject jRepresentation, jobject jQueryParamsMap, jobject jListener)
1031 LOGD("OcResource_put");
1032 std::string resourceType;
1035 resourceType = env->GetStringUTFChars(jResourceType, nullptr);
1037 std::string resourceInterface;
1038 if (jResourceInterface)
1040 resourceInterface = env->GetStringUTFChars(jResourceInterface, nullptr);
1042 if (!jRepresentation)
1044 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1047 if (!jQueryParamsMap)
1049 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1054 ThrowOcException(OC_STACK_INVALID_PARAM, "onPutListener cannot be null");
1057 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1063 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
1064 if (!representation)
1070 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1074 OCStackResult result = resource->put(
1082 if (OC_STACK_OK != result)
1084 ThrowOcException(result, "OcResource_put");
1087 catch (OCException& e)
1089 LOGE("%s", e.reason().c_str());
1090 ThrowOcException(e.code(), e.reason().c_str());
1095 * Class: org_iotivity_base_OcResource
1097 * Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcRepresentation;
1098 Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPutListener;I)V
1100 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_put3
1101 (JNIEnv *env, jobject thiz, jstring jResourceType, jstring jResourceInterface, jobject jRepresentation,
1102 jobject jQueryParamsMap, jobject jListener, jint jQoS)
1104 LOGD("OcResource_put");
1105 if (!jRepresentation)
1107 ThrowOcException(OC_STACK_INVALID_PARAM, "representation cannot be null");
1110 if (!jQueryParamsMap)
1112 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1117 ThrowOcException(OC_STACK_INVALID_PARAM, "onPutListener cannot be null");
1120 std::string resourceType;
1123 resourceType = env->GetStringUTFChars(jResourceType, nullptr);
1125 std::string resourceInterface;
1126 if (jResourceInterface)
1128 resourceInterface = env->GetStringUTFChars(jResourceInterface, nullptr);
1131 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1137 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
1138 if (!representation)
1144 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1148 OCStackResult result = resource->put(
1155 JniUtils::getQOS(env, static_cast<int>(jQoS)));
1157 if (OC_STACK_OK != result)
1159 ThrowOcException(result, "OcResource_put");
1162 catch (OCException& e)
1164 LOGE("%s", e.reason().c_str());
1165 ThrowOcException(e.code(), e.reason().c_str());
1170 * Class: org_iotivity_base_OcResource
1172 * Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPostListener;)V
1174 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_post
1175 (JNIEnv *env, jobject thiz, jobject jRepresentation, jobject jQueryParamsMap, jobject jListener)
1177 LOGD("OcResource_post");
1178 if (!jRepresentation)
1180 ThrowOcException(OC_STACK_INVALID_PARAM, "representation cannot be null");
1183 if (!jQueryParamsMap)
1185 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1190 ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null");
1193 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1199 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
1200 if (!representation)
1206 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1210 OCStackResult result = resource->post(
1216 if (OC_STACK_OK != result)
1218 ThrowOcException(result, "OcResource_post");
1221 catch (OCException& e)
1223 LOGE("%s", e.reason().c_str());
1224 ThrowOcException(e.code(), e.reason().c_str());
1229 * Class: org_iotivity_base_OcResource
1231 * Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPostListener;I)V
1233 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_post1
1234 (JNIEnv *env, jobject thiz, jobject jRepresentation, jobject jQueryParamsMap, jobject jListener, jint jQoS)
1236 LOGD("OcResource_post");
1237 if (!jRepresentation)
1239 ThrowOcException(OC_STACK_INVALID_PARAM, "representation cannot be null");
1242 if (!jQueryParamsMap)
1244 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1249 ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null");
1252 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1258 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
1259 if (!representation)
1265 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1269 OCStackResult result = resource->post(
1274 JniUtils::getQOS(env, static_cast<int>(jQoS)));
1276 if (OC_STACK_OK != result)
1278 ThrowOcException(result, "OcResource_post");
1281 catch (OCException& e)
1283 LOGE("%s", e.reason().c_str());
1284 ThrowOcException(e.code(), e.reason().c_str());
1289 * Class: org_iotivity_base_OcResource
1291 * Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcRepresentation;
1292 Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPostListener;)V
1294 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_post2
1295 (JNIEnv *env, jobject thiz, jstring jResourceType, jstring jResourceInterface,
1296 jobject jRepresentation, jobject jQueryParamsMap, jobject jListener)
1298 LOGD("OcResource_post");
1299 if (!jRepresentation)
1301 ThrowOcException(OC_STACK_INVALID_PARAM, "representation cannot be null");
1304 if (!jQueryParamsMap)
1306 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1311 ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null");
1314 std::string resourceType;
1317 resourceType = env->GetStringUTFChars(jResourceType, nullptr);
1319 std::string resourceInterface;
1320 if (jResourceInterface)
1322 resourceInterface = env->GetStringUTFChars(jResourceInterface, nullptr);
1325 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1331 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
1332 if (!representation)
1338 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1342 OCStackResult result = resource->post(
1350 if (OC_STACK_OK != result)
1352 ThrowOcException(result, "OcResource_post");
1355 catch (OCException& e)
1357 LOGE("%s", e.reason().c_str());
1358 ThrowOcException(e.code(), e.reason().c_str());
1363 * Class: org_iotivity_base_OcResource
1365 * Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcRepresentation;
1366 Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPostListener;I)V
1368 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_post3
1369 (JNIEnv *env, jobject thiz, jstring jResourceType, jstring jResourceInterface,
1370 jobject jRepresentation, jobject jQueryParamsMap, jobject jListener, jint jQoS)
1372 LOGD("OcResource_post");
1373 if (!jRepresentation)
1375 ThrowOcException(OC_STACK_INVALID_PARAM, "representation cannot be null");
1378 if (!jQueryParamsMap)
1380 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1385 ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null");
1388 std::string resourceType;
1391 resourceType = env->GetStringUTFChars(jResourceType, nullptr);
1393 std::string resourceInterface;
1394 if (jResourceInterface)
1396 resourceInterface = env->GetStringUTFChars(jResourceInterface, nullptr);
1399 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1405 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
1406 if (!representation)
1412 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1416 OCStackResult result = resource->post(
1423 JniUtils::getQOS(env, static_cast<int>(jQoS)));
1425 if (OC_STACK_OK != result)
1427 ThrowOcException(result, "OcResource_post");
1430 catch (OCException& e)
1432 LOGE("%s", e.reason().c_str());
1433 ThrowOcException(e.code(), e.reason().c_str());
1438 * Class: org_iotivity_base_OcResource
1439 * Method: deleteResource
1440 * Signature: (Lorg/iotivity/base/OcResource/OnDeleteListener;)V
1442 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_deleteResource
1443 (JNIEnv *env, jobject thiz, jobject jListener)
1445 LOGD("OcResource_deleteResource");
1448 ThrowOcException(OC_STACK_INVALID_PARAM, "onDeleteListener cannot be null");
1451 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1459 OCStackResult result = resource->deleteResource(
1463 if (OC_STACK_OK != result)
1465 ThrowOcException(result, "OcResource_deleteResource");
1468 catch (OCException& e)
1470 LOGE("%s", e.reason().c_str());
1471 ThrowOcException(e.code(), e.reason().c_str());
1476 * Class: org_iotivity_base_OcResource
1477 * Method: deleteResource1
1478 * Signature: (Lorg/iotivity/base/OcResource/OnDeleteListener;I)V
1480 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_deleteResource1
1481 (JNIEnv *env, jobject thiz, jobject jListener, jint jQoS)
1483 LOGD("OcResource_deleteResource");
1486 ThrowOcException(OC_STACK_INVALID_PARAM, "onDeleteListener cannot be null");
1489 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1497 OCStackResult result = resource->deleteResource(
1500 JniUtils::getQOS(env, static_cast<int>(jQoS)));
1502 if (OC_STACK_OK != result)
1504 ThrowOcException(result, "OcResource_deleteResource");
1507 catch (OCException& e)
1509 LOGE("%s", e.reason().c_str());
1510 ThrowOcException(e.code(), e.reason().c_str());
1515 * Class: org_iotivity_base_OcResource
1517 * Signature: (Lorg/iotivity/base/ObserveType;Ljava/util/Map;
1518 Lorg/iotivity/base/OcResource/OnObserveListener;)V
1520 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_observe
1521 (JNIEnv *env, jobject thiz, jint observeType, jobject jQueryParamsMap, jobject jListener)
1523 LOGD("OcResource_observe");
1524 if (!jQueryParamsMap)
1526 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1531 ThrowOcException(OC_STACK_INVALID_PARAM, "onObserveListener cannot be null");
1534 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1541 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1545 OCStackResult result = resource->observe(
1547 JniUtils::getObserveType(env, static_cast<int>(observeType)),
1551 if (OC_STACK_OK != result)
1553 ThrowOcException(result, "OcResource_observe");
1556 catch (OCException& e)
1558 LOGE("%s", e.reason().c_str());
1559 ThrowOcException(e.code(), e.reason().c_str());
1564 * Class: org_iotivity_base_OcResource
1566 * Signature: (Lorg/iotivity/base/ObserveType;Ljava/util/Map;
1567 Lorg/iotivity/base/OcResource/OnObserveListener;I)V
1569 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_observe1
1570 (JNIEnv *env, jobject thiz, jint observeType, jobject jQueryParamsMap,
1571 jobject jListener, jint jQoS)
1573 LOGD("OcResource_observe");
1574 if (!jQueryParamsMap)
1576 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1581 ThrowOcException(OC_STACK_INVALID_PARAM, "onObserveListener cannot be null");
1584 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1591 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1595 OCStackResult result = resource->observe(
1597 JniUtils::getObserveType(env, static_cast<int>(observeType)),
1600 JniUtils::getQOS(env, static_cast<int>(jQoS)));
1602 if (OC_STACK_OK != result)
1604 ThrowOcException(result, "OcResource_observe");
1607 catch (OCException& e)
1609 LOGE("%s", e.reason().c_str());
1610 ThrowOcException(e.code(), e.reason().c_str());
1615 * Class: org_iotivity_base_OcResource
1616 * Method: cancelObserve1
1619 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_cancelObserve1
1620 (JNIEnv *env, jobject thiz, jint jQoS)
1622 LOGD("OcResource_cancelObserve1");
1623 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1631 OCStackResult result = resource->cancelObserve(
1633 JniUtils::getQOS(env, static_cast<int>(jQoS)));
1635 if (OC_STACK_OK != result)
1637 ThrowOcException(result, "OcResource_cancelObserve");
1640 catch (OCException& e)
1642 LOGE("%s", e.reason().c_str());
1643 ThrowOcException(e.code(), e.reason().c_str());
1648 * Class: org_iotivity_base_OcResource
1649 * Method: setHeaderOptions
1650 * Signature: ([Lorg/iotivity/OcHeaderOption;)V
1652 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_setHeaderOptions
1653 (JNIEnv *env, jobject thiz, jobjectArray jheaderOptionArr)
1655 LOGD("OcResource_setHeaderOptions");
1656 if (!jheaderOptionArr)
1658 ThrowOcException(OC_STACK_INVALID_PARAM, "headerOptionList cannot be null");
1661 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1667 HeaderOptions headerOptions;
1668 JniUtils::convertJavaHeaderOptionsArrToVector(env, jheaderOptionArr, headerOptions);
1670 resource->setHeaderOptions(headerOptions);
1674 * Class: org_iotivity_base_OcResource
1675 * Method: unsetHeaderOptions
1678 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_unsetHeaderOptions
1679 (JNIEnv *env, jobject thiz)
1681 LOGD("OcResource_unsetHeaderOptions");
1682 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1688 resource->unsetHeaderOptions();
1692 * Class: org_iotivity_base_OcResource
1694 * Signature: ()Ljava/lang/String;
1696 JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcResource_getHost
1697 (JNIEnv *env, jobject thiz)
1699 LOGD("OcResource_getHost");
1700 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1706 return env->NewStringUTF(resource->host().c_str());
1710 * Class: org_iotivity_base_OcResource
1712 * Signature: ()Ljava/lang/String;
1714 JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcResource_getUri
1715 (JNIEnv *env, jobject thiz)
1717 LOGD("OcResource_getUri");
1718 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1724 return env->NewStringUTF(resource->uri().c_str());
1728 * Class: org_iotivity_base_OcResource
1729 * Method: getConnectivityTypeN
1732 JNIEXPORT jint JNICALL Java_org_iotivity_base_OcResource_getConnectivityTypeN
1733 (JNIEnv *env, jobject thiz)
1735 LOGD("OcResource_getConnectivityType");
1736 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1742 OCConnectivityType connectivityType = resource->connectivityType();
1743 return static_cast<jint>(connectivityType);
1747 * Class: org_iotivity_base_OcResource
1748 * Method: isObservable
1751 JNIEXPORT jboolean JNICALL Java_org_iotivity_base_OcResource_isObservable
1752 (JNIEnv *env, jobject thiz)
1754 LOGD("OcResource_isObservable");
1755 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1761 return (jboolean)resource->isObservable();
1765 * Class: org_iotivity_base_OcResource
1766 * Method: getResourceTypes
1767 * Signature: ()Ljava/util/List;
1769 JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcResource_getResourceTypes
1770 (JNIEnv *env, jobject thiz)
1772 LOGD("OcResource_getResourceTypes");
1773 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1779 std::vector<std::string> resourceTypes = resource->getResourceTypes();
1781 return JniUtils::convertStrVectorToJavaStrList(env, resourceTypes);
1785 * Class: org_iotivity_base_OcResource
1786 * Method: getResourceInterfaces
1787 * Signature: ()Ljava/util/List;
1789 JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcResource_getResourceInterfaces
1790 (JNIEnv *env, jobject thiz)
1792 LOGD("OcResource_getResourceInterfaces");
1793 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1799 std::vector<std::string> resourceInterfaces = resource->getResourceInterfaces();
1801 return JniUtils::convertStrVectorToJavaStrList(env, resourceInterfaces);
1805 * Class: org_iotivity_base_OcResource
1806 * Method: getUniqueIdentifier
1807 * Signature: ()Lorg/iotivity/base/OcResourceIdentifier;
1809 JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcResource_getUniqueIdentifier
1810 (JNIEnv *env, jobject thiz)
1812 LOGD("OcResource_getUniqueIdentifier");
1813 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1819 JniOcResourceIdentifier *jniResourceIdentifier =
1820 new JniOcResourceIdentifier(resource->uniqueIdentifier());
1821 if (!jniResourceIdentifier)
1826 jlong handle = reinterpret_cast<jlong>(jniResourceIdentifier);
1827 jobject jResourceIdentifier = env->NewObject(g_cls_OcResourceIdentifier,
1828 g_mid_OcResourceIdentifier_N_ctor, handle);
1829 if (!jResourceIdentifier)
1831 delete jniResourceIdentifier;
1833 return jResourceIdentifier;
1837 * Class: org_iotivity_base_OcResource
1838 * Method: getServerId
1839 * Signature: ()Ljava/lang/String;
1841 JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcResource_getServerId
1842 (JNIEnv *env, jobject thiz)
1844 LOGD("OcResource_getServerId");
1845 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1851 return env->NewStringUTF(resource->sid().c_str());
1855 * Class: org_iotivity_base_OcResource
1856 * Method: getDeviceName
1857 * Signature: ()Ljava/lang/String;
1859 JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcResource_getDeviceName
1860 (JNIEnv *env, jobject thiz)
1862 LOGD("OcResource_getDeviceName");
1863 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1869 return env->NewStringUTF(resource->deviceName().c_str());
1873 * Class: org_iotivity_base_OcResource
1877 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_dispose
1878 (JNIEnv *env, jobject thiz)
1880 LOGD("OcResource_dispose");
1881 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1886 * Class: org_iotivity_base_OcResource
1887 * Method: discoveryMQTopicsImpl
1888 * Signature: (Ljava/util/Map;Lorg/iotivity/base/OcPlatform/OnResourceFoundListener;I)V
1890 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_discoveryMQTopicsImpl
1891 (JNIEnv *env, jobject thiz, jobject jQueryParamsMap, jobject jListener, jint jQoS)
1893 LOGD("OcResource_discoveryMQTopicsImpl");
1896 if (!jQueryParamsMap)
1898 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1904 ThrowOcException(OC_STACK_INVALID_PARAM, "listener cannot be null");
1908 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1915 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1919 OCStackResult result = resource->discoveryMQTopics(
1923 JniUtils::getQOS(env, static_cast<int>(jQoS)));
1925 if (OC_STACK_OK != result)
1927 ThrowOcException(result, "OcResource_discoveryMQTopicsImpl");
1930 catch (OCException& e)
1932 LOGE("%s", e.reason().c_str());
1933 ThrowOcException(e.code(), e.reason().c_str());
1936 ThrowOcException(JNI_NO_SUPPORT, "not support");
1941 * Class: org_iotivity_base_OcResource
1942 * Method: createMQTopicImpl
1943 * Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/String;Ljava/util/Map
1944 * ;Lorg/iotivity/base/OcPlatform/OnMQTopicCreatedListener;I)V
1946 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_createMQTopicImpl
1947 (JNIEnv *env, jobject thiz, jobject jRepresentation, jstring jUri,
1948 jobject jQueryParamsMap, jobject jListener, jint jQoS)
1950 LOGD("OcResource_createMQTopicImpl");
1953 if (!jQueryParamsMap)
1955 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1961 ThrowOcException(OC_STACK_INVALID_PARAM, "listener cannot be null");
1965 if (!jRepresentation)
1967 ThrowOcException(OC_STACK_INVALID_PARAM, "representation null");
1971 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1977 std::string targetUri;
1980 targetUri = env->GetStringUTFChars(jUri, nullptr);
1983 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env,
1985 if (!representation)
1991 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1995 OCStackResult result = resource->createMQTopic(
2001 JniUtils::getQOS(env, static_cast<int>(jQoS)));
2003 if (OC_STACK_OK != result)
2005 ThrowOcException(result, "OcResource_createMQTopicImpl");
2008 catch (OCException& e)
2010 LOGE("%s", e.reason().c_str());
2011 ThrowOcException(e.code(), e.reason().c_str());
2014 ThrowOcException(JNI_NO_SUPPORT, "not support");
2019 * Class: org_iotivity_base_OcResource
2020 * Method: subscribeMQTopic
2021 * Signature: (Ljava/util/Map;Lorg/iotivity/base/OcResource/OnObserveListener;I)V
2023 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_subscribeMQTopicImpl
2024 (JNIEnv *env, jobject thiz, jobject jQueryParamsMap, jobject jListener, jint jQoS)
2026 LOGD("OcResource_subscribeMQTopicImpl");
2027 #ifdef MQ_SUBSCRIBER
2028 if (!jQueryParamsMap)
2030 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
2035 ThrowOcException(OC_STACK_INVALID_PARAM, "onObserveListener cannot be null");
2038 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
2045 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
2049 OCStackResult result = resource->subscribeMQTopic(
2053 JniUtils::getQOS(env, static_cast<int>(jQoS)));
2055 if (OC_STACK_OK != result)
2057 ThrowOcException(result, "OcResource_subscribeMQTopicImpl");
2060 catch (OCException& e)
2062 LOGE("%s", e.reason().c_str());
2063 ThrowOcException(e.code(), e.reason().c_str());
2066 ThrowOcException(JNI_NO_SUPPORT, "not support");
2071 * Class: org_iotivity_base_OcResource
2072 * Method: unsubscribeMQTopicImpl
2075 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_unsubscribeMQTopicImpl
2076 (JNIEnv *env, jobject thiz, jint jQoS)
2078 LOGD("OcResource_unsubscribeMQTopicImpl");
2079 #ifdef MQ_SUBSCRIBER
2080 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
2088 OCStackResult result = resource->unsubscribeMQTopic(
2089 JniUtils::getQOS(env, static_cast<int>(jQoS)));
2090 if (OC_STACK_OK != result)
2092 ThrowOcException(result, "OcResource_unsubscribeMQTopicImpl");
2095 catch (OCException& e)
2097 LOGE("%s", e.reason().c_str());
2098 ThrowOcException(e.code(), e.reason().c_str());
2101 ThrowOcException(JNI_NO_SUPPORT, "not support");
2106 * Class: org_iotivity_base_OcResource
2107 * Method: requestMQPublishImpl
2108 * Signature: (Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPostListener;I)V
2110 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_requestMQPublishImpl
2111 (JNIEnv *env, jobject thiz, jobject jQueryParamsMap, jobject jListener, jint jQoS)
2113 LOGD("OcResource_requestMQPublishImpl");
2114 #ifdef MQ_SUBSCRIBER
2115 if (!jQueryParamsMap)
2117 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
2122 ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null");
2126 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
2133 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
2137 OCStackResult result = resource->requestMQPublish(
2141 JniUtils::getQOS(env, static_cast<int>(jQoS)));
2143 if (OC_STACK_OK != result)
2145 ThrowOcException(result, "OcResource_requestMQPublishImpl");
2148 catch (OCException& e)
2150 LOGE("%s", e.reason().c_str());
2151 ThrowOcException(e.code(), e.reason().c_str());
2154 ThrowOcException(JNI_NO_SUPPORT, "not support");
2159 * Class: org_iotivity_base_OcResource
2160 * Method: publishMQTopicImpl
2161 * Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/Map;
2162 * Lorg/iotivity/base/OcResource/OnPostListener;I)V
2164 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_publishMQTopicImpl
2165 (JNIEnv *env, jobject thiz, jobject jRepresentation, jobject jQueryParamsMap,
2166 jobject jListener, jint jQoS)
2168 LOGD("OcResource_publishMQTopicImpl");
2170 if (!jRepresentation)
2172 ThrowOcException(OC_STACK_INVALID_PARAM, "representation cannot be null");
2176 if (!jQueryParamsMap)
2178 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
2184 ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null");
2188 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
2194 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env,
2196 if (!representation)
2202 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
2206 OCStackResult result = resource->publishMQTopic(
2211 JniUtils::getQOS(env, static_cast<int>(jQoS)));
2213 if (OC_STACK_OK != result)
2215 ThrowOcException(result, "OcResource_publishMQTopicImpl");
2218 catch (OCException& e)
2220 LOGE("%s", e.reason().c_str());
2221 ThrowOcException(e.code(), e.reason().c_str());
2224 ThrowOcException(JNI_NO_SUPPORT, "not support");