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 class JniOcResourceImpl : public std::enable_shared_from_this<JniOcResourceImpl>
30 typedef std::shared_ptr<JniOcResourceImpl> Ptr;
32 JniOcResourceImpl(std::shared_ptr<OCResource> &resource);
35 OCStackResult get(JNIEnv* env, const QueryParamsMap &queryParametersMap, jobject jListener);
36 OCStackResult get(JNIEnv* env, const QueryParamsMap &queryParametersMap, jobject jListener,
37 QualityOfService QoS);
38 OCStackResult get(JNIEnv* env, const std::string &resourceType, const std::string &resourceInterface,
39 const QueryParamsMap &queryParametersMap, jobject jListener);
40 OCStackResult get(JNIEnv* env, const std::string &resourceType, const std::string &resourceInterface,
41 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS);
43 OCStackResult put(JNIEnv* env, const OCRepresentation &representation, const QueryParamsMap &queryParametersMap,
45 OCStackResult put(JNIEnv* env, const OCRepresentation &representation, const QueryParamsMap &queryParametersMap,
46 jobject jListener, QualityOfService QoS);
47 OCStackResult put(JNIEnv* env, const std::string &resourceType, const std::string &resourceInterface,
48 const OCRepresentation &representation, const QueryParamsMap &queryParametersMap, jobject jListener);
49 OCStackResult put(JNIEnv* env, const std::string &resourceType, const std::string &resourceInterface,
50 const OCRepresentation &representation, const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS);
52 OCStackResult post(JNIEnv* env, const OCRepresentation &representation, const QueryParamsMap &queryParametersMap,
54 OCStackResult post(JNIEnv* env, const OCRepresentation &representation, const QueryParamsMap &queryParametersMap,
55 jobject jListener, QualityOfService QoS);
56 OCStackResult post(JNIEnv* env, const std::string &resourceType, const std::string &resourceInterface,
57 const OCRepresentation &representation, const QueryParamsMap &queryParametersMap, jobject jListener);
58 OCStackResult post(JNIEnv* env, const std::string &resourceType, const std::string &resourceInterface,
59 const OCRepresentation &representation, const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS);
61 OCStackResult deleteResource(JNIEnv* env, jobject jListener);
62 OCStackResult deleteResource(JNIEnv* env, jobject jListener, QualityOfService QoS);
64 OCStackResult observe(JNIEnv* env, ObserveType observeType, const QueryParamsMap &queryParametersMap,
66 OCStackResult observe(JNIEnv* env, ObserveType observeType, const QueryParamsMap &queryParametersMap,
67 jobject jListener, QualityOfService qos);
69 OCStackResult cancelObserve(JNIEnv* env);
70 OCStackResult cancelObserve(JNIEnv* env, QualityOfService qos);
72 void setHeaderOptions(const HeaderOptions &headerOptions);
73 void unsetHeaderOptions();
76 OCConnectivityType connectivityType() const;
78 std::vector< std::string > getResourceTypes() const;
79 std::vector< std::string > getResourceInterfaces(void) const;
80 OCResourceIdentifier uniqueIdentifier() const;
81 std::string sid() const;
82 std::string deviceName() const;
84 JniOnGetListener* addOnGetListener(JNIEnv* env, jobject jListener);
85 JniOnPutListener* addOnPutListener(JNIEnv* env, jobject jListener);
86 JniOnPostListener* addOnPostListener(JNIEnv* env, jobject jListener);
87 JniOnDeleteListener* addOnDeleteListener(JNIEnv* env, jobject jListener);
88 JniOnObserveListener* addOnObserveListener(JNIEnv* env, jobject jListener);
90 void removeOnGetListener(JNIEnv* env, jobject jListener);
91 void removeOnPutListener(JNIEnv* env, jobject jListener);
92 void removeOnPostListener(JNIEnv* env, jobject jListener);
93 void removeOnDeleteListener(JNIEnv* env, jobject jListener);
94 void removeOnObserveListener(JNIEnv* env, jobject jListener);
96 std::shared_ptr<OCResource> getOCResource();
99 JniOnMQTopicFoundListener* addOnTopicFoundListener(JNIEnv* env, jobject jListener);
100 void removeOnTopicFoundListener(JNIEnv* env, jobject jListener);
102 JniOnMQSubscribeListener* addOnMQTopicSubscribeListener(JNIEnv* env, jobject jListener);
103 void removeOnMQTopicSubscribeListener(JNIEnv* env, jobject jListener);
105 OCStackResult discoveryMQTopics(JNIEnv* env, const QueryParamsMap &queryParametersMap,
106 jobject jListener, QualityOfService QoS);
107 OCStackResult createMQTopic(JNIEnv* env, const OCRepresentation &representation,
108 const std::string &targetUri,
109 const QueryParamsMap &queryParametersMap,
110 jobject jListener, QualityOfService QoS);
113 OCStackResult subscribeMQTopic(JNIEnv* env, const QueryParamsMap &queryParametersMap,
114 jobject jListener, QualityOfService QoS);
115 OCStackResult unsubscribeMQTopic(QualityOfService QoS);
116 OCStackResult requestMQPublish(JNIEnv* env, const QueryParamsMap &queryParametersMap,
117 jobject jListener, QualityOfService QoS);
120 OCStackResult publishMQTopic(JNIEnv* env, const OCRepresentation &representation,
121 const QueryParamsMap &queryParametersMap,
122 jobject jListener, QualityOfService QoS);
127 static void onGetCallback(const HeaderOptions& opts, const OCRepresentation& rep,
128 const int eCode, JniOnGetListener *listener,
129 std::weak_ptr<JniOcResourceImpl> weakRef);
131 static void onPutCallback(const HeaderOptions& opts, const OCRepresentation& rep,
132 const int eCode, JniOnPutListener *listener,
133 std::weak_ptr<JniOcResourceImpl> weakRef);
135 static void onPostCallback(const HeaderOptions& opts, const OCRepresentation& rep,
136 const int eCode, JniOnPostListener *listener,
137 std::weak_ptr<JniOcResourceImpl> weakRef);
139 static void onDeleteCallback(const HeaderOptions& opts,
140 const int eCode, JniOnDeleteListener *listener,
141 std::weak_ptr<JniOcResourceImpl> weakRef);
143 static void onObserveCallback(const HeaderOptions& opts, const OCRepresentation& rep,
144 const int eCode, const int& sequenceNumber,
145 JniOnObserveListener *listener,
146 std::weak_ptr<JniOcResourceImpl> weakRef);
149 JniListenerManager<JniOnGetListener> m_onGetManager;
150 JniListenerManager<JniOnPutListener> m_onPutManager;
151 JniListenerManager<JniOnPostListener> m_onPostManager;
152 JniListenerManager<JniOnDeleteListener> m_onDeleteManager;
153 JniListenerManager<JniOnObserveListener> m_onObserveManager;
155 JniListenerManager<JniOnMQTopicFoundListener> m_onFoundTopicResourceManager;
156 JniListenerManager<JniOnMQSubscribeListener> m_onSubcribeTopicManager;
159 std::shared_ptr<OCResource> m_sharedResource;
162 JniOcResourceImpl::JniOcResourceImpl(std::shared_ptr<OCResource> &resource)
163 : m_sharedResource(resource) {}
165 JniOcResourceImpl::~JniOcResourceImpl()
167 LOGD("~JniOcResourceImpl()");
169 m_sharedResource = nullptr;
171 jint envRet = JNI_ERR;
172 JNIEnv *env = GetJNIEnv(envRet);
178 m_onGetManager.removeAllListeners(env);
179 m_onPutManager.removeAllListeners(env);
180 m_onPostManager.removeAllListeners(env);
181 m_onDeleteManager.removeAllListeners(env);
182 m_onObserveManager.removeAllListeners(env);
184 m_onFoundTopicResourceManager.removeAllListeners(env);
185 m_onSubcribeTopicManager.removeAllListeners(env);
188 if (JNI_EDETACHED == envRet)
190 g_jvm->DetachCurrentThread();
194 void JniOcResourceImpl::onGetCallback(const HeaderOptions& opts, const OCRepresentation& rep,
195 const int eCode, JniOnGetListener *listener,
196 std::weak_ptr<JniOcResourceImpl> weakRef)
198 auto obj = weakRef.lock();
201 LOGD("Get callback called on deleted object\n");
205 listener->onGetCallback(opts, rep, eCode);
208 OCStackResult JniOcResourceImpl::get(JNIEnv* env, const QueryParamsMap &queryParametersMap, jobject jListener)
210 JniOnGetListener *onGetListener = addOnGetListener(env, jListener);
212 GetCallback getCallback = std::bind(JniOcResourceImpl::onGetCallback, std::placeholders::_1,
213 std::placeholders::_2, std::placeholders::_3, onGetListener,
216 return m_sharedResource->get(queryParametersMap, getCallback);
219 OCStackResult JniOcResourceImpl::get(JNIEnv* env, const QueryParamsMap &queryParametersMap, jobject jListener,
220 QualityOfService QoS)
222 JniOnGetListener *onGetListener = addOnGetListener(env, jListener);
224 GetCallback getCallback = std::bind(JniOcResourceImpl::onGetCallback, std::placeholders::_1,
225 std::placeholders::_2, std::placeholders::_3, onGetListener,
228 return m_sharedResource->get(queryParametersMap, getCallback, QoS);
231 OCStackResult JniOcResourceImpl::get(
233 const std::string &resourceType,
234 const std::string &resourceInterface,
235 const QueryParamsMap &queryParametersMap,
238 JniOnGetListener *onGetListener = addOnGetListener(env, jListener);
240 GetCallback getCallback = std::bind(JniOcResourceImpl::onGetCallback, std::placeholders::_1,
241 std::placeholders::_2, std::placeholders::_3, onGetListener,
244 return m_sharedResource->get(resourceType, resourceInterface, queryParametersMap,
248 OCStackResult JniOcResourceImpl::get(JNIEnv* env, const std::string &resourceType,
249 const std::string &resourceInterface, const QueryParamsMap &queryParametersMap,
250 jobject jListener, QualityOfService QoS)
252 JniOnGetListener *onGetListener = addOnGetListener(env, jListener);
254 GetCallback getCallback = std::bind(JniOcResourceImpl::onGetCallback, std::placeholders::_1,
255 std::placeholders::_2, std::placeholders::_3, onGetListener,
258 return m_sharedResource->get(resourceType, resourceInterface, queryParametersMap,
262 void JniOcResourceImpl::onPutCallback(const HeaderOptions& opts, const OCRepresentation& rep,
263 const int eCode, JniOnPutListener *listener,
264 std::weak_ptr<JniOcResourceImpl> weakRef)
266 auto obj = weakRef.lock();
269 LOGD("Put callback called on deleted object\n");
273 listener->onPutCallback(opts, rep, eCode);
276 OCStackResult JniOcResourceImpl::put(JNIEnv* env, const OCRepresentation &representation,
277 const QueryParamsMap &queryParametersMap, jobject jListener)
279 JniOnPutListener *onPutListener = addOnPutListener(env, jListener);
281 PutCallback putCallback = std::bind(JniOcResourceImpl::onPutCallback, std::placeholders::_1,
282 std::placeholders::_2, std::placeholders::_3, onPutListener,
285 return m_sharedResource->put(representation, queryParametersMap, putCallback);
288 OCStackResult JniOcResourceImpl::put(JNIEnv* env, const OCRepresentation &representation,
289 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
291 JniOnPutListener *onPutListener = addOnPutListener(env, jListener);
293 PutCallback putCallback = std::bind(JniOcResourceImpl::onPutCallback, std::placeholders::_1,
294 std::placeholders::_2, std::placeholders::_3, onPutListener,
297 return m_sharedResource->put(representation, queryParametersMap, putCallback, QoS);
300 OCStackResult JniOcResourceImpl::put(JNIEnv* env, const std::string &resourceType,
301 const std::string &resourceInterface, const OCRepresentation &representation,
302 const QueryParamsMap &queryParametersMap, jobject jListener)
304 JniOnPutListener *onPutListener = addOnPutListener(env, jListener);
306 PutCallback putCallback = std::bind(JniOcResourceImpl::onPutCallback, std::placeholders::_1,
307 std::placeholders::_2, std::placeholders::_3, onPutListener,
310 return m_sharedResource->put(resourceType, resourceInterface, representation,
311 queryParametersMap, putCallback);
314 OCStackResult JniOcResourceImpl::put(JNIEnv* env, const std::string &resourceType,
315 const std::string &resourceInterface, const OCRepresentation &representation,
316 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
318 JniOnPutListener *onPutListener = addOnPutListener(env, jListener);
320 PutCallback putCallback = std::bind(JniOcResourceImpl::onPutCallback, std::placeholders::_1,
321 std::placeholders::_2, std::placeholders::_3, onPutListener,
324 return m_sharedResource->put(resourceType, resourceInterface, representation,
325 queryParametersMap, putCallback, QoS);
328 void JniOcResourceImpl::onPostCallback(const HeaderOptions& opts, const OCRepresentation& rep,
329 const int eCode, JniOnPostListener *listener,
330 std::weak_ptr<JniOcResourceImpl> weakRef)
332 auto obj = weakRef.lock();
335 LOGD("Post callback called on deleted object\n");
339 listener->onPostCallback(opts, rep, eCode);
342 OCStackResult JniOcResourceImpl::post(JNIEnv* env, const OCRepresentation &representation,
343 const QueryParamsMap &queryParametersMap, jobject jListener)
345 JniOnPostListener *onPostListener = addOnPostListener(env, jListener);
347 PostCallback postCallback = std::bind(JniOcResourceImpl::onPostCallback, std::placeholders::_1,
348 std::placeholders::_2, std::placeholders::_3, onPostListener,
351 return m_sharedResource->post(representation, queryParametersMap, postCallback);
354 OCStackResult JniOcResourceImpl::post(JNIEnv* env, const OCRepresentation &representation,
355 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
357 JniOnPostListener *onPostListener = addOnPostListener(env, jListener);
359 PostCallback postCallback = std::bind(JniOcResourceImpl::onPostCallback, std::placeholders::_1,
360 std::placeholders::_2, std::placeholders::_3, onPostListener,
363 return m_sharedResource->post(representation, queryParametersMap, postCallback, QoS);
366 OCStackResult JniOcResourceImpl::post(JNIEnv* env, const std::string &resourceType,
367 const std::string &resourceInterface, const OCRepresentation &representation,
368 const QueryParamsMap &queryParametersMap, jobject jListener)
370 JniOnPostListener *onPostListener = addOnPostListener(env, jListener);
372 PostCallback postCallback = std::bind(JniOcResourceImpl::onPostCallback, std::placeholders::_1,
373 std::placeholders::_2, std::placeholders::_3, onPostListener,
376 return m_sharedResource->post(resourceType, resourceInterface, representation,
377 queryParametersMap, postCallback);
380 OCStackResult JniOcResourceImpl::post(JNIEnv* env, const std::string &resourceType,
381 const std::string &resourceInterface, const OCRepresentation &representation,
382 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
384 JniOnPostListener *onPostListener = addOnPostListener(env, jListener);
386 PostCallback postCallback = std::bind(JniOcResourceImpl::onPostCallback, std::placeholders::_1,
387 std::placeholders::_2, std::placeholders::_3, onPostListener,
390 return m_sharedResource->post(resourceType, resourceInterface, representation,
391 queryParametersMap, postCallback, QoS);
394 void JniOcResourceImpl::onDeleteCallback(const HeaderOptions& opts,
395 const int eCode, JniOnDeleteListener *listener,
396 std::weak_ptr<JniOcResourceImpl> weakRef)
398 auto obj = weakRef.lock();
401 LOGD("Delete callback called on deleted object\n");
405 listener->onDeleteCallback(opts, eCode);
408 OCStackResult JniOcResourceImpl::deleteResource(JNIEnv* env, jobject jListener)
410 JniOnDeleteListener *onDeleteListener = addOnDeleteListener(env, jListener);
412 DeleteCallback deleteCallback = std::bind(JniOcResourceImpl::onDeleteCallback, std::placeholders::_1,
413 std::placeholders::_2, onDeleteListener,
416 return m_sharedResource->deleteResource(deleteCallback);
419 OCStackResult JniOcResourceImpl::deleteResource(JNIEnv* env, jobject jListener, QualityOfService QoS)
421 JniOnDeleteListener *onDeleteListener = addOnDeleteListener(env, jListener);
423 DeleteCallback deleteCallback = std::bind(JniOcResourceImpl::onDeleteCallback, std::placeholders::_1,
424 std::placeholders::_2, onDeleteListener,
427 return m_sharedResource->deleteResource(deleteCallback, QoS);
430 void JniOcResourceImpl::onObserveCallback(const HeaderOptions& opts, const OCRepresentation& rep,
431 const int eCode, const int& sequenceNumber,
432 JniOnObserveListener *listener,
433 std::weak_ptr<JniOcResourceImpl> weakRef)
435 auto obj = weakRef.lock();
438 LOGD("Observe callback called on deleted object\n");
442 listener->onObserveCallback(opts, rep, eCode, sequenceNumber);
445 OCStackResult JniOcResourceImpl::observe(JNIEnv* env, ObserveType observeType,
446 const QueryParamsMap &queryParametersMap, jobject jListener)
448 JniOnObserveListener *onObserveListener = addOnObserveListener(env, jListener);
450 ObserveCallback observeCallback = std::bind(JniOcResourceImpl::onObserveCallback, std::placeholders::_1,
451 std::placeholders::_2, std::placeholders::_3,
452 std::placeholders::_4, onObserveListener,
455 return m_sharedResource->observe(observeType, queryParametersMap, observeCallback);
458 OCStackResult JniOcResourceImpl::observe(JNIEnv* env, ObserveType observeType,
459 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
461 JniOnObserveListener *onObserveListener = addOnObserveListener(env, jListener);
463 ObserveCallback observeCallback = std::bind(JniOcResourceImpl::onObserveCallback, std::placeholders::_1,
464 std::placeholders::_2, std::placeholders::_3,
465 std::placeholders::_4, onObserveListener,
468 return m_sharedResource->observe(observeType, queryParametersMap, observeCallback, QoS);
471 OCStackResult JniOcResourceImpl::cancelObserve(JNIEnv* env, QualityOfService qos)
473 // In Low case, after delete the callback and send empty message when client receive the notify.
474 // But TCP does not support EMPTY message.
475 if ((CT_ADAPTER_IP & connectivityType()) && QualityOfService::HighQos != qos)
477 this->m_onObserveManager.removeAllListeners(env);
479 return m_sharedResource->cancelObserve(qos);
482 void JniOcResourceImpl::setHeaderOptions(const HeaderOptions &headerOptions)
484 m_sharedResource->setHeaderOptions(headerOptions);
487 void JniOcResourceImpl::unsetHeaderOptions()
489 m_sharedResource->unsetHeaderOptions();
492 std::string JniOcResourceImpl::host()
494 return m_sharedResource->host();
497 std::string JniOcResourceImpl::uri()
499 return m_sharedResource->uri();
502 OCConnectivityType JniOcResourceImpl::connectivityType() const
504 return m_sharedResource->connectivityType();
507 bool JniOcResourceImpl::isObservable()
509 return m_sharedResource->isObservable();
512 std::vector< std::string > JniOcResourceImpl::getResourceTypes() const
514 return m_sharedResource->getResourceTypes();
517 std::vector< std::string > JniOcResourceImpl::getResourceInterfaces(void) const
519 return m_sharedResource->getResourceInterfaces();
522 OCResourceIdentifier JniOcResourceImpl::uniqueIdentifier() const
524 return m_sharedResource->uniqueIdentifier();
527 std::string JniOcResourceImpl::sid() const
529 return m_sharedResource->sid();
532 std::string JniOcResourceImpl::deviceName() const
534 return m_sharedResource->deviceName();
537 JniOnGetListener* JniOcResourceImpl::addOnGetListener(JNIEnv* env, jobject jListener)
539 return this->m_onGetManager.addListener(env, jListener,
540 std::bind(&JniOcResourceImpl::removeOnGetListener, this,
541 std::placeholders::_1, std::placeholders::_2));
544 JniOnPutListener* JniOcResourceImpl::addOnPutListener(JNIEnv* env, jobject jListener)
546 return this->m_onPutManager.addListener(env, jListener,
547 std::bind(&JniOcResourceImpl::removeOnPutListener, this,
548 std::placeholders::_1, std::placeholders::_2));
551 JniOnPostListener* JniOcResourceImpl::addOnPostListener(JNIEnv* env, jobject jListener)
553 return this->m_onPostManager.addListener(env, jListener,
554 std::bind(&JniOcResourceImpl::removeOnPostListener, this,
555 std::placeholders::_1, std::placeholders::_2));
558 JniOnDeleteListener* JniOcResourceImpl::addOnDeleteListener(JNIEnv* env, jobject jListener)
560 return this->m_onDeleteManager.addListener(env, jListener,
561 std::bind(&JniOcResourceImpl::removeOnDeleteListener, this,
562 std::placeholders::_1, std::placeholders::_2));
565 JniOnObserveListener* JniOcResourceImpl::addOnObserveListener(JNIEnv* env, jobject jListener)
567 return this->m_onObserveManager.addListener(env, jListener,
568 std::bind(&JniOcResourceImpl::removeOnObserveListener, this,
569 std::placeholders::_1, std::placeholders::_2));
572 void JniOcResourceImpl::removeOnGetListener(JNIEnv* env, jobject jListener)
574 this->m_onGetManager.removeListener(env, jListener);
577 void JniOcResourceImpl::removeOnPutListener(JNIEnv* env, jobject jListener)
579 this->m_onPutManager.removeListener(env, jListener);
582 void JniOcResourceImpl::removeOnPostListener(JNIEnv* env, jobject jListener)
584 this->m_onPostManager.removeListener(env, jListener);
587 void JniOcResourceImpl::removeOnDeleteListener(JNIEnv* env, jobject jListener)
589 this->m_onDeleteManager.removeListener(env, jListener);
592 void JniOcResourceImpl::removeOnObserveListener(JNIEnv* env, jobject jListener)
594 this->m_onObserveManager.removeListener(env, jListener);
598 JniOnMQTopicFoundListener* JniOcResourceImpl::addOnTopicFoundListener(JNIEnv* env, jobject jListener)
600 return this->m_onFoundTopicResourceManager.addListener(env, jListener,
601 std::bind(&JniOcResource::removeOnTopicFoundListener, this,
602 std::placeholders::_1, std::placeholders::_2));
605 void JniOcResourceImpl::removeOnTopicFoundListener(JNIEnv* env, jobject jListener)
607 this->m_onFoundTopicResourceManager.removeListener(env, jListener);
610 JniOnMQSubscribeListener* JniOcResourceImpl::addOnMQTopicSubscribeListener(JNIEnv* env, jobject jListener)
612 return this->m_onSubcribeTopicManager.addListener(env, jListener,
613 std::bind(&JniOcResource::removeOnMQTopicSubscribeListener, this
614 std::placeholders::_1, std::placeholders::_2));
617 void JniOcResourceImpl::removeOnMQTopicSubscribeListener(JNIEnv* env, jobject jListener)
619 this->m_onSubcribeTopicManager.removeListener(env, jListener);
623 std::shared_ptr<OCResource> JniOcResourceImpl::getOCResource()
625 return this->m_sharedResource;
629 OCStackResult JniOcResourceImpl::discoveryMQTopics(JNIEnv* env,
630 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
632 JniOnMQTopicFoundListener *onTopicFoundListener = addOnTopicFoundListener(env, jListener);
634 MQTopicCallback findCallback = std::bind([](const int& eCode,
635 const std::string& uri, std::shared_ptr<OCResource> resource,
636 JniOnMQTopicFoundListener *listener,
637 std::weak_ptr<JniOcResourceImpl> weakRef)
639 auto obj = weakRef.lock();
642 LOGD("Topic callback called on deleted object\n");
645 listener->foundTopicCallback(eCode, uri, resource);
646 }, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
647 onTopicFoundListener, shared_from_this());
649 return m_sharedResource->discoveryMQTopics(queryParametersMap, findCallback, QoS);
652 OCStackResult JniOcResourceImpl::createMQTopic(JNIEnv* env,
653 const OCRepresentation &representation, const std::string &targetUri,
654 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
656 JniOnMQTopicFoundListener *onTopicCreatedListener = addOnTopicFoundListener(env, jListener);
658 MQTopicCallback createCallback = std::bind([](const int& eCode,
659 const std::string& uri,
660 std::shared_ptr<OCResource> resource,
661 JniOnMQTopicFoundListener *listener,
662 std::weak_ptr<JniOcResourceImpl> weakRef)
664 auto obj = weakRef.lock();
667 LOGD("Topic callback called on deleted object\n");
670 listener->createdTopicCallback(eCode, uri, resource);
671 }, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
672 onTopicCreatedListener, shared_from_this());
674 return m_sharedResource->createMQTopic(representation, targetUri,
676 createCallback, QoS);
680 OCStackResult JniOcResourceImpl::subscribeMQTopic(JNIEnv* env,
681 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
683 JniOnMQSubscribeListener *onSubscribeListener = addOnMQTopicSubscribeListener(env, jListener);
685 ObserveCallback subscribeCallback = std::bind([](const HeaderOptions& opts,
686 const OCRepresentation& rep, const int& eCode,
687 const int& sequenceNumber,
688 JniOnMQSubscribeListener *listener,
689 std::weak_ptr<JniOcResourceImpl> weakRef)
691 auto obj = weakRef.lock();
694 LOGD("Subscribe MQ callback called on deleted object\n");
697 listener->onSubscribeCallback(opts, rep, eCode, sequenceNumber);
698 }, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4,
699 onSubscribeListener, shared_from_this());
701 return m_sharedResource->subscribeMQTopic(ObserveType::Observe, queryParametersMap,
702 subscribeCallback, QoS);
705 OCStackResult JniOcResourceImpl::unsubscribeMQTopic(QualityOfService QoS)
707 return m_sharedResource->unsubscribeMQTopic(QoS);
710 OCStackResult JniOcResourceImpl::requestMQPublish(JNIEnv* env,
711 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
713 JniOnPostListener *onPostListener = addOnPostListener(env, jListener);
715 PostCallback postCallback = std::bind(JniOcResourceImpl::onPostCallback, std::placeholders::_1,
716 std::placeholders::_2, std::placeholders::_3, onPostListener,
719 return m_sharedResource->requestMQPublish(queryParametersMap, postCallback, QoS);
723 OCStackResult JniOcResourceImpl::publishMQTopic(JNIEnv* env, const OCRepresentation &representation,
724 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
726 JniOnPostListener *onPostListener = addOnPostListener(env, jListener);
728 PostCallback postCallback = std::bind(JniOcResourceImpl::onPostCallback, std::placeholders::_1,
729 std::placeholders::_2, std::placeholders::_3, onPostListener,
732 return m_sharedResource->publishMQTopic(representation, queryParametersMap,
738 JniOcResource::JniOcResource(std::shared_ptr<OCResource> &resource)
740 m_impl = std::make_shared<JniOcResourceImpl>(resource);
743 OCStackResult JniOcResource::get(JNIEnv* env, const QueryParamsMap &queryParametersMap, jobject jListener)
745 return m_impl->get(env, queryParametersMap, jListener);
748 OCStackResult JniOcResource::get(JNIEnv* env, const QueryParamsMap &queryParametersMap, jobject jListener,
749 QualityOfService QoS)
751 return m_impl->get(env, queryParametersMap, jListener, QoS);
754 OCStackResult JniOcResource::get(
756 const std::string &resourceType,
757 const std::string &resourceInterface,
758 const QueryParamsMap &queryParametersMap,
761 return m_impl->get(env, resourceType, resourceInterface, queryParametersMap, jListener);
764 OCStackResult JniOcResource::get(JNIEnv* env, const std::string &resourceType,
765 const std::string &resourceInterface, const QueryParamsMap &queryParametersMap,
766 jobject jListener, QualityOfService QoS)
768 return m_impl->get(env, resourceType, resourceInterface, queryParametersMap, jListener, QoS);
771 OCStackResult JniOcResource::put(JNIEnv* env, const OCRepresentation &representation,
772 const QueryParamsMap &queryParametersMap, jobject jListener)
774 return m_impl->put(env, representation, queryParametersMap, jListener);
777 OCStackResult JniOcResource::put(JNIEnv* env, const OCRepresentation &representation,
778 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
780 return m_impl->put(env, representation, queryParametersMap, jListener, QoS);
783 OCStackResult JniOcResource::put(JNIEnv* env, const std::string &resourceType,
784 const std::string &resourceInterface, const OCRepresentation &representation,
785 const QueryParamsMap &queryParametersMap, jobject jListener)
787 return m_impl->put(env, resourceType, resourceInterface, representation, queryParametersMap, jListener);
790 OCStackResult JniOcResource::put(JNIEnv* env, const std::string &resourceType,
791 const std::string &resourceInterface, const OCRepresentation &representation,
792 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
794 return m_impl->put(env, resourceType, resourceInterface, representation, queryParametersMap, jListener, QoS);
797 OCStackResult JniOcResource::post(JNIEnv* env, const OCRepresentation &representation,
798 const QueryParamsMap &queryParametersMap, jobject jListener)
800 return m_impl->post(env, representation, queryParametersMap, jListener);
803 OCStackResult JniOcResource::post(JNIEnv* env, const OCRepresentation &representation,
804 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
806 return m_impl->post(env, representation, queryParametersMap, jListener, QoS);
809 OCStackResult JniOcResource::post(JNIEnv* env, const std::string &resourceType,
810 const std::string &resourceInterface, const OCRepresentation &representation,
811 const QueryParamsMap &queryParametersMap, jobject jListener)
813 return m_impl->post(env, resourceType, resourceInterface, representation, queryParametersMap, jListener);
816 OCStackResult JniOcResource::post(JNIEnv* env, const std::string &resourceType,
817 const std::string &resourceInterface, const OCRepresentation &representation,
818 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
820 return m_impl->post(env, resourceType, resourceInterface, representation, queryParametersMap, jListener, QoS);
823 OCStackResult JniOcResource::deleteResource(JNIEnv* env, jobject jListener)
825 return m_impl->deleteResource(env, jListener);
828 OCStackResult JniOcResource::deleteResource(JNIEnv* env, jobject jListener, QualityOfService QoS)
830 return m_impl->deleteResource(env, jListener, QoS);
833 OCStackResult JniOcResource::observe(JNIEnv* env, ObserveType observeType,
834 const QueryParamsMap &queryParametersMap, jobject jListener)
836 return m_impl->observe(env, observeType, queryParametersMap, jListener);
839 OCStackResult JniOcResource::observe(JNIEnv* env, ObserveType observeType,
840 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
842 return m_impl->observe(env, observeType, queryParametersMap, jListener, QoS);
845 OCStackResult JniOcResource::cancelObserve(JNIEnv* env, QualityOfService qos)
847 return m_impl->cancelObserve(env, qos);
850 void JniOcResource::setHeaderOptions(const HeaderOptions &headerOptions)
852 m_impl->setHeaderOptions(headerOptions);
855 void JniOcResource::unsetHeaderOptions()
857 m_impl->unsetHeaderOptions();
860 std::string JniOcResource::host()
862 return m_impl->host();
865 std::string JniOcResource::uri()
867 return m_impl->uri();
870 OCConnectivityType JniOcResource::connectivityType() const
872 return m_impl->connectivityType();
875 bool JniOcResource::isObservable()
877 return m_impl->isObservable();
880 std::vector< std::string > JniOcResource::getResourceTypes() const
882 return m_impl->getResourceTypes();
885 std::vector< std::string > JniOcResource::getResourceInterfaces(void) const
887 return m_impl->getResourceInterfaces();
890 OCResourceIdentifier JniOcResource::uniqueIdentifier() const
892 return m_impl->uniqueIdentifier();
895 std::string JniOcResource::sid() const
897 return m_impl->sid();
900 std::string JniOcResource::deviceName() const
902 return m_impl->deviceName();
905 std::shared_ptr<OCResource> JniOcResource::getOCResource()
907 return m_impl->getOCResource();
910 JniOcResource* JniOcResource::getJniOcResourcePtr(JNIEnv *env, jobject thiz)
912 JniOcResource *resource = GetHandle<JniOcResource>(env, thiz);
913 if (env->ExceptionCheck())
915 LOGE("Failed to get native handle from OcResource");
919 ThrowOcException(JNI_NO_NATIVE_POINTER, "");
925 OCStackResult JniOcResource::discoveryMQTopics(JNIEnv* env,
926 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
928 return m_impl->discoveryMQTopics(env, queryParametersMap, jListener, QoS);
931 OCStackResult JniOcResource::createMQTopic(JNIEnv* env,
932 const OCRepresentation &representation, const std::string &targetUri,
933 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
935 return m_impl->createMQTopic(env, representation, targetUri, queryParametersMap, jListener, QoS);
939 OCStackResult JniOcResource::subscribeMQTopic(JNIEnv* env,
940 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
942 return m_impl->subscribeMQTopic(env, queryParametersMap, jListener, QoS);
945 OCStackResult JniOcResource::unsubscribeMQTopic(QualityOfService QoS)
947 return m_impl->unsubscribeMQTopic(QoS);
950 OCStackResult JniOcResource::requestMQPublish(JNIEnv* env,
951 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
953 return m_impl->requestMQPublish(env, queryParametersMap, jListener, QoS);
957 OCStackResult JniOcResource::publishMQTopic(JNIEnv* env, const OCRepresentation &representation,
958 const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
960 return m_impl->publishMQTopic(env, representation, queryParametersMap, jListener, QoS);
965 * Class: org_iotivity_base_OcResource
967 * Signature: (Ljava/util/Map;Lorg/iotivity/base/OcResource/OnGetListener;)V
969 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_get
970 (JNIEnv *env, jobject thiz, jobject jQueryParamsMap, jobject jListener)
972 LOGD("OcResource_get");
973 if (!jQueryParamsMap)
975 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
980 ThrowOcException(OC_STACK_INVALID_PARAM, "onGetListener cannot be null");
983 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
990 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
994 OCStackResult result = resource->get(
999 if (OC_STACK_OK != result)
1001 ThrowOcException(result, "OcResource_get");
1004 catch (OCException& e)
1006 LOGE("%s", e.reason().c_str());
1007 ThrowOcException(e.code(), e.reason().c_str());
1012 * Class: org_iotivity_base_OcResource
1014 * Signature: (Ljava/util/Map;Lorg/iotivity/base/OcResource/OnGetListener;I)V
1016 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_get1
1017 (JNIEnv *env, jobject thiz, jobject jQueryParamsMap, jobject jListener, jint jQoS)
1019 LOGD("OcResource_get");
1020 if (!jQueryParamsMap)
1022 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1027 ThrowOcException(OC_STACK_INVALID_PARAM, "onGetListener cannot be null");
1030 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1037 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1041 OCStackResult result = resource->get(
1045 JniUtils::getQOS(env, static_cast<int>(jQoS)));
1047 if (OC_STACK_OK != result)
1049 ThrowOcException(result, "OcResource_get");
1052 catch (OCException& e)
1054 LOGE("%s", e.reason().c_str());
1055 ThrowOcException(e.code(), e.reason().c_str());
1060 * Class: org_iotivity_base_OcResource
1062 * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;
1063 Lorg/iotivity/base/OcResource/OnGetListener;)V
1065 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_get2
1066 (JNIEnv *env, jobject thiz, jstring jResourceType, jstring jResourceInterface,
1067 jobject jQueryParamsMap, jobject jListener)
1069 LOGD("OcResource_get");
1070 std::string resourceType;
1073 resourceType = env->GetStringUTFChars(jResourceType, nullptr);
1075 std::string resourceInterface;
1076 if (jResourceInterface)
1078 resourceInterface = env->GetStringUTFChars(jResourceInterface, nullptr);
1080 if (!jQueryParamsMap)
1082 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1087 ThrowOcException(OC_STACK_INVALID_PARAM, "onGetListener cannot be null");
1090 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1097 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1100 OCStackResult result = resource->get(
1107 if (OC_STACK_OK != result)
1109 ThrowOcException(result, "OcResource_get");
1112 catch (OCException& e)
1114 LOGE("%s", e.reason().c_str());
1115 ThrowOcException(e.code(), e.reason().c_str());
1120 * Class: org_iotivity_base_OcResource
1122 * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;
1123 Lorg/iotivity/base/OcResource/OnGetListener;I)V
1125 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_get3
1126 (JNIEnv *env, jobject thiz, jstring jResourceType, jstring jResourceInterface,
1127 jobject jQueryParamsMap, jobject jListener, jint jQoS)
1129 LOGD("OcResource_get");
1130 if (!jQueryParamsMap)
1132 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1137 ThrowOcException(OC_STACK_INVALID_PARAM, "onGetListener cannot be null");
1140 std::string resourceType;
1143 resourceType = env->GetStringUTFChars(jResourceType, nullptr);
1145 std::string resourceInterface;
1146 if (jResourceInterface)
1148 resourceInterface = env->GetStringUTFChars(jResourceInterface, nullptr);
1150 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1157 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1161 OCStackResult result = resource->get(
1167 JniUtils::getQOS(env, static_cast<int>(jQoS)));
1169 if (OC_STACK_OK != result)
1171 ThrowOcException(result, "OcResource_get");
1174 catch (OCException& e)
1176 LOGE("%s", e.reason().c_str());
1177 ThrowOcException(e.code(), e.reason().c_str());
1182 * Class: org_iotivity_base_OcResource
1184 * Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/Map;
1185 Lorg/iotivity/base/OcResource/OnPutListener;)V
1187 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_put
1188 (JNIEnv *env, jobject thiz, jobject jRepresentation, jobject jQueryParamsMap, jobject jListener)
1190 LOGD("OcResource_put");
1191 if (!jRepresentation)
1193 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1196 if (!jQueryParamsMap)
1198 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1203 ThrowOcException(OC_STACK_INVALID_PARAM, "onPutListener cannot be null");
1206 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1212 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
1213 if (!representation)
1219 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1223 OCStackResult result = resource->put(
1229 if (OC_STACK_OK != result)
1231 ThrowOcException(result, "OcResource_put");
1234 catch (OCException& e)
1236 LOGE("%s", e.reason().c_str());
1237 ThrowOcException(e.code(), e.reason().c_str());
1242 * Class: org_iotivity_base_OcResource
1244 * Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/Map;
1245 Lorg/iotivity/base/OcResource/OnPutListener;I)V
1247 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_put1
1248 (JNIEnv *env, jobject thiz, jobject jRepresentation, jobject jQueryParamsMap,
1249 jobject jListener, jint jQoS)
1251 LOGD("OcResource_put");
1252 if (!jRepresentation)
1254 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1257 if (!jQueryParamsMap)
1259 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1264 ThrowOcException(OC_STACK_INVALID_PARAM, "onPutListener cannot be null");
1267 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1273 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
1274 if (!representation)
1280 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1284 OCStackResult result = resource->put(
1289 JniUtils::getQOS(env, static_cast<int>(jQoS)));
1291 if (OC_STACK_OK != result)
1293 ThrowOcException(result, "OcResource_put");
1296 catch (OCException& e)
1298 LOGE("%s", e.reason().c_str());
1299 ThrowOcException(e.code(), e.reason().c_str());
1304 * Class: org_iotivity_base_OcResource
1306 * Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcRepresentation;
1307 Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPutListener;)V
1309 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_put2
1310 (JNIEnv *env, jobject thiz, jstring jResourceType, jstring jResourceInterface,
1311 jobject jRepresentation, jobject jQueryParamsMap, jobject jListener)
1313 LOGD("OcResource_put");
1314 std::string resourceType;
1317 resourceType = env->GetStringUTFChars(jResourceType, nullptr);
1319 std::string resourceInterface;
1320 if (jResourceInterface)
1322 resourceInterface = env->GetStringUTFChars(jResourceInterface, nullptr);
1324 if (!jRepresentation)
1326 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1329 if (!jQueryParamsMap)
1331 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1336 ThrowOcException(OC_STACK_INVALID_PARAM, "onPutListener cannot be null");
1339 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1345 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
1346 if (!representation)
1352 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1356 OCStackResult result = resource->put(
1364 if (OC_STACK_OK != result)
1366 ThrowOcException(result, "OcResource_put");
1369 catch (OCException& e)
1371 LOGE("%s", e.reason().c_str());
1372 ThrowOcException(e.code(), e.reason().c_str());
1377 * Class: org_iotivity_base_OcResource
1379 * Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcRepresentation;
1380 Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPutListener;I)V
1382 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_put3
1383 (JNIEnv *env, jobject thiz, jstring jResourceType, jstring jResourceInterface, jobject jRepresentation,
1384 jobject jQueryParamsMap, jobject jListener, jint jQoS)
1386 LOGD("OcResource_put");
1387 if (!jRepresentation)
1389 ThrowOcException(OC_STACK_INVALID_PARAM, "representation cannot be null");
1392 if (!jQueryParamsMap)
1394 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1399 ThrowOcException(OC_STACK_INVALID_PARAM, "onPutListener cannot be null");
1402 std::string resourceType;
1405 resourceType = env->GetStringUTFChars(jResourceType, nullptr);
1407 std::string resourceInterface;
1408 if (jResourceInterface)
1410 resourceInterface = env->GetStringUTFChars(jResourceInterface, nullptr);
1413 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1419 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
1420 if (!representation)
1426 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1430 OCStackResult result = resource->put(
1437 JniUtils::getQOS(env, static_cast<int>(jQoS)));
1439 if (OC_STACK_OK != result)
1441 ThrowOcException(result, "OcResource_put");
1444 catch (OCException& e)
1446 LOGE("%s", e.reason().c_str());
1447 ThrowOcException(e.code(), e.reason().c_str());
1452 * Class: org_iotivity_base_OcResource
1454 * Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPostListener;)V
1456 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_post
1457 (JNIEnv *env, jobject thiz, jobject jRepresentation, jobject jQueryParamsMap, jobject jListener)
1459 LOGD("OcResource_post");
1460 if (!jRepresentation)
1462 ThrowOcException(OC_STACK_INVALID_PARAM, "representation cannot be null");
1465 if (!jQueryParamsMap)
1467 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1472 ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null");
1475 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1481 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
1482 if (!representation)
1488 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1492 OCStackResult result = resource->post(
1498 if (OC_STACK_OK != result)
1500 ThrowOcException(result, "OcResource_post");
1503 catch (OCException& e)
1505 LOGE("%s", e.reason().c_str());
1506 ThrowOcException(e.code(), e.reason().c_str());
1511 * Class: org_iotivity_base_OcResource
1513 * Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPostListener;I)V
1515 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_post1
1516 (JNIEnv *env, jobject thiz, jobject jRepresentation, jobject jQueryParamsMap, jobject jListener, jint jQoS)
1518 LOGD("OcResource_post");
1519 if (!jRepresentation)
1521 ThrowOcException(OC_STACK_INVALID_PARAM, "representation cannot be null");
1524 if (!jQueryParamsMap)
1526 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1531 ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null");
1534 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1540 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
1541 if (!representation)
1547 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1551 OCStackResult result = resource->post(
1556 JniUtils::getQOS(env, static_cast<int>(jQoS)));
1558 if (OC_STACK_OK != result)
1560 ThrowOcException(result, "OcResource_post");
1563 catch (OCException& e)
1565 LOGE("%s", e.reason().c_str());
1566 ThrowOcException(e.code(), e.reason().c_str());
1571 * Class: org_iotivity_base_OcResource
1573 * Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcRepresentation;
1574 Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPostListener;)V
1576 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_post2
1577 (JNIEnv *env, jobject thiz, jstring jResourceType, jstring jResourceInterface,
1578 jobject jRepresentation, jobject jQueryParamsMap, jobject jListener)
1580 LOGD("OcResource_post");
1581 if (!jRepresentation)
1583 ThrowOcException(OC_STACK_INVALID_PARAM, "representation cannot be null");
1586 if (!jQueryParamsMap)
1588 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1593 ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null");
1596 std::string resourceType;
1599 resourceType = env->GetStringUTFChars(jResourceType, nullptr);
1601 std::string resourceInterface;
1602 if (jResourceInterface)
1604 resourceInterface = env->GetStringUTFChars(jResourceInterface, nullptr);
1607 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1613 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
1614 if (!representation)
1620 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1624 OCStackResult result = resource->post(
1632 if (OC_STACK_OK != result)
1634 ThrowOcException(result, "OcResource_post");
1637 catch (OCException& e)
1639 LOGE("%s", e.reason().c_str());
1640 ThrowOcException(e.code(), e.reason().c_str());
1645 * Class: org_iotivity_base_OcResource
1647 * Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcRepresentation;
1648 Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPostListener;I)V
1650 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_post3
1651 (JNIEnv *env, jobject thiz, jstring jResourceType, jstring jResourceInterface,
1652 jobject jRepresentation, jobject jQueryParamsMap, jobject jListener, jint jQoS)
1654 LOGD("OcResource_post");
1655 if (!jRepresentation)
1657 ThrowOcException(OC_STACK_INVALID_PARAM, "representation cannot be null");
1660 if (!jQueryParamsMap)
1662 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1667 ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null");
1670 std::string resourceType;
1673 resourceType = env->GetStringUTFChars(jResourceType, nullptr);
1675 std::string resourceInterface;
1676 if (jResourceInterface)
1678 resourceInterface = env->GetStringUTFChars(jResourceInterface, nullptr);
1681 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1687 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
1688 if (!representation)
1694 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1698 OCStackResult result = resource->post(
1705 JniUtils::getQOS(env, static_cast<int>(jQoS)));
1707 if (OC_STACK_OK != result)
1709 ThrowOcException(result, "OcResource_post");
1712 catch (OCException& e)
1714 LOGE("%s", e.reason().c_str());
1715 ThrowOcException(e.code(), e.reason().c_str());
1720 * Class: org_iotivity_base_OcResource
1721 * Method: deleteResource
1722 * Signature: (Lorg/iotivity/base/OcResource/OnDeleteListener;)V
1724 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_deleteResource
1725 (JNIEnv *env, jobject thiz, jobject jListener)
1727 LOGD("OcResource_deleteResource");
1730 ThrowOcException(OC_STACK_INVALID_PARAM, "onDeleteListener cannot be null");
1733 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1741 OCStackResult result = resource->deleteResource(
1745 if (OC_STACK_OK != result)
1747 ThrowOcException(result, "OcResource_deleteResource");
1750 catch (OCException& e)
1752 LOGE("%s", e.reason().c_str());
1753 ThrowOcException(e.code(), e.reason().c_str());
1758 * Class: org_iotivity_base_OcResource
1759 * Method: deleteResource1
1760 * Signature: (Lorg/iotivity/base/OcResource/OnDeleteListener;I)V
1762 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_deleteResource1
1763 (JNIEnv *env, jobject thiz, jobject jListener, jint jQoS)
1765 LOGD("OcResource_deleteResource");
1768 ThrowOcException(OC_STACK_INVALID_PARAM, "onDeleteListener cannot be null");
1771 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1779 OCStackResult result = resource->deleteResource(
1782 JniUtils::getQOS(env, static_cast<int>(jQoS)));
1784 if (OC_STACK_OK != result)
1786 ThrowOcException(result, "OcResource_deleteResource");
1789 catch (OCException& e)
1791 LOGE("%s", e.reason().c_str());
1792 ThrowOcException(e.code(), e.reason().c_str());
1797 * Class: org_iotivity_base_OcResource
1799 * Signature: (Lorg/iotivity/base/ObserveType;Ljava/util/Map;
1800 Lorg/iotivity/base/OcResource/OnObserveListener;)V
1802 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_observe
1803 (JNIEnv *env, jobject thiz, jint observeType, jobject jQueryParamsMap, jobject jListener)
1805 LOGD("OcResource_observe");
1806 if (!jQueryParamsMap)
1808 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1813 ThrowOcException(OC_STACK_INVALID_PARAM, "onObserveListener cannot be null");
1816 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1823 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1827 OCStackResult result = resource->observe(
1829 JniUtils::getObserveType(env, static_cast<int>(observeType)),
1833 if (OC_STACK_OK != result)
1835 ThrowOcException(result, "OcResource_observe");
1838 catch (OCException& e)
1840 LOGE("%s", e.reason().c_str());
1841 ThrowOcException(e.code(), e.reason().c_str());
1846 * Class: org_iotivity_base_OcResource
1848 * Signature: (Lorg/iotivity/base/ObserveType;Ljava/util/Map;
1849 Lorg/iotivity/base/OcResource/OnObserveListener;I)V
1851 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_observe1
1852 (JNIEnv *env, jobject thiz, jint observeType, jobject jQueryParamsMap,
1853 jobject jListener, jint jQoS)
1855 LOGD("OcResource_observe");
1856 if (!jQueryParamsMap)
1858 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
1863 ThrowOcException(OC_STACK_INVALID_PARAM, "onObserveListener cannot be null");
1866 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1873 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
1877 OCStackResult result = resource->observe(
1879 JniUtils::getObserveType(env, static_cast<int>(observeType)),
1882 JniUtils::getQOS(env, static_cast<int>(jQoS)));
1884 if (OC_STACK_OK != result)
1886 ThrowOcException(result, "OcResource_observe");
1889 catch (OCException& e)
1891 LOGE("%s", e.reason().c_str());
1892 ThrowOcException(e.code(), e.reason().c_str());
1897 * Class: org_iotivity_base_OcResource
1898 * Method: cancelObserve1
1901 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_cancelObserve1
1902 (JNIEnv *env, jobject thiz, jint jQoS)
1904 LOGD("OcResource_cancelObserve1");
1905 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1913 OCStackResult result = resource->cancelObserve(
1915 JniUtils::getQOS(env, static_cast<int>(jQoS)));
1917 if (OC_STACK_OK != result)
1919 ThrowOcException(result, "OcResource_cancelObserve");
1922 catch (OCException& e)
1924 LOGE("%s", e.reason().c_str());
1925 ThrowOcException(e.code(), e.reason().c_str());
1930 * Class: org_iotivity_base_OcResource
1931 * Method: setHeaderOptions
1932 * Signature: ([Lorg/iotivity/OcHeaderOption;)V
1934 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_setHeaderOptions
1935 (JNIEnv *env, jobject thiz, jobjectArray jheaderOptionArr)
1937 LOGD("OcResource_setHeaderOptions");
1938 if (!jheaderOptionArr)
1940 ThrowOcException(OC_STACK_INVALID_PARAM, "headerOptionList cannot be null");
1943 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1949 HeaderOptions headerOptions;
1950 JniUtils::convertJavaHeaderOptionsArrToVector(env, jheaderOptionArr, headerOptions);
1952 resource->setHeaderOptions(headerOptions);
1956 * Class: org_iotivity_base_OcResource
1957 * Method: unsetHeaderOptions
1960 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_unsetHeaderOptions
1961 (JNIEnv *env, jobject thiz)
1963 LOGD("OcResource_unsetHeaderOptions");
1964 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1970 resource->unsetHeaderOptions();
1974 * Class: org_iotivity_base_OcResource
1976 * Signature: ()Ljava/lang/String;
1978 JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcResource_getHost
1979 (JNIEnv *env, jobject thiz)
1981 LOGD("OcResource_getHost");
1982 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
1988 return env->NewStringUTF(resource->host().c_str());
1992 * Class: org_iotivity_base_OcResource
1994 * Signature: ()Ljava/lang/String;
1996 JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcResource_getUri
1997 (JNIEnv *env, jobject thiz)
1999 LOGD("OcResource_getUri");
2000 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
2006 return env->NewStringUTF(resource->uri().c_str());
2010 * Class: org_iotivity_base_OcResource
2011 * Method: getConnectivityTypeN
2014 JNIEXPORT jint JNICALL Java_org_iotivity_base_OcResource_getConnectivityTypeN
2015 (JNIEnv *env, jobject thiz)
2017 LOGD("OcResource_getConnectivityType");
2018 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
2024 OCConnectivityType connectivityType = resource->connectivityType();
2025 return static_cast<jint>(connectivityType);
2029 * Class: org_iotivity_base_OcResource
2030 * Method: isObservable
2033 JNIEXPORT jboolean JNICALL Java_org_iotivity_base_OcResource_isObservable
2034 (JNIEnv *env, jobject thiz)
2036 LOGD("OcResource_isObservable");
2037 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
2043 return (jboolean)resource->isObservable();
2047 * Class: org_iotivity_base_OcResource
2048 * Method: getResourceTypes
2049 * Signature: ()Ljava/util/List;
2051 JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcResource_getResourceTypes
2052 (JNIEnv *env, jobject thiz)
2054 LOGD("OcResource_getResourceTypes");
2055 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
2061 std::vector<std::string> resourceTypes = resource->getResourceTypes();
2063 return JniUtils::convertStrVectorToJavaStrList(env, resourceTypes);
2067 * Class: org_iotivity_base_OcResource
2068 * Method: getResourceInterfaces
2069 * Signature: ()Ljava/util/List;
2071 JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcResource_getResourceInterfaces
2072 (JNIEnv *env, jobject thiz)
2074 LOGD("OcResource_getResourceInterfaces");
2075 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
2081 std::vector<std::string> resourceInterfaces = resource->getResourceInterfaces();
2083 return JniUtils::convertStrVectorToJavaStrList(env, resourceInterfaces);
2087 * Class: org_iotivity_base_OcResource
2088 * Method: getUniqueIdentifier
2089 * Signature: ()Lorg/iotivity/base/OcResourceIdentifier;
2091 JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcResource_getUniqueIdentifier
2092 (JNIEnv *env, jobject thiz)
2094 LOGD("OcResource_getUniqueIdentifier");
2095 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
2101 JniOcResourceIdentifier *jniResourceIdentifier =
2102 new JniOcResourceIdentifier(resource->uniqueIdentifier());
2103 if (!jniResourceIdentifier)
2108 jlong handle = reinterpret_cast<jlong>(jniResourceIdentifier);
2109 jobject jResourceIdentifier = env->NewObject(g_cls_OcResourceIdentifier,
2110 g_mid_OcResourceIdentifier_N_ctor, handle);
2111 if (!jResourceIdentifier)
2113 delete jniResourceIdentifier;
2115 return jResourceIdentifier;
2119 * Class: org_iotivity_base_OcResource
2120 * Method: getServerId
2121 * Signature: ()Ljava/lang/String;
2123 JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcResource_getServerId
2124 (JNIEnv *env, jobject thiz)
2126 LOGD("OcResource_getServerId");
2127 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
2133 return env->NewStringUTF(resource->sid().c_str());
2137 * Class: org_iotivity_base_OcResource
2138 * Method: getDeviceName
2139 * Signature: ()Ljava/lang/String;
2141 JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcResource_getDeviceName
2142 (JNIEnv *env, jobject thiz)
2144 LOGD("OcResource_getDeviceName");
2145 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
2151 return env->NewStringUTF(resource->deviceName().c_str());
2155 * Class: org_iotivity_base_OcResource
2159 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_dispose
2160 (JNIEnv *env, jobject thiz)
2162 LOGD("OcResource_dispose");
2163 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
2168 * Class: org_iotivity_base_OcResource
2169 * Method: discoveryMQTopicsImpl
2170 * Signature: (Ljava/util/Map;Lorg/iotivity/base/OcPlatform/OnResourceFoundListener;I)V
2172 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_discoveryMQTopicsImpl
2173 (JNIEnv *env, jobject thiz, jobject jQueryParamsMap, jobject jListener, jint jQoS)
2175 LOGD("OcResource_discoveryMQTopicsImpl");
2178 if (!jQueryParamsMap)
2180 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
2186 ThrowOcException(OC_STACK_INVALID_PARAM, "listener cannot be null");
2190 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
2197 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
2201 OCStackResult result = resource->discoveryMQTopics(
2205 JniUtils::getQOS(env, static_cast<int>(jQoS)));
2207 if (OC_STACK_OK != result)
2209 ThrowOcException(result, "OcResource_discoveryMQTopicsImpl");
2212 catch (OCException& e)
2214 LOGE("%s", e.reason().c_str());
2215 ThrowOcException(e.code(), e.reason().c_str());
2218 ThrowOcException(JNI_NO_SUPPORT, "not support");
2223 * Class: org_iotivity_base_OcResource
2224 * Method: createMQTopicImpl
2225 * Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/String;Ljava/util/Map
2226 * ;Lorg/iotivity/base/OcPlatform/OnMQTopicCreatedListener;I)V
2228 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_createMQTopicImpl
2229 (JNIEnv *env, jobject thiz, jobject jRepresentation, jstring jUri,
2230 jobject jQueryParamsMap, jobject jListener, jint jQoS)
2232 LOGD("OcResource_createMQTopicImpl");
2235 if (!jQueryParamsMap)
2237 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
2243 ThrowOcException(OC_STACK_INVALID_PARAM, "listener cannot be null");
2247 if (!jRepresentation)
2249 ThrowOcException(OC_STACK_INVALID_PARAM, "representation null");
2253 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
2259 std::string targetUri;
2262 targetUri = env->GetStringUTFChars(jUri, nullptr);
2265 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env,
2267 if (!representation)
2273 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
2277 OCStackResult result = resource->createMQTopic(
2283 JniUtils::getQOS(env, static_cast<int>(jQoS)));
2285 if (OC_STACK_OK != result)
2287 ThrowOcException(result, "OcResource_createMQTopicImpl");
2290 catch (OCException& e)
2292 LOGE("%s", e.reason().c_str());
2293 ThrowOcException(e.code(), e.reason().c_str());
2296 ThrowOcException(JNI_NO_SUPPORT, "not support");
2301 * Class: org_iotivity_base_OcResource
2302 * Method: subscribeMQTopic
2303 * Signature: (Ljava/util/Map;Lorg/iotivity/base/OcResource/OnObserveListener;I)V
2305 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_subscribeMQTopicImpl
2306 (JNIEnv *env, jobject thiz, jobject jQueryParamsMap, jobject jListener, jint jQoS)
2308 LOGD("OcResource_subscribeMQTopicImpl");
2309 #ifdef MQ_SUBSCRIBER
2310 if (!jQueryParamsMap)
2312 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
2317 ThrowOcException(OC_STACK_INVALID_PARAM, "onObserveListener cannot be null");
2320 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
2327 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
2331 OCStackResult result = resource->subscribeMQTopic(
2335 JniUtils::getQOS(env, static_cast<int>(jQoS)));
2337 if (OC_STACK_OK != result)
2339 ThrowOcException(result, "OcResource_subscribeMQTopicImpl");
2342 catch (OCException& e)
2344 LOGE("%s", e.reason().c_str());
2345 ThrowOcException(e.code(), e.reason().c_str());
2348 ThrowOcException(JNI_NO_SUPPORT, "not support");
2353 * Class: org_iotivity_base_OcResource
2354 * Method: unsubscribeMQTopicImpl
2357 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_unsubscribeMQTopicImpl
2358 (JNIEnv *env, jobject thiz, jint jQoS)
2360 LOGD("OcResource_unsubscribeMQTopicImpl");
2361 #ifdef MQ_SUBSCRIBER
2362 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
2370 OCStackResult result = resource->unsubscribeMQTopic(
2371 JniUtils::getQOS(env, static_cast<int>(jQoS)));
2372 if (OC_STACK_OK != result)
2374 ThrowOcException(result, "OcResource_unsubscribeMQTopicImpl");
2377 catch (OCException& e)
2379 LOGE("%s", e.reason().c_str());
2380 ThrowOcException(e.code(), e.reason().c_str());
2383 ThrowOcException(JNI_NO_SUPPORT, "not support");
2388 * Class: org_iotivity_base_OcResource
2389 * Method: requestMQPublishImpl
2390 * Signature: (Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPostListener;I)V
2392 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_requestMQPublishImpl
2393 (JNIEnv *env, jobject thiz, jobject jQueryParamsMap, jobject jListener, jint jQoS)
2395 LOGD("OcResource_requestMQPublishImpl");
2396 #ifdef MQ_SUBSCRIBER
2397 if (!jQueryParamsMap)
2399 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
2404 ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null");
2408 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
2415 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
2419 OCStackResult result = resource->requestMQPublish(
2423 JniUtils::getQOS(env, static_cast<int>(jQoS)));
2425 if (OC_STACK_OK != result)
2427 ThrowOcException(result, "OcResource_requestMQPublishImpl");
2430 catch (OCException& e)
2432 LOGE("%s", e.reason().c_str());
2433 ThrowOcException(e.code(), e.reason().c_str());
2436 ThrowOcException(JNI_NO_SUPPORT, "not support");
2441 * Class: org_iotivity_base_OcResource
2442 * Method: publishMQTopicImpl
2443 * Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/Map;
2444 * Lorg/iotivity/base/OcResource/OnPostListener;I)V
2446 JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_publishMQTopicImpl
2447 (JNIEnv *env, jobject thiz, jobject jRepresentation, jobject jQueryParamsMap,
2448 jobject jListener, jint jQoS)
2450 LOGD("OcResource_publishMQTopicImpl");
2452 if (!jRepresentation)
2454 ThrowOcException(OC_STACK_INVALID_PARAM, "representation cannot be null");
2458 if (!jQueryParamsMap)
2460 ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
2466 ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null");
2470 JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
2476 OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env,
2478 if (!representation)
2484 JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
2488 OCStackResult result = resource->publishMQTopic(
2493 JniUtils::getQOS(env, static_cast<int>(jQoS)));
2495 if (OC_STACK_OK != result)
2497 ThrowOcException(result, "OcResource_publishMQTopicImpl");
2500 catch (OCException& e)
2502 LOGE("%s", e.reason().c_str());
2503 ThrowOcException(e.code(), e.reason().c_str());
2506 ThrowOcException(JNI_NO_SUPPORT, "not support");