Imported Upstream version 1.0.1
[platform/upstream/iotivity.git] / service / simulator / java / jni / simulator_resource_server_jni.cpp
index c9b08c9..209ef47 100644 (file)
@@ -234,6 +234,12 @@ Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_addAttributeStrin
         return;
     }
 
+    if (!jValue)
+    {
+        throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM, "Attribute value cannot be null!");
+        return;
+    }
+
     SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env,
                                          jobject);
     if (!resource)
@@ -482,7 +488,7 @@ Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_setAllowedValuesS
 
 JNIEXPORT jint JNICALL
 Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_startResourceAutomation
-(JNIEnv *env, jobject object, jint automationType, jobject listener)
+(JNIEnv *env, jobject object, jint automationType, jint updateInterval, jobject listener)
 {
     SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env, object);
     if (!resource)
@@ -514,7 +520,7 @@ Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_startResourceAuto
 
     try
     {
-        automationId = resource->startUpdateAutomation(type, callback);
+        automationId = resource->startUpdateAutomation(type, updateInterval, callback);
     }
     catch (InvalidArgsException &e)
     {
@@ -533,7 +539,7 @@ Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_startResourceAuto
 
 JNIEXPORT jint JNICALL
 Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_startAttributeAutomation
-(JNIEnv *env, jobject object, jstring attrName, jint automationType, jobject listener)
+(JNIEnv *env, jobject object, jstring attrName, jint automationType, jint updateInterval, jobject listener)
 {
     SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env, object);
     if (!resource)
@@ -572,7 +578,7 @@ Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_startAttributeAut
     int automationId = -1;
     try
     {
-        automationId = resource->startUpdateAutomation(attrNamePtr, type, callback);
+        automationId = resource->startUpdateAutomation(attrNamePtr, type, updateInterval, callback);
     }
     catch (InvalidArgsException &e)
     {
@@ -639,7 +645,25 @@ Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_removeAttribute
     }
 
     std::string str = env->GetStringUTFChars(jKey, NULL);
-    resource->removeAttribute(str);
+    try
+    {
+        resource->removeAttribute(str);
+    }
+    catch (InvalidArgsException &e)
+    {
+        throwInvalidArgsException(env, e.code(), e.what());
+        return;
+    }
+    catch (SimulatorException &e)
+    {
+        throwSimulatorException(env, e.code(), e.what());
+        return;
+    }
+    catch (...)
+    {
+        throwSimulatorException(env, SIMULATOR_ERROR, "Unknown Exception");
+        return;
+    }
 }
 
 JNIEXPORT jobjectArray JNICALL