[Resource-Encapsulation] Added Resource Container in Java SDK
authorJay Sharma <jay.sharma@samsung.com>
Tue, 1 Sep 2015 08:10:58 +0000 (13:40 +0530)
committerMadan Lanka <lanka.madan@samsung.com>
Fri, 4 Sep 2015 05:36:30 +0000 (05:36 +0000)
- Updated Java sdk for resource Container
- updated client and server jni files for exceptions.

Change-Id: I7406be52e1cb596a27a9b8d130e029f30075fffe
Signed-off-by: Jay Sharma <jay.sharma@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2332
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Rami Jung <rami.jung@samsung.com>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
16 files changed:
service/resource-encapsulation/sdk/java/jni/Android.mk
service/resource-encapsulation/sdk/java/jni/jniutil/inc/jni_re_jvm.h
service/resource-encapsulation/sdk/java/jni/jniutil/inc/jni_re_utils.h
service/resource-encapsulation/sdk/java/jni/jniutil/src/jni_re_jvm.cpp
service/resource-encapsulation/sdk/java/jni/jniutil/src/jni_re_utils.cpp
service/resource-encapsulation/sdk/java/jni/re/include/jni_re_rcs_bundle_info.h [new file with mode: 0644]
service/resource-encapsulation/sdk/java/jni/re/include/jni_re_rcs_resource_container.h [new file with mode: 0644]
service/resource-encapsulation/sdk/java/jni/re/src/jni_re_rcs_bundle_info.cpp [new file with mode: 0644]
service/resource-encapsulation/sdk/java/jni/re/src/jni_re_rcs_remoteresourceobject.cpp
service/resource-encapsulation/sdk/java/jni/re/src/jni_re_rcs_resource_container.cpp [new file with mode: 0644]
service/resource-encapsulation/sdk/java/jni/re/src/jni_re_resource_attributes.cpp
service/resource-encapsulation/sdk/java/jni/re/src/jni_re_resource_builder.cpp
service/resource-encapsulation/sdk/java/src/org/iotivity/ResourceEncapsulation/client/RCSAddress.java
service/resource-encapsulation/sdk/java/src/org/iotivity/ResourceEncapsulation/server/Builder.java
service/resource-encapsulation/sdk/java/src/org/iotivity/ResourceEncapsulation/server/RCSBundleInfo.java [new file with mode: 0644]
service/resource-encapsulation/sdk/java/src/org/iotivity/ResourceEncapsulation/server/RCSResourceContainer.java [new file with mode: 0644]

index 62b4335..2212fb1 100644 (file)
@@ -8,6 +8,12 @@ include $(PREBUILT_SHARED_LIBRARY)
 
 include $(CLEAR_VARS)
 OIC_LIB_PATH := ../../../../../out/android/$(TARGET_ARCH_ABI)/release
+LOCAL_MODULE := android-oc_loggercore
+LOCAL_SRC_FILES := $(OIC_LIB_PATH)/liboc_logger_core.so
+include $(PREBUILT_SHARED_LIBRARY)
+
+include $(CLEAR_VARS)
+OIC_LIB_PATH := ../../../../../out/android/$(TARGET_ARCH_ABI)/release
 LOCAL_MODULE := android-octbstack
 LOCAL_SRC_FILES := $(OIC_LIB_PATH)/liboctbstack.so
 include $(PREBUILT_SHARED_LIBRARY)
@@ -55,6 +61,12 @@ LOCAL_SRC_FILES := $(OIC_LIB_PATH)/librcs_server.so
 include $(PREBUILT_SHARED_LIBRARY)
 
 include $(CLEAR_VARS)
+OIC_LIB_PATH := ../../../../../out/android/$(TARGET_ARCH_ABI)/release
+LOCAL_MODULE := android-resourcecontainer
+LOCAL_SRC_FILES := $(OIC_LIB_PATH)/librcs_container.so
+include $(PREBUILT_SHARED_LIBRARY)
+
+include $(CLEAR_VARS)
 OIC_SRC_DIR := ../../../../..
 LOCAL_MODULE    := re-jni
 
@@ -79,6 +91,7 @@ LOCAL_SHARED_LIBRARIES := android-ocstack-jni
 LOCAL_SHARED_LIBRARIES += android-resourcecommon
 LOCAL_SHARED_LIBRARIES += android-resourceclient
 LOCAL_SHARED_LIBRARIES += android-resourceserver
+LOCAL_SHARED_LIBRARIES += android-resourcecontainer
 LOCAL_SHARED_LIBRARIES += android-oc
 LOCAL_SHARED_LIBRARIES += android-octbstack
 
index ce6e70b..46a1d1d 100644 (file)
@@ -48,26 +48,37 @@ extern jclass g_cls_String;
 extern jclass g_cls_LinkedList;
 extern jclass g_cls_Iterator;
 extern jclass g_cls_Vector;
+extern jclass g_cls_Map;
+extern jclass g_cls_Set;
+extern jclass g_cls_MapEntry;
 extern jclass g_cls_RCSRemoteResourceObject;
 extern jclass g_cls_RCSRemoteResourceAttributesObject;
 extern jclass g_cls_RCSException;
 
 extern jclass g_cls_RCSResourceObject;
 extern jclass g_cls_RCSRequest;
+extern jclass g_cls_RCSBundleInfo;
 
 extern jmethodID g_mid_Integer_ctor;
 extern jmethodID g_mid_Double_ctor;
 extern jmethodID g_mid_Boolean_ctor;
 extern jmethodID g_mid_LinkedList_ctor;
 extern jmethodID g_mid_LinkedList_add_object;
+extern jmethodID g_mid_Map_entrySet;
+extern jmethodID g_mid_MapEntry_getKey;
+extern jmethodID g_mid_MapEntry_getValue;
+extern jmethodID g_mid_Set_iterator;
 extern jmethodID g_mid_Iterator_hasNext;
 extern jmethodID g_mid_Iterator_next;
+extern jmethodID g_mid_HashMap_ctor;
+extern jmethodID g_mid_HashMap_put;
 extern jmethodID g_mid_RCSRemoteResourceObject_ctor;
 extern jmethodID g_mid_RCSRemoteResourceAttributesObject_ctor;
 extern jmethodID g_mid_RCSException_ctor;
 
 extern jmethodID g_mid_RCSResourceObject_ctor;
 extern jmethodID g_mid_RCSRequest_ctor;
+extern jmethodID g_mid_RCSBundleInfo_ctor;
 
 typedef void(*RemoveListenerCallback)(JNIEnv *env, jobject jListener);
 
index 548f88b..1af08e5 100644 (file)
@@ -31,6 +31,8 @@
 #include "RCSRemoteResourceObject.h"
 #include "RCSResourceObject.h"
 
+#include <map>
+#include <list>
 #include <jni.h>
 
 using namespace OIC::Service;
@@ -78,10 +80,23 @@ RCSResourceObject::SetRequestHandlerPolicy convertJavasetRequestHandlerPolicyToN
  */
 int convertSetRequestHandlerPolicyToInt( RCSResourceObject::SetRequestHandlerPolicy policy);
 
