m_onPostManager.removeAllListeners(env);
m_onDeleteManager.removeAllListeners(env);
m_onObserveManager.removeAllListeners(env);
+#ifdef WITH_MQ
+ m_onFoundTopicResourceManager.removeAllListeners(env);
+ m_onSubcribeTopicManager.removeAllListeners(env);
+#endif
if (JNI_EDETACHED == envRet)
{
OCStackResult JniOcResource::cancelObserve(JNIEnv* env, QualityOfService qos)
{
- if (QualityOfService::HighQos != qos)
+ // In Low case, after delete the callback and send empty message when client receive the notify.
+ // But TCP does not support EMPTY message.
+ if ((CT_ADAPTER_IP & connectivityType()) && QualityOfService::HighQos != qos)
{
this->m_onObserveManager.removeAllListeners(env);
}
return m_sharedResource->sid();
}
+std::string JniOcResource::deviceName() const
+{
+ return m_sharedResource->deviceName();
+}
+
JniOnGetListener* JniOcResource::addOnGetListener(JNIEnv* env, jobject jListener)
{
return this->m_onGetManager.addListener(env, jListener, this);
this->m_onObserveManager.removeListener(env, jListener);
}
+#ifdef WITH_MQ
+JniOnMQTopicFoundListener* JniOcResource::addOnTopicFoundListener(JNIEnv* env, jobject jListener)
+{
+ return this->m_onFoundTopicResourceManager.addListener(env, jListener, this);
+}
+
+void JniOcResource::removeOnTopicFoundListener(JNIEnv* env, jobject jListener)
+{
+ this->m_onFoundTopicResourceManager.removeListener(env, jListener);
+}
+
+JniOnMQSubscribeListener* JniOcResource::addOnMQTopicSubscribeListener(JNIEnv* env, jobject jListener)
+{
+ return this->m_onSubcribeTopicManager.addListener(env, jListener, this);
+}
+
+void JniOcResource::removeOnMQTopicSubscribeListener(JNIEnv* env, jobject jListener)
+{
+ this->m_onSubcribeTopicManager.removeListener(env, jListener);
+}
+#endif
+
std::shared_ptr<OCResource> JniOcResource::getOCResource()
{
return this->m_sharedResource;
return resource;
}
+#ifdef WITH_MQ
+OCStackResult JniOcResource::discoveryMQTopics(JNIEnv* env,
+ const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
+{
+ JniOnMQTopicFoundListener *onTopicFoundListener = addOnTopicFoundListener(env, jListener);
+
+ MQTopicCallback findCallback = [onTopicFoundListener](const int& eCode,
+ const std::string& uri, std::shared_ptr<OCResource> resource)
+ {
+ onTopicFoundListener->foundTopicCallback(eCode, uri, resource);
+ };
+
+ return m_sharedResource->discoveryMQTopics(queryParametersMap, findCallback, QoS);
+}
+
+OCStackResult JniOcResource::createMQTopic(JNIEnv* env,
+ const OCRepresentation &representation, const std::string &targetUri,
+ const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
+{
+ JniOnMQTopicFoundListener *onTopicCreatedListener = addOnTopicFoundListener(env, jListener);
+
+ MQTopicCallback createCallback = [onTopicCreatedListener](const int& eCode,
+ const std::string& uri, std::shared_ptr<OCResource> resource)
+ {
+ onTopicCreatedListener->createdTopicCallback(eCode, uri, resource);
+ };
+
+ return m_sharedResource->createMQTopic(representation, targetUri,
+ queryParametersMap,
+ createCallback, QoS);
+}
+#endif
+#ifdef MQ_SUBSCRIBER
+OCStackResult JniOcResource::subscribeMQTopic(JNIEnv* env,
+ const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
+{
+ JniOnMQSubscribeListener *onSubscribeListener = addOnMQTopicSubscribeListener(env, jListener);
+
+ ObserveCallback subscribeCallback = [onSubscribeListener](const HeaderOptions& opts,
+ const OCRepresentation& rep, const int& eCode, const int& sequenceNumber)
+ {
+ onSubscribeListener->onSubscribeCallback(opts, rep, eCode, sequenceNumber);
+ };
+
+ return m_sharedResource->subscribeMQTopic(ObserveType::Observe, queryParametersMap,
+ subscribeCallback, QoS);
+}
+
+OCStackResult JniOcResource::unsubscribeMQTopic(QualityOfService QoS)
+{
+ return m_sharedResource->unsubscribeMQTopic(QoS);
+}
+
+OCStackResult JniOcResource::requestMQPublish(JNIEnv* env,
+ const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
+{
+ JniOnPostListener *onPostListener = addOnPostListener(env, jListener);
+
+ PostCallback postCallback = [onPostListener](const HeaderOptions& opts,
+ const OCRepresentation& rep, const int eCode)
+ {
+ onPostListener->onPostCallback(opts, rep, eCode);
+ };
+
+ return m_sharedResource->requestMQPublish(queryParametersMap, postCallback, QoS);
+}
+#endif
+#ifdef MQ_PUBLISHER
+OCStackResult JniOcResource::publishMQTopic(JNIEnv* env, const OCRepresentation &representation,
+ const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS)
+{
+ JniOnPostListener *onPostListener = addOnPostListener(env, jListener);
+
+ PostCallback postCallback = [onPostListener](const HeaderOptions& opts,
+ const OCRepresentation& rep, const int eCode)
+ {
+ onPostListener->onPostCallback(opts, rep, eCode);
+ };
+
+ return m_sharedResource->publishMQTopic(representation, queryParametersMap,
+ postCallback, QoS);
+}
+#endif
+
/*
* Class: org_iotivity_base_OcResource
* Method: get
/*
* Class: org_iotivity_base_OcResource
+* Method: getDeviceName
+* Signature: ()Ljava/lang/String;
+*/
+JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcResource_getDeviceName
+(JNIEnv *env, jobject thiz)
+{
+ LOGD("OcResource_getDeviceName");
+ JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
+ if (!resource)
+ {
+ return nullptr;
+ }
+
+ return env->NewStringUTF(resource->deviceName().c_str());
+}
+
+/*
+* Class: org_iotivity_base_OcResource
* Method: dispose
* Signature: ()V
*/
QueryParamsMap qpm;
JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
- //todo
- // discoveryMQTopics call
+ try
+ {
+ OCStackResult result = resource->discoveryMQTopics(
+ env,
+ qpm,
+ jListener,
+ JniUtils::getQOS(env, static_cast<int>(jQoS)));
+
+ if (OC_STACK_OK != result)
+ {
+ ThrowOcException(result, "OcResource_discoveryMQTopicsImpl");
+ }
+ }
+ catch (OCException& e)
+ {
+ LOGE("%s", e.reason().c_str());
+ ThrowOcException(e.code(), e.reason().c_str());
+ }
#else
ThrowOcException(JNI_NO_SUPPORT, "not support");
#endif
QueryParamsMap qpm;
JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
- //todo
- // createMQTopic call
+ try
+ {
+ OCStackResult result = resource->createMQTopic(
+ env,
+ *representation,
+ targetUri,
+ qpm,
+ jListener,
+ JniUtils::getQOS(env, static_cast<int>(jQoS)));
+
+ if (OC_STACK_OK != result)
+ {
+ ThrowOcException(result, "OcResource_createMQTopicImpl");
+ }
+ }
+ catch (OCException& e)
+ {
+ LOGE("%s", e.reason().c_str());
+ ThrowOcException(e.code(), e.reason().c_str());
+ }
#else
ThrowOcException(JNI_NO_SUPPORT, "not support");
#endif
QueryParamsMap qpm;
JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
- //todo
- // subscribeMQTopic call
+ try
+ {
+ OCStackResult result = resource->subscribeMQTopic(
+ env,
+ qpm,
+ jListener,
+ JniUtils::getQOS(env, static_cast<int>(jQoS)));
+
+ if (OC_STACK_OK != result)
+ {
+ ThrowOcException(result, "OcResource_subscribeMQTopicImpl");
+ }
+ }
+ catch (OCException& e)
+ {
+ LOGE("%s", e.reason().c_str());
+ ThrowOcException(e.code(), e.reason().c_str());
+ }
#else
ThrowOcException(JNI_NO_SUPPORT, "not support");
#endif
return;
}
- //todo
- // unsubscribeMQTopic call
+ try
+ {
+ OCStackResult result = resource->unsubscribeMQTopic(
+ JniUtils::getQOS(env, static_cast<int>(jQoS)));
+ if (OC_STACK_OK != result)
+ {
+ ThrowOcException(result, "OcResource_unsubscribeMQTopicImpl");
+ }
+ }
+ catch (OCException& e)
+ {
+ LOGE("%s", e.reason().c_str());
+ ThrowOcException(e.code(), e.reason().c_str());
+ }
#else
ThrowOcException(JNI_NO_SUPPORT, "not support");
#endif
QueryParamsMap qpm;
JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
- //todo
- // requestMQPublish call
+ try
+ {
+ OCStackResult result = resource->requestMQPublish(
+ env,
+ qpm,
+ jListener,
+ JniUtils::getQOS(env, static_cast<int>(jQoS)));
+
+ if (OC_STACK_OK != result)
+ {
+ ThrowOcException(result, "OcResource_requestMQPublishImpl");
+ }
+ }
+ catch (OCException& e)
+ {
+ LOGE("%s", e.reason().c_str());
+ ThrowOcException(e.code(), e.reason().c_str());
+ }
#else
ThrowOcException(JNI_NO_SUPPORT, "not support");
#endif
QueryParamsMap qpm;
JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
- //todo
- // publishMQTopic call
+ try
+ {
+ OCStackResult result = resource->publishMQTopic(
+ env,
+ *representation,
+ qpm,
+ jListener,
+ JniUtils::getQOS(env, static_cast<int>(jQoS)));
+
+ if (OC_STACK_OK != result)
+ {
+ ThrowOcException(result, "OcResource_publishMQTopicImpl");
+ }
+ }
+ catch (OCException& e)
+ {
+ LOGE("%s", e.reason().c_str());
+ ThrowOcException(e.code(), e.reason().c_str());
+ }
#else
ThrowOcException(JNI_NO_SUPPORT, "not support");
#endif