Updating JNI modules of service provider
authorG S Senthil Kumar <senthil.gs@samsung.com>
Fri, 7 Aug 2015 15:04:30 +0000 (20:34 +0530)
committerMadan Lanka <lanka.madan@samsung.com>
Tue, 11 Aug 2015 10:54:39 +0000 (10:54 +0000)
It has the following changes:
    1. Implementation of resource model change callback.
    2. Handled multi-resource creation.
    3. Updated the jni method names to comply with their corresponding
       java package.
    4. Renamed simulator_resource_jni.h/.cpp to
       simulator_resource_server_jni.h/.cpp

Change-Id: I3b25116b2506bb095d1248711e442c20f7791a07
Signed-off-by: G S Senthil Kumar <senthil.gs@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2137
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
service/simulator/java/jni/simulator_common_jni.h
service/simulator/java/jni/simulator_manager_jni.cpp
service/simulator/java/jni/simulator_manager_jni.h
service/simulator/java/jni/simulator_resource_attributes_jni.cpp
service/simulator/java/jni/simulator_resource_attributes_jni.h
service/simulator/java/jni/simulator_resource_jni_util.cpp
service/simulator/java/jni/simulator_resource_model_jni.cpp
service/simulator/java/jni/simulator_resource_model_jni.h
service/simulator/java/jni/simulator_resource_server_jni.cpp [moved from service/simulator/java/jni/simulator_resource_jni.cpp with 55% similarity]
service/simulator/java/jni/simulator_resource_server_jni.h [moved from service/simulator/java/jni/simulator_resource_jni.h with 51% similarity]

index 10e7c9d..472748c 100644 (file)
@@ -35,6 +35,10 @@ typedef struct
     jclass classSimulatorResourceAttribute;
     jclass classSimulatorRemoteResource;
     jclass classSimulatorCallback;
+    jclass classMap;
+    jclass classMapEntry;
+    jclass classSet;
+    jclass classIterator;
 
     jmethodID classIntegerCtor;
     jmethodID classDoubleCtor;
@@ -49,6 +53,13 @@ typedef struct
     jmethodID classSimulatorResourceSetName;
     jmethodID classSimulatorResourceModelCtor;
     jmethodID classSimulatorResourceAttributeCtor;
+    jmethodID classSimulatorResourceModelId;
+    jmethodID classMapEntrySet;
+    jmethodID classMapGetKey;
+    jmethodID classMapGetValue;
+    jmethodID classIteratorId;
+    jmethodID classHasNextId;
+    jmethodID classNextId;
 } SimulatorClassRefs;
 
 static jfieldID GetHandleField(JNIEnv *env, jobject jobj)
index a7553cb..3cb5573 100644 (file)
  ******************************************************************/
 
 #include "simulator_manager_jni.h"
-#include "simulator_resource_jni.h"
+#include "simulator_resource_server_jni.h"
 #include "simulator_common_jni.h"
 #include "simulator_manager.h"
 #include "simulator_remote_resource_jni.h"
+#include "simulator_resource_model_jni.h"
 
 SimulatorClassRefs gSimulatorClassRefs;
 std::mutex gEnvMutex;
@@ -185,49 +186,142 @@ class JNIFoundResourceListener
         jweak m_listener;
 
 };
+
+void onResourceModelChange(jweak jlistenerRef, const std::string &uri,
+                           const SimulatorResourceModel &resModel)
+{
+    JNIEnv *env = getEnv();
+    if (nullptr == env)
+        return;
+
+    jobject modelChangeListener = env->NewLocalRef(jlistenerRef);
+    if (!modelChangeListener)
+    {
+        releaseEnv();
+        return;
+    }
+
+    jclass modelChangeCls = env->GetObjectClass(modelChangeListener);
+    if (!modelChangeCls)
+    {
+        releaseEnv();
+        return;
+    }
+
+    jmethodID foundModelChangeMId = env->GetMethodID(modelChangeCls, "onResourceModelChanged",
+                                    "(Ljava/lang/String;Lorg/oic/simulator/serviceprovider/SimulatorResourceModel;)V");
+    if (!foundModelChangeMId)
+    {
+        releaseEnv();
+        return;
+    }
+
+    JniSimulatorResourceModel *jniModel = new JniSimulatorResourceModel(resModel);
+    if (!jniModel)
+    {
+        releaseEnv();
+        return;
+    }
+
+    jobject jModel = JniSimulatorResourceModel::toJava(env, reinterpret_cast<jlong>(jniModel));
+
+    jstring jUri = env->NewStringUTF(uri.c_str());
+
+    env->CallVoidMethod(modelChangeListener, foundModelChangeMId, jUri, jModel);
+    if ((env)->ExceptionCheck())
+    {
+        releaseEnv();
+        return;
+    }
+
+    env->DeleteLocalRef(jUri);
+
+    releaseEnv();
+}
+
+
 JNIEXPORT jobject JNICALL