-
+/**
+ *@brief Convert int to OCEntityHandlerResult
+ */
 OCEntityHandlerResult convertIntToOCEntityHandlerResult(int result);
 
 /**
+ *@brief Convert java map to native map
+ */
+void convertJavaMapToParamsMap(JNIEnv *env, jobject hashMap,
+                               std::map<std::string, std::string> &params);
+
+/**
+ *@brief Convert native string list to java list
+ */
+jobject convertStrListToJavaStrList(JNIEnv *env, std::list<std::string> &list);
+
+/**
  * @brief Throw the RCS exception to the upper layer
  */
 void throwRCSException(JNIEnv *env, std::string reason);
index 9fe316e..e53d9ab 100644 (file)
@@ -29,18 +29,26 @@ jclass g_cls_String = NULL;
 jclass g_cls_LinkedList = NULL;
 jclass g_cls_Iterator = NULL;
 jclass g_cls_Vector = NULL;
+jclass g_cls_Map = NULL;
+jclass g_cls_Set = NULL;
+jclass g_cls_MapEntry = NULL;
 jclass g_cls_RCSRemoteResourceObject = NULL;
 jclass g_cls_RCSRemoteResourceAttributesObject = NULL;
 jclass g_cls_RCSException = NULL;
 
 jclass g_cls_RCSResourceObject = NULL;
 jclass g_cls_RCSRequest = NULL;
+jclass g_cls_RCSBundleInfo = NULL;
 
 jmethodID g_mid_Integer_ctor = NULL;
 jmethodID g_mid_Double_ctor = NULL;
 jmethodID g_mid_Boolean_ctor = NULL;
 jmethodID g_mid_LinkedList_ctor = NULL;
+jmethodID g_mid_Set_iterator = NULL;
 jmethodID g_mid_LinkedList_add_object = NULL;
+jmethodID g_mid_Map_entrySet = NULL;
+jmethodID g_mid_MapEntry_getKey = NULL;
+jmethodID g_mid_MapEntry_getValue = NULL;
 jmethodID g_mid_Iterator_hasNext = NULL;
 jmethodID g_mid_Iterator_next = NULL;
 jmethodID g_mid_RCSRemoteResourceObject_ctor = NULL;
@@ -49,7 +57,7 @@ jmethodID g_mid_RCSException_ctor = NULL;
 
 jmethodID g_mid_RCSResourceObject_ctor = NULL;
 jmethodID g_mid_RCSRequest_ctor = NULL;
-
+jmethodID g_mid_RCSBundleInfo_ctor = NULL;
 
 // JNI OnLoad
 JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
@@ -111,6 +119,35 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
     g_mid_LinkedList_add_object = env->GetMethodID(g_cls_LinkedList, "add", "(Ljava/lang/Object;)Z");
     if (!g_mid_LinkedList_add_object) return JNI_ERR;
 
+    //Map
+    clazz = env->FindClass("java/util/Map");
+    if (!clazz) return JNI_ERR;
+    g_cls_Map = (jclass)env->NewGlobalRef(clazz);
+    env->DeleteLocalRef(clazz);
+
+    g_mid_Map_entrySet = env->GetMethodID(g_cls_Map, "entrySet", "()Ljava/util/Set;");
+    if (!g_mid_Map_entrySet) return JNI_ERR;
+
+    //MapEntry
+    clazz = env->FindClass("java/util/Map$Entry");
+    if (!clazz) return JNI_ERR;
+    g_cls_MapEntry = (jclass)env->NewGlobalRef(clazz);
+    env->DeleteLocalRef(clazz);
+
+    g_mid_MapEntry_getKey = env->GetMethodID(g_cls_MapEntry, "getKey", "()Ljava/lang/Object;");
+    if (!g_mid_MapEntry_getKey) return JNI_ERR;
+    g_mid_MapEntry_getValue = env->GetMethodID(g_cls_MapEntry, "getValue", "()Ljava/lang/Object;");
+    if (!g_mid_MapEntry_getValue) return JNI_ERR;
+
+    //Set
+    clazz = env->FindClass("java/util/Set");
+    if (!clazz) return JNI_ERR;
+    g_cls_Set = (jclass)env->NewGlobalRef(clazz);
+    env->DeleteLocalRef(clazz);
+
+    g_mid_Set_iterator = env->GetMethodID(g_cls_Set, "iterator", "()Ljava/util/Iterator;");
+    if (!g_mid_Set_iterator) return JNI_ERR;
+
     //Iterator
     clazz = env->FindClass("java/util/Iterator");
     if (!clazz) return JNI_ERR;
@@ -141,11 +178,12 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
 
     //ResourceState enum
     jclass tmpclazz = reinterpret_cast<jclass>
-           (env->FindClass("org/iotivity/ResourceEncapsulation/client/RCSRemoteResourceObject$ResourceState"));
-     if (!tmpclazz) {
-       LOGE("Failed to get the class ResourceState");
+            (env->FindClass("org/iotivity/ResourceEncapsulation/client/RCSRemoteResourceObject$ResourceState"));
+    if (!tmpclazz)
+    {
+        LOGE("Failed to get the class ResourceState");
         return JNI_ERR;
-   }
+    }
     ResourceStateWrapper::clazz = reinterpret_cast<jclass> (env->NewGlobalRef(tmpclazz));
     env->DeleteLocalRef(tmpclazz);
 
@@ -184,9 +222,15 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
     g_cls_RCSRequest = (jclass)env->NewGlobalRef(clazz);
     env->DeleteLocalRef(clazz);
 
-    /* g_mid_RCSRequest_ctor = env->GetMethodID(g_cls_RCSRequest, "<init>",
-                                          "(J)V");
-       if (!g_mid_RCSRequest_ctor) return JNI_ERR;*/
+    //RCSBundleInfo
+    clazz = env->FindClass("org/iotivity/ResourceEncapsulation/server/RCSBundleInfo");
+    if (!clazz) return JNI_ERR;
+    g_cls_RCSBundleInfo = (jclass)env->NewGlobalRef(clazz);
+    env->DeleteLocalRef(clazz);
+
+    g_mid_RCSBundleInfo_ctor = env->GetMethodID(g_cls_RCSBundleInfo, "<init>",
+                               "(J)V");
+    if (!g_mid_RCSBundleInfo_ctor) return JNI_ERR;
 
     return JNI_CURRENT_VERSION;
 }
@@ -213,6 +257,10 @@ JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved)
     env->DeleteGlobalRef(g_cls_RCSException);
     env->DeleteGlobalRef(g_cls_RCSResourceObject);
     env->DeleteGlobalRef(g_cls_RCSRequest);
