jclass classSimulatorResourceAttribute;
jclass classSimulatorRemoteResource;
jclass classSimulatorCallback;
+ jclass classMap;
+ jclass classMapEntry;
+ jclass classSet;
+ jclass classIterator;
jmethodID classIntegerCtor;
jmethodID classDoubleCtor;
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)
******************************************************************/
#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;
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
}
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;
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
}
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());
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))
{
return JNI_ERR;
}
-
// Get the reference to methods
gSimulatorClassRefs.classIntegerCtor = env->GetMethodID(gSimulatorClassRefs.classInteger, "<init>",
"(I)V");
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)
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;
}
#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
};
JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceAttribute_create
+Java_org_oic_simulator_SimulatorResourceAttribute_create
(JNIEnv *env, jobject object, jstring attrName)
{
if (!attrName)
}
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,
}
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,
}
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,
}
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,
}
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,
}
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,
#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
+++ /dev/null
-/******************************************************************
- *
- * 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 "simulator_resource_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)
- : m_sharedResource(resource) {}
-
-SimulatorResourcePtr JniSimulatorResource::getJniSimulatorResourcePtr(JNIEnv *env, jobject thiz)
-{
- JniSimulatorResource *resource = GetHandle<JniSimulatorResource>(env, thiz);
- if (env->ExceptionCheck())
- {
- return NULL;
- }
- return resource->m_sharedResource;
-}
-
-jobject JniSimulatorResource::toJava(JNIEnv *env, jlong resource)
-{
- jobject resourceObj = (jobject) env->NewObject(gSimulatorClassRefs.classSimulatorResource,
- gSimulatorClassRefs.classSimulatorResourceCtor, resource);
- if (NULL == resourceObj)
- {
- return NULL;
- }
- return resourceObj;
-}
-
-void JniSimulatorResource::setUri(JNIEnv *env, jobject jobj, const std::string &uri)
-{
- if (!env || !jobj)
- return;
-
- jstring jURI = env->NewStringUTF(uri.c_str());
- if (!jURI)
- return;
-
- env->CallVoidMethod(jobj, gSimulatorClassRefs.classSimulatorResourceSetURI, jURI);
- env->DeleteLocalRef(jURI);
-}
-
-void JniSimulatorResource::setResourceType(JNIEnv *env, jobject jobj,
- const std::string &resourceType)
-{
- if (!env || !jobj)
- return;
-
- jstring jResourceType = env->NewStringUTF(resourceType.c_str());
- if (!jResourceType)
- return;
-
- env->CallVoidMethod(jobj, gSimulatorClassRefs.classSimulatorResourceSetResourceType, jResourceType);
- env->DeleteLocalRef(jResourceType);
-}
-
-void JniSimulatorResource::setResourceName(JNIEnv *env, jobject jobj, const std::string &name)
-{
- if (!env || !jobj)
- return;
-
- jstring jName = env->NewStringUTF(name.c_str());
- if (!jName)
- return;
-
- env->CallVoidMethod(jobj, gSimulatorClassRefs.classSimulatorResourceSetName, jName);
- env->DeleteLocalRef(jName);
-}
-
-JNIEXPORT jobject JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_getModel
-(JNIEnv *env, jobject object)
-{
- SimulatorResourcePtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, object);
- if (nullptr == resource.get())
- {
- std::cout << "getModel: Resource is NULL";
- return nullptr;
- }
-
- SimulatorResourceModel resModel = resource->getModel();
- JniSimulatorResourceModel *model = new JniSimulatorResourceModel(resModel);
- jobject jModel = JniSimulatorResourceModel::toJava(env, reinterpret_cast<jlong>(model));
- return jModel;
-}
-
-JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_updateAttributeFromAllowedValues
-(JNIEnv *env, jobject object, jstring attrName, jint index)
-{
- SimulatorResourcePtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, object);
- if (nullptr == resource.get())
- {
- std::cout << "updateAttributeFromAllowedValues: Resource is NULL";
- return;
- }
-
- const char *attrNamePtr = env->GetStringUTFChars(attrName, NULL);
- if (!attrNamePtr)
- {
- std::cout << "updateAttributeFromAllowedValues: Failed to convert jstring to char string!";
- return;
- }
-
- resource->updateAttributeFromAllowedValues(attrNamePtr, static_cast<int>(index));
- env->ReleaseStringUTFChars(attrName, attrNamePtr);
-}
-
-JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_setRange
-(JNIEnv *env, jobject object, jstring attrName, jint min, jint max)
-{
- SimulatorResourcePtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, object);
- if (nullptr == resource.get())
- {
- std::cout << "setRange: Resource is NULL";
- return;
- }
-
- const char *attrNamePtr = env->GetStringUTFChars(attrName, NULL);
- if (!attrNamePtr)
- {
- std::cout << "setRange: Failed to convert jstring to char string!";
- return;
- }
-
- resource->setRange(attrNamePtr, static_cast<int>(min), static_cast<int>(max));
- env->ReleaseStringUTFChars(attrName, attrNamePtr);
-}
-
-JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_setInterfaceType
-(JNIEnv *env, jobject jobject, const std::string &interfaceType)
-{
- jstring jInterfaceType = env->NewStringUTF(interfaceType.c_str());
- if (!jInterfaceType)
- {
- std::cout << "setInterfaceType: InterfaceType is NULL";
- return;
- }
-
- env->CallVoidMethod(jobject, gSimulatorClassRefs.classSimulatorResourceSetInterfaceType,
- jInterfaceType);
- env->DeleteLocalRef(jInterfaceType);
-}
-
-JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_addAttributeInteger
-(JNIEnv *env, jobject jobject, jstring jKey, jint jValue)
-{
- if (!jKey)
- {
- std::cout << "addAttributeInteger: AttributeName is Empty";
- return;
- }
-
- SimulatorResourcePtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, jobject);
- if (nullptr == resource.get())
- {
- std::cout << "addAttributeInteger: Resource is NULL";
- return;
- }
-
- std::string str = env->GetStringUTFChars(jKey, NULL);
- resource->addAttribute(str, static_cast<int>(jValue));
-}
-
-JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_addAttributeDouble
-(JNIEnv *env, jobject jobject, jstring jKey, jdouble jValue)
-{
- if (!jKey)
- {
- std::cout << "addAttributeDouble: AttributeName is Empty";
- return;
- }
-
- SimulatorResourcePtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, jobject);
- if (nullptr == resource.get())
- {
- std::cout << "addAttributeDouble: Resource is NULL";
- return;
- }
-
- std::string str = env->GetStringUTFChars(jKey, NULL);
- resource->addAttribute(str, static_cast<double>(jValue));
-}
-
-JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_addAttributeBoolean
-(JNIEnv *env, jobject jobject, jstring jKey, jboolean jValue)
-{
- if (!jKey)
- {
- std::cout << "addAttributeBoolean: AttributeName is Empty";
- return;
- }
-
- SimulatorResourcePtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, jobject);
- if (nullptr == resource.get())
- {
- std::cout << "addAttributeBoolean: Resource is NULL";
- return;
- }
-
- std::string str = env->GetStringUTFChars(jKey, NULL);
- resource->addAttribute(str, static_cast<bool>(jValue));
-}
-
-JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_addAttributeStringN
-(JNIEnv *env, jobject jobject, jstring jKey, jstring jValue)
-{
- if (!jKey)
- {
- std::cout << "addAttributeStringN: AttributeName is Empty";
- return;
- }
-
- SimulatorResourcePtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, jobject);
- if (nullptr == resource.get())
- {
- std::cout << "addAttributeStringN: Resource is NULL";
- return;
- }
-
- std::string key = env->GetStringUTFChars(jKey, NULL);
- std::string value = env->GetStringUTFChars(jValue, NULL);
-
- resource->addAttribute(key, value);
-}
-
-JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_updateAttributeInteger
-(JNIEnv *env, jobject jobject, jstring jKey, jint jValue)
-{
- if (!jKey)
- {
- std::cout << "updateAttributeInteger: AttributeName is Empty";
- return;
- }
-
- SimulatorResourcePtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, jobject);
- if (nullptr == resource.get())
- {
- std::cout << "updateAttributeInteger: Resource is NULL";
- return;
- }
-
- std::string str = env->GetStringUTFChars(jKey, NULL);
- resource->updateAttribute(str, static_cast<int>(jValue));
-}
-
-JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_updateAttributeDouble
-(JNIEnv *env, jobject jobject, jstring jKey, jdouble jValue)
-{
- if (!jKey)
- {
- std::cout << "updateAttributeDouble: AttributeName is Empty";
- return;
- }
-
- SimulatorResourcePtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, jobject);
- if (nullptr == resource.get())
- {
- std::cout << "updateAttributeDouble: Resource is NULL";
- return;
- }
-
- std::string str = env->GetStringUTFChars(jKey, NULL);
- resource->updateAttribute(str, static_cast<double>(jValue));
-}
-
-JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_updateAttributeBoolean
-(JNIEnv *env, jobject jobject, jstring jKey, jboolean jValue)
-{
- if (!jKey)
- {
- std::cout << "updateAttributeBoolean: AttributeName is Empty";
- return;
- }
-
- SimulatorResourcePtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, jobject);
- if (nullptr == resource.get())
- {
- std::cout << "updateAttributeBoolean: Resource is NULL";
- return;
- }
-
- std::string str = env->GetStringUTFChars(jKey, NULL);
- resource->updateAttribute(str, static_cast<bool>(jValue));
-}
-
-JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_updateAttributeStringN
-(JNIEnv *env, jobject jobject, jstring jKey, jstring jValue)
-{
- if (!jKey)
- {
- std::cout << "updateAttributeStringN: AttributeName is Empty";
- return;
- }
-
- SimulatorResourcePtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, jobject);
- if (nullptr == resource.get())
- {
- std::cout << "updateAttributeStringN: Resource is NULL";
- return;
- }
-
- std::string key = env->GetStringUTFChars(jKey, NULL);
- std::string value = env->GetStringUTFChars(jValue, NULL);
-
- resource->updateAttribute(key, value);
-}
-
-JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_setAllowedValuesInteger
-(JNIEnv *env, jobject object, jstring jKey, jobject jAllowedValues)
-{
- if (!jKey)
- {
- std::cout << "setAllowedValuesInteger: AttributeName is Empty";
- return;
- }
-
- SimulatorResourcePtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, object);
- if (nullptr == resource.get())
- {
- std::cout << "setAllowedValuesInteger: Resource is NULL";
- return;
- }
-
- std::string str = env->GetStringUTFChars(jKey, NULL);
- resource->setAllowedValues(str, convertIntegerVector(env, jAllowedValues));
-}
-
-JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_setAllowedValuesDouble
-(JNIEnv *env, jobject object, jstring jKey, jobject jAllowedValues)
-{
- if (!jKey)
- {
- std::cout << "setAllowedValuesDouble: AttributeName is Empty";
- return;
- }
-
- SimulatorResourcePtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, object);
- if (nullptr == resource.get())
- {
- std::cout << "setAllowedValuesDouble: Resource is NULL";
- return;
- }
-
- std::string str = env->GetStringUTFChars(jKey, NULL);
- resource->setAllowedValues(str, convertDoubleVector(env, jAllowedValues));
-}
-
-JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_setAllowedValuesStringN
-(JNIEnv *env, jobject object, jstring jKey, jobject jAllowedValues)
-{
- if (!jKey)
- {
- std::cout << "setAllowedValuesStringN: AttributeName is Empty";
- return;
- }
-
- SimulatorResourcePtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, object);
- if (nullptr == resource.get())
- {
- std::cout << "setAllowedValuesStringN: Resource is NULL";
- return;
- }
-
- std::string str = env->GetStringUTFChars(jKey, NULL);
- resource->setAllowedValues(str, convertStringVector(env, jAllowedValues));
-}
-
-JNIEXPORT jint JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_startResourceAutomation
-(JNIEnv *env, jobject object)
-{
- SimulatorResourcePtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, object);
- if (nullptr == resource.get())
- {
- return -1;
- }
-
- int automationId;
- if (SIMULATOR_SUCCESS != resource->startUpdateAutomation(AutomationType::NORMAL, automationId))
- return -1;
-
- return automationId;
-}
-
-JNIEXPORT jint JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_startAttributeAutomation
-(JNIEnv *env, jobject object, jstring attrName)
-{
- SimulatorResourcePtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, object);
- if (nullptr == resource.get())
- {
- return -1;
- }
-
- const char *attrNamePtr = env->GetStringUTFChars(attrName, NULL);
-
- int automationId = -1;
- resource->startUpdateAutomation(AutomationType::NORMAL, automationId);
-
- env->ReleaseStringUTFChars(attrName, attrNamePtr);
- return automationId;
-}
-
-JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_startAutomation
-(JNIEnv *env, jobject object, jint automationId)
-{
- SimulatorResourcePtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, object);
- if (nullptr == resource.get())
- {
- return;
- }
-
- resource->stopUpdateAutomation(automationId);
-}
-
-JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_removeAttribute
-(JNIEnv *env, jobject jobject, jstring jKey)
-{
- if (!jKey)
- {
- std::cout << "removeAttribute: AttributeName is Empty";
- return;
- }
-
- SimulatorResourcePtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, jobject);
- if (nullptr == resource.get())
- {
- std::cout << "removeAttribute: Resource is NULL";
- return;
- }
-
- std::string str = env->GetStringUTFChars(jKey, NULL);
- resource->removeAttribute(str);
-}
-
-JNIEXPORT void JNICALL Java_org_iotivity_simulator_SimulatorResourceServer_dispose
-(JNIEnv *env, jobject thiz)
-{
- JniSimulatorResource *resource = GetHandle<JniSimulatorResource>(env, thiz);
- delete resource;
-}
-
+++ /dev/null
-/******************************************************************
- *
- * 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.
- *
- ******************************************************************/
-
-#ifndef SIMULATOR_RESOURCE_JNI_H_
-#define SIMULATOR_RESOURCE_JNI_H_
-
-#include <jni.h>
-#include "simulator_resource.h"
-
-class JniSimulatorResource
-{
- public:
- JniSimulatorResource(SimulatorResourcePtr &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);
- private:
- SimulatorResourcePtr m_sharedResource;
-};
-
-
-#ifdef __cplusplus
-extern "C" {
-
-JNIEXPORT jobject JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_getModel
-(JNIEnv *, jobject);
-
-JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_updateAttributeFromAllowedValues
-(JNIEnv *, jobject, jstring, jint);
-
-JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_setRange
-(JNIEnv *, jobject, jstring, jint, jint);
-
-JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_addAttributeInteger
-(JNIEnv *, jobject, jstring, jint);
-
-JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_addAttributeDouble
-(JNIEnv *, jobject, jstring, jdouble);
-
-JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_addAttributeBoolean
-(JNIEnv *, jobject, jstring, jboolean);
-
-JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_addAttributeStringN
-(JNIEnv *, jobject, jstring, jstring);
-
-JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_updateAttributeInteger
-(JNIEnv *, jobject, jstring, jint);
-
-JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_updateAttributeDouble
-(JNIEnv *, jobject, jstring, jdouble);
-
-JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_updateAttributeBoolean
-(JNIEnv *, jobject, jstring, jboolean);
-
-JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_updateAttributeStringN
-(JNIEnv *, jobject, jstring, jstring);
-
-JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_setAllowedValuesInteger
-(JNIEnv *, jobject, jstring, jobject);
-
-JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_setAllowedValuesDouble
-(JNIEnv *, jobject, jstring, jobject);
-
-JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_setAllowedValuesStringN
-(JNIEnv *, jobject, jstring, jobject);
-
-JNIEXPORT jint JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_startResourceAutomation
-(JNIEnv *, jobject);
-
-JNIEXPORT jint JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_startAttributeAutomation
-(JNIEnv *, jobject, jstring);
-
-JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_startAutomation
-(JNIEnv *, jobject, jint);
-
-JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_removeAttribute
-(JNIEnv *, jobject, jstring);
-
-JNIEXPORT void JNICALL
-Java_org_iotivity_simulator_SimulatorResourceServer_dispose
-(JNIEnv *, jobject);
-
-}
-#endif
-#endif //SIMULATOR_RESOURCE_JNI_H_
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;
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;
}
JNIEXPORT jint JNICALL
-Java_org_iotivity_simulator_SimulatorResourceModel_size
+Java_org_oic_simulator_serviceprovider_SimulatorResourceModel_size
(JNIEnv *env, jobject thiz)
{
SimulatorResourceModel resourceModel;
}
JNIEXPORT jobject JNICALL
-Java_org_iotivity_simulator_SimulatorResourceModel_getAttributes
+Java_org_oic_simulator_serviceprovider_SimulatorResourceModel_getAttributes
(JNIEnv *env, jobject thiz)
{
SimulatorResourceModel resourceModel;
}
JNIEXPORT jobject JNICALL
-Java_org_iotivity_simulator_SimulatorResourceModel_getAttribute
+Java_org_oic_simulator_serviceprovider_SimulatorResourceModel_getAttribute
(JNIEnv *env, jobject thiz, jstring jAttrName)
{
if (!jAttrName)
}
JNIEXPORT jobjectArray JNICALL
-Java_org_iotivity_simulator_SimulatorResourceModel_getAllowedValues
+Java_org_oic_simulator_serviceprovider_SimulatorResourceModel_getAllowedValues
(JNIEnv *env, jobject thiz, jstring jAttrName)
{
if (!jAttrName)
}
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);
#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);
--- /dev/null
+/******************************************************************
+ *
+ * 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 "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(SimulatorResourceServerPtr &resource)
+ : m_sharedResource(resource) {}
+
+SimulatorResourceServerPtr JniSimulatorResource::getJniSimulatorResourcePtr(JNIEnv *env,
+ jobject thiz)
+{
+ JniSimulatorResource *resource = GetHandle<JniSimulatorResource>(env, thiz);
+ if (env->ExceptionCheck())
+ {
+ return NULL;
+ }
+ return resource->m_sharedResource;
+}
+
+jobject JniSimulatorResource::toJava(JNIEnv *env, jlong resource)
+{
+ jobject resourceObj = (jobject) env->NewObject(gSimulatorClassRefs.classSimulatorResource,
+ gSimulatorClassRefs.classSimulatorResourceCtor, resource);
+ if (NULL == resourceObj)
+ {
+ return NULL;
+ }
+ return resourceObj;
+}
+
+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)
+ {
+ 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 onAutomationComplete(jweak jlistenerRef, const std::string &uri,
+ const int automationID)
+{
+ std::cout << "onAutomationComplete JNI entry" << std::endl;
+ JNIEnv *env = getEnv();
+ if (nullptr == env)
+ return;
+
+ jobject autoCompleteListener = env->NewLocalRef(jlistenerRef);
+ if (!autoCompleteListener)
+ {
+ releaseEnv();
+ return;
+ }
+
+ jclass autoCompleteCls = env->GetObjectClass(autoCompleteListener);
+ if (!autoCompleteCls)
+ {
+ releaseEnv();
+ return;
+ }
+
+ jmethodID autoCompleteMId = env->GetMethodID(autoCompleteCls, "onAutomationComplete",
+ "(Ljava/lang/String;I)V");
+ if (!autoCompleteMId)
+ {
+ releaseEnv();
+ return;
+ }
+
+ jstring jUri = env->NewStringUTF(uri.c_str());
+
+ env->CallVoidMethod(autoCompleteListener, autoCompleteMId, jUri, automationID);
+ if ((env)->ExceptionCheck())
+ {
+ releaseEnv();
+ return;
+ }
+
+ env->DeleteLocalRef(jUri);
+
+ releaseEnv();
+}
+
+JNIEXPORT jobject JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_getModel
+(JNIEnv *env, jobject object)
+{
+ SimulatorResourceServerPtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, object);
+ if (nullptr == resource.get())
+ {
+ std::cout << "getModel: Resource is NULL";
+ return nullptr;
+ }
+
+ SimulatorResourceModel resModel = resource->getModel();
+ JniSimulatorResourceModel *model = new JniSimulatorResourceModel(resModel);
+ jobject jModel = JniSimulatorResourceModel::toJava(env, reinterpret_cast<jlong>(model));
+ return jModel;
+}
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_updateAttributeFromAllowedValues
+(JNIEnv *env, jobject object, jstring attrName, jint index)
+{
+ SimulatorResourceServerPtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, object);
+ if (nullptr == resource.get())
+ {
+ std::cout << "updateAttributeFromAllowedValues: Resource is NULL";
+ return;
+ }
+
+ const char *attrNamePtr = env->GetStringUTFChars(attrName, NULL);
+ if (!attrNamePtr)
+ {
+ std::cout << "updateAttributeFromAllowedValues: Failed to convert jstring to char string!";
+ return;
+ }
+
+ resource->updateAttributeFromAllowedValues(attrNamePtr, static_cast<int>(index));
+ env->ReleaseStringUTFChars(attrName, attrNamePtr);
+}
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_setRange
+(JNIEnv *env, jobject object, jstring attrName, jint min, jint max)
+{
+ SimulatorResourceServerPtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, object);
+ if (nullptr == resource.get())
+ {
+ std::cout << "setRange: Resource is NULL";
+ return;
+ }
+
+ const char *attrNamePtr = env->GetStringUTFChars(attrName, NULL);
+ if (!attrNamePtr)
+ {
+ std::cout << "setRange: Failed to convert jstring to char string!";
+ return;
+ }
+
+ resource->setRange(attrNamePtr, static_cast<int>(min), static_cast<int>(max));
+ env->ReleaseStringUTFChars(attrName, attrNamePtr);
+}
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_setInterfaceType
+(JNIEnv *env, jobject jobject, const std::string &interfaceType)
+{
+ jstring jInterfaceType = env->NewStringUTF(interfaceType.c_str());
+ if (!jInterfaceType)
+ {
+ std::cout << "setInterfaceType: InterfaceType is NULL";
+ return;
+ }
+
+ env->CallVoidMethod(jobject, gSimulatorClassRefs.classSimulatorResourceSetInterfaceType,
+ jInterfaceType);
+ env->DeleteLocalRef(jInterfaceType);
+}
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_addAttributeInteger
+(JNIEnv *env, jobject jobject, jstring jKey, jint jValue)
+{
+ if (!jKey)
+ {
+ std::cout << "addAttributeInteger: AttributeName is Empty";
+ return;
+ }
+
+ SimulatorResourceServerPtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env,
+ jobject);
+ if (nullptr == resource.get())
+ {
+ std::cout << "addAttributeInteger: Resource is NULL";
+ return;
+ }
+
+ std::string str = env->GetStringUTFChars(jKey, NULL);
+ resource->addAttribute(str, static_cast<int>(jValue));
+}
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_addAttributeDouble
+(JNIEnv *env, jobject jobject, jstring jKey, jdouble jValue)
+{
+ if (!jKey)
+ {
+ std::cout << "addAttributeDouble: AttributeName is Empty";
+ return;
+ }
+
+ SimulatorResourceServerPtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env,
+ jobject);
+ if (nullptr == resource.get())
+ {
+ std::cout << "addAttributeDouble: Resource is NULL";
+ return;
+ }
+
+ std::string str = env->GetStringUTFChars(jKey, NULL);
+ resource->addAttribute(str, static_cast<double>(jValue));
+}
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_addAttributeBoolean
+(JNIEnv *env, jobject jobject, jstring jKey, jboolean jValue)
+{
+ if (!jKey)
+ {
+ std::cout << "addAttributeBoolean: AttributeName is Empty";
+ return;
+ }
+
+ SimulatorResourceServerPtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env,
+ jobject);
+ if (nullptr == resource.get())
+ {
+ std::cout << "addAttributeBoolean: Resource is NULL";
+ return;
+ }
+
+ std::string str = env->GetStringUTFChars(jKey, NULL);
+ resource->addAttribute(str, static_cast<bool>(jValue));
+}
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_addAttributeStringN
+(JNIEnv *env, jobject jobject, jstring jKey, jstring jValue)
+{
+ if (!jKey)
+ {
+ std::cout << "addAttributeStringN: AttributeName is Empty";
+ return;
+ }
+
+ SimulatorResourceServerPtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env,
+ jobject);
+ if (nullptr == resource.get())
+ {
+ std::cout << "addAttributeStringN: Resource is NULL";
+ return;
+ }
+
+ std::string key = env->GetStringUTFChars(jKey, NULL);
+ std::string value = env->GetStringUTFChars(jValue, NULL);
+
+ resource->addAttribute(key, value);
+}
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_updateAttributeInteger
+(JNIEnv *env, jobject jobject, jstring jKey, jint jValue)
+{
+ if (!jKey)
+ {
+ std::cout << "updateAttributeInteger: AttributeName is Empty";
+ return;
+ }
+
+ SimulatorResourceServerPtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env,
+ jobject);
+ if (nullptr == resource.get())
+ {
+ std::cout << "updateAttributeInteger: Resource is NULL";
+ return;
+ }
+
+ std::string str = env->GetStringUTFChars(jKey, NULL);
+ resource->updateAttribute(str, static_cast<int>(jValue));
+}
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_updateAttributeDouble
+(JNIEnv *env, jobject jobject, jstring jKey, jdouble jValue)
+{
+ if (!jKey)
+ {
+ std::cout << "updateAttributeDouble: AttributeName is Empty";
+ return;
+ }
+
+ SimulatorResourceServerPtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env,
+ jobject);
+ if (nullptr == resource.get())
+ {
+ std::cout << "updateAttributeDouble: Resource is NULL";
+ return;
+ }
+
+ std::string str = env->GetStringUTFChars(jKey, NULL);
+ resource->updateAttribute(str, static_cast<double>(jValue));
+}
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_updateAttributeBoolean
+(JNIEnv *env, jobject jobject, jstring jKey, jboolean jValue)
+{
+ if (!jKey)
+ {
+ std::cout << "updateAttributeBoolean: AttributeName is Empty";
+ return;
+ }
+
+ SimulatorResourceServerPtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env,
+ jobject);
+ if (nullptr == resource.get())
+ {
+ std::cout << "updateAttributeBoolean: Resource is NULL";
+ return;
+ }
+
+ std::string str = env->GetStringUTFChars(jKey, NULL);
+ resource->updateAttribute(str, static_cast<bool>(jValue));
+}
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_updateAttributeStringN
+(JNIEnv *env, jobject jobject, jstring jKey, jstring jValue)
+{
+ if (!jKey)
+ {
+ std::cout << "updateAttributeStringN: AttributeName is Empty";
+ return;
+ }
+
+ SimulatorResourceServerPtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env,
+ jobject);
+ if (nullptr == resource.get())
+ {
+ std::cout << "updateAttributeStringN: Resource is NULL";
+ return;
+ }
+
+ std::string key = env->GetStringUTFChars(jKey, NULL);
+ std::string value = env->GetStringUTFChars(jValue, NULL);
+
+ resource->updateAttribute(key, value);
+}
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_setAllowedValuesInteger
+(JNIEnv *env, jobject object, jstring jKey, jobject jAllowedValues)
+{
+ if (!jKey)
+ {
+ std::cout << "setAllowedValuesInteger: AttributeName is Empty";
+ return;
+ }
+
+ SimulatorResourceServerPtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, object);
+ if (nullptr == resource.get())
+ {
+ std::cout << "setAllowedValuesInteger: Resource is NULL";
+ return;
+ }
+
+ std::string str = env->GetStringUTFChars(jKey, NULL);
+ resource->setAllowedValues(str, convertIntegerVector(env, jAllowedValues));
+}
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_setAllowedValuesDouble
+(JNIEnv *env, jobject object, jstring jKey, jobject jAllowedValues)
+{
+ if (!jKey)
+ {
+ std::cout << "setAllowedValuesDouble: AttributeName is Empty";
+ return;
+ }
+
+ SimulatorResourceServerPtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, object);
+ if (nullptr == resource.get())
+ {
+ std::cout << "setAllowedValuesDouble: Resource is NULL";
+ return;
+ }
+
+ std::string str = env->GetStringUTFChars(jKey, NULL);
+ resource->setAllowedValues(str, convertDoubleVector(env, jAllowedValues));
+}
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_setAllowedValuesStringN
+(JNIEnv *env, jobject object, jstring jKey, jobject jAllowedValues)
+{
+ if (!jKey)
+ {
+ std::cout << "setAllowedValuesStringN: AttributeName is Empty";
+ return;
+ }
+
+ SimulatorResourceServerPtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, object);
+ if (nullptr == resource.get())
+ {
+ std::cout << "setAllowedValuesStringN: Resource is NULL";
+ return;
+ }
+
+ std::string str = env->GetStringUTFChars(jKey, NULL);
+ resource->setAllowedValues(str, convertStringVector(env, jAllowedValues));
+}
+
+JNIEXPORT jint JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_startResourceAutomation
+(JNIEnv *env, jobject object, jint automationType, jobject listener)
+{
+ 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(type, callback,
+ automationId))
+ return -1;
+
+ return automationId;
+}
+
+JNIEXPORT jint JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_startAttributeAutomation
+(JNIEnv *env, jobject object, jstring attrName, jint automationType, jobject listener)
+{
+ 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(attrNamePtr, type, callback, automationId);
+
+ env->ReleaseStringUTFChars(attrName, attrNamePtr);
+ return automationId;
+}
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_stopAutomation
+(JNIEnv *env, jobject object, jint automationId)
+{
+ SimulatorResourceServerPtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env, object);
+ if (nullptr == resource.get())
+ {
+ return;
+ }
+
+ resource->stopUpdateAutomation(automationId);
+}
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_removeAttribute
+(JNIEnv *env, jobject jobject, jstring jKey)
+{
+ if (!jKey)
+ {
+ std::cout << "removeAttribute: AttributeName is Empty";
+ return;
+ }
+
+ SimulatorResourceServerPtr resource = JniSimulatorResource::getJniSimulatorResourcePtr(env,
+ jobject);
+ if (nullptr == resource.get())
+ {
+ std::cout << "removeAttribute: Resource is NULL";
+ return;
+ }
+
+ std::string str = env->GetStringUTFChars(jKey, NULL);
+ resource->removeAttribute(str);
+}
+
+JNIEXPORT void JNICALL Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_dispose
+(JNIEnv *env, jobject thiz)
+{
+ JniSimulatorResource *resource = GetHandle<JniSimulatorResource>(env, thiz);
+ delete resource;
+}
+
--- /dev/null
+/******************************************************************
+ *
+ * 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.
+ *
+ ******************************************************************/
+
+#ifndef SIMULATOR_RESOURCE_JNI_H_
+#define SIMULATOR_RESOURCE_JNI_H_
+
+#include <jni.h>
+#include "simulator_resource_server.h"
+
+class JniSimulatorResource
+{
+ public:
+ JniSimulatorResource(SimulatorResourceServerPtr &resource);
+
+ static jobject toJava(JNIEnv *env, jlong resource);
+ void setResourceInfo(JNIEnv *env, jobject jobj);
+ static SimulatorResourceServerPtr getJniSimulatorResourcePtr(JNIEnv *env, jobject thiz);
+ private:
+ SimulatorResourceServerPtr m_sharedResource;
+};
+
+
+#ifdef __cplusplus
+extern "C" {
+
+JNIEXPORT jobject JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_getModel
+(JNIEnv *, jobject);
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_updateAttributeFromAllowedValues
+(JNIEnv *, jobject, jstring, jint);
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_setRange
+(JNIEnv *, jobject, jstring, jint, jint);
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_addAttributeInteger
+(JNIEnv *, jobject, jstring, jint);
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_addAttributeDouble
+(JNIEnv *, jobject, jstring, jdouble);
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_addAttributeBoolean
+(JNIEnv *, jobject, jstring, jboolean);
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_addAttributeStringN
+(JNIEnv *, jobject, jstring, jstring);
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_updateAttributeInteger
+(JNIEnv *, jobject, jstring, jint);
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_updateAttributeDouble
+(JNIEnv *, jobject, jstring, jdouble);
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_updateAttributeBoolean
+(JNIEnv *, jobject, jstring, jboolean);
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_updateAttributeStringN
+(JNIEnv *, jobject, jstring, jstring);
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_setAllowedValuesInteger
+(JNIEnv *, jobject, jstring, jobject);
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_setAllowedValuesDouble
+(JNIEnv *, jobject, jstring, jobject);
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_setAllowedValuesStringN
+(JNIEnv *, jobject, jstring, jobject);
+
+JNIEXPORT jint JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_startResourceAutomation
+(JNIEnv *, jobject, jint, jobject);
+
+JNIEXPORT jint JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_startAttributeAutomation
+(JNIEnv *, jobject, jstring, jint, jobject);
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_stopAutomation
+(JNIEnv *, jobject, jint);
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_removeAttribute
+(JNIEnv *, jobject, jstring);
+
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_dispose
+(JNIEnv *, jobject);
+
+}
+#endif
+#endif //SIMULATOR_RESOURCE_JNI_H_