-Java_org_iotivity_simulator_SimulatorManagerNativeInterface_createResource
-(JNIEnv *env, jclass object, jstring jConfigPath)
+Java_org_oic_simulator_SimulatorManagerNativeInterface_createResource
+(JNIEnv *env, jclass object, jstring configPath, jobject listener)
 {
-    if (!jConfigPath)
+    if (!configPath)
         return NULL;
 
-    const char *configPath = env->GetStringUTFChars(jConfigPath, NULL);
-    if (!configPath)
+    if (!listener)
         return NULL;
 
-    std::string config(configPath);
-    std::shared_ptr<SimulatorResource> resource = SimulatorManager::getInstance()->createResource(
-                config, nullptr);
-    if (NULL == resource.get())
+    jweak jlistenerRef = env->NewWeakGlobalRef(listener);
+    SimulatorResourceServer::ResourceModelChangedCB callback =  [jlistenerRef](const std::string & uri,
+            const SimulatorResourceModel & resModel)
+    {
+        onResourceModelChange(jlistenerRef, uri, resModel);
+    };
+
+    const char *configPathCStr = env->GetStringUTFChars(configPath, NULL);
+    SimulatorResourceServerPtr resource = SimulatorManager::getInstance()->createResource(
+            configPathCStr, callback);
+    if (nullptr == resource)
+    {
+        if (configPathCStr)
+            env->ReleaseStringUTFChars(configPath, configPathCStr);
         return NULL;
+    }
 
     JniSimulatorResource *jniSimResource = new JniSimulatorResource(resource);
     jobject jSimulatorResource = JniSimulatorResource::toJava(env,
                                  reinterpret_cast<jlong>(jniSimResource));
 
-    // Setting the uri and resourceType
-    std::string uri = resource->getURI();
-    std::string resourceType = resource->getResourceType();
-    std::string name = resource->getName();
-
-    JniSimulatorResource::setUri(env, jSimulatorResource, uri);
-    JniSimulatorResource::setResourceType(env, jSimulatorResource, resourceType);
-    JniSimulatorResource::setResourceName(env, jSimulatorResource, name);
+    jniSimResource->setResourceInfo(env, jSimulatorResource);
 
+    if (configPathCStr)
+        env->ReleaseStringUTFChars(configPath, configPathCStr);
     return jSimulatorResource;
 }
 
 JNIEXPORT jobjectArray JNICALL
-Java_org_iotivity_simulator_SimulatorManagerNativeInterface_createResources
-(JNIEnv *env, jclass object, jstring jConfigPath, jint count)
+Java_org_oic_simulator_SimulatorManagerNativeInterface_createResources
+(JNIEnv *env, jclass object, jstring configPath, jint count, jobject listener)
 {
-    //TODO: Need to implement this method
-    return nullptr;
+    if (!configPath)
+        return NULL;
+
+    if (!listener)
+        return NULL;
+
+    jweak jlistenerRef = env->NewWeakGlobalRef(listener);
+    SimulatorResourceServer::ResourceModelChangedCB callback =  [jlistenerRef](const std::string & uri,
+            const SimulatorResourceModel & resModel)
+    {
+        onResourceModelChange(jlistenerRef, uri, resModel);
+    };
+
+
+    const char *configPathCStr = env->GetStringUTFChars(configPath, NULL);
+    std::vector<SimulatorResourceServerPtr> resources =
+        SimulatorManager::getInstance()->createResource(configPathCStr, count, callback);
+
+    // Construct the object array and send it java layer
+    jobjectArray resourceArray = env->NewObjectArray(resources.size(),
+                                 gSimulatorClassRefs.classSimulatorResource, NULL);
+    if (resourceArray)
+    {
+        for (size_t i = 0; i < resources.size(); i++)
+        {
+            JniSimulatorResource *jniSimResource = new JniSimulatorResource(resources[i]);
+            jobject jSimulatorResource = JniSimulatorResource::toJava(env,
+                                         reinterpret_cast<jlong>(jniSimResource));
+            jniSimResource->setResourceInfo(env, jSimulatorResource);
+            env->SetObjectArrayElement(resourceArray, i, jSimulatorResource);
+        }
+    }
+
+    if (configPathCStr)
+        env->ReleaseStringUTFChars(configPath, configPathCStr);
+    return resourceArray;
 }
 
 JNIEXPORT jobjectArray JNICALL
-Java_org_iotivity_simulator_SimulatorManagerNativeInterface_getResources
+Java_org_oic_simulator_SimulatorManagerNativeInterface_getResources
 (JNIEnv *env, jclass object)
 {
     //TODO: Need to implement this method
@@ -235,13 +329,13 @@ Java_org_iotivity_simulator_SimulatorManagerNativeInterface_getResources
 }
 
 JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorManagerNativeInterface_deleteResource
+Java_org_oic_simulator_SimulatorManagerNativeInterface_deleteResource
 (JNIEnv *env, jclass object, jobject jResource)
 {
     if (!jResource)
         return;
 
-    std::shared_ptr<SimulatorResource> resource =
+    SimulatorResourceServerPtr resource =
         JniSimulatorResource::getJniSimulatorResourcePtr(env, jResource);
     if (!resource)
         return;
@@ -249,19 +343,21 @@ Java_org_iotivity_simulator_SimulatorManagerNativeInterface_deleteResource
     SimulatorManager::getInstance()->deleteResource(resource);
 }
 
-
 JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorManagerNativeInterface_deleteResources
+Java_org_oic_simulator_SimulatorManagerNativeInterface_deleteResources
 (JNIEnv *env, jclass object, jstring resourceType)
 {
-    if (!resourceType)
-        return;
-
-    const char *type = env->GetStringUTFChars(resourceType, NULL);
-    if (!type)
-        return;
+    std::string type;
+    const char *typeCStr = NULL;
+    if (resourceType)
+    {
+        typeCStr = env->GetStringUTFChars(resourceType, NULL);
+        type = typeCStr;
+    }
 
     SimulatorManager::getInstance()->deleteResources(type);
+    if (typeCStr)
+        env->ReleaseStringUTFChars(resourceType, typeCStr);
 }
 
 JNIEXPORT jint JNICALL
@@ -336,7 +432,7 @@ Java_org_oic_simulator_SimulatorManagerNativeInterface_getFoundResources
 }
 
 JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorManagerNativeInterface_setLogger
+Java_org_oic_simulator_SimulatorManagerNativeInterface_setLogger
 (JNIEnv *env, jclass object, jobject logger)
 {
     static std::shared_ptr<ILogger> target(new JNILogger());
@@ -398,6 +494,26 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
         return JNI_ERR;
     }
 
