Added Android java API for Cloud MQ Client.
authorjihwan.seo <jihwan.seo@samsung.com>
Thu, 4 Aug 2016 00:13:08 +0000 (09:13 +0900)
committerJon A. Cruz <jon@joncruz.org>
Thu, 11 Aug 2016 21:01:09 +0000 (21:01 +0000)
- added Native Caller for MQ API

Change-Id: I7a15877cd041b8321088c9f8ec530fe77b390b2f
Signed-off-by: jihwan.seo <jihwan.seo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/9999
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jaehong Jo <jaehong.jo@samsung.com>
Reviewed-by: Jon A. Cruz <jon@joncruz.org>
android/android_api/base/jni/JniOcResource.cpp
android/android_api/base/jni/JniOcResource.h
android/android_api/base/jni/JniOcStack.h
android/android_api/base/src/main/java/org/iotivity/base/OcResource.java

index 743c1bc..3f597db 100644 (file)
@@ -1603,3 +1603,251 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_dispose
     JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
     delete resource;
 }
+
+/*
+* Class:     org_iotivity_base_OcResource
+* Method:    discoveryMQTopicsImpl
+* Signature: (Ljava/util/Map;Lorg/iotivity/base/OcPlatform/OnResourceFoundListener;I)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_discoveryMQTopicsImpl
+(JNIEnv *env, jobject thiz, jobject jQueryParamsMap, jobject jListener, jint jQoS)
+{
+    LOGD("OcResource_discoveryMQTopicsImpl");
+
+#ifdef WITH_MQ
+    if (!jQueryParamsMap)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
+        return;
+    }
+
+    if (!jListener)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "listener cannot be null");
+        return;
+    }
+
+    JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
+    if (!resource)
+    {
+        return;
+    }
+
+    QueryParamsMap qpm;
+    JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
+
+    //todo
+    // discoveryMQTopics call
+#else
+    ThrowOcException(JNI_NO_SUPPORT, "not support");
+#endif
+}
+
+/*
+* Class:     org_iotivity_base_OcResource
+* Method:    createMQTopicImpl
+* Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/String;Ljava/util/Map
+*             ;Lorg/iotivity/base/OcPlatform/OnMQTopicCreatedListener;I)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_createMQTopicImpl
+(JNIEnv *env, jobject thiz, jobject jRepresentation, jstring jUri,
+ jobject jQueryParamsMap, jobject jListener, jint jQoS)
+{
+    LOGD("OcResource_createMQTopicImpl");
+
+#ifdef WITH_MQ
+    if (!jQueryParamsMap)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
+        return;
+    }
+
+    if (!jListener)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "listener cannot be null");
+        return;
+    }
+
+    if (!jRepresentation)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "representation null");
+        return;
+    }
+
+    JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
+    if (!resource)
+    {
+        return;
+    }
+
+    std::string targetUri;
+    if (jUri)
+    {
+        targetUri = env->GetStringUTFChars(jUri, nullptr);
+    }
+
+    OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env,
+                                                                                   jRepresentation);
+    if (!representation)
+    {
+        return;
+    }
+
+    QueryParamsMap qpm;
+    JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
+
+    //todo
+    // createMQTopic call
+#else
+    ThrowOcException(JNI_NO_SUPPORT, "not support");
+#endif
+}
+
+/*
+* Class:     org_iotivity_base_OcResource
+* Method:    subscribeMQTopic
+* Signature: (Ljava/util/Map;Lorg/iotivity/base/OcResource/OnObserveListener;I)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_subscribeMQTopicImpl
+(JNIEnv *env, jobject thiz, jobject jQueryParamsMap, jobject jListener, jint jQoS)
+{
+    LOGD("OcResource_subscribeMQTopicImpl");
+#ifdef MQ_SUBSCRIBER
+    if (!jQueryParamsMap)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
+        return;
+    }
+    if (!jListener)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "onObserveListener cannot be null");
+        return;
+    }
+    JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
+    if (!resource)
+    {
+        return;
+    }
+
+    QueryParamsMap qpm;
+    JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
+
+    //todo
+    // subscribeMQTopic call
+#else
+    ThrowOcException(JNI_NO_SUPPORT, "not support");
+#endif
+}
+
+/*
+* Class:     org_iotivity_base_OcResource
+* Method:    unsubscribeMQTopicImpl
+* Signature: (I)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_unsubscribeMQTopicImpl
+(JNIEnv *env, jobject thiz, jint jQoS)
+{
+    LOGD("OcResource_unsubscribeMQTopicImpl");
+#ifdef MQ_SUBSCRIBER
+    JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
+    if (!resource)
+    {
+        return;
+    }
+
+    //todo
+    // unsubscribeMQTopic call
+#else
+    ThrowOcException(JNI_NO_SUPPORT, "not support");
+#endif
+}
+
+/*
+* Class:     org_iotivity_base_OcResource
+* Method:    requestMQPublishImpl
+* Signature: (Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPostListener;I)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_requestMQPublishImpl
+(JNIEnv *env, jobject thiz, jobject jQueryParamsMap, jobject jListener, jint jQoS)
+{
+    LOGD("OcResource_requestMQPublishImpl");
+#ifdef MQ_SUBSCRIBER
+    if (!jQueryParamsMap)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
+        return;
+    }
+    if (!jListener)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null");
+        return;
+    }
+
+    JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
+    if (!resource)
+    {
+        return;
+    }
+
+    QueryParamsMap qpm;
+    JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
+
+    //todo
+    // requestMQPublish call
+#else
+    ThrowOcException(JNI_NO_SUPPORT, "not support");
+#endif
+}
+
+/*
+* Class:     org_iotivity_base_OcResource
+* Method:    publishMQTopicImpl
+* Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/Map;
+*             Lorg/iotivity/base/OcResource/OnPostListener;I)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_publishMQTopicImpl
+(JNIEnv *env, jobject thiz, jobject jRepresentation, jobject jQueryParamsMap,
+ jobject jListener, jint jQoS)
+{
+    LOGD("OcResource_publishMQTopicImpl");
+#ifdef MQ_PUBLISHER
+    if (!jRepresentation)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "representation cannot be null");
+        return;
+    }
+
+    if (!jQueryParamsMap)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null");
+        return;
+    }
+
+    if (!jListener)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null");
+        return;
+    }
+
+    JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz);
+    if (!resource)
+    {
+        return;
+    }
+
+    OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env,
+                                                                                   jRepresentation);
+    if (!representation)
+    {
+        return;
+    }
+
+    QueryParamsMap qpm;
+    JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm);
+
+    //todo
+    // publishMQTopic call
+#else
+    ThrowOcException(JNI_NO_SUPPORT, "not support");
+#endif
+}
index a038312..5911a96 100644 (file)
@@ -345,7 +345,57 @@ extern "C" {
     JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_dispose
         (JNIEnv *, jobject);
 
+    /*
+    * Class:     org_iotivity_base_OcResource
+    * Method:    subscribeMQTopicImpl
+    * Signature: (Ljava/util/Map;Lorg/iotivity/base/OcResource/OnObserveListener;I)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_subscribeMQTopicImpl
+        (JNIEnv *, jobject, jobject, jobject, jint);
+
+    /*
+    * Class:     org_iotivity_base_OcResource
+    * Method:    unsubscribeMQTopicImpl
+    * Signature: (I)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_unsubscribeMQTopicImpl
+        (JNIEnv *, jobject, jint);
+
+    /*
+    * Class:     org_iotivity_base_OcResource
+    * Method:    requestMQPublishImpl
+    * Signature: (Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPostListener;I)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_requestMQPublishImpl
+        (JNIEnv *, jobject, jobject, jobject, jint);
+
+    /*
+    * Class:     org_iotivity_base_OcResource
+    * Method:    publishMQTopicImpl
+    * Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/Map
+    *             ;Lorg/iotivity/base/OcResource/OnPostListener;I)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_publishMQTopicImpl
+        (JNIEnv *, jobject, jobject, jobject, jobject, jint);
+
+    /*
+    * Class:     org_iotivity_base_OcResource
+    * Method:    discoveryMQTopicsImpl
+    * Signature: (Ljava/util/Map;Lorg/iotivity/base/OcResource/OnMQTopicFoundListener;I)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_discoveryMQTopicsImpl
+        (JNIEnv *, jobject, jobject, jobject, jint);
+
+    /*
+    * Class:     org_iotivity_base_OcResource
+    * Method:    createMQTopicImpl
+    * Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/String;Ljava/util/Map
+    *             ;Lorg/iotivity/base/OcPlatform/OnMQTopicCreatedListener;I)V
+    */
+    JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_createMQTopicImpl
+        (JNIEnv *, jobject, jobject, jstring, jobject, jobject, jint);
+
 #ifdef __cplusplus
 }
 #endif
