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)
{
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);
+}
+
+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);
+}
+#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);
+}
+
+OCStackResult JniOcResource::unsubscribeMQTopic(QualityOfService QoS)
+{
+ return m_sharedResource->unsubscribeMQTopic();
+}
+
+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);
+}
+#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);
+}
+#endif
+
/*
* Class: org_iotivity_base_OcResource
* Method: get
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
#include "JniOnDeleteListener.h"
#include "JniOnObserveListener.h"
#include "JniOcResourceIdentifier.h"
+#ifdef WITH_MQ
+#include "JniOnMQTopicFoundListener.h"
+#include "JniOnMQSubscribeListener.h"
+#endif
#ifndef _Included_org_iotivity_base_OcResource
#define _Included_org_iotivity_base_OcResource
std::string uri();
OCConnectivityType connectivityType() const;
bool isObservable();
- std::vector< std::string > getResourceTypes() const;
- std::vector< std::string > getResourceInterfaces(void) const;
+ std::vector< std::string > getResourceTypes() const;
+ std::vector< std::string > getResourceInterfaces(void) const;
OCResourceIdentifier uniqueIdentifier() const;
std::string sid() const;
static JniOcResource* getJniOcResourcePtr(JNIEnv *env, jobject thiz);
+#ifdef WITH_MQ
+ JniOnMQTopicFoundListener* addOnTopicFoundListener(JNIEnv* env, jobject jListener);
+ void removeOnTopicFoundListener(JNIEnv* env, jobject jListener);
+
+ JniOnMQSubscribeListener* addOnMQTopicSubscribeListener(JNIEnv* env, jobject jListener);
+ void removeOnMQTopicSubscribeListener(JNIEnv* env, jobject jListener);
+
+ OCStackResult discoveryMQTopics(JNIEnv* env, const QueryParamsMap &queryParametersMap,
+ jobject jListener, QualityOfService QoS);
+ OCStackResult createMQTopic(JNIEnv* env, const OCRepresentation &representation,
+ const std::string &targetUri,
+ const QueryParamsMap &queryParametersMap,
+ jobject jListener, QualityOfService QoS);
+#endif
+#ifdef MQ_SUBSCRIBER
+ OCStackResult subscribeMQTopic(JNIEnv* env, const QueryParamsMap &queryParametersMap,
+ jobject jListener, QualityOfService QoS);
+ OCStackResult unsubscribeMQTopic(QualityOfService QoS);
+ OCStackResult requestMQPublish(JNIEnv* env, const QueryParamsMap &queryParametersMap,
+ jobject jListener, QualityOfService QoS);
+#endif
+#ifdef MQ_PUBLISHER
+ OCStackResult publishMQTopic(JNIEnv* env, const OCRepresentation &representation,
+ const QueryParamsMap &queryParametersMap,
+ jobject jListener, QualityOfService QoS);
+#endif
+
private:
JniListenerManager<JniOnGetListener> m_onGetManager;
JniListenerManager<JniOnPutListener> m_onPutManager;
JniListenerManager<JniOnPostListener> m_onPostManager;
JniListenerManager<JniOnDeleteListener> m_onDeleteManager;
JniListenerManager<JniOnObserveListener> m_onObserveManager;
+#ifdef WITH_MQ
+ JniListenerManager<JniOnMQTopicFoundListener> m_onFoundTopicResourceManager;
+ JniListenerManager<JniOnMQSubscribeListener> m_onSubcribeTopicManager;
+#endif
std::shared_ptr<OCResource> m_sharedResource;
};