+    if (false == getClassRef(env, "java/util/Map", gSimulatorClassRefs.classMap))
+    {
+        return JNI_ERR;
+    }
+
+    if (false == getClassRef(env, "java/util/Map$Entry", gSimulatorClassRefs.classMapEntry))
+    {
+        return JNI_ERR;
+    }
+
+    if (false == getClassRef(env, "java/util/Set", gSimulatorClassRefs.classSet))
+    {
+        return JNI_ERR;
+    }
+
+    if (false == getClassRef(env, "java/util/Iterator", gSimulatorClassRefs.classIterator))
+    {
+        return JNI_ERR;
+    }
+
     if (false == getClassRef(env, "org/oic/simulator/serviceprovider/SimulatorResourceServer",
                              gSimulatorClassRefs.classSimulatorResource))
     {
@@ -422,7 +538,6 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
         return JNI_ERR;
     }
 
-
     // Get the reference to methods
     gSimulatorClassRefs.classIntegerCtor = env->GetMethodID(gSimulatorClassRefs.classInteger, "<init>",
                                            "(I)V");
@@ -455,6 +570,36 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
     if (!gSimulatorClassRefs.classVectorAddElement)
         return JNI_ERR;
 
+    gSimulatorClassRefs.classMapEntrySet = env->GetMethodID(
+            gSimulatorClassRefs.classMap, "entrySet", "()Ljava/util/Set;");
+    if (!gSimulatorClassRefs.classMapEntrySet)
+        return JNI_ERR;
+
+    gSimulatorClassRefs.classMapGetKey = env->GetMethodID(
+            gSimulatorClassRefs.classMapEntry, "getKey", "()Ljava/lang/Object;");
+    if (!gSimulatorClassRefs.classMapGetKey)
+        return JNI_ERR;
+
+    gSimulatorClassRefs.classMapGetValue = env->GetMethodID(
+            gSimulatorClassRefs.classMapEntry, "getValue", "()Ljava/lang/Object;");
+    if (!gSimulatorClassRefs.classMapGetValue)
+        return JNI_ERR;
+
+    gSimulatorClassRefs.classIteratorId = env->GetMethodID(
+            gSimulatorClassRefs.classSet, "iterator", "()Ljava/util/Iterator;");
+    if (!gSimulatorClassRefs.classIteratorId)
+        return JNI_ERR;
+
+    gSimulatorClassRefs.classHasNextId = env->GetMethodID(
+            gSimulatorClassRefs.classIterator, "hasNext", "()Z");
+    if (!gSimulatorClassRefs.classHasNextId)
+        return JNI_ERR;
+
+    gSimulatorClassRefs.classNextId = env->GetMethodID(
+                                          gSimulatorClassRefs.classIterator, "next", "()Ljava/lang/Object;");
+    if (!gSimulatorClassRefs.classNextId)
+        return JNI_ERR;
+
     gSimulatorClassRefs.classSimulatorResourceCtor = env->GetMethodID(
                 gSimulatorClassRefs.classSimulatorResource, "<init>", "(J)V");
     if (!gSimulatorClassRefs.classSimulatorResourceCtor)
@@ -490,6 +635,11 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
     if (!gSimulatorClassRefs.classSimulatorResourceAttributeCtor)
         return JNI_ERR;
 
+    gSimulatorClassRefs.classSimulatorResourceModelId = env->GetMethodID(
+                gSimulatorClassRefs.classSimulatorResourceModel, "<init>", "(J)V");
+    if (!gSimulatorClassRefs.classSimulatorResourceModelId)
+        return JNI_ERR;
+
     gvm = vm;
     return JNI_VERSION_1_6;
 }
index 2089536..410aa71 100644 (file)
@@ -28,27 +28,27 @@ extern "C" {
 #endif
 
 JNIEXPORT jobject JNICALL
-Java_org_iotivity_simulator_SimulatorManagerNativeInterface_createResource
-(JNIEnv *env, jclass object, jstring jConfigPath);
+Java_org_oic_simulator_SimulatorManagerNativeInterface_createResource
+(JNIEnv *env, jclass object, jstring jConfigPath, jobject jListener);
 
 JNIEXPORT jobjectArray JNICALL
-Java_org_iotivity_simulator_SimulatorManagerNativeInterface_createResources
-(JNIEnv *env, jclass object, jstring jConfigPath, jint count);
+Java_org_oic_simulator_SimulatorManagerNativeInterface_createResources
+(JNIEnv *env, jclass object, jstring jConfigPath, jint count, jobject jListener);
 
 JNIEXPORT jobjectArray JNICALL
-Java_org_iotivity_simulator_SimulatorManageNativeInterfacer_getResources
+Java_org_oic_simulator_SimulatorManageNativeInterface_getResources
 (JNIEnv *env, jclass object);
 
 JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorManagerNativeInterface_deleteResource
+Java_org_oic_simulator_SimulatorManagerNativeInterface_deleteResource
 (JNIEnv *env, jclass object, jobject jResource);
 
 JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorManagerNativeInterface_deleteResources
+Java_org_oic_simulator_SimulatorManagerNativeInterface_deleteResources
 (JNIEnv *env, jclass object, jstring resourceType);
 
 JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorManagerNativeInterface_setLogger
+Java_org_oic_simulator_SimulatorManagerNativeInterface_setLogger
 (JNIEnv *env, jclass object, jobject logger);
 
 JNIEXPORT jint JNICALL
index c2aafbd..62241de 100644 (file)
@@ -67,7 +67,7 @@ class attribute_value_visitor : public boost::static_visitor<jobject>
 };
 
 JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceAttribute_create
+Java_org_oic_simulator_SimulatorResourceAttribute_create
 (JNIEnv *env, jobject object, jstring attrName)
 {
     if (!attrName)
@@ -92,7 +92,7 @@ Java_org_iotivity_simulator_SimulatorResourceAttribute_create
 }
 
 JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceAttribute_dispose