-#endif
\ No newline at end of file
+#endif
index 8b7bc6f..273a6ac 100644 (file)
@@ -38,6 +38,7 @@
 #define JNI_NO_NATIVE_POINTER 1001
 #define JNI_INVALID_VALUE 1002
 #define JNI_NO_SUCH_KEY 1003
+#define JNI_NO_SUPPORT 1004
 
 jobject getOcException(JNIEnv* env, const char* file, const char* functionName, const int line,
     const int code, const char* message);
index b74c2e5..3270d69 100644 (file)
@@ -591,4 +591,174 @@ public class OcResource {
     private native void dispose();
 
     private long mNativeHandle;
+
+    /**
+     * Method to discovery Topics
+     *
+     * @param queryParamsMap    map which can have the query parameter name and value
+     * @param onTopicFoundListener    event handler The handler method will be invoked with a map
+     *                                of attribute name and values.
+     * @param qualityOfService the quality of communication.
+     * @throws OcException
+     */
+    public void discoveryMQTopics(Map<String, String> queryParamsMap,
+                                  OnMQTopicFoundListener onTopicFoundListener,
+                                  QualityOfService qualityOfService) throws OcException {
+        this.discoveryMQTopicsImpl(queryParamsMap, onTopicFoundListener,
+                                   qualityOfService.getValue());
+    }
+
+    private synchronized native void discoveryMQTopicsImpl(
+            Map<String, String> queryParamsMap,
+            OnMQTopicFoundListener onTopicFoundListener,
+            int qualityOfService) throws OcException;
+
+    /**
+     * Method to create Topic into MQ Brober.
+     *
+     * @param ocRepresentation  representation of the MQ Broker.
+     * @param uri               new MQ Topic uri which want to create.
+     * @param queryParamsMap    map which can have the query parameter name and value.
+     * @param onTopicCreatedListener    event handler The handler method will be invoked with a map
+     *                                  of attribute name and values.
+     * @param qualityOfService the quality of communication.
+     * @throws OcException
+     */
+    public void createMQTopic(OcRepresentation ocRepresentation,
+                              String uri,
+                              Map<String, String> queryParamsMap,
+                              OnMQTopicCreatedListener onTopicCreatedListener,
+                              QualityOfService qualityOfService) throws OcException {
+        this.createMQTopicImpl(ocRepresentation, uri, queryParamsMap,
+                               onTopicCreatedListener, qualityOfService.getValue());
+    }
+
+    private synchronized native void createMQTopicImpl(
+            OcRepresentation ocRepresentation,
+            String uri,
+            Map<String, String> queryParamsMap,
+            OnMQTopicCreatedListener onTopicCreatedListener,
+            int qualityOfService) throws OcException;
+
+    /**
+     * Method to set subscribe on the Topic.
+     *
+     * @param queryParamsMap    map which can have the query parameter name and value.
+     * @param onObserveListener event handler The handler method will be invoked with a map
+     *                          of attribute name and values.
+     * @param qualityOfService the quality of communication.
+     * @throws OcException
+     */
+    public void subscribeMQTopic(Map<String, String> queryParamsMap,
+                                 OnObserveListener onObserveListener,
+                                 QualityOfService qualityOfService) throws OcException {
+        this.subscribeMQTopicImpl(queryParamsMap,
+                                  onObserveListener,
+                                  qualityOfService.getValue());
+    }
+
+    private synchronized native void subscribeMQTopicImpl(Map<String, String> queryParamsMap,
+            OnObserveListener onObserveListener,
+            int qualityOfService) throws OcException;
+
+    /**
+     * Method to cancel the observation on the Topic.
+     *
+     * @param qualityOfService the quality of communication.
+     * @throws OcException
+     */
+    public void unsubscribeMQTopic(QualityOfService qualityOfService) throws OcException{
+        this.unsubscribeMQTopicImpl(qualityOfService.getValue());
+    }
+
+    private native void unsubscribeMQTopicImpl(
+            int qualityOfService) throws OcException;
+
+    /**
+     * Method to requestMQPublish on a Topic
+     *
+     * @param queryParamsMap   Map which can have the query parameter name and value
+     * @param onPostListener   event handler The event handler will be invoked with a map of
+     *                         attribute name and values.
+     * @param qualityOfService the quality of communication.
+     * @throws OcException
+     */
+    public void requestMQPublish(Map<String, String> queryParamsMap,
+                     OnPostListener onPostListener,
+                     QualityOfService qualityOfService) throws OcException {
+        this.requestMQPublishImpl(queryParamsMap,
+                                  onPostListener,
+                                  qualityOfService.getValue());
+    }
+
+    private native void requestMQPublishImpl(Map<String, String> queryParamsMap,
+                              OnPostListener onPostListener,
+                              int qualityOfService) throws OcException;
+
+    /**
+     * Method to publishMQTopic on a Topic
+     *
+     * @param ocRepresentation representation of the resource
+     * @param queryParamsMap   Map which can have the query parameter name and value
+     * @param onPostListener   event handler The event handler will be invoked with a map of
+     *                         attribute name and values.
+     * @param qualityOfService the quality of communication.
+     * @throws OcException
+     */
+    public void publishMQTopic(OcRepresentation ocRepresentation,
+                     Map<String, String> queryParamsMap,
+                     OnPostListener onPostListener,
+                     QualityOfService qualityOfService) throws OcException {
+        this.publishMQTopicImpl(ocRepresentation,
+                                queryParamsMap,
+                                onPostListener,
+                                qualityOfService.getValue());
+    }
+
+    private native void publishMQTopicImpl(OcRepresentation ocRepresentation,
+                              Map<String, String> queryParamsMap,
+                              OnPostListener onPostListener,
+                              int qualityOfService) throws OcException;
+
+    /**
+     * An OnMQTopicFoundListener can be registered via the OcResource.discoveryMQTopics call.
+     * Event listeners are notified asynchronously
+     */
+    public interface OnMQTopicFoundListener {
+        public void onTopicDiscoveried(OcResource resource);
+        public void onDiscoveryTopicFailed(Throwable ex, String uri);
+    }
+
+    /**
+     * An OnMQTopicCreatedListener can be registered via the OcResource.createMQTopic call.
+     * Event listeners are notified asynchronously
+     */
+    public interface OnMQTopicCreatedListener {
+        public void onTopicResourceCreated(OcResource resource);
+        public void onCreateTopicFailed(Throwable ex, String uri);
+    }
+
+    /**
+     * An OnMQTopicSubscribeListener can be registered via the OcResource.subscribeMQTopic call.
+     * Event listeners are notified asynchronously
+     */
+    public interface OnMQTopicSubscribeListener {
+        /**
+         * To Subscriber.
+         */
+        public static final int SUBSCRIBER = 0;
+        /**
+         * To Unrubscriber.
+         */
+        public static final int UNSUBSCRIBER = 1;
+        /**
+         * Others.
+         */
+        public static final int NO_OPTION = 2;
+        public void onSubScribeCompleted(List<OcHeaderOption> headerOptionList,
+                OcRepresentation ocRepresentation,
+                int sequenceNumber);
+
+        public void onSubScribeFailed(Throwable ex);
+    }
 }