+    env->DeleteGlobalRef(g_cls_Map);
+    env->DeleteGlobalRef(g_cls_Set);
+    env->DeleteGlobalRef(g_cls_MapEntry);
+    env->DeleteGlobalRef(g_cls_RCSBundleInfo);
 
     if (env)
     {
index 5466f72..e259a8a 100644 (file)
@@ -158,21 +158,21 @@ jobject convertNativeResourceStateToJavaResourceState(ResourceState nativeResour
     LOGI("convertNativeResourceStateToJavaResourceState enter");
 
     ResourceStateWrapper::ALIVE_ID = env->GetStaticFieldID(ResourceStateWrapper::clazz, "ALIVE",
-                         "Lorg/iotivity/ResourceEncapsulation/client/RCSRemoteResourceObject$ResourceState;");
+                   "Lorg/iotivity/ResourceEncapsulation/client/RCSRemoteResourceObject$ResourceState;");
     ResourceStateWrapper::REQUESTED_ID = env->GetStaticFieldID(ResourceStateWrapper::clazz, "REQUESTED",
-                         "Lorg/iotivity/ResourceEncapsulation/client/RCSRemoteResourceObject$ResourceState;");
+                   "Lorg/iotivity/ResourceEncapsulation/client/RCSRemoteResourceObject$ResourceState;");
     ResourceStateWrapper::LOST_SIGNAL_ID = env->GetStaticFieldID(ResourceStateWrapper::clazz,
-                         "LOST_SIGNAL", "Lorg/iotivity/ResourceEncapsulation/client/RCSRemoteResourceObject$ResourceState;");
+                    "LOST_SIGNAL", "Lorg/iotivity/ResourceEncapsulation/client/RCSRemoteResourceObject$ResourceState;");
     ResourceStateWrapper::DESTROYED_ID = env->GetStaticFieldID(ResourceStateWrapper::clazz, "DESTROYED",
-                         "Lorg/iotivity/ResourceEncapsulation/client/RCSRemoteResourceObject$ResourceState;");
+                    "Lorg/iotivity/ResourceEncapsulation/client/RCSRemoteResourceObject$ResourceState;");
     ResourceStateWrapper::NONE_ID = env->GetStaticFieldID(ResourceStateWrapper::clazz, "NONE",
-                          "Lorg/iotivity/ResourceEncapsulation/client/RCSRemoteResourceObject$ResourceState;");
+                    "Lorg/iotivity/ResourceEncapsulation/client/RCSRemoteResourceObject$ResourceState;");
 
     ResourceStateWrapper::ordinal_ID = env->GetMethodID(ResourceStateWrapper::clazz, "ordinal", "()I");
     ResourceStateWrapper::toString_ID = env->GetMethodID(ResourceStateWrapper::clazz, "toString",
                                         "()Ljava/lang/String;");
     ResourceStateWrapper::valueOf_ID = env->GetStaticMethodID(ResourceStateWrapper::clazz, "valueOf",
-                                       "(Ljava/lang/String;)Lorg/iotivity/ResourceEncapsulation/client/RCSRemoteResourceObject$ResourceState;");
+                   "(Ljava/lang/String;)Lorg/iotivity/ResourceEncapsulation/client/RCSRemoteResourceObject$ResourceState;");
 
     LOGI("convertNativeResourceStateToJavaResourceState ResourceStateWrapper::clazz == NULL first time");
 
@@ -251,3 +251,58 @@ int convertSetRequestHandlerPolicyToInt(RCSResourceObject::SetRequestHandlerPoli
     }
     return 0;
 }