+Java_org_oic_simulator_SimulatorResourceAttribute_dispose
 (JNIEnv *env, jobject object)
 {
     SimulatorResourceModel::Attribute *attribute = GetHandle<SimulatorResourceModel::Attribute>(env,
@@ -101,7 +101,7 @@ Java_org_iotivity_simulator_SimulatorResourceAttribute_dispose
 }
 
 JNIEXPORT int JNICALL
-Java_org_iotivity_simulator_SimulatorResourceAttribute_allowedValuesSize
+Java_org_oic_simulator_SimulatorResourceAttribute_allowedValuesSize
 (JNIEnv *env, jobject object)
 {
     SimulatorResourceModel::Attribute *attribute = GetHandle<SimulatorResourceModel::Attribute>(env,
@@ -115,7 +115,7 @@ Java_org_iotivity_simulator_SimulatorResourceAttribute_allowedValuesSize
 }
 
 JNIEXPORT jstring JNICALL
-Java_org_iotivity_simulator_SimulatorResourceAttribute_valueToString
+Java_org_oic_simulator_SimulatorResourceAttribute_valueToString
 (JNIEnv *env, jobject object)
 {
     SimulatorResourceModel::Attribute *attribute = GetHandle<SimulatorResourceModel::Attribute>(env,
@@ -130,7 +130,7 @@ Java_org_iotivity_simulator_SimulatorResourceAttribute_valueToString
 }
 
 JNIEXPORT jstring JNICALL
-Java_org_iotivity_simulator_SimulatorResourceAttribute_allowedValuesToString
+Java_org_oic_simulator_SimulatorResourceAttribute_allowedValuesToString
 (JNIEnv *env, jobject object)
 {
     SimulatorResourceModel::Attribute *attribute = GetHandle<SimulatorResourceModel::Attribute>(env,
@@ -145,7 +145,7 @@ Java_org_iotivity_simulator_SimulatorResourceAttribute_allowedValuesToString
 }
 
 JNIEXPORT jstring JNICALL
-Java_org_iotivity_simulator_SimulatorResourceAttribute_getName
+Java_org_oic_simulator_SimulatorResourceAttribute_getName
 (JNIEnv *env, jobject object)
 {
     SimulatorResourceModel::Attribute *attribute = GetHandle<SimulatorResourceModel::Attribute>(env,
@@ -160,7 +160,7 @@ Java_org_iotivity_simulator_SimulatorResourceAttribute_getName
 }
 
 JNIEXPORT jobject JNICALL
-Java_org_iotivity_simulator_SimulatorResourceAttribute_getValue
+Java_org_oic_simulator_SimulatorResourceAttribute_getValue
 (JNIEnv *env, jobject object)
 {
     SimulatorResourceModel::Attribute *attribute = GetHandle<SimulatorResourceModel::Attribute>(env,
index a6afc91..df7d2d5 100644 (file)
@@ -35,31 +35,31 @@ extern "C" {
 #endif
 
 JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceAttribute_create
+Java_org_oic_simulator_SimulatorResourceAttribute_create
 (JNIEnv *, jobject, jstring);
 
 JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceAttribute_dispose
+Java_org_oic_simulator_SimulatorResourceAttribute_dispose
 (JNIEnv *, jobject);
 
 JNIEXPORT int JNICALL
-Java_org_iotivity_simulator_SimulatorResourceAttribute_allowedValuesSize
+Java_org_oic_simulator_SimulatorResourceAttribute_allowedValuesSize
 (JNIEnv *, jobject);
 
 JNIEXPORT jstring JNICALL
-Java_org_iotivity_simulator_SimulatorResourceAttribute_valueToString
+Java_org_oic_simulator_SimulatorResourceAttribute_valueToString
 (JNIEnv *, jobject);
 
 JNIEXPORT jstring JNICALL
-Java_org_iotivity_simulator_SimulatorResourceAttribute_allowedValuesToString
+Java_org_oic_simulator_SimulatorResourceAttribute_allowedValuesToString
 (JNIEnv *, jobject);
 
 JNIEXPORT jstring JNICALL
-Java_org_iotivity_simulator_SimulatorResourceAttribute_getName
+Java_org_oic_simulator_SimulatorResourceAttribute_getName
 (JNIEnv *, jobject);
 
 JNIEXPORT jobject JNICALL
-Java_org_iotivity_simulator_SimulatorResourceAttribute_getValue
+Java_org_oic_simulator_SimulatorResourceAttribute_getValue
 (JNIEnv *, jobject);
 
 #ifdef __cplusplus
index f53e5a0..a93998c 100644 (file)
@@ -35,7 +35,7 @@ std::vector<int> convertIntegerVector(JNIEnv *env, jobject jVectorInt)
         return vectorInt;
     }
 
-    jmethodID get = env->GetMethodID(vectorClass, "get", "(I)I");
+    jmethodID get = env->GetMethodID(vectorClass, "get", "(I)""Ljava/lang/Object;");
     if (NULL == get)
     {
         return vectorInt;
@@ -70,7 +70,7 @@ std::vector<double> convertDoubleVector(JNIEnv *env, jobject jVectorDouble)
         return vectorDouble;
     }
 
-    jmethodID get = env->GetMethodID(vectorClass, "get", "(I)D");
+    jmethodID get = env->GetMethodID(vectorClass, "get", "(I)""Ljava/lang/Object;");
     if (NULL == get)
     {
         return vectorDouble;
index 4280f32..b886d39 100644 (file)
@@ -73,7 +73,7 @@ static void addEntryToHashMap(JNIEnv *env, jobject mapobj, jobject key, jobject
 }
 
 JNIEXPORT jint JNICALL
-Java_org_iotivity_simulator_SimulatorResourceModel_size
+Java_org_oic_simulator_serviceprovider_SimulatorResourceModel_size
 (JNIEnv *env, jobject thiz)
 {
     SimulatorResourceModel resourceModel;
@@ -87,7 +87,7 @@ Java_org_iotivity_simulator_SimulatorResourceModel_size
 }
 
 JNIEXPORT jobject JNICALL
-Java_org_iotivity_simulator_SimulatorResourceModel_getAttributes
+Java_org_oic_simulator_serviceprovider_SimulatorResourceModel_getAttributes
 (JNIEnv *env, jobject thiz)
 {
     SimulatorResourceModel resourceModel;
@@ -126,7 +126,7 @@ Java_org_iotivity_simulator_SimulatorResourceModel_getAttributes
 }
 
 JNIEXPORT jobject JNICALL
-Java_org_iotivity_simulator_SimulatorResourceModel_getAttribute
+Java_org_oic_simulator_serviceprovider_SimulatorResourceModel_getAttribute
 (JNIEnv *env, jobject thiz, jstring jAttrName)
 {
     if (!jAttrName)
@@ -170,7 +170,7 @@ Java_org_iotivity_simulator_SimulatorResourceModel_getAttribute
 }
 
 JNIEXPORT jobjectArray JNICALL
-Java_org_iotivity_simulator_SimulatorResourceModel_getAllowedValues
+Java_org_oic_simulator_serviceprovider_SimulatorResourceModel_getAllowedValues
 (JNIEnv *env, jobject thiz, jstring jAttrName)
 {
     if (!jAttrName)
@@ -225,7 +225,7 @@ Java_org_iotivity_simulator_SimulatorResourceModel_getAllowedValues
 }
 
 JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceModel_dispose
+Java_org_oic_simulator_serviceprovider_SimulatorResourceModel_dispose
 (JNIEnv *env, jobject thiz)
 {
     JniSimulatorResourceModel *resourceModel = GetHandle<JniSimulatorResourceModel>(env, thiz);
index 43202a3..0100076 100644 (file)
@@ -42,23 +42,23 @@ extern "C" {
 #endif
 
 JNIEXPORT jint JNICALL
-Java_org_iotivity_simulator_SimulatorResourceModel_size
+Java_org_oic_simulator_serviceprovider_SimulatorResourceModel_size
 (JNIEnv *, jobject);
 
 JNIEXPORT jobject JNICALL
-Java_org_iotivity_simulator_SimulatorResourceModel_getAttributes
+Java_org_oic_simulator_serviceprovider_SimulatorResourceModel_getAttributes
 (JNIEnv *, jobject);
 
 JNIEXPORT jobject JNICALL
-Java_org_iotivity_simulator_SimulatorResourceModel_getAttribute
+Java_org_oic_simulator_serviceprovider_SimulatorResourceModel_getAttribute
 (JNIEnv *, jobject, jstring);
 
 JNIEXPORT jobjectArray JNICALL
-Java_org_iotivity_simulator_SimulatorResourceModel_getAllowedValues
+Java_org_oic_simulator_serviceprovider_SimulatorResourceModel_getAllowedValues
 (JNIEnv *, jobject, jstring);
 
 JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceModel_dispose
+Java_org_oic_simulator_serviceprovider_SimulatorResourceModel_dispose
 (JNIEnv *, jobject);
 
 
  *
  ******************************************************************/
 
-#include "simulator_resource_jni.h"
+#include "simulator_resource_server_jni.h"
 #include "simulator_resource_jni_util.h"
 #include "simulator_common_jni.h"
 #include "simulator_resource_model_jni.h"
 
 extern SimulatorClassRefs gSimulatorClassRefs;
 
-JniSimulatorResource::JniSimulatorResource(SimulatorResourcePtr &resource)
+JniSimulatorResource::JniSimulatorResource(SimulatorResourceServerPtr &resource)
     : m_sharedResource(resource) {}
 
-SimulatorResourcePtr JniSimulatorResource::getJniSimulatorResourcePtr(JNIEnv *env, jobject thiz)
+SimulatorResourceServerPtr JniSimulatorResource::getJniSimulatorResourcePtr(JNIEnv *env,
+        jobject thiz)
 {
     JniSimulatorResource *resource = GetHandle<JniSimulatorResource>(env, thiz);
     if (env->ExceptionCheck())
@@ -49,51 +50,95 @@ jobject JniSimulatorResource::toJava(JNIEnv *env, jlong resource)
     return resourceObj;
 }
 
-void JniSimulatorResource::setUri(JNIEnv *env, jobject jobj, const std::string &uri)
+void JniSimulatorResource::setResourceInfo(JNIEnv *env, jobject jobj)
 {
     if (!env || !jobj)
         return;
 
+    std::string uri = m_sharedResource->getURI();
+    std::string resourceType = m_sharedResource->getResourceType();
+    std::string name = m_sharedResource->getName();
+    std::string interfaceType = m_sharedResource->getInterfaceType();
+
     jstring jURI = env->NewStringUTF(uri.c_str());
-    if (!jURI)
-        return;
+    if (jURI)
+    {
+        env->CallVoidMethod(jobj, gSimulatorClassRefs.classSimulatorResourceSetURI, jURI);
+        env->DeleteLocalRef(jURI);
+    }
 
-    env->CallVoidMethod(jobj, gSimulatorClassRefs.classSimulatorResourceSetURI, jURI);
-    env->DeleteLocalRef(jURI);
+    jstring jResourceType = env->NewStringUTF(resourceType.c_str());
+    if (jResourceType)
+    {
+        env->CallVoidMethod(jobj, gSimulatorClassRefs.classSimulatorResourceSetResourceType, jResourceType);
+        env->DeleteLocalRef(jResourceType);
+    }
+
+    jstring jName = env->NewStringUTF(name.c_str());
+    if (jName)
+    {
+        env->CallVoidMethod(jobj, gSimulatorClassRefs.classSimulatorResourceSetName, jName);
+        env->DeleteLocalRef(jName);
+    }
+
+    jstring jInterfaceType = env->NewStringUTF(interfaceType.c_str());
+    if (jInterfaceType)
+    {
+        env->CallVoidMethod(jobj, gSimulatorClassRefs.classSimulatorResourceSetInterfaceType,
+                            jInterfaceType);
+        env->DeleteLocalRef(jInterfaceType);
+    }
 }
 
-void JniSimulatorResource::setResourceType(JNIEnv *env, jobject jobj,
-        const std::string &resourceType)
+void onAutomationComplete(jweak jlistenerRef, const std::string &uri,
+                          const int automationID)
 {
-    if (!env || !jobj)
+    std::cout << "onAutomationComplete JNI entry" << std::endl;
+    JNIEnv *env = getEnv();
+    if (nullptr == env)
         return;
 
-    jstring jResourceType = env->NewStringUTF(resourceType.c_str());
-    if (!jResourceType)
+    jobject autoCompleteListener = env->NewLocalRef(jlistenerRef);
+    if (!autoCompleteListener)
+    {
+        releaseEnv();
         return;
+    }
 
-    env->CallVoidMethod(jobj, gSimulatorClassRefs.classSimulatorResourceSetResourceType, jResourceType);
-    env->DeleteLocalRef(jResourceType);
-}
+    jclass autoCompleteCls = env->GetObjectClass(autoCompleteListener);
+    if (!autoCompleteCls)
+    {
+        releaseEnv();
+        return;
+    }
 
-void JniSimulatorResource::setResourceName(JNIEnv *env, jobject jobj, const std::string &name)
-{
-    if (!env || !jobj)
+    jmethodID autoCompleteMId = env->GetMethodID(autoCompleteCls, "onAutomationComplete",
+                                "(Ljava/lang/String;I)V");
+    if (!autoCompleteMId)
+    {
+        releaseEnv();
         return;
+    }
 
-    jstring jName = env->NewStringUTF(name.c_str());
-    if (!jName)
+    jstring jUri = env->NewStringUTF(uri.c_str());
+
+    env->CallVoidMethod(autoCompleteListener, autoCompleteMId, jUri, automationID);
+    if ((env)->ExceptionCheck())
+    {
+        releaseEnv();
         return;
+    }
+
+    env->DeleteLocalRef(jUri);
 
-    env->CallVoidMethod(jobj, gSimulatorClassRefs.classSimulatorResourceSetName, jName);
-    env->DeleteLocalRef(jName);
+    releaseEnv();
 }
 
 JNIEXPORT jobject JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_getModel
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_getModel
 (JNIEnv *env, jobject object)
 {
-    SimulatorResourcePtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, object);
+    SimulatorResourceServerPtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, object);
     if (nullptr == resource.get())
     {
         std::cout << "getModel: Resource is NULL";
@@ -107,10 +152,10 @@ Java_org_iotivity_simulator_SimulatorResourceServer_getModel
 }
 
 JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_updateAttributeFromAllowedValues
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_updateAttributeFromAllowedValues
 (JNIEnv *env, jobject object, jstring attrName, jint index)
 {
-    SimulatorResourcePtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, object);
+    SimulatorResourceServerPtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, object);
     if (nullptr == resource.get())
     {
         std::cout << "updateAttributeFromAllowedValues: Resource is NULL";
@@ -129,10 +174,10 @@ Java_org_iotivity_simulator_SimulatorResourceServer_updateAttributeFromAllowedVa
 }
 
 JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_setRange
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_setRange
 (JNIEnv *env, jobject object, jstring attrName, jint min, jint max)
 {
-    SimulatorResourcePtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, object);
+    SimulatorResourceServerPtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, object);
     if (nullptr == resource.get())
     {
         std::cout << "setRange: Resource is NULL";
@@ -151,7 +196,7 @@ Java_org_iotivity_simulator_SimulatorResourceServer_setRange
 }
 
 JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_setInterfaceType
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_setInterfaceType
 (JNIEnv *env, jobject jobject, const std::string &interfaceType)
 {
     jstring jInterfaceType = env->NewStringUTF(interfaceType.c_str());
@@ -166,7 +211,8 @@ Java_org_iotivity_simulator_SimulatorResourceServer_setInterfaceType
     env->DeleteLocalRef(jInterfaceType);
 }
 
-JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_addAttributeInteger
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_addAttributeInteger
 (JNIEnv *env, jobject jobject, jstring jKey, jint jValue)
 {
     if (!jKey)
@@ -175,7 +221,8 @@ JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_addAt
         return;
     }
 
-    SimulatorResourcePtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, jobject);
+    SimulatorResourceServerPtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env,
+                                          jobject);
     if (nullptr == resource.get())
     {
         std::cout << "addAttributeInteger: Resource is NULL";
@@ -186,7 +233,8 @@ JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_addAt
     resource->addAttribute(str, static_cast<int>(jValue));
 }
 
-JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_addAttributeDouble
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_addAttributeDouble
 (JNIEnv *env, jobject jobject, jstring jKey, jdouble jValue)
 {
     if (!jKey)
@@ -195,7 +243,8 @@ JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_addAt
         return;
     }
 
-    SimulatorResourcePtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, jobject);
+    SimulatorResourceServerPtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env,
+                                          jobject);
     if (nullptr == resource.get())
     {
         std::cout << "addAttributeDouble: Resource is NULL";
@@ -206,7 +255,8 @@ JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_addAt
     resource->addAttribute(str, static_cast<double>(jValue));
 }
 
-JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_addAttributeBoolean
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_addAttributeBoolean
 (JNIEnv *env, jobject jobject, jstring jKey, jboolean jValue)
 {
     if (!jKey)
@@ -215,7 +265,8 @@ JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_addAt
         return;
     }
 
-    SimulatorResourcePtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, jobject);
+    SimulatorResourceServerPtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env,
+                                          jobject);
     if (nullptr == resource.get())
     {
         std::cout << "addAttributeBoolean: Resource is NULL";
@@ -226,7 +277,8 @@ JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_addAt
     resource->addAttribute(str, static_cast<bool>(jValue));
 }
 
-JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_addAttributeStringN
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_addAttributeStringN
 (JNIEnv *env, jobject jobject, jstring jKey, jstring jValue)
 {
     if (!jKey)
@@ -235,7 +287,8 @@ JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_addAt
         return;
     }
 
-    SimulatorResourcePtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, jobject);
+    SimulatorResourceServerPtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env,
+                                          jobject);
     if (nullptr == resource.get())
     {
         std::cout << "addAttributeStringN: Resource is NULL";
@@ -248,7 +301,8 @@ JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_addAt
     resource->addAttribute(key, value);
 }
 
-JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_updateAttributeInteger
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_updateAttributeInteger
 (JNIEnv *env, jobject jobject, jstring jKey, jint jValue)
 {
     if (!jKey)
@@ -257,7 +311,8 @@ JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_updat
         return;
     }
 
-    SimulatorResourcePtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, jobject);
+    SimulatorResourceServerPtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env,
+                                          jobject);
     if (nullptr == resource.get())
     {
         std::cout << "updateAttributeInteger: Resource is NULL";
@@ -268,7 +323,8 @@ JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_updat
     resource->updateAttribute(str, static_cast<int>(jValue));
 }
 
-JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_updateAttributeDouble
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_updateAttributeDouble
 (JNIEnv *env, jobject jobject, jstring jKey, jdouble jValue)
 {
     if (!jKey)
@@ -277,7 +333,8 @@ JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_updat
         return;
     }
 
-    SimulatorResourcePtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, jobject);
+    SimulatorResourceServerPtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env,
+                                          jobject);
     if (nullptr == resource.get())
     {
         std::cout << "updateAttributeDouble: Resource is NULL";
@@ -288,7 +345,8 @@ JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_updat
     resource->updateAttribute(str, static_cast<double>(jValue));
 }
 
-JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_updateAttributeBoolean
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_updateAttributeBoolean
 (JNIEnv *env, jobject jobject, jstring jKey, jboolean jValue)
 {
     if (!jKey)
@@ -297,7 +355,8 @@ JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_updat
         return;
     }
 