+
+void convertJavaMapToParamsMap(JNIEnv *env, jobject hashMap,
+                               std::map<std::string, std::string> &params)
+{
+
+    LOGI("convertJavaMapToParamsMap Enter");
+    if (!hashMap)
+    {
+        LOGI("convertJavaMapToParamsMap hashMap is NULL");
+        return;
+    }
+
+    jobject jEntrySet = env->CallObjectMethod(hashMap, g_mid_Map_entrySet);
+    jobject jIterator = env->CallObjectMethod(jEntrySet, g_mid_Set_iterator);
+    if (!jEntrySet || !jIterator || env->ExceptionCheck())
+    {
+        LOGI("convertJavaMapToParamsMap !jEntrySet || !jIterator || env->ExceptionCheck()");
+        return;
+    }
+
+    while (env->CallBooleanMethod(jIterator, g_mid_Iterator_hasNext))
+    {
+        jobject jEntry = env->CallObjectMethod(jIterator, g_mid_Iterator_next);
+        if (!jEntry) return;
+        jstring jKey = (jstring)env->CallObjectMethod(jEntry, g_mid_MapEntry_getKey);
+        if (!jKey) return;
+        jstring jValue = (jstring)env->CallObjectMethod(jEntry, g_mid_MapEntry_getValue);
+        if (!jValue) return;
+
+        LOGI("convertJavaMapToParamsMap about to insert");
+        params.insert(std::make_pair(env->GetStringUTFChars(jKey, NULL),
+                                     env->GetStringUTFChars(jValue, NULL)));
+
+        if (env->ExceptionCheck()) return;
+        env->DeleteLocalRef(jEntry);
+        env->DeleteLocalRef(jKey);
+        env->DeleteLocalRef(jValue);
+    }
+}
+
+jobject convertStrListToJavaStrList(JNIEnv *env, std::list<std::string> &nativeList)
+{
+    jobject jList = env->NewObject(g_cls_LinkedList, g_mid_LinkedList_ctor);
+    if (!jList) return nullptr;
+
+    for (std::list<std::string>::iterator it = nativeList.begin(); it != nativeList.end(); ++it)
+    {
+        jstring jStr = env->NewStringUTF((*it).c_str());
+        if (!jStr) return nullptr;
+        env->CallBooleanMethod(jList, g_mid_LinkedList_add_object, jStr);
+        if (env->ExceptionCheck()) return nullptr;
+        env->DeleteLocalRef(jStr);
+    }
+    return jList;
+}
\ No newline at end of file
diff --git a/service/resource-encapsulation/sdk/java/jni/re/include/jni_re_rcs_bundle_info.h b/service/resource-encapsulation/sdk/java/jni/re/include/jni_re_rcs_bundle_info.h
new file mode 100644 (file)
index 0000000..5cd811a
--- /dev/null
@@ -0,0 +1,160 @@
+/******************************************************************
+ *
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+
+/** @file   jni_re_rcs_bundle_info.h
+ *
+ * @brief This file contains the JniBundleInfo class
+ *               & declaration of RCSBundleInfo APIs for JNI implementation
+ */
+
+#ifndef __JNI_RE_RCS_BUNDLE_INFO_H_
+#define __JNI_RE_RCS_BUNDLE_INFO_H_
+
+#include <jni.h>
+
+#include <RCSBundleInfo.h>
+
+using namespace OIC::Service;
+
+/**
+ * @class   JniBundleInfo
+ * @brief   This class provides the API for getting the RCSBundleInfo pointer
+ *
+ */
+class JniBundleInfo
+{
+    public:
+        /**
+         * @brief Get the RCSBundleInfo pointer
+         *      internally get the native handle by calling REGetHandle
+         */
+        static RCSBundleInfo *getRCSBundleInfoPtr(JNIEnv *env, jobject thiz);
+};
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+* API for getting the Id of the bundle
+*
+* @return jstring - Id of the bundle
+*
+*/
+JNIEXPORT jstring JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSBundleInfo_nativeGetID
+(JNIEnv *env, jobject jObject);
+
+/**
+* API for getting the path of the bundle
+*
+* @return jstring - path of the bundle
+*
+*/
+JNIEXPORT jstring JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSBundleInfo_nativeGetPath
+(JNIEnv *env, jobject jObject);
+
+/**
+* API for getting the Activator name for the bundle
+*
+* @return jstring - Name of the activator
+*
+*/
+JNIEXPORT jstring JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSBundleInfo_nativeGetActivatorName
+(JNIEnv *env, jobject jObject);
+
+/**
+* API for getting the library path for the bundle
+*
+* @return jstring - Library path  in string form
+*
+*/
+JNIEXPORT jstring JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSBundleInfo_nativeGetLibraryPath
+(JNIEnv *env, jobject jObject);
+
+/**
+* API for getting the version of the bundle
+*
+* @return jstring - version of the bundle
+*
+*/
+JNIEXPORT jstring JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSBundleInfo_nativeGetVersion
+(JNIEnv *env, jobject jObject);
+
+
+/**
+* API for setting the Id of the bundle
+*
+* @param id - Id of the bundle in string form
+*
+*/
+JNIEXPORT void JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSBundleInfo_nativeSetID
+(JNIEnv *env, jobject jObject, jstring id);
+
+/**
+* API for setting the path of the bundle
+*
+* @param path - path of the bundle in string form
+*
+*/
+JNIEXPORT void JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSBundleInfo_nativeSetPath
+(JNIEnv *env, jobject jObject, jstring path);
+
+/**
+* API for setting the Activator name for the bundle
+*
+* @param activator - Activator name in string form
+*
+*/
+JNIEXPORT void JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSBundleInfo_nativeSetActivatorName
+(JNIEnv *env, jobject jObject, jstring activatorname);
+
+/**
+* API for setting the library path for the bundle
+*
+* @param libpath - Library path in string form
+*
+*/
+JNIEXPORT void JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSBundleInfo_nativeSetLibraryPath
+(JNIEnv *env, jobject jObject, jstring libraryPath);
+
+/**
+* API for setting the version of the bundle
+*
+* @param version - version of the bundle in string form
+*
+*/
+JNIEXPORT void JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSBundleInfo_nativeSetVersion
+(JNIEnv *env, jobject jObject, jstring version);
+
+#ifdef __cplusplus
+}
+#endif
+#endif //__JNI_RE_RCS_BUNDLE_INFO_H_
+
diff --git a/service/resource-encapsulation/sdk/java/jni/re/include/jni_re_rcs_resource_container.h b/service/resource-encapsulation/sdk/java/jni/re/include/jni_re_rcs_resource_container.h
new file mode 100644 (file)
index 0000000..3a7e138
--- /dev/null
@@ -0,0 +1,149 @@
+/******************************************************************
+ *
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+
+/** @file   jni_re_rcs_resource_container.h
+ *
+ *   @brief  This file contains the declaration of RCSResourceContainer
+ *    APIs for JNI implementation
+ */
+
+#ifndef __JNI_RE_RCS_RESOURCE_CONTAINER_H_
+#define __JNI_RE_RCS_RESOURCE_CONTAINER_H_
+
+#include <jni.h>
+
+#include "jni_re_jvm.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * API for starting the Container
+ *
+ * @details This API start the container with the provided Configuration file.
+ *
+ * @param configFile - configuration File that contains the Bundle/Bundles information.
+ *
+ */
+JNIEXPORT void JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSResourceContainer_nativeStartContainer
+(JNIEnv *env, jobject jObject, jstring configFile);
+
+
+/**
+* API for stopping the Container
+*/
+JNIEXPORT void JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSResourceContainer_nativeStopContainer
+(JNIEnv *env, jobject jObject);
+
+/**
+ * API for adding the bundle to the Container
+ *
+ * @param bundleId - Id of the Bundle
+ * @param bundleUri - Uri of the bundle
+ * @param bundlePath - Path of the bundle
+ * @param params  - key-value pairs in string form for other Bundle parameters
+ *
+ */
+JNIEXPORT void JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSResourceContainer_nativeAddBundle
+(JNIEnv *env, jobject jObject, jstring bundleId, jstring bundleUri, jstring bundlePath,
+ jobject params);
+
+
+/**
+* API for getting the list of all bundles in the container
+*
+* @return jobject -List of BundleInfo pointer each associated with a bundle
+*
+*/
+JNIEXPORT jobject JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSResourceContainer_nativeListBundles
+(JNIEnv *env, jobject jObject);
+
+/**
+ * API for removing the bundle from the container
+ *
+ * @param bundleId - Id of the Bundle
+ *
+ */
+JNIEXPORT void JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSResourceContainer_nativeRemoveBundle
+(JNIEnv *env, jobject jObject, jstring bundleId);
+
+/**
+ * API for starting the bundle.
+ *
+ * @param bundleId - Id of the Bundle
+ *
+ */
+JNIEXPORT void JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSResourceContainer_nativeStartBundle
+(JNIEnv *env, jobject jObject, jstring bundleId);
+
+/**
+* API for Stopping the bundle
+*
+* @param bundleId - Id of the Bundle
+*
+*/
+JNIEXPORT void JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSResourceContainer_nativeStopBundle
+(JNIEnv *env, jobject jObject, jstring bundleId);
+
+/**
+* API for adding the Resource configuration information to the bundle
+*
+* @param bundleId - Id of the Bundle
+* @param resourceUri - URI of the resource
+* @param params  - key-value pairs in string form for other Bundle parameters
+*
+*/
+JNIEXPORT void JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSResourceContainer_nativeAddResourceConfig
+(JNIEnv *env, jobject jObject, jstring bundleId, jstring resourceUri, jobject params);
+
+/**
+* API for removing the Resource configuration information from the bundle
+*
+* @param bundleId - Id of the Bundle
+* @param resourceUri - URI of the resource
+*
+*/
+JNIEXPORT void JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSResourceContainer_nativeRemoveResourceConfig
+(JNIEnv *env, jobject jObject, jstring bundleId, jstring resourceUri);
+
+/**
+* API for getting the list of Bundle Resources
+*
+* @param bundleId - Id of the Bundle
+*
+*/
+JNIEXPORT jobject JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSResourceContainer_nativeListBundleResources
+(JNIEnv *env, jobject jObject, jstring bundleId);
+
+#ifdef __cplusplus
+}
+#endif
+#endif //__JNI_RE_RCS_RESOURCE_CONTAINER_H_
diff --git a/service/resource-encapsulation/sdk/java/jni/re/src/jni_re_rcs_bundle_info.cpp b/service/resource-encapsulation/sdk/java/jni/re/src/jni_re_rcs_bundle_info.cpp
new file mode 100644 (file)
index 0000000..873058e
--- /dev/null
@@ -0,0 +1,140 @@
+/******************************************************************
+ *
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+
+#include "jni_re_rcs_bundle_info.h"
+#include "jni_re_jvm.h"
+#include "jni_re_utils.h"
+
+using namespace OIC::Service;
+
+RCSBundleInfo *JniBundleInfo::getRCSBundleInfoPtr(JNIEnv *env, jobject interfaceObject)
+{
+    RCSBundleInfo *rep = REGetHandle<RCSBundleInfo>(env, interfaceObject);
+    if (env->ExceptionCheck())
+    {
+        LOGE("Failed to get native handle from RCSBundleInfo");
+    }
+    if (!rep)
+    {
+        throwRCSException(env, "JNI no native pointer");
+    }
+    return rep;
+}
+
+JNIEXPORT jstring JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSBundleInfo_nativeGetID
+(JNIEnv *env, jobject jObject)
+{
+    LOGI("RCSBundleInfo_nativeGetID");
+    RCSBundleInfo *bundleInfo = JniBundleInfo::getRCSBundleInfoPtr(env, jObject);
+    std::string nativeId = bundleInfo->getID();
+    return env->NewStringUTF(nativeId.c_str());
+}
+
+JNIEXPORT jstring JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSBundleInfo_nativeGetPath
+(JNIEnv *env, jobject jObject)
+{
+    LOGI("RCSBundleInfo_nativeGetPath");
+    RCSBundleInfo *bundleInfo = JniBundleInfo::getRCSBundleInfoPtr(env, jObject);
+    std::string nativePath = bundleInfo->getPath();
+    return env->NewStringUTF(nativePath.c_str());
+}
+
+JNIEXPORT jstring JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSBundleInfo_nativeGetActivatorName
+(JNIEnv *env, jobject jObject)
+{
+    LOGI("RCSBundleInfo_nativeGetActivatorName");
+    RCSBundleInfo *bundleInfo = JniBundleInfo::getRCSBundleInfoPtr(env, jObject);
+    std::string nativeActivatorName = bundleInfo->getActivatorName();
+    return env->NewStringUTF(nativeActivatorName.c_str());
+}
+
+JNIEXPORT jstring JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSBundleInfo_nativeGetLibraryPath
+(JNIEnv *env, jobject jObject)
+{
+    LOGI("RCSBundleInfo_nativeGetLibraryPath");
+    RCSBundleInfo *bundleInfo = JniBundleInfo::getRCSBundleInfoPtr(env, jObject);
+    std::string nativeGetLibraryPath = bundleInfo->getLibraryPath();
+    return env->NewStringUTF(nativeGetLibraryPath.c_str());
+}
+
+JNIEXPORT jstring JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSBundleInfo_nativeGetVersion
+(JNIEnv *env, jobject jObject)
+{
+    LOGI("RCSBundleInfo_nativeGetVersion");
+    RCSBundleInfo *bundleInfo = JniBundleInfo::getRCSBundleInfoPtr(env, jObject);
+    std::string nativeGetVersion = bundleInfo->getVersion();
+    return env->NewStringUTF(nativeGetVersion.c_str());
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSBundleInfo_nativeSetID
+(JNIEnv *env, jobject jObject, jstring jId)
+{
+    LOGI("RCSBundleInfo_nativeSetID");
+    std::string id = env->GetStringUTFChars(jId, NULL);
+    RCSBundleInfo *bundleInfo = JniBundleInfo::getRCSBundleInfoPtr(env, jObject);
+    bundleInfo->setID(id);
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSBundleInfo_nativeSetPath
+(JNIEnv *env, jobject jObject, jstring jPath)
+{
+    LOGI("RCSBundleInfo_nativeSetPath");
+    std::string path = env->GetStringUTFChars(jPath, NULL);
+    RCSBundleInfo *bundleInfo = JniBundleInfo::getRCSBundleInfoPtr(env, jObject);
+    bundleInfo->setPath(path);
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSBundleInfo_nativeSetActivatorName
+(JNIEnv *env, jobject jObject, jstring jActivatorName)
+{
+    LOGI("RCSBundleInfo_nativeSetActivatorName");
+    std::string activatorName = env->GetStringUTFChars(jActivatorName, NULL);
+    RCSBundleInfo *bundleInfo = JniBundleInfo::getRCSBundleInfoPtr(env, jObject);
+    bundleInfo->setActivatorName(activatorName);
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSBundleInfo_nativeSetLibraryPath
+(JNIEnv *env, jobject jObject, jstring jLibraryPath)
+{
+    LOGI("RCSBundleInfo_nativeSetLibraryPath");
+    std::string libraryPath = env->GetStringUTFChars(jLibraryPath, NULL);
+    RCSBundleInfo *bundleInfo = JniBundleInfo::getRCSBundleInfoPtr(env, jObject);
+    bundleInfo->setLibraryPath(libraryPath);
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSBundleInfo_nativeSetVersion
+(JNIEnv *env, jobject jObject, jstring jVersion)
+{
+    LOGI("RCSBundleInfo_nativeSetVersion");
+    std::string version = env->GetStringUTFChars(jVersion, NULL);
+    RCSBundleInfo *bundleInfo = JniBundleInfo::getRCSBundleInfoPtr(env, jObject);
+    bundleInfo->setVersion(version);
+}
+
index 56cf292..441ac3d 100644 (file)
@@ -107,20 +107,28 @@ int JniRCSRemoteResourceObject::getCacheState()
 
 void JniRCSRemoteResourceObject::startMonitoring(JNIEnv *env, jobject jListener)
 {
-    JniResourceStateChangeListener *onResourceStateChanged = addOnStateChangeListener(env, jListener);
-    RCSRemoteResourceObject::StateChangedCallback stateChangecb = [onResourceStateChanged](
-                OIC::Service::ResourceState state)
-    {
-        onResourceStateChanged->stateChangeCallback(state);
-    };
+
     try
     {
+        JniResourceStateChangeListener *onResourceStateChanged = addOnStateChangeListener(env, jListener);
+        RCSRemoteResourceObject::StateChangedCallback stateChangecb = [onResourceStateChanged](
+                    OIC::Service::ResourceState state)
+        {
+            onResourceStateChanged->stateChangeCallback(state);
+        };
         m_sharedResource->startMonitoring(stateChangecb);
     }
+    catch (InvalidParameterException exception)
+    {
+        LOGE("native startMonitoring InvalidParameterException");
+        throwRCSException(env,  exception.what());
+    }
     catch (BadRequestException exception)
     {
+        LOGE("native startMonitoring : BadRequestException ");
         throwRCSException(env,  exception.what());
     }
+
 }
 
 void  JniRCSRemoteResourceObject::stopMonitoring()
@@ -331,6 +339,13 @@ JNIEXPORT void JNICALL
 Java_org_iotivity_ResourceEncapsulation_client_RCSRemoteResourceObject_nativeStartMonitoring
 (JNIEnv *env, jobject interfaceClass, jobject jStateChangedListener)
 {
+
+    if (!jStateChangedListener)
+    {
+        LOGE("RCSRemoteResourceObject_nativeStartMonitoring : listener is NULL");
+        throwRCSException(env,  "Invalid parameter");
+        return;
+    }
     LOGD("RCSRemoteResourceObject_nativeStartMonitoring");
     JniRCSRemoteResourceObject *resource = JniRCSRemoteResourceObject::getJniRCSRemoteResourceObject(
             env, interfaceClass);
@@ -404,7 +419,7 @@ Java_org_iotivity_ResourceEncapsulation_client_RCSRemoteResourceObject_nativeIsC
     LOGD("RCSRemoteResourceObject_nativeIsMonitoring");
     JniRCSRemoteResourceObject *resource = JniRCSRemoteResourceObject::getJniRCSRemoteResourceObject(
             env, interfaceClass);
-    return (jboolean)resource->isMonitoring();
+    return (jboolean)resource->isCachedAvailable();
 }
 
 JNIEXPORT jobject JNICALL
@@ -421,10 +436,16 @@ JNIEXPORT jstring JNICALL
 Java_org_iotivity_ResourceEncapsulation_client_RCSRemoteResourceObject_nativeGetCachedAttribute
 (JNIEnv *env, jobject interfaceClass, jstring jKey)
 {
+    if (!jKey)
+    {
+        LOGE("RCSRemoteResourceObject_nativeGetCachedAttributes : key is NULL");
+        throwRCSException(env,  "Key is empty");
+        return NULL;
+    }
     LOGD("RCSRemoteResourceObject_nativeGetRemoteAttributes");
     JniRCSRemoteResourceObject *resource = JniRCSRemoteResourceObject::getJniRCSRemoteResourceObject(
             env, interfaceClass);
-    resource->getCachedAttribute(env, jKey, interfaceClass);
+    return resource->getCachedAttribute(env, jKey, interfaceClass);
 }
 
 JNIEXPORT void JNICALL
diff --git a/service/resource-encapsulation/sdk/java/jni/re/src/jni_re_rcs_resource_container.cpp b/service/resource-encapsulation/sdk/java/jni/re/src/jni_re_rcs_resource_container.cpp
new file mode 100644 (file)
index 0000000..ce739f8
--- /dev/null
@@ -0,0 +1,175 @@
+/******************************************************************
+ *
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+
+#include "jni_re_rcs_resource_container.h"
+#include "jni_re_utils.h"
+#include "RCSResourceContainer.h"
+#include "RCSBundleInfo.h"
+
+using namespace OIC::Service;
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSResourceContainer_nativeStartContainer
+(JNIEnv *env, jobject jObject, jstring configFile)
+{
+    LOGD("RCSResourceContainer_nativeStartContainer");
+    RCSResourceContainer *container = RCSResourceContainer::getInstance();
+    std::string nativeFilePath = env->GetStringUTFChars(configFile, NULL);
+    container->startContainer(nativeFilePath);
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSResourceContainer_nativeStopContainer
+(JNIEnv *env, jobject jObject)
+{
+    LOGD("RCSResourceContainer_nativeStopContainers");
+    RCSResourceContainer *container = RCSResourceContainer::getInstance();
+    container->stopContainer();
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSResourceContainer_nativeAddBundle
+(JNIEnv *env, jobject jObject, jstring jBundleId, jstring jBundleUri, jstring jBundlePath,
+ jobject jParams)
+{
+    LOGD("RCSResourceContainer_nativeAddBundle");
+    std::string bundleId = env->GetStringUTFChars(jBundleId, NULL);
+    std::string bundleUri = env->GetStringUTFChars(jBundleUri, NULL);
+    std::string bundlePath = env->GetStringUTFChars(jBundlePath, NULL);
+
+    std::map<std::string, std::string> params;
+    //convert java map to native param map
+    convertJavaMapToParamsMap(env, jParams, params);
+
+    RCSResourceContainer *container = RCSResourceContainer::getInstance();
+    container->addBundle(bundleId, bundleUri, bundlePath, params);
+}
+
+JNIEXPORT jobject JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSResourceContainer_nativeListBundles
+(JNIEnv *env, jobject jObject)
+{
+    LOGD("RCSResourceContainer_nativeListBundles");
+
+    RCSResourceContainer *container = RCSResourceContainer::getInstance();
+    std::list<RCSBundleInfo *> nativeBundleInfoList = container->listBundles();
+
+    if (nativeBundleInfoList.size() == 0)
+    {
+        LOGD("RCSResourceContainer_nativeListBundles size of bundle list is zerooooo");
+    }
+    else
+    {
+        LOGD("RCSResourceContainer_nativeListBundles size of bundle list is not zerooooo");
+    }
+    //conversion from native list bundle to java list bundle...
+    jobject jList = env->NewObject(g_cls_LinkedList, g_mid_LinkedList_ctor);
+    if (!jList) return nullptr;
+
+    std::list<RCSBundleInfo *>::iterator bundleIt;
+
+    for (bundleIt = nativeBundleInfoList.begin(); bundleIt != nativeBundleInfoList.end(); bundleIt++)
+    {
+        jlong handle = reinterpret_cast<jlong>(*bundleIt);
+
+        //set native handle
+        jclass clazz = env->FindClass("org/iotivity/ResourceEncapsulation/server/RCSBundleInfo");
+        jfieldID fid =  env->GetFieldID(clazz, "m_nativeHandle", "J");
+
+        //create java RCSBundleInfo Object
+        jobject resourceObj = (jobject) env->NewObject(g_cls_RCSBundleInfo, g_mid_RCSBundleInfo_ctor,
+                              handle);
+
+        env->CallBooleanMethod(jList, g_mid_LinkedList_add_object, resourceObj);
+
+        if (env->ExceptionCheck()) return nullptr;
+        env->DeleteLocalRef(resourceObj);
+    }
+    return jList ;
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSResourceContainer_nativeRemoveBundle
+(JNIEnv *env, jobject jObject, jstring jBundleId)
+{
+    LOGD("RCSResourceContainer_nativeRemoveBundle");
+    std::string bundleId = env->GetStringUTFChars(jBundleId, NULL);
+    RCSResourceContainer *container = RCSResourceContainer::getInstance();
+    container->removeBundle(bundleId);
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSResourceContainer_nativeStartBundle
+(JNIEnv *env, jobject jObject, jstring jBundleId)
+{
+    LOGD("RCSResourceContainer_nativeStartBundle");
+    std::string bundleId = env->GetStringUTFChars(jBundleId, NULL);
+    RCSResourceContainer *container = RCSResourceContainer::getInstance();
+    container->startBundle(bundleId);
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSResourceContainer_nativeStopBundle
+(JNIEnv *env, jobject jObject, jstring jBundleId)
+{
+    LOGD("RCSResourceContainer_nativeStopBundle");
+    std::string bundleId = env->GetStringUTFChars(jBundleId, NULL);
+    RCSResourceContainer *container = RCSResourceContainer::getInstance();
+    container->stopBundle(bundleId);
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSResourceContainer_nativeAddResourceConfig
+(JNIEnv *env, jobject jObject, jstring jBundleId, jstring jResourceUri, jobject jParams)
+{
+    LOGD("RCSResourceContainer_nativeAddResourceConfig");
+    std::string bundleId = env->GetStringUTFChars(jBundleId, NULL);
+    std::string resourceUri = env->GetStringUTFChars(jResourceUri, NULL);
+
+    std::map<std::string, std::string> params;
+    //convert java map to native param map
+    convertJavaMapToParamsMap(env, jParams, params);
+
+    RCSResourceContainer *container = RCSResourceContainer::getInstance();
+    container->addResourceConfig(bundleId, resourceUri, params);
+}
+
+JNIEXPORT void JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSResourceContainer_nativeRemoveResourceConfig
+(JNIEnv *env, jobject jObject, jstring jBundleId, jstring jResourceUri)
+{
+    LOGD("RCSResourceContainer_nativeRemoveResourceConfig");
+    std::string bundleId = env->GetStringUTFChars(jBundleId, NULL);
+    std::string resourceUri = env->GetStringUTFChars(jResourceUri, NULL);
+    RCSResourceContainer *container = RCSResourceContainer::getInstance();
+    container->removeResourceConfig(bundleId, resourceUri);
+}
+
+JNIEXPORT jobject JNICALL
+Java_org_iotivity_ResourceEncapsulation_server_RCSResourceContainer_nativeListBundleResources
+(JNIEnv *env, jobject jObject, jstring jBundleId)
+{
+    LOGD("RCSResourceContainer_nativeListBundleResources");
+    std::string bundleId = env->GetStringUTFChars(jBundleId, NULL);
+    RCSResourceContainer *container = RCSResourceContainer::getInstance();
+    std::list<std::string> nativeList = container->listBundleResources(bundleId);
+    return convertStrListToJavaStrList(env, nativeList);
+}
+
index db9149e..f4b6e95 100644 (file)
@@ -156,7 +156,7 @@ Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetVa
 }
 
 JNIEXPORT void JNICALL
-Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueStringN
+Java_org_iotivity_ResourceEncapsulation_common_RCSResourceAttributes_nativeSetValueString
 (JNIEnv *env, jobject interfaceObject, jstring jKey, jstring jValue)
 {
     LOGD("RCSResourceAttributes_setValueStringN");
index 84243d7..c9e386c 100644 (file)
@@ -58,12 +58,22 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_ResourceEncapsulation_server_Builder
             NativeRCSResourceObject = RCSResourceObject::Builder(resourceURI, resourceType,
                                       resourceInterface).setDiscoverable((bool)jObservableFlag).setObservable((
                                                   bool)jObservableFlag).setAttributes(*attributesObj).build();
+
+            jobject jResource = env->NewObject(g_cls_RCSResourceObject, g_mid_RCSResourceObject_ctor);
+            JniRCSResourceObject *jniRCSResourceObject = new JniRCSResourceObject(NativeRCSResourceObject);
+            RESetHandle<JniRCSResourceObject>(env, jResource, jniRCSResourceObject);
+            return jResource;
         }
         else
         {
             NativeRCSResourceObject = RCSResourceObject::Builder(resourceURI, resourceType,
                                       resourceInterface).setDiscoverable((bool)jObservableFlag).setObservable((
                                                   bool)jObservableFlag).build();
+
+            jobject jResource = env->NewObject(g_cls_RCSResourceObject, g_mid_RCSResourceObject_ctor);
+            JniRCSResourceObject *jniRCSResourceObject = new JniRCSResourceObject(NativeRCSResourceObject);
+            RESetHandle<JniRCSResourceObject>(env, jResource, jniRCSResourceObject);
+            return jResource;
         }
     }
     catch (OIC::Service::PlatformException exception)
@@ -71,11 +81,9 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_ResourceEncapsulation_server_Builder
         LOGE("nativeBuild : platform Exception");
         throwRCSException(env,  exception.what());
     }
-
-    jobject jResource = env->NewObject(g_cls_RCSResourceObject, g_mid_RCSResourceObject_ctor);
-    JniRCSResourceObject *jniRCSResourceObject = new JniRCSResourceObject(NativeRCSResourceObject);
-    RESetHandle<JniRCSResourceObject>(env, jResource, jniRCSResourceObject);
-
-    return jResource;
-
+    catch (OIC::Service::RCSException exception)
+    {
+        LOGE("nativeBuild : RCSException");
+        throwRCSException(env,  exception.what());
+    }
 }
index d944a7f..aa1deb7 100644 (file)
@@ -51,6 +51,7 @@ public class RCSAddress {
         System.loadLibrary("rcs_common");
         System.loadLibrary("rcs_client");
         System.loadLibrary("rcs_server");
+        System.loadLibrary("rcs_container");
         System.loadLibrary("re-jni");
     }
 
index 6f2de55..e174152 100644 (file)
@@ -48,6 +48,7 @@ public class Builder {
         System.loadLibrary("rcs_common");
         System.loadLibrary("rcs_client");
         System.loadLibrary("rcs_server");
+        System.loadLibrary("rcs_container");
         System.loadLibrary("re-jni");
     }
 
diff --git a/service/resource-encapsulation/sdk/java/src/org/iotivity/ResourceEncapsulation/server/RCSBundleInfo.java b/service/resource-encapsulation/sdk/java/src/org/iotivity/ResourceEncapsulation/server/RCSBundleInfo.java
new file mode 100644 (file)
index 0000000..ab966fe
--- /dev/null
@@ -0,0 +1,166 @@
+/******************************************************************
+ *
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+/**
+ * @file    RCSBundleInfo.java
+ *
+ *  This file contains RCSBundleInfo class, which provides APIs related to Bundle information.
+ *
+ */
+
+package org.iotivity.ResourceEncapsulation.server;
+
+/**
+ * This class provides APIs for getting and setting the Bundle Information
+ */
+public class RCSBundleInfo {
+
+    private long    m_nativeHandle;
+    private boolean m_nativeNeedsDelete;
+
+    // native methods
+    private native String nativeGetID();
+
+    private native String nativeGetPath();
+
+    private native String nativeGetActivatorName();
+
+    private native String nativeGetLibraryPath();
+
+    private native String nativeGetVersion();
+
+    private native void nativeSetID(String id);
+
+    private native void nativeSetPath(String path);
+
+    private native void nativeSetActivatorName(String activatorName);
+
+    private native void nativeSetLibraryPath(String libraryPath);
+
+    private native void nativeSetVersion(String version);
+
+    private RCSBundleInfo(long nativeHandle) {
+        this.m_nativeHandle = nativeHandle;
+    }
+
+    /**
+     * API for getting the Id of the bundle
+     *
+     * @return string - Id of the bundle
+     *
+     */
+    public String getID() {
+        return this.nativeGetID();
+    }
+
+    /**
+     * API for getting the path of the bundle
+     *
+     * @return path - path of the bundle
+     *
+     */
+    public String getPath() {
+        return this.nativeGetPath();
+    }
+
+    /**
+     * API for setting the Activator name for the bundle
+     *
+     * @return string - Name of the activator
+     *
+     */
+    public String getActivatorName() {
+        return nativeGetActivatorName();
+    }
+
+    /**
+     * API for getting the library path for the bundle
+     *
+     * @return string - Library path in string form
+     *
+     */
+    public String getLibraryPath() {
+        return nativeGetLibraryPath();
+    }
+
+    /**
+     * API for getting the version of the bundle
+     *
+     * @return string - version of the bundle
+     *
+     */
+    public String getVersion() {
+        return nativeGetVersion();
+    }
+
+    /**
+     * API for setting the Id of the bundle
+     *
+     * @param id
+     *            - Id of the bundle in string form
+     *
+     */
+    public void setID(String id) {
+        this.nativeSetID(id);
+    }
+
+    /**
+     * API for setting the path of the bundle
+     *
+     * @param path
+     *            - path of the bundle in string form
+     *
+     */
+    public void setPath(String path) {
+        this.nativeSetPath(path);
+    }
+
+    /**
+     * API for setting the Activator name for the bundle
+     *
+     * @param activator
+     *            - Activator name in string form
+     *
+     */
+    public void setActivatorName(String activatorName) {
+        this.nativeSetActivatorName(activatorName);
+    }
+
+    /**
+     * API for setting the library path for the bundle
+     *
+     * @param libpath
+     *            - Library path in string form
+     *
+     */
+    public void setLibraryPath(String libraryPath) {
+        this.nativeSetLibraryPath(libraryPath);
+    }
+
+    /**
+     * API for setting the version of the bundle
+     *
+     * @param version
+     *            - version of the bundle in string form
+     *
+     */
+    public void setVersion(String version) {
+        this.nativeSetVersion(version);
+    }
+}
diff --git a/service/resource-encapsulation/sdk/java/src/org/iotivity/ResourceEncapsulation/server/RCSResourceContainer.java b/service/resource-encapsulation/sdk/java/src/org/iotivity/ResourceEncapsulation/server/RCSResourceContainer.java
new file mode 100644 (file)
index 0000000..a8c674a
--- /dev/null
@@ -0,0 +1,221 @@
+/******************************************************************
+ *
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+/**
+ * @file    RCSResourceContainer.java
+ *
+ *    This file contains the Resource Container APIs
+ *
+ */
+
+package org.iotivity.ResourceEncapsulation.server;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * This class provides APIs for managing the container and bundles in the
+ * container.
+ */
+public class RCSResourceContainer {
+
+    static {
+        System.loadLibrary("gnustl_shared");
+        System.loadLibrary("oc_logger");
+        System.loadLibrary("oc_logger_core");
+        System.loadLibrary("connectivity_abstraction");
+        System.loadLibrary("ca-interface");
+        System.loadLibrary("octbstack");
+        System.loadLibrary("oc");
+        System.loadLibrary("ocstack-jni");
+        System.loadLibrary("rcs_client");
+        System.loadLibrary("rcs_server");
+        System.loadLibrary("rcs_common");
+        System.loadLibrary("rcs_container");
+        System.loadLibrary("re-jni");
+    }
+
+    private static RCSResourceContainer rcsResourceContainerInstance;
+
+    // native methods
+    private native void nativeStartContainer(String configFile);
+
+    private native void nativeStopContainer();
+
+    private native void nativeAddBundle(String bundleId, String bundleUri,
+            String bundlePath, Map<String, String> params);
+
+    private native void nativeRemoveBundle(String bundleId);
+
+    private native List<RCSBundleInfo> nativeListBundles();
+
+    private native void nativeStartBundle(String bundleId);
+
+    private native void nativeStopBundle(String bundleId);
+
+    private native void nativeAddResourceConfig(String bundleId,
+            String resourceUri, Map<String, String> params);
+
+    private native void nativeRemoveResourceConfig(String bundleId,
+            String resourceUri);
+
+    private native List<String> nativeListBundleResources(String bundleId);
+
+    /**
+     * API for getting the Instance of ResourceContainer class
+     *
+     * @return RCSResourceContainer - Instance of the "RCSResourceContainer"
+     *         class
+     *
+     */
+    public static RCSResourceContainer getInstance() {
+        if (null == rcsResourceContainerInstance) {
+            rcsResourceContainerInstance = new RCSResourceContainer();
+        }
+        return rcsResourceContainerInstance;
+    }
+
+    /**
+     * API for starting the Container
+     *
+     * <p>
+     * This API start the container with the provided Configuration file.
+     *
+     * @param configFile
+     *            - configuration File that contains the Bundle/Bundles
+     *            information.
+     *
+     */
+    public void startContainer(String configFile) {
+        this.nativeStartContainer(configFile);
+    }
+
+    /**
+     * API for stopping the Container
+     */
+    public void stopContainer() {
+        this.nativeStopContainer();
+    }
+
+    /**
+     * API for getting the list of all bundles in the container
+     *
+     * @return list<RCSBundleInfo> -List of BundleInfo objects each associated
+     *         with a bundle
+     *
+     *         {@link RCSBundleInfo}
+     */
+    public List<RCSBundleInfo> listBundles() {
+        return this.nativeListBundles();
+    }
+
+    /**
+     * API for adding the bundle to the Container
+     *
+     * @param bundleId
+     *            - Id of the Bundle
+     * @param bundleUri
+     *            - Uri of the bundle
+     * @param bundlePath
+     *            - Path of the bundle
+     * @param params
+     *            - key-value pairs in string form for other Bundle parameters
+     *
+     *            <p>
+     *            It is dynamic configuration
+     */
+    public void addBundle(String bundleId, String bundleUri, String bundlePath,
+            Map<String, String> params) {
+        this.nativeAddBundle(bundleId, bundleUri, bundlePath, params);
+    }
+
+    /**
+     * API for removing the bundle from the container
+     *
+     * @param bundleId
+     *            - Id of the Bundle
+     *
+     */
+    public void removeBundle(String bundleId) {
+        this.nativeRemoveBundle(bundleId);
+    }
+
+    /**
+     * API for starting the bundle.
+     *
+     * @param bundleId
+     *            - Id of the Bundle
+     *
+     */
+    public void startBundle(String bundleId) {
+        this.nativeStartBundle(bundleId);
+    }
+
+    /**
+     * API for Stopping the bundle
+     *
+     * @param bundleId
+     *            - Id of the Bundle
+     *
+     */
+    public void stopBundle(String bundleId) {
+        this.nativeStopBundle(bundleId);
+    }
+
+    /**
+     * API for adding the Resource configuration information to the bundle
+     *
+     * @param bundleId
+     *            - Id of the Bundle
+     * @param resourceUri
+     *            - URI of the resource
+     * @param params
+     *            - key-value pairs in string form for other Bundle parameters
+     *
+     */
+    public void addResourceConfig(String bundleId, String resourceUri,
+            Map<String, String> params) {
+        this.nativeAddResourceConfig(bundleId, resourceUri, params);
+    }
+
+    /**
+     * API for removing the Resource configuration information from the bundle
+     *
+     * @param bundleId
+     *            - Id of the Bundle
+     * @param resourceUri
+     *            - URI of the resource
+     *
+     */
+    public void removeResourceConfig(String bundleId, String resourceUri) {
+        this.nativeRemoveResourceConfig(bundleId, resourceUri);
+    }
+
+    /**
+     * API for getting the list of Bundle Resources
+     *
+     * @param bundleId
+     *            - Id of the Bundle
+     *
+     * @return List<String> All the bundle resources
+     */
+    public List<String> listBundleResources(String bundleId) {
+        return this.nativeListBundleResources(bundleId);
+    }
+}