-    SimulatorResourcePtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, jobject);
+    SimulatorResourceServerPtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env,
+                                          jobject);
     if (nullptr == resource.get())
     {
         std::cout << "updateAttributeBoolean: Resource is NULL";
@@ -308,7 +367,8 @@ JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_updat
     resource->updateAttribute(str, static_cast<bool>(jValue));
 }
 
-JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_updateAttributeStringN
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_updateAttributeStringN
 (JNIEnv *env, jobject jobject, jstring jKey, jstring jValue)
 {
     if (!jKey)
@@ -317,7 +377,8 @@ JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_updat
         return;
     }
 
-    SimulatorResourcePtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, jobject);
+    SimulatorResourceServerPtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env,
+                                          jobject);
     if (nullptr == resource.get())
     {
         std::cout << "updateAttributeStringN: Resource is NULL";
@@ -330,7 +391,8 @@ JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_updat
     resource->updateAttribute(key, value);
 }
 
-JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_setAllowedValuesInteger
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_setAllowedValuesInteger
 (JNIEnv *env, jobject object, jstring jKey, jobject jAllowedValues)
 {
     if (!jKey)
@@ -339,7 +401,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_setAl
         return;
     }
 
-    SimulatorResourcePtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, object);
+    SimulatorResourceServerPtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, object);
     if (nullptr == resource.get())
     {
         std::cout << "setAllowedValuesInteger: Resource is NULL";
@@ -350,7 +412,8 @@ JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_setAl
     resource->setAllowedValues(str, convertIntegerVector(env, jAllowedValues));
 }
 
-JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_setAllowedValuesDouble
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_setAllowedValuesDouble
 (JNIEnv *env, jobject object, jstring jKey, jobject jAllowedValues)
 {
     if (!jKey)
@@ -359,7 +422,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_setAl
         return;
     }
 
-    SimulatorResourcePtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, object);
+    SimulatorResourceServerPtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, object);
     if (nullptr == resource.get())
     {
         std::cout << "setAllowedValuesDouble: Resource is NULL";
@@ -370,7 +433,8 @@ JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_setAl
     resource->setAllowedValues(str, convertDoubleVector(env, jAllowedValues));
 }
 
-JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_setAllowedValuesStringN
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_setAllowedValuesStringN
 (JNIEnv *env, jobject object, jstring jKey, jobject jAllowedValues)
 {
     if (!jKey)
@@ -379,7 +443,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_setAl
         return;
     }
 
-    SimulatorResourcePtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, object);
+    SimulatorResourceServerPtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, object);
     if (nullptr == resource.get())
     {
         std::cout << "setAllowedValuesStringN: Resource is NULL";
@@ -391,46 +455,87 @@ JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_setAl
 }
 
 JNIEXPORT jint JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_startResourceAutomation
-(JNIEnv *env, jobject object)
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_startResourceAutomation
+(JNIEnv *env, jobject object, jint automationType, jobject listener)
 {
-    SimulatorResourcePtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, object);
+    SimulatorResourceServerPtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, object);
     if (nullptr == resource.get())
     {
         return -1;
     }
 
+    if (!listener)
+    {
+        return -1;
+    }
+
+    jweak jlistenerRef = env->NewWeakGlobalRef(listener);
+    updateCompleteCallback callback =  [jlistenerRef](const std::string & uri, const int automationID)
+    {
+        onAutomationComplete(jlistenerRef, uri, automationID);
+    };
+
+    AutomationType type = AutomationType::NORMAL;
+    if (1 == automationType)
+    {
+        type = AutomationType::RECURRENT;
+    }
+
     int automationId;
-    if (SIMULATOR_SUCCESS != resource->startUpdateAutomation(AutomationType::NORMAL, automationId))
+    if (SIMULATOR_SUCCESS != resource->startUpdateAutomation(type, callback,
+            automationId))
         return -1;
 
     return automationId;
 }
 
 JNIEXPORT jint JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_startAttributeAutomation
-(JNIEnv *env, jobject object, jstring attrName)
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_startAttributeAutomation
+(JNIEnv *env, jobject object, jstring attrName, jint automationType, jobject listener)
 {
-    SimulatorResourcePtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, object);
+    std::cout << "starAttributeAutomation JNI" << std::endl;
+    SimulatorResourceServerPtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, object);
     if (nullptr == resource.get())
     {
         return -1;
     }
 
+    if (!attrName)
+    {
+        return -1;
+    }
+
+    if (!listener)
+    {
+        return -1;
+    }
+
+    jweak jlistenerRef = env->NewWeakGlobalRef(listener);
+    updateCompleteCallback callback =  [jlistenerRef](const std::string & uri, const int automationID)
+    {
+        onAutomationComplete(jlistenerRef, uri, automationID);
+    };
+
     const char *attrNamePtr = env->GetStringUTFChars(attrName, NULL);
 
+    AutomationType type = AutomationType::NORMAL;
+    if (1 == automationType)
+    {
+        type = AutomationType::RECURRENT;
+    }
+
     int automationId = -1;
-    resource->startUpdateAutomation(AutomationType::NORMAL, automationId);
+    resource->startUpdateAutomation(attrNamePtr, type, callback, automationId);
 
     env->ReleaseStringUTFChars(attrName, attrNamePtr);
     return automationId;
 }
 
 JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_startAutomation
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_stopAutomation
 (JNIEnv *env, jobject object, jint automationId)
 {
-    SimulatorResourcePtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, object);
+    SimulatorResourceServerPtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, object);
     if (nullptr == resource.get())
     {
         return;
@@ -439,7 +544,8 @@ Java_org_iotivity_simulator_SimulatorResourceServer_startAutomation
     resource->stopUpdateAutomation(automationId);
 }
 
-JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_removeAttribute
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_removeAttribute
 (JNIEnv *env, jobject jobject, jstring jKey)
 {
     if (!jKey)
@@ -448,7 +554,8 @@ JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_remov
         return;
     }
 
-    SimulatorResourcePtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, jobject);
+    SimulatorResourceServerPtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env,
+                                          jobject);
     if (nullptr == resource.get())
     {
         std::cout << "removeAttribute: Resource is NULL";
@@ -459,7 +566,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_remov
     resource->removeAttribute(str);
 }
 
-JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_dispose
+JNIEXPORT void JNICALL Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_dispose
 (JNIEnv *env, jobject thiz)
 {
     JniSimulatorResource *resource = GetHandle<JniSimulatorResource>(env, thiz);
 #define SIMULATOR_RESOURCE_JNI_H_
 
 #include <jni.h>
-#include "simulator_resource.h"
+#include "simulator_resource_server.h"
 
 class JniSimulatorResource
 {
     public:
-        JniSimulatorResource(SimulatorResourcePtr &resource);
+        JniSimulatorResource(SimulatorResourceServerPtr &resource);
 
         static jobject toJava(JNIEnv *env, jlong resource);
-        static void setUri(JNIEnv *env, jobject jobj, const std::string &uri);
-        static void setResourceType(JNIEnv *env, jobject jobj, const std::string &resourceType);
-        static void setResourceName(JNIEnv *env, jobject jobj, const std::string &name);
-        static void setInterfaceType(JNIEnv *env, jobject jobject, const std::string &interfaceType);
-        static SimulatorResourcePtr getJniSimulatorResourcePtr(JNIEnv *env, jobject thiz);
+        void setResourceInfo(JNIEnv *env, jobject jobj);
+        static SimulatorResourceServerPtr getJniSimulatorResourcePtr(JNIEnv *env, jobject thiz);
     private:
-        SimulatorResourcePtr m_sharedResource;
+        SimulatorResourceServerPtr m_sharedResource;
 };
 
 
@@ -44,79 +41,79 @@ class JniSimulatorResource
 extern "C" {
 
 JNIEXPORT jobject JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_getModel
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_getModel
 (JNIEnv *, jobject);
 
 JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_updateAttributeFromAllowedValues
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_updateAttributeFromAllowedValues
 (JNIEnv *, jobject, jstring, jint);
 
 JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_setRange
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_setRange
 (JNIEnv *, jobject, jstring, jint, jint);
 
 JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_addAttributeInteger
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_addAttributeInteger
 (JNIEnv *, jobject, jstring, jint);
 
 JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_addAttributeDouble
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_addAttributeDouble
 (JNIEnv *, jobject, jstring, jdouble);
 
 JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_addAttributeBoolean
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_addAttributeBoolean
 (JNIEnv *, jobject, jstring, jboolean);
 
 JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_addAttributeStringN
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_addAttributeStringN
 (JNIEnv *, jobject, jstring, jstring);
 
 JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_updateAttributeInteger
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_updateAttributeInteger
 (JNIEnv *, jobject, jstring, jint);
 
 JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_updateAttributeDouble
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_updateAttributeDouble
 (JNIEnv *, jobject, jstring, jdouble);
 
 JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_updateAttributeBoolean
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_updateAttributeBoolean
 (JNIEnv *, jobject, jstring, jboolean);
 
 JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_updateAttributeStringN
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_updateAttributeStringN
 (JNIEnv *, jobject, jstring, jstring);
 
 JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_setAllowedValuesInteger
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_setAllowedValuesInteger
 (JNIEnv *, jobject, jstring, jobject);
 
 JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_setAllowedValuesDouble
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_setAllowedValuesDouble
 (JNIEnv *, jobject, jstring, jobject);
 
 JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_setAllowedValuesStringN
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_setAllowedValuesStringN
 (JNIEnv *, jobject, jstring, jobject);
 
 JNIEXPORT jint JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_startResourceAutomation
-(JNIEnv *, jobject);
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_startResourceAutomation
+(JNIEnv *, jobject, jint, jobject);
 
 JNIEXPORT jint JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_startAttributeAutomation
-(JNIEnv *, jobject, jstring);
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_startAttributeAutomation
+(JNIEnv *, jobject, jstring, jint, jobject);
 
 JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_startAutomation
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_stopAutomation
 (JNIEnv *, jobject, jint);
 
 JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_removeAttribute
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_removeAttribute
 (JNIEnv *, jobject, jstring);
 
 JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_dispose
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_dispose
 (JNIEnv *, jobject);
 
 }