From f7f4e3e486af1641d1bf42c3bb24122f84a78c8c Mon Sep 17 00:00:00 2001 From: Jay Sharma Date: Thu, 10 Sep 2015 21:58:14 +0530 Subject: [PATCH] [Services - Things Manager] Removed Things Manager class and exposed its component classes for SDK - Updated Java SDK - Updated JNI layer Change-Id: I910b9990c9d60865519af152cf8057302d713547 Signed-off-by: Jay Sharma Reviewed-on: https://gerrit.iotivity.org/gerrit/2425 Tested-by: jenkins-iotivity Reviewed-by: Madan Lanka --- service/things-manager/sdk/java/jni/Android.mk | 1 + .../sdk/java/jni/jniutil/inc/jni_getter.h | 30 +- .../sdk/java/jni/jniutil/inc/jni_object.h | 35 +- .../sdk/java/jni/jniutil/inc/jni_setter.h | 26 +- .../sdk/java/jni/jniutil/inc/jni_string.h | 31 +- .../java/jni/jniutil/inc/jni_things_manager_jvm.h | 44 +- .../sdk/java/jni/jniutil/src/jni_getter.cpp | 5 +- .../sdk/java/jni/jniutil/src/jni_object.cpp | 23 +- .../sdk/java/jni/jniutil/src/jni_setter.cpp | 8 +- .../sdk/java/jni/jniutil/src/jni_string.cpp | 3 +- .../jni/jniutil/src/jni_things_manager_jvm.cpp | 178 ++-- .../sdk/java/jni/tm/inc/jni_action.h | 35 +- .../sdk/java/jni/tm/inc/jni_action_set.h | 46 +- .../sdk/java/jni/tm/inc/jni_capability.h | 40 +- .../sdk/java/jni/tm/inc/jni_group_manager.h | 171 ++++ .../java/jni/tm/inc/jni_group_manager_callbacks.h | 110 +++ .../java/jni/tm/inc/jni_group_synchronization.h | 156 +++ .../tm/inc/jni_group_synchronization_callbacks.h | 52 + .../sdk/java/jni/tm/inc/jni_things_configuration.h | 104 ++ .../tm/inc/jni_things_configuration_callbacks.h | 95 ++ .../sdk/java/jni/tm/inc/jni_things_maintenance.h | 81 ++ .../jni/tm/inc/jni_things_maintenance_callbacks.h | 83 ++ .../sdk/java/jni/tm/inc/jni_things_manager.h | 372 ------- .../java/jni/tm/inc/jni_things_manager_callbacks.h | 208 ---- .../sdk/java/jni/tm/inc/jni_things_manager_util.h | 56 +- .../sdk/java/jni/tm/src/jni_action.cpp | 8 +- .../sdk/java/jni/tm/src/jni_action_set.cpp | 4 +- .../sdk/java/jni/tm/src/jni_capability.cpp | 4 +- .../sdk/java/jni/tm/src/jni_group_manager.cpp | 456 +++++++++ .../jni/tm/src/jni_group_manager_callbacks.cpp | 335 +++++++ .../java/jni/tm/src/jni_group_synchronization.cpp | 375 ++++++++ .../tm/src/jni_group_synchronization_callbacks.cpp | 106 ++ .../java/jni/tm/src/jni_things_configuration.cpp | 155 +++ .../tm/src/jni_things_configuration_callbacks.cpp | 179 ++++ .../sdk/java/jni/tm/src/jni_things_maintenance.cpp | 123 +++ .../tm/src/jni_things_maintenance_callbacks.cpp | 161 ++++ .../sdk/java/jni/tm/src/jni_things_manager.cpp | 1013 -------------------- .../jni/tm/src/jni_things_manager_callbacks.cpp | 594 ------------ .../java/jni/tm/src/jni_things_manager_util.cpp | 115 ++- .../java/src/org/iotivity/service/tm/Action.java | 18 +- .../src/org/iotivity/service/tm/ActionSet.java | 19 +- .../src/org/iotivity/service/tm/Capability.java | 21 +- .../src/org/iotivity/service/tm/GroupManager.java | 535 +++++++++++ .../iotivity/service/tm/GroupSynchronization.java | 283 ++++++ .../org/iotivity/service/tm/IActionListener.java | 88 -- .../service/tm/IConfigurationListener.java | 60 -- .../iotivity/service/tm/IDiagnosticsListener.java | 51 - .../service/tm/IFindCandidateResourceListener.java | 46 - .../iotivity/service/tm/IFindGroupListener.java | 43 - .../service/tm/ISubscribePresenceListener.java | 42 - .../src/org/iotivity/service/tm/OCStackResult.java | 11 +- .../iotivity/service/tm/ThingsConfiguration.java | 289 ++++++ .../org/iotivity/service/tm/ThingsMaintenance.java | 225 +++++ .../src/org/iotivity/service/tm/ThingsManager.java | 819 ---------------- .../iotivity/service/tm/ThingsManagerCallback.java | 415 -------- .../service/tm/ThingsManagerInterface.java | 652 ------------- .../service/tm/ThingsManagerNativeInterface.java | 362 ------- .../sdk/java/src/org/iotivity/service/tm/Time.java | 32 +- 58 files changed, 4558 insertions(+), 5074 deletions(-) create mode 100644 service/things-manager/sdk/java/jni/tm/inc/jni_group_manager.h create mode 100644 service/things-manager/sdk/java/jni/tm/inc/jni_group_manager_callbacks.h create mode 100644 service/things-manager/sdk/java/jni/tm/inc/jni_group_synchronization.h create mode 100644 service/things-manager/sdk/java/jni/tm/inc/jni_group_synchronization_callbacks.h create mode 100644 service/things-manager/sdk/java/jni/tm/inc/jni_things_configuration.h create mode 100644 service/things-manager/sdk/java/jni/tm/inc/jni_things_configuration_callbacks.h create mode 100644 service/things-manager/sdk/java/jni/tm/inc/jni_things_maintenance.h create mode 100644 service/things-manager/sdk/java/jni/tm/inc/jni_things_maintenance_callbacks.h delete mode 100644 service/things-manager/sdk/java/jni/tm/inc/jni_things_manager.h delete mode 100644 service/things-manager/sdk/java/jni/tm/inc/jni_things_manager_callbacks.h create mode 100644 service/things-manager/sdk/java/jni/tm/src/jni_group_manager.cpp create mode 100644 service/things-manager/sdk/java/jni/tm/src/jni_group_manager_callbacks.cpp create mode 100644 service/things-manager/sdk/java/jni/tm/src/jni_group_synchronization.cpp create mode 100644 service/things-manager/sdk/java/jni/tm/src/jni_group_synchronization_callbacks.cpp create mode 100644 service/things-manager/sdk/java/jni/tm/src/jni_things_configuration.cpp create mode 100644 service/things-manager/sdk/java/jni/tm/src/jni_things_configuration_callbacks.cpp create mode 100644 service/things-manager/sdk/java/jni/tm/src/jni_things_maintenance.cpp create mode 100644 service/things-manager/sdk/java/jni/tm/src/jni_things_maintenance_callbacks.cpp delete mode 100644 service/things-manager/sdk/java/jni/tm/src/jni_things_manager.cpp delete mode 100644 service/things-manager/sdk/java/jni/tm/src/jni_things_manager_callbacks.cpp create mode 100644 service/things-manager/sdk/java/src/org/iotivity/service/tm/GroupManager.java create mode 100644 service/things-manager/sdk/java/src/org/iotivity/service/tm/GroupSynchronization.java delete mode 100644 service/things-manager/sdk/java/src/org/iotivity/service/tm/IActionListener.java delete mode 100644 service/things-manager/sdk/java/src/org/iotivity/service/tm/IConfigurationListener.java delete mode 100644 service/things-manager/sdk/java/src/org/iotivity/service/tm/IDiagnosticsListener.java delete mode 100644 service/things-manager/sdk/java/src/org/iotivity/service/tm/IFindCandidateResourceListener.java delete mode 100644 service/things-manager/sdk/java/src/org/iotivity/service/tm/IFindGroupListener.java delete mode 100644 service/things-manager/sdk/java/src/org/iotivity/service/tm/ISubscribePresenceListener.java create mode 100644 service/things-manager/sdk/java/src/org/iotivity/service/tm/ThingsConfiguration.java create mode 100644 service/things-manager/sdk/java/src/org/iotivity/service/tm/ThingsMaintenance.java delete mode 100644 service/things-manager/sdk/java/src/org/iotivity/service/tm/ThingsManager.java delete mode 100644 service/things-manager/sdk/java/src/org/iotivity/service/tm/ThingsManagerCallback.java delete mode 100644 service/things-manager/sdk/java/src/org/iotivity/service/tm/ThingsManagerInterface.java delete mode 100644 service/things-manager/sdk/java/src/org/iotivity/service/tm/ThingsManagerNativeInterface.java diff --git a/service/things-manager/sdk/java/jni/Android.mk b/service/things-manager/sdk/java/jni/Android.mk index 2d17144..8384451 100644 --- a/service/things-manager/sdk/java/jni/Android.mk +++ b/service/things-manager/sdk/java/jni/Android.mk @@ -49,6 +49,7 @@ LOCAL_MODULE := things-manager-jni LOCAL_C_INCLUDES := $(LOCAL_PATH)/jniutil/inc \ $(OIC_SRC_DIR)/android/android_api/base/jni \ $(OIC_SRC_DIR)/resource/include \ + $(OIC_SRC_DIR)/resource/c_common \ $(OIC_SRC_DIR)/resource/csdk/stack/include \ $(OIC_SRC_DIR)/resource/oc_logger/include \ $(OIC_SRC_DIR)/extlibs/boost/boost_1_58_0 \ diff --git a/service/things-manager/sdk/java/jni/jniutil/inc/jni_getter.h b/service/things-manager/sdk/java/jni/jniutil/inc/jni_getter.h index 4a6ff39..ad42d77 100644 --- a/service/things-manager/sdk/java/jni/jniutil/inc/jni_getter.h +++ b/service/things-manager/sdk/java/jni/jniutil/inc/jni_getter.h @@ -1,4 +1,4 @@ -/****************************************************************** +/* ***************************************************************** * * Copyright 2015 Samsung Electronics All Rights Reserved. * @@ -19,29 +19,25 @@ ******************************************************************/ /** - * @file jni_getter.h - * - * @brief This file contains the JGetter class declarations and its functions required - * for getting and setting basic data types in C++ and Java + * @file + * This file contains the JGetter class declarations and its functions required + * for getting and setting basic data types in C++ and Java. */ -#ifndef __JNI_GETTER_H_ -#define __JNI_GETTER_H_ - +#ifndef JNI_GETTER_H_ +#define JNI_GETTER_H_ #include #include /** - * @class JGetter - * @brief This class provide utility for get/set basic data types in C++ and Java - * + * This class provide utility for get/set basic data types in C++ and Java. */ class JGetter { public: /** - * This function is called to get String field from the C++ object + * This function is called to get String field from the C++ object. * * @param env * JNI Environment reference @@ -58,7 +54,7 @@ class JGetter std::string &value); /** - * This function is called to get Boolean field from the C++ object + * This function is called to get Boolean field from the C++ object. * * @param env * JNI Environment reference @@ -75,7 +71,7 @@ class JGetter bool &value); /** - * This function is called to get Integer field from the C++ object + * This function is called to get Integer field from the C++ object. * * @param env * JNI Environment reference @@ -91,7 +87,7 @@ class JGetter static bool getJIntField(JNIEnv *env, jobject &object, const char *fieldName, int &value); /** - * This function is called to get Object reference from the C++ object + * This function is called to get Object reference from the C++ object. * * @param env * JNI Environment reference @@ -104,9 +100,9 @@ class JGetter * @param value * reference to Object reference mentioned in fieldName * - * @return returns true on success and false on failer. + * @return returns true on success and false on failure */ static bool getJObjectField(JNIEnv *env, jobject &object, const char *fieldName, const char *fieldType, jobject &value); }; -#endif //__JNI_GETTER_H_ \ No newline at end of file +#endif //JNI_GETTER_H_ diff --git a/service/things-manager/sdk/java/jni/jniutil/inc/jni_object.h b/service/things-manager/sdk/java/jni/jniutil/inc/jni_object.h index b1a5f7f..3ec8cce 100644 --- a/service/things-manager/sdk/java/jni/jniutil/inc/jni_object.h +++ b/service/things-manager/sdk/java/jni/jniutil/inc/jni_object.h @@ -1,4 +1,4 @@ -/****************************************************************** +/* ***************************************************************** * * Copyright 2015 Samsung Electronics All Rights Reserved. * @@ -19,45 +19,40 @@ ******************************************************************/ /** - * @file jni_object.h - * - * @brief This file contains the JObject class declarations and its functions required - * for getting and setting basic data types in C++ and Java + * @file + * This file contains the JObject class declarations and its functions required + * for getting and setting basic data types in C++ and Java. */ -#ifndef __JNI_OBJECT_H_ -#define __JNI_OBJECT_H_ - +#ifndef JNI_OBJECT_H_ +#define JNI_OBJECT_H_ #include #include "JniOcResource.h" /** - * @class JObject - * @brief This class provides a set of functions for JNI object. - * + * This class provides a set of functions for JNI object. */ class JObject { public: /** - * @brief constructor + * constructor */ JObject(JNIEnv *env); /** - * @brief constructor + * constructor */ JObject(JNIEnv *env, jobject obj); /** - * @brief constructor + * constructor */ JObject(JNIEnv *env, const char *classPath); /** - * @brief destructor - * + * destructor */ virtual ~JObject(); @@ -65,15 +60,11 @@ class JObject * Function to get the jobject. * * @return jobject, returns a new JNI object or NULL otherwise. - * */ virtual jobject getObject() const; /** * Function to detach the jobject. - * - * @return void - * */ void detachObject(); @@ -91,8 +82,8 @@ class JObject */ jclass m_pClazz; /** - * Boolean variable to check if an object is new + * Boolean variable to check if an object is new. */ bool m_fIsNewObject; }; -#endif //__JNI_OBJECT_H_ \ No newline at end of file +#endif //JNI_OBJECT_H_ diff --git a/service/things-manager/sdk/java/jni/jniutil/inc/jni_setter.h b/service/things-manager/sdk/java/jni/jniutil/inc/jni_setter.h index 3d58cfd..a8d536d 100644 --- a/service/things-manager/sdk/java/jni/jniutil/inc/jni_setter.h +++ b/service/things-manager/sdk/java/jni/jniutil/inc/jni_setter.h @@ -1,4 +1,4 @@ -/****************************************************************** +/* ***************************************************************** * * Copyright 2015 Samsung Electronics All Rights Reserved. * @@ -19,22 +19,18 @@ ******************************************************************/ /** - * @file jni_setter.h - * - * @brief This file contains the JSetter class declarations and and its functions required - * to set data types in C++ object from Java object -*/ - -#ifndef __JNI_SETTER_H_ -#define __JNI_SETTER_H_ + * @file + * This file contains the JSetter class declarations and and its functions required + * to set data types in C++ object from Java object. + */ +#ifndef JNI_SETTER_H_ +#define JNI_SETTER_H_ #include /** - * @class JSetter - * @brief This class provide utility to set data types in C++ object from Java object - * + * This class provide utility to set data types in C++ object from Java object. */ class JSetter { @@ -74,7 +70,7 @@ class JSetter jlong value); /** - * This function is called to Set Boolean field to C++ object + * This function is called to Set Boolean field to C++ object. * * @param env * JNI Environment reference @@ -89,7 +85,7 @@ class JSetter */ static bool setJBoolField(JNIEnv *env, jobject &object, const char *fieldName, bool value); /** - * This function is called to Set String field from the C++ object + * This function is called to Set String field from the C++ object. * * @param env * JNI Environment reference @@ -125,4 +121,4 @@ class JSetter const char *fieldType, const jobject value); }; -#endif //__JNI_SETTER_H_ \ No newline at end of file +#endif //JNI_SETTER_H_ diff --git a/service/things-manager/sdk/java/jni/jniutil/inc/jni_string.h b/service/things-manager/sdk/java/jni/jniutil/inc/jni_string.h index ed1c102..c184a0f 100644 --- a/service/things-manager/sdk/java/jni/jniutil/inc/jni_string.h +++ b/service/things-manager/sdk/java/jni/jniutil/inc/jni_string.h @@ -1,4 +1,4 @@ -/****************************************************************** +/* ***************************************************************** * * Copyright 2015 Samsung Electronics All Rights Reserved. * @@ -19,42 +19,37 @@ ******************************************************************/ /** - * @file jni_string.h - * - * @brief This file contains the declaration of JString class and its members related to JString. - * -*/ - -#ifndef __JNI_STRING_H_ -#define __JNI_STRING_H_ + * @file + * This file contains the declaration of JString class and its members related to JString. + */ +#ifndef JNI_STRING_H_ +#define JNI_STRING_H_ #include #include "jni_object.h" /** - * @class JString - * @brief This class inherits JObject class and provides a set of functions for JNI String. - * + * This class inherits JObject class and provides a set of functions for JNI String. */ class JString : public JObject { public: /** - * @brief constructor + * constructor */ JString(JNIEnv *env, jstring value); /** - * @brief constructor + * constructor */ JString(JNIEnv *env, const char *value); /** - * @brief constructor + * constructor */ JString(JNIEnv *env, const std::string &value); /** - * @brief destructor + * destructor */ ~JString(); @@ -64,7 +59,6 @@ class JString : public JObject * @param value - String value to set to a private member variable. * * @return bool - true on success - * */ bool getValue(std::string &value); @@ -72,11 +66,10 @@ class JString : public JObject * Function to get the private string value. * * @return C String value. - * */ const char *c_str(); private: std::string m_cstr; }; -#endif //__JNI_STRING_H_ +#endif //JNI_STRING_H_ diff --git a/service/things-manager/sdk/java/jni/jniutil/inc/jni_things_manager_jvm.h b/service/things-manager/sdk/java/jni/jniutil/inc/jni_things_manager_jvm.h index 8caa476..0a1138e 100644 --- a/service/things-manager/sdk/java/jni/jniutil/inc/jni_things_manager_jvm.h +++ b/service/things-manager/sdk/java/jni/jniutil/inc/jni_things_manager_jvm.h @@ -1,4 +1,4 @@ -/****************************************************************** +/* ***************************************************************** * * Copyright 2015 Samsung Electronics All Rights Reserved. * @@ -19,25 +19,29 @@ ******************************************************************/ /** - * @file jni_things_manager_jvm.h - * - * @brief This file contains the essential declarations and functions required - * for JNI implementation + * @file + * This file contains the essential declarations and functions required + * for JNI implementation. */ -#ifndef __JNI_THINGS_MANAGER_JVM_H_ -#define __JNI_THINGS_MANAGER_JVM_H_ - +#ifndef JNI_THINGS_MANAGER_JVM_H_ +#define JNI_THINGS_MANAGER_JVM_H_ #include #include #include -#define TM_SERVICE_NATIVE_API_CLASS_PATH "org/iotivity/service/tm/ThingsManagerNativeInterface" -#define TM_SERVICE_NATIVE_API_CLASS_TYPE "Lorg/iotivity/service/tm/ThingsManagerNativeInterface;" +#define TM_SERVICE_GROUP_MANAGER_CLASS_PATH "org/iotivity/service/tm/GroupManager" +#define TM_SERVICE_GROUP_MANAGER_CLASS_TYPE "Lorg/iotivity/service/tm/GroupManager;" + +#define TM_SERVICE_GROUP_SYNCHRONIZATION_CLASS_PATH "org/iotivity/service/tm/GroupSynchronization" +#define TM_SERVICE_GROUP_SYNCHRONIZATION_CLASS_TYPE "Lorg/iotivity/service/tm/GroupSynchronization;" -#define TM_SERVICE_CALLBACK_CLASS_PATH "org/iotivity/service/tm/ThingsManagerCallback" -#define TM_SERVICE_CALLBACK_CLASS_TYPE "Lorg/iotivity/service/tm/ThingsManagerCallback;" +#define TM_SERVICE_THINGS_CONFIGURATION_CLASS_PATH "org/iotivity/service/tm/ThingsConfiguration" +#define TM_SERVICE_THINGS_CONFIGURATION_CLASS_TYPE "Lorg/iotivity/service/tm/ThingsConfigurationn;" + +#define TM_SERVICE_THINGS_MAINTENANCE_CLASS_PATH "org/iotivity/service/tm/ThingsMaintenance" +#define TM_SERVICE_THINGS_MAINTENANCE_CLASS_TYPE "Lorg/iotivity/service/tm/ThingsMaintenance;" #define TM_SERVICE_PLATFORM_CLASS_PATH "org/iotivity/base/OcPlatform" #define TM_SERVICE_PLATFORM_CLASS_TYPE "Lorg/iotivity/base/OcPlatform;" @@ -74,25 +78,23 @@ #define TM_JAVA_STRING_TYPE "Ljava/lang/String;" /** - * @class ThingsManagerJVM - * @brief This class provides functions related to JNI Environment. - * + * This class provides functions related to JNI Environment. */ class ThingsManagerJVM { public: /** - * @brief destructor + * destructor */ ~ThingsManagerJVM() {}; /** - * @brief Get JVM instance + * Get JVM instance */ static JNIEnv *getEnv(); /** - * @brief Release aquired JVM instance + * Release aquired JVM instance. */ static void releaseEnv(); @@ -104,12 +106,12 @@ class ThingsManagerJVM private: /** - * @brief constructor + * constructor */ ThingsManagerJVM(); /** - * Mutex for thread synchronization + * Mutex for thread synchronization. */ static std::mutex m_currentThreadMutex; }; @@ -122,4 +124,4 @@ jobject GetJObjectInstance(const char *szClassPath); #ifdef __cplusplus } #endif -#endif //__JNI_THINGS_MANAGER_JVM_H_ \ No newline at end of file +#endif //JNI_THINGS_MANAGER_JVM_H_ diff --git a/service/things-manager/sdk/java/jni/jniutil/src/jni_getter.cpp b/service/things-manager/sdk/java/jni/jniutil/src/jni_getter.cpp index 7021905..8f269f7 100644 --- a/service/things-manager/sdk/java/jni/jniutil/src/jni_getter.cpp +++ b/service/things-manager/sdk/java/jni/jniutil/src/jni_getter.cpp @@ -1,4 +1,4 @@ -/****************************************************************** +/* ***************************************************************** * * Copyright 2015 Samsung Electronics All Rights Reserved. * @@ -17,6 +17,7 @@ * limitations under the License. * ******************************************************************/ + #include "jni_getter.h" #include @@ -25,7 +26,6 @@ #define LOG_TAG "TM_JGetter" - bool JGetter::getJStringField(JNIEnv *env, jobject &object, const char *fieldName, std::string &value) { @@ -77,7 +77,6 @@ bool JGetter::getJStringField(JNIEnv *env, jobject &object, const char *fieldNam return true; } - bool JGetter::getJBoolField(JNIEnv *env, jobject &object, const char *fieldName, bool &value) { if (NULL == env || diff --git a/service/things-manager/sdk/java/jni/jniutil/src/jni_object.cpp b/service/things-manager/sdk/java/jni/jniutil/src/jni_object.cpp index 94a7b27..9da4ece 100644 --- a/service/things-manager/sdk/java/jni/jniutil/src/jni_object.cpp +++ b/service/things-manager/sdk/java/jni/jniutil/src/jni_object.cpp @@ -1,10 +1,27 @@ +/* ***************************************************************** + * + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ + #include "jni_object.h" -//#define NULL 0 #define LOG_TAG "TM_JObject" - - JObject::JObject(JNIEnv *env) : m_pEnv( env ), m_pObject(NULL), m_pClazz( NULL ), diff --git a/service/things-manager/sdk/java/jni/jniutil/src/jni_setter.cpp b/service/things-manager/sdk/java/jni/jniutil/src/jni_setter.cpp index ee23c1d..be8adad 100644 --- a/service/things-manager/sdk/java/jni/jniutil/src/jni_setter.cpp +++ b/service/things-manager/sdk/java/jni/jniutil/src/jni_setter.cpp @@ -1,4 +1,4 @@ -/****************************************************************** +/* ***************************************************************** * * Copyright 2015 Samsung Electronics All Rights Reserved. * @@ -17,6 +17,7 @@ * limitations under the License. * ******************************************************************/ + #include "jni_setter.h" #include @@ -25,7 +26,6 @@ #define LOG_TAG "TM_JSetter" - bool JSetter::setJStringField(JNIEnv *env, jobject &object, const char *fieldName, const char *value) { @@ -76,7 +76,6 @@ bool JSetter::setJStringField(JNIEnv *env, jobject &object, const char *fieldNam return true; } - bool JSetter::setJIntField(JNIEnv *env, jobject &object, const char *fieldName, int value) { if (NULL == env || NULL == fieldName) @@ -106,7 +105,6 @@ bool JSetter::setJIntField(JNIEnv *env, jobject &object, const char *fieldName, return true; } - bool JSetter::setJLongField(JNIEnv *env, jobject &object, const char *fieldName, jlong value) { if (NULL == env || NULL == fieldName) @@ -136,7 +134,6 @@ bool JSetter::setJLongField(JNIEnv *env, jobject &object, const char *fieldName, return true; } - bool JSetter::setJBoolField(JNIEnv *env, jobject &object, const char *fieldName, bool value) { if (NULL == env || NULL == fieldName) @@ -166,7 +163,6 @@ bool JSetter::setJBoolField(JNIEnv *env, jobject &object, const char *fieldName, return true; } - bool JSetter::setJObjectField(JNIEnv *env, jobject &object, const char *fieldName, const char *fieldType, const jobject value) { diff --git a/service/things-manager/sdk/java/jni/jniutil/src/jni_string.cpp b/service/things-manager/sdk/java/jni/jniutil/src/jni_string.cpp index 7710507..8e95410 100644 --- a/service/things-manager/sdk/java/jni/jniutil/src/jni_string.cpp +++ b/service/things-manager/sdk/java/jni/jniutil/src/jni_string.cpp @@ -1,4 +1,4 @@ -/****************************************************************** +/* ***************************************************************** * * Copyright 2015 Samsung Electronics All Rights Reserved. * @@ -17,6 +17,7 @@ * limitations under the License. * ******************************************************************/ + #include "jni_string.h" #define LOG_TAG "TM_JString" diff --git a/service/things-manager/sdk/java/jni/jniutil/src/jni_things_manager_jvm.cpp b/service/things-manager/sdk/java/jni/jniutil/src/jni_things_manager_jvm.cpp index f0b69e7..6d85966 100644 --- a/service/things-manager/sdk/java/jni/jniutil/src/jni_things_manager_jvm.cpp +++ b/service/things-manager/sdk/java/jni/jniutil/src/jni_things_manager_jvm.cpp @@ -1,4 +1,4 @@ -/****************************************************************** +/* ***************************************************************** * * Copyright 2015 Samsung Electronics All Rights Reserved. * @@ -17,34 +17,37 @@ * limitations under the License. * ******************************************************************/ -#include "jni_things_manager_jvm.h" + #include -#include "jni_things_manager.h" + +#include "jni_things_manager_jvm.h" +#include "jni_group_manager.h" +#include "jni_group_synchronization.h" +#include "jni_things_configuration.h" +#include "jni_things_maintenance.h" #include "jni_things_manager_util.h" #include "JniOcResource.h" #define TM_ERROR_JNI_FOUND_CLASS_FAILED -2005 /** - * @class JClassMap - * @brief This class provides functions for initializing the Java class path and Java class. - * + * This class provides functions for initializing the Java class path and Java class. */ class JClassMap { public: /** - * Java Class - */ + * Java Class + */ jclass classRef; /** - * Java Class Path - */ + * Java Class Path + */ const char *szClassPath; /** - * @brief constructor - */ + * constructor + */ JClassMap(const char *path) : classRef(NULL) { @@ -53,26 +56,24 @@ class JClassMap }; /** - * @class JObjectMap - * @brief This class provides functins for initializing the Java Class path and Java Class - * Object. - * + * This class provides functions for initializing the Java Class path + * and Java Class Object. */ class JObjectMap { public: /** - * Java Object - */ + * Java Object + */ jobject object; /** - * Java Class Path - */ + * Java Class Path + */ const char *szClassPath; /** - * @brief constructor - */ + * @brief constructor + */ JObjectMap(const char *path) : object(NULL) { @@ -82,8 +83,10 @@ class JObjectMap static JClassMap gJClassMapArray[] = { - JClassMap(TM_SERVICE_NATIVE_API_CLASS_PATH), - JClassMap(TM_SERVICE_CALLBACK_CLASS_PATH), + JClassMap(TM_SERVICE_GROUP_MANAGER_CLASS_PATH), + JClassMap(TM_SERVICE_GROUP_SYNCHRONIZATION_CLASS_PATH), + JClassMap(TM_SERVICE_THINGS_CONFIGURATION_CLASS_PATH), + JClassMap(TM_SERVICE_THINGS_MAINTENANCE_CLASS_PATH), JClassMap(TM_SERVICE_OCRESOURCE_PATH), JClassMap(TM_SERVICE_OCREPRESENTATION_PATH), JClassMap(TM_SERVICE_HEADER_OPTION_PATH), @@ -97,38 +100,64 @@ static JClassMap gJClassMapArray[] = static JObjectMap gJObjectMapArray[] = { - JObjectMap(TM_SERVICE_CALLBACK_CLASS_PATH) + JObjectMap(TM_SERVICE_GROUP_SYNCHRONIZATION_CLASS_PATH), + JObjectMap(TM_SERVICE_THINGS_CONFIGURATION_CLASS_PATH), + JObjectMap(TM_SERVICE_THINGS_MAINTENANCE_CLASS_PATH) +}; + +static JNINativeMethod gGroupManagerMethodTable[] = +{ + { "nativeFindCandidateResource", "(Ljava/util/Vector;I)I", (void *) JNIGroupManagerFindCandidateResource}, + { "nativeSubscribeCollectionPresence", "(Lorg/iotivity/base/OcResource;)I", (void *) JNIGroupManagerSubscribeCollectionPresence}, + { "nativeBindResourceToGroup", "(Lorg/iotivity/base/OcResource;Lorg/iotivity/base/OcResourceHandle;)Lorg/iotivity/base/OcResourceHandle;", (void *) JNIGroupManagerBindResourceToGroup}, + { "nativeAddActionSet", "(Lorg/iotivity/base/OcResource;Lorg/iotivity/service/tm/ActionSet;)I", (void *) JNIGroupManagerAddActionSet}, + { "nativeExecuteActionSet", "(Lorg/iotivity/base/OcResource;Ljava/lang/String;)I", (void *) JNIGroupManagerExecuteActionSet}, + { "nativeExecuteActionSetWithDelay", "(Lorg/iotivity/base/OcResource;Ljava/lang/String;J)I", (void *) JNIGroupManagerExecuteActionSetWithDelay}, + { "nativeCancelActionSet", "(Lorg/iotivity/base/OcResource;Ljava/lang/String;)I", (void *) JNIGroupManagerCancelActionSet}, + { "nativeGetActionSet", "(Lorg/iotivity/base/OcResource;Ljava/lang/String;)I", (void *) JNIGroupManagerGetActionSet}, + { "nativeDeleteActionSet", "(Lorg/iotivity/base/OcResource;Ljava/lang/String;)I", (void *) JNIGroupManagerDeleteActionSet} +}; + +static JNINativeMethod gGroupSynchronizationMethodTable[] = +{ + { "nativeFindGroup", "(Ljava/util/Vector;)I", (void *) JNIGroupSynchronizationFindGroup}, + { "nativeCreateGroup", "(Ljava/lang/String;)I", (void *) JNIGroupSynchronizationCreateGroup}, + { "nativeJoinGroupString", "(Ljava/lang/String;Lorg/iotivity/base/OcResourceHandle;)I", (void *) JNIGroupSynchronizationJoinGroupString}, + { "nativeJoinGroupObject", "(Lorg/iotivity/base/OcResource;Lorg/iotivity/base/OcResourceHandle;)I", (void *) JNIGroupSynchronizationJoinGroupObject}, + { "nativeLeaveGroup", "(Ljava/lang/String;Lorg/iotivity/base/OcResourceHandle;)I", (void *) JNIGroupSynchronizationLeaveGroup}, + { "nativeLeaveGroupForResource", "(Lorg/iotivity/base/OcResource;Ljava/lang/String;Lorg/iotivity/base/OcResourceHandle;)I", (void *) JNIGroupSynchronizationLeaveGroupForResource}, + { "nativeDeleteGroup", "(Ljava/lang/String;)V", (void *) JNIGroupSynchronizationDeleteGroup}, + { "nativeGetGroupList", "()Ljava/util/Map;", (void *) JNIGroupSynchronizationGetGroupList} +}; + +static JNINativeMethod gThingsConfigurationMethodTable[] = +{ + { "nativeUpdateConfigurations", "(Lorg/iotivity/base/OcResource;Ljava/util/Map;)I", (void *) JNIThingsConfigurationUpdateConfigurations}, + { "nativeGetConfigurations", "(Lorg/iotivity/base/OcResource;Ljava/util/Vector;)I", (void *) JNIThingsConfigurationGetConfigurations}, + { "nativeGetListOfSupportedConfigurationUnits", "()Ljava/lang/String;", (void *) JNIThingsConfigurationGetListOfSupportedConfigurationUnits}, + { "nativeDoBootstrap", "()I", (void *) JNIThingsConfigurationDoBootstrap}, }; -static JNINativeMethod gThingsManagerMethodTable[] = +static JNINativeMethod gThingsMaintenanceMethodTable[] = { - { "findCandidateResources", "(Ljava/util/Vector;I)I", (void *) JNIThingsManagerFindCandidateResource}, - { "subscribeCollectionPresence", "(Lorg/iotivity/base/OcResource;)I", (void *) JNIThingsManagerSubscribeCollectionPresence}, - { "bindResourceToGroup", "(Lorg/iotivity/base/OcResource;Lorg/iotivity/base/OcResourceHandle;)Lorg/iotivity/base/OcResourceHandle;", (void *) JNIThingsManagerBindResourceToGroup}, - { "findGroup", "(Ljava/util/Vector;)I", (void *) JNIThingsManagerFindGroup}, - { "createGroup", "(Ljava/lang/String;)I", (void *) JNIThingsManagerCreateGroup}, - { "joinGroup", "(Ljava/lang/String;Lorg/iotivity/base/OcResourceHandle;)I", (void *) JNIThingsManagerJoinGroupString}, - { "joinGroup", "(Lorg/iotivity/base/OcResource;Lorg/iotivity/base/OcResourceHandle;)I", (void *) JNIThingsManagerJoinGroupObject}, - { "leaveGroup", "(Ljava/lang/String;Lorg/iotivity/base/OcResourceHandle;)I", (void *) JNIThingsManagerLeaveGroup}, - { "leaveGroup", "(Lorg/iotivity/base/OcResource;Ljava/lang/String;Lorg/iotivity/base/OcResourceHandle;)I", (void *) JNIThingsManagerLeaveGroupForResource}, - { "deleteGroup", "(Ljava/lang/String;)V", (void *) JNIThingsManagerDeleteGroup}, - { "getGroupList", "()Ljava/util/Map;", (void *) JNIThingsManagerGetGroupList}, - { "updateConfigurations", "(Lorg/iotivity/base/OcResource;Ljava/util/Map;)I", (void *) JNIThingsManagerUpdateConfigurations}, - { "getConfigurations", "(Lorg/iotivity/base/OcResource;Ljava/util/Vector;)I", (void *) JNIThingsManagerGetConfigurations}, - { "getListOfSupportedConfigurationUnits", "()Ljava/lang/String;", (void *) JNIThingsManagerGetListOfSupportedConfigurationUnits}, - { "doBootstrap", "()I", (void *) JNIThingsManagerDoBootstrap}, - { "reboot", "(Lorg/iotivity/base/OcResource;)I", (void *) JNIThingsManagerReboot}, - { "factoryReset", "(Lorg/iotivity/base/OcResource;)I", (void *) JNIThingsManagerFactoryReset}, - { "addActionSet", "(Lorg/iotivity/base/OcResource;Lorg/iotivity/service/tm/ActionSet;)I", (void *) JNIThingsManagerAddActionSet}, - { "executeActionSet", "(Lorg/iotivity/base/OcResource;Ljava/lang/String;)I", (void *) JNIThingsManagerExecuteActionSet}, - { "executeActionSet", "(Lorg/iotivity/base/OcResource;Ljava/lang/String;J)I", (void *) JNIThingsManagerExecuteActionSetWithDelay}, - { "cancelActionSet", "(Lorg/iotivity/base/OcResource;Ljava/lang/String;)I", (void *) JNIThingsManagerCancelActionSet}, - { "getActionSet", "(Lorg/iotivity/base/OcResource;Ljava/lang/String;)I", (void *) JNIThingsManagerGetActionSet}, - { "deleteActionSet", "(Lorg/iotivity/base/OcResource;Ljava/lang/String;)I", (void *) JNIThingsManagerDeleteActionSet}, + { "nativeReboot", "(Lorg/iotivity/base/OcResource;)I", (void *) JNIThingsMaintenanceReboot}, + { "nativeFactoryReset", "(Lorg/iotivity/base/OcResource;)I", (void *) JNIThingsMaintenanceFactoryReset}, + { "nativeGetListOfSupportedMaintenanceUnits", "()Ljava/lang/String;", (void *) JNIThingsMaintenanceGetListOfSupportedConfigurationUnits} + }; -static int gThingsManagerMethodTableSize = sizeof(gThingsManagerMethodTable) / sizeof( - gThingsManagerMethodTable[0]); +static int gGroupManagerMethodTableSize = sizeof(gGroupManagerMethodTable) / sizeof( + gGroupManagerMethodTable[0]); + +static int gGroupSynchronizationMethodTableSize = sizeof(gGroupSynchronizationMethodTable) / sizeof( + gGroupSynchronizationMethodTable[0]); + + +static int gThingsConfigurationMethodTableSize = sizeof(gThingsConfigurationMethodTable) / sizeof( + gThingsConfigurationMethodTable[0]); + +static int gThingsMaintenanceMethodTableSize = sizeof(gThingsMaintenanceMethodTable) / sizeof( + gThingsMaintenanceMethodTable[0]); int InitializeJClassMapArray(JNIEnv *env) @@ -346,14 +375,53 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) return JNI_ERR; } - jclass thingsManagerClassRef = GetJClass(TM_SERVICE_NATIVE_API_CLASS_PATH); - if (NULL == thingsManagerClassRef) + // Group Manager + jclass groupManagerClassRef = GetJClass(TM_SERVICE_GROUP_MANAGER_CLASS_PATH); + + if (NULL == groupManagerClassRef) { LOGE("JNI_OnLoad: GetJClass gThingsManagerClass failed !"); return JNI_ERR; } - env->RegisterNatives(thingsManagerClassRef, gThingsManagerMethodTable, - gThingsManagerMethodTableSize); + + env->RegisterNatives(groupManagerClassRef, gGroupManagerMethodTable, + gGroupManagerMethodTableSize); + + // Group Synchronization + jclass groupSynchronizationClassRef = GetJClass(TM_SERVICE_GROUP_SYNCHRONIZATION_CLASS_PATH); + + if (NULL == groupSynchronizationClassRef) + { + LOGE("JNI_OnLoad: GetJClass gThingsManagerClass failed !"); + return JNI_ERR; + } + + env->RegisterNatives(groupSynchronizationClassRef, gGroupSynchronizationMethodTable, + gGroupSynchronizationMethodTableSize); + + //Things Configuration + jclass thingsConfigurationClassRef = GetJClass(TM_SERVICE_THINGS_CONFIGURATION_CLASS_PATH); + + if (NULL == thingsConfigurationClassRef) + { + LOGE("JNI_OnLoad: GetJClass gThingsManagerClass failed !"); + return JNI_ERR; + } + + env->RegisterNatives(thingsConfigurationClassRef, gThingsConfigurationMethodTable, + gThingsConfigurationMethodTableSize); + + //Things Maintenance + jclass thingsMaintenanceClassRef = GetJClass(TM_SERVICE_THINGS_MAINTENANCE_CLASS_PATH); + + if (NULL == thingsMaintenanceClassRef) + { + LOGE("JNI_OnLoad: GetJClass gThingsManagerClass failed !"); + return JNI_ERR; + } + + env->RegisterNatives(thingsMaintenanceClassRef, gThingsMaintenanceMethodTable, + gThingsMaintenanceMethodTableSize); ThingsManagerJVM::m_jvm = vm; diff --git a/service/things-manager/sdk/java/jni/tm/inc/jni_action.h b/service/things-manager/sdk/java/jni/tm/inc/jni_action.h index e26ab83..536c41a 100644 --- a/service/things-manager/sdk/java/jni/tm/inc/jni_action.h +++ b/service/things-manager/sdk/java/jni/tm/inc/jni_action.h @@ -1,4 +1,4 @@ -/****************************************************************** +/* ***************************************************************** * * Copyright 2015 Samsung Electronics All Rights Reserved. * @@ -19,14 +19,13 @@ ******************************************************************/ /** - * @file jni_action.h - * - * @brief This file contains the declaration of JniAction class and its members related to JniAction. + * @file + * This file contains the declaration of JniAction class and + * its members related to JniAction. */ -#ifndef __JNI_ACTION_H_ -#define __JNI_ACTION_H_ - +#ifndef JNI_ACTION_H_ +#define JNI_ACTION_H_ #include #include @@ -35,51 +34,47 @@ #include "jni_capability.h" /** - * @class JniAction - * @brief This class provides a set of functions to get and set Action Class member variables - * + * This class provides a set of functions to get and + * set Action Class member variables. */ class JniAction : public JObject { public: /** - * @brief constructor + * constructor */ JniAction(JNIEnv *env, jobject obj); /** - * @brief constructor + * constructor */ JniAction(JNIEnv *env); /** - * @brief destructor - * + * destructor */ ~JniAction(); /** - * Retrieves target value from JniAction class object + * Retrieves target value from JniAction class object. * * @param target - target value * * @return Boolean, true on success, otherwise false - * */ bool getTarget(std::string &target); /** - * Sets target value of JniAction class object + * Sets target value of JniAction class object. * * @param target - target value * * @return Boolean, true on success, otherwise false - * */ bool setTarget(const std::string target); /** - * Retrieves capability values from JniAction class object + * Retrieves capability values from JniAction class object. * * @param capabilityList - capability list * @@ -88,4 +83,4 @@ class JniAction : public JObject bool getJniCapabilityValues(std::vector &capabilityList); }; -#endif //__JNI_ACTION_H_ \ No newline at end of file +#endif //JNI_ACTION_H_ diff --git a/service/things-manager/sdk/java/jni/tm/inc/jni_action_set.h b/service/things-manager/sdk/java/jni/tm/inc/jni_action_set.h index 07afd7c..d239cd6 100644 --- a/service/things-manager/sdk/java/jni/tm/inc/jni_action_set.h +++ b/service/things-manager/sdk/java/jni/tm/inc/jni_action_set.h @@ -1,4 +1,4 @@ -/****************************************************************** +/* ***************************************************************** * * Copyright 2015 Samsung Electronics All Rights Reserved. * @@ -19,20 +19,18 @@ ******************************************************************/ /** - * @file jni_action_set.h - * - * @brief This file contains the declaration of JniActionSet class - * and its members related to JniActionSet. + * @file + * This file contains the declaration of JniActionSet class + * and its members related to JniActionSet. */ -#ifndef __JNI_ACTIONSET_H_ -#define __JNI_ACTIONSET_H_ - +#ifndef JNI_ACTIONSET_H_ +#define JNI_ACTIONSET_H_ #include #include -#include "ThingsManager.h" +#include "GroupManager.h" #include "ActionSet.h" #include "jni_object.h" #include "jni_action.h" @@ -41,36 +39,33 @@ using namespace OC; using namespace OIC; /** - * @class JniActionSet - * @brief This class provides a set of functions to get and set ActionSet Class member variables - * + * This class provides a set of functions to get and + * set ActionSet Class member variables. */ class JniActionSet : public JObject { public: /** - * @brief constructor + * constructor */ JniActionSet(JNIEnv *env, jobject obj); /** - * @brief constructor + * constructor */ JniActionSet(JNIEnv *env); /** - * @brief destructor - * + * destructor */ ~JniActionSet(); /** - * Retrieves target value from JniActionSet class object + * Retrieves target value from JniActionSet class object. * * @param name - ActionSet Name * * @return Boolean, true on success, otherwise false - * */ bool getJniActionSetName(std::string &name); @@ -80,12 +75,11 @@ class JniActionSet : public JObject * @param name - ActionSet Name * * @return Boolean, true on success, otherwise false - * */ bool setJniActionSetName(const std::string name); /** - * Retrieves capability values from JniActionSet class object + * Retrieves capability values from JniActionSet class object. * * @param actionList - List of Actions * @@ -94,9 +88,9 @@ class JniActionSet : public JObject bool getJniListOfActions(std::vector &actionList); /** - * Converts actionSet class from java to CPP + * Converts actionSet class from java to CPP. * - * @param env - Default JNI Environment Pointer + * @param env - Default JNI Environment Pointer * @param jnewActionSet - action set * * @return OIC CPP ActionSet @@ -104,15 +98,15 @@ class JniActionSet : public JObject ActionSet *getActionSet(JNIEnv *env, jobject jnewActionSet); /** - * Converts Time class from java to CPP + * Converts Time class from java to CPP. * - * @param env - Default JNI Environment Pointer + * @param env - Default JNI Environment Pointer * @param jnewActionSet - Java action set - * @param pActionSet - CPP action set + * @param pActionSet - CPP action set * * @return Boolean, true on success, otherwise false */ bool setTimeInfo(JNIEnv *env, jobject jnewActionSet, OIC::ActionSet *pActionSet); }; -#endif //__JNI_ACTIONSET_H_ +#endif //JNI_ACTIONSET_H_ diff --git a/service/things-manager/sdk/java/jni/tm/inc/jni_capability.h b/service/things-manager/sdk/java/jni/tm/inc/jni_capability.h index c355ec7..c25d77b 100644 --- a/service/things-manager/sdk/java/jni/tm/inc/jni_capability.h +++ b/service/things-manager/sdk/java/jni/tm/inc/jni_capability.h @@ -1,4 +1,4 @@ -/****************************************************************** +/* ***************************************************************** * * Copyright 2015 Samsung Electronics All Rights Reserved. * @@ -19,15 +19,13 @@ ******************************************************************/ /** - * @file jni_capability.h - * - * @brief This file contains the utility functions for conversions from java to CPP - * and viceversa + * @file + * This file contains the utility functions for conversions from java to CPP + * and viceversa. */ -#ifndef __JNI_CAPABILITY_H_ -#define __JNI_CAPABILITY_H_ - +#ifndef JNI_CAPABILITY_H_ +#define JNI_CAPABILITY_H_ #include @@ -35,59 +33,54 @@ #include "jni_object.h" /** - * @class JniCapability - * @brief This class provides a set of functions to get and set Capability Class member variables - * + * This class provides a set of functions to get and + * set Capability Class member variables. */ class JniCapability : public JObject { public: /** - * @brief constructor + * constructor */ JniCapability(JNIEnv *env, jobject obj); /** - * @brief constructor + * constructor */ JniCapability(JNIEnv *env); /** - * @brief destructor - * + * destructor */ ~JniCapability(); /** - * Retrieves Capability value from JniCapability class object + * Retrieves Capability value from JniCapability class object. * * @param capability * [OUT] capability value * * @return Boolean, true on success, otherwise false - * */ bool getJniCapabilityValue(std::string &capability); /** - * Sets Capability value of JniCapability class object + * Sets Capability value of JniCapability class object. * * @param capability * [IN] capability value * * @return Boolean, true on success, otherwise false - * */ bool setJniCapabilityValue(const std::string capability); /** - * Retrieves status of JniCapability class object + * Retrieves status of JniCapability class object. * * @param status * [OUT] status * * @return Boolean, true on success, otherwise false - * */ bool getJniCapabilityStatus(std::string &status); @@ -97,9 +90,8 @@ class JniCapability : public JObject * @param status * [IN] status * - * @return Boolean, true on success, otherwise false - * + * @return Boolean, true on success, otherwise false. */ bool setJniCapabilityStatus(const std::string status); }; -#endif //__JNI_CAPABILITY_H_ \ No newline at end of file +#endif //JNI_CAPABILITY_H_ diff --git a/service/things-manager/sdk/java/jni/tm/inc/jni_group_manager.h b/service/things-manager/sdk/java/jni/tm/inc/jni_group_manager.h new file mode 100644 index 0000000..bab475d --- /dev/null +++ b/service/things-manager/sdk/java/jni/tm/inc/jni_group_manager.h @@ -0,0 +1,171 @@ +/* ***************************************************************** + * + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ + +/** + * @file + * This file contains the declaration of Group Manager APIs + * for JNI implementation. + */ + +#ifndef JNI_GROUP_MANAGER_H_ +#define JNI_GROUP_MANAGER_H_ + +#include +#include + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * API for discoverying candidate resources. + * + * @param resourceTypes - required resource types(called "candidate") + * @param waitSec - Delay time in seconds to add before starting to find the resources in network. + * + * @return OCStackResult - return value of this API. + * It returns OC_STACK_OK if success. + * + * NOTE: OCStackResult is defined in ocstack.h. + */ +JNIEXPORT jint JNICALL JNIGroupManagerFindCandidateResource +(JNIEnv *env, jobject interfaceObject, jobject resourceTypes, jint waitSec); + +/** + * API for subscribing child's state. + * + * @param resource - collection resource for subscribing presence of all child resources. + * + * @return OCStackResult - return value of this API. + * It returns OC_STACK_OK if success. + * + * NOTE: OCStackResult is defined in ocstack.h. + */ +JNIEXPORT jint JNICALL JNIGroupManagerSubscribeCollectionPresence +(JNIEnv *env, jobject interfaceObject, jobject resource); + + +/** + * API for register and bind resource to group. + * + * @param resource - resource for register and bind to group. It has all data. + * @param collectionHandle - collection resource handle. It will be added child resource. + * + * @return childHandle - child resource handle. + * + * NOTE: OCStackResult is defined in ocstack.h. + */ +JNIEXPORT jobject JNICALL JNIGroupManagerBindResourceToGroup +(JNIEnv *env, jobject interfaceObject, jobject resource, jobject collectionHandle); + +/** + * API for adding an Action Set. + * + * @param resource - resource type representing the target group + * @param newActionSet - list of Action Set to be added + * + * @return OCStackResult - return value of this API. + * It returns OC_STACK_OK if success. + * + * NOTE: OCStackResult is defined in ocstack.h. + */ + +JNIEXPORT jint JNICALL JNIGroupManagerAddActionSet +(JNIEnv *env, jobject interfaceObject, jobject resource, jobject newActionSet); + +/** + * API for executing the Action Set. + * + * @param resource - resource type representing the target group + * @param actionSetName - Action Set name for executing the Action set + * + * @return OCStackResult - return value of this API. + * It returns OC_STACK_OK if success. + * + * NOTE: OCStackResult is defined in ocstack.h. + */ +JNIEXPORT jint JNICALL JNIGroupManagerExecuteActionSet +(JNIEnv *env, jobject interfaceObject, jobject resource, jstring actionSetName); + +/** + * API for executing the Action Set. + * + * @param resource - resource type representing the target group + * @param actionSetName - Action Set name for executing the Action set + * @param delay - waiting time for until action set run. + * + * @return OCStackResult - return value of this API. + * It returns OC_STACK_OK if success. + * + * NOTE: OCStackResult is defined in ocstack.h. + */ +JNIEXPORT jint JNICALL JNIGroupManagerExecuteActionSetWithDelay +(JNIEnv *env, jobject interfaceObject, jobject resource, jstring actionSetName, jlong delay); + +/** + * API for cancelling the Action Set. + * + * @param resource - resource type representing the target group + * @param actionSetName - Action Set name for cancelling the Action set + * + * @return OCStackResult - return value of this API. + * It returns OC_STACK_OK if success. + * + * NOTE: OCStackResult is defined in ocstack.h. + */ +JNIEXPORT jint JNICALL JNIGroupManagerCancelActionSet +(JNIEnv *env, jobject interfaceObject, jobject resource, jstring actionSetName); + + +/** + * API for reading the Action Set. + * + * @param resource - resource type representing the target group + * @param actionSetName - Action Set name for reading the Action set + * + * @return OCStackResult - return value of this API. + * It returns OC_STACK_OK if success. + * + * NOTE: OCStackResult is defined in ocstack.h. + */ +JNIEXPORT jint JNICALL JNIGroupManagerGetActionSet +(JNIEnv *env, jobject interfaceObject, jobject resource, jstring actionSetName); + +/** + * API for removing the Action Set. + * + * @param resource - resource type representing the target group + * @param actionSetName - Action Set name for removing the Action set + * + * @return OCStackResult - return value of this API. + * It returns OC_STACK_OK if success. + * + * NOTE: OCStackResult is defined in ocstack.h. + */ +JNIEXPORT jint JNICALL JNIGroupManagerDeleteActionSet +(JNIEnv *env, jobject interfaceObject, jobject resource, jstring actionSetName); + +#ifdef __cplusplus +} +#endif +#endif //JNI_GROUP_MANAGER_H_ diff --git a/service/things-manager/sdk/java/jni/tm/inc/jni_group_manager_callbacks.h b/service/things-manager/sdk/java/jni/tm/inc/jni_group_manager_callbacks.h new file mode 100644 index 0000000..dfece9e --- /dev/null +++ b/service/things-manager/sdk/java/jni/tm/inc/jni_group_manager_callbacks.h @@ -0,0 +1,110 @@ +/* ***************************************************************** + * + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ + +/** + * @file + * This file contains the declaration of GroupManagerCallbacks class + * and its members related to ThingsManagerCallbacks. + */ + +#ifndef JNI_GROUP_MANAGER_CALLBACKS_H_ +#define JNI_GROUP_MANAGER_CALLBACKS_H_ + +#include + +#include "GroupManager.h" + +/** + *This class provides a set of callback functions for group management. + */ +class GroupManagerCallbacks +{ + public: + GroupManagerCallbacks() {} + virtual ~GroupManagerCallbacks() {} + + /** + * This callback method is called when resources are discovered in network. + * + * @param resourceVector - List of resources discovered in the network + */ + static void onFoundCandidateResource(std::vector< std::shared_ptr > + resourceVector); + + /** + * This callback method is called for child resource presence status. + * + * @param resource - URI of resource. + * @param result - error code. + */ + static void onSubscribePresence(std::string resource, OCStackResult result); + + /** + * This callback method is called when a response for the executeActionSet + * or deleteActionSet request just arrives. + * + * @param headerOptions - It comprises of optionID and optionData as members. + * @param rep - Configuration parameters are carried as a pair of attribute key and value + * in a form of OCRepresentation instance. + * @param eCode - error code. + */ + static void onPostResponse(const OC::HeaderOptions &headerOptions, + const OC::OCRepresentation &rep, const int eCode); + + /** + * This callback method is called when a response for the addActionSet request + * just arrives. + * + * @param headerOptions - It comprises of optionID and optionData as members. + * @param rep - Configuration parameters are carried as a pair of attribute key and value + * in a form of OCRepresentation instance. + * @param eCode - error code. + */ + static void onPutResponse(const OC::HeaderOptions &headerOptions, + const OC::OCRepresentation &rep, const int eCode); + + /** + * This callback method is called when a response for the getActionSet request + * just arrives. + * + * @param headerOptions - It comprises of optionID and optionData as members. + * @param rep - Configuration parameters are carried as a pair of attribute key and value + * in a form of OCRepresentation instance. + * @param eCode - error code. + */ + static void onGetResponse(const OC::HeaderOptions &headerOptions, + const OC::OCRepresentation &rep, const int eCode); + + /** + * This method invokes the Callback function with particular name and signature. + * + * @param headerOptions - It comprises of optionID and optionData as members. + * @param rep - Configuration parameters are carried as a pair of attribute key and value + * in a form of OCRepresentation instance. + * @param eCode - error code. + * @param callbackName - callbackName to be invoked. + * @param signature - Signature of the callback method to be called. + */ + static void invokeCallback(const OC::HeaderOptions &headerOptions, + const OC::OCRepresentation &rep, const int eCode, + const char *callbackName, const char *signature); +}; +#endif //JNI_GROUP_MANAGER_CALLBACKS_H_ + diff --git a/service/things-manager/sdk/java/jni/tm/inc/jni_group_synchronization.h b/service/things-manager/sdk/java/jni/tm/inc/jni_group_synchronization.h new file mode 100644 index 0000000..2e5d505 --- /dev/null +++ b/service/things-manager/sdk/java/jni/tm/inc/jni_group_synchronization.h @@ -0,0 +1,156 @@ +/* ***************************************************************** + * + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ + +/** + * @file + * This file contains the declaration of Group Synchronization APIs + * for JNI implementation. + */ + +#ifndef JNI_GROUP_SYNCHRONIZATION_H_ +#define JNI_GROUP_SYNCHRONIZATION_H_ + +#include +#include + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * API for finding a specific remote group when a resource tries to join a group. + * Callback is called when a group is found or not. + * + * @param resourceTypes - resource types of a group to find and join + * + * @return OCStackResult - return value of this API. + * It returns OC_STACK_OK if success. + * + * NOTE: It return OC_STACK ERROR when It was finding a group. + * You should call this api when the group finding process has stopped. + * OCStackResult is defined in ocstack.h. + */ + +JNIEXPORT jint JNICALL JNIGroupSynchronizationFindGroup +(JNIEnv *env, jobject interfaceObject, jobject resourceTypes); + +/** + * API for creating a new group. + * + * @param resourceType - resource type of a group to create + * + * @return OCStackResult - return value of this API. + * It returns OC_STACK_OK if success. + * + * NOTE: OCStackResult is defined in ocstack.h. + */ +JNIEXPORT jint JNICALL JNIGroupSynchronizationCreateGroup +(JNIEnv *env, jobject interfaceObject, jstring resourceType); + +/** + * API for joining a group. This API is used when a resource that has a group tries + * to find a specific remote resource and makes it join a group + * + * @param resourceType - resource type of a group to join. + * @param resourceHandle - resource handle to join a group. + * + * @return OCStackResult - return value of this API. + * It returns OC_STACK_OK if success. + * + * NOTE: If you want to join the resource in the remote(other) process, use the API + * jniThingsManagerJoinGroupObject instead of this. + * OCStackResult is defined in ocstack.h. + */ +JNIEXPORT jint JNICALL JNIGroupSynchronizationJoinGroupString +(JNIEnv *env, jobject interfaceObject, jstring resourceType, jobject resourceHandle); + +/** + * API for joining a group. This API is used when a resource that + * doesn't have a group tries to find and join a specific remote group. + * + * @param resource - group resource pointer to join. + * @param resourceHandle - resource handle to join a group. + * + * @return OCStackResult - return value of this API. + * It returns OC_STACK_OK if success. + * + * NOTE: NOTE: If you want to join the resource in the same process, use the API + * jniThingsManagerJoinGroupString instead of this. + * OCStackResult is defined in ocstack.h. + */ +JNIEXPORT jint JNICALL JNIGroupSynchronizationJoinGroupObject +(JNIEnv *env, jobject interfaceObject, jobject resource, jobject resourceHandle); + +/** + * API for leaving a joined group. + * + * @param resourceType - resource type of a group to leave. + * @param resourceHandle - resource handle to join a group. + * + * @return OCStackResult - return value of this API. + * It returns OC_STACK_OK if success. + * + * NOTE: OCStackResult is defined in ocstack.h. + */ +JNIEXPORT jint JNICALL JNIGroupSynchronizationLeaveGroup +(JNIEnv *env, jobject interfaceObject, jstring resourceType, jobject resourceHandle); + +/** + * API for leaving a joined group. + * + * @param resource - resource of a group to leave. + * @param resourceType - resource type of a group to leave. + * @param resourceHandle - resource handle to join a group. + * + * @return OCStackResult - return value of this API. + * It returns OC_STACK_OK if success. + * + * NOTE: OCStackResult is defined in ocstack.h. + */ +JNIEXPORT jint JNICALL JNIGroupSynchronizationLeaveGroupForResource +(JNIEnv *env, jobject interfaceObject, jobject resource, jstring resourceType, + jobject resourceHandle); + +/** + * API for deleting a group. + * + * @param collectionResourceType - resource type of a group to delete. + * + * @return void + */ +JNIEXPORT void JNICALL JNIGroupSynchronizationDeleteGroup +(JNIEnv *env, jobject interfaceObject, jstring collectionResourceType); + +/** + * API for getting a list of joined groups. + * + * @return std::map - return value of this API. + * It returns group resource type and group resource handle as a map type. + */ +JNIEXPORT jobject JNICALL JNIGroupSynchronizationGetGroupList +(JNIEnv *env, jobject interfaceObject); + +#ifdef __cplusplus +} +#endif +#endif //JNI_GROUP_SYNCHRONIZATION_H_ diff --git a/service/things-manager/sdk/java/jni/tm/inc/jni_group_synchronization_callbacks.h b/service/things-manager/sdk/java/jni/tm/inc/jni_group_synchronization_callbacks.h new file mode 100644 index 0000000..f84d5e3 --- /dev/null +++ b/service/things-manager/sdk/java/jni/tm/inc/jni_group_synchronization_callbacks.h @@ -0,0 +1,52 @@ +/* ***************************************************************** + * + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ + +/** + * @file + * This file contains the declaration of GroupSynchronizationCallbacks class. + */ + +#ifndef JNI_GROUP_SYNCHRONIZATION_CALLBACKS_H_ +#define JNI_GROUP_SYNCHRONIZATION_CALLBACKS_H_ + +#include + +#include "GroupSynchronization.h" + +/** + * This class provides callback function for group Synchronization. + */ +class GroupSynchronizationCallbacks +{ + + public: + GroupSynchronizationCallbacks() {} + virtual ~GroupSynchronizationCallbacks() {} + + /** + * This callback method is called to notify whether group is found or not. + * + * @param resource - Resource URI + */ + static void onFoundGroup(std::shared_ptr resource); + + +}; +#endif //JNI_GROUP_SYNCHRONIZATION_CALLBACKS_H_ diff --git a/service/things-manager/sdk/java/jni/tm/inc/jni_things_configuration.h b/service/things-manager/sdk/java/jni/tm/inc/jni_things_configuration.h new file mode 100644 index 0000000..0447fe3 --- /dev/null +++ b/service/things-manager/sdk/java/jni/tm/inc/jni_things_configuration.h @@ -0,0 +1,104 @@ +/* ***************************************************************** + * + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ + +/** + * @file + * This file contains the declaration of Things Configuration API's + * for JNI implementation. + */ + +#ifndef JNI_THINGS_CONFIGURATION_H_ +#define JNI_THINGS_CONFIGURATION_H_ + +#include +#include + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * API for updating configuration value of multiple things of a target group + * or a single thing. + * Before using the below function, a developer should acquire a resource pointer of + * (collection) resource that he wants to send a request by calling findResource() function + * provided in OCPlatform. And he should also notice a "Configuration Name" term which + * represents a nickname of a target attribute of a resource that he wants to update. + * The base motivation to introduce the term is to avoid a usage of URI to access a resource + * from a developer. Thus, a developer should know which configuration names are supported + * by Things Configuration class and what the configuration name means. + * To get a list of supported configuration names, use getListOfSupportedConfigurationUnits() + * function, which provides the list in JSON format. + * + * @param resource - resource pointer representing the target group or the single thing. + * @param configurations - ConfigurationUnit: a nickname of attribute of target resource + * (e.g., installedlocation, currency, (IP)address) + * Value : a value to be updated + * + * @return OCStackResult - return value of this API. + * It returns OC_STACK_OK if success. + * + * NOTE: OCStackResult is defined in ocstack.h. + */ +JNIEXPORT jint JNICALL JNIThingsConfigurationUpdateConfigurations +(JNIEnv *env, jobject interfaceObject, jobject resource, jobject configurations); + +/** + * API for getting configuration value of multiple things of a target group + * or a single thing. + * + * @param resource - resource pointer representing the target group or the single thing. + * @param configurations - ConfigurationUnit: a nickname of attribute of target resource. + * + * @return OCStackResult - return value of this API. + * It returns OC_STACK_OK if success. + * + * NOTE: OCStackResult is defined in ocstack.h. + */ +JNIEXPORT jint JNICALL JNIThingsConfigurationGetConfigurations +(JNIEnv *env, jobject interfaceObject, jobject resource, jobject configurations); + +/** + * API for showing the list of supported configuration units (configurable parameters). + * + * @return std::string - return value of this API. + * It returns the list in JSON format + */ +JNIEXPORT jstring JNICALL JNIThingsConfigurationGetListOfSupportedConfigurationUnits +(JNIEnv *env, jobject interfaceObject); + +/** + * API for boostrapping system configuration parameters from a bootstrap server. + * + * @return OCStackResult - return value of this API. + * It returns OC_STACK_OK if success. + * + * NOTE: OCStackResult is defined in ocstack.h. + */ +JNIEXPORT jint JNICALL JNIThingsConfigurationDoBootstrap +(JNIEnv *env, jobject interfaceObject); + +#ifdef __cplusplus +} +#endif +#endif //JNI_THINGS_CONFIGURATION_H_ diff --git a/service/things-manager/sdk/java/jni/tm/inc/jni_things_configuration_callbacks.h b/service/things-manager/sdk/java/jni/tm/inc/jni_things_configuration_callbacks.h new file mode 100644 index 0000000..b30c478 --- /dev/null +++ b/service/things-manager/sdk/java/jni/tm/inc/jni_things_configuration_callbacks.h @@ -0,0 +1,95 @@ +/* ***************************************************************** + * + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ + +/** + * @file + * This file contains the declaration of ThingsConfigurationCallbacks class + */ + +#ifndef JNI_THINGS_CONFIGURATON_CALLBACKS_H_ +#define JNI_THINGS_CONFIGURATON_CALLBACKS_H_ + +#include + +#include "ThingsConfiguration.h" + +/** + * This class provides a set of callback functions for things configuration. + */ +class ThingsConfigurationCallbacks +{ + + public: + ThingsConfigurationCallbacks() {} + virtual ~ThingsConfigurationCallbacks() {} + + /** + * This callback method is called when a response for the updateConfigurations request + * just arrives. + * + * @param headerOptions - It comprises of optionID and optionData as members. + * @param rep - Configuration parameters are carried as a pair of attribute key and value + * in a form of OCRepresentation instance. + * @param eCode - error code. + */ + static void onUpdateConfigurationsResponse(const OC::HeaderOptions &headerOptions, + const OC::OCRepresentation &rep, const int eCode); + + /** + * This callback method is called when a response for the getConfigurations request + * just arrives. + * + * @param headerOptions - It comprises of optionID and optionData as members. + * @param rep - Configuration parameters are carried as a pair of attribute key and value + * in a form of OCRepresentation instance. + * @param eCode - error code. + */ + static void onGetConfigurationsResponse(const OC::HeaderOptions &headerOptions, + const OC::OCRepresentation &rep, const int eCode); + + /** + * This callback method is called when a response for the doBootstrap request + * just arrives. + * + * @param headerOptions - It comprises of optionID and optionData as members. + * @param rep - Configuration parameters are carried as a pair of attribute key and value + * in a form of OCRepresentation instance. + * @param eCode - error code. + */ + static void onBootStrapResponse(const OC::HeaderOptions &headerOptions, + const OC::OCRepresentation &rep, + const int eCode); + + /** + * This method invokes the Callback function with particular name and signature. + * + * @param headerOptions - It comprises of optionID and optionData as members. + * @param rep - Configuration parameters are carried as a pair of attribute key and value + * in a form of OCRepresentation instance. + * @param eCode - error code. + * @param callbackName - callbackName to be invoked. + * @param signature - Signature of the callback method to be called. + */ + static void invokeCallback(const OC::HeaderOptions &headerOptions, + const OC::OCRepresentation &rep, const int eCode, const char *callbackName, + const char *signature); + +}; +#endif //JNI_GROUP_SYNCHRONIZATION_CALLBACKS_H_ diff --git a/service/things-manager/sdk/java/jni/tm/inc/jni_things_maintenance.h b/service/things-manager/sdk/java/jni/tm/inc/jni_things_maintenance.h new file mode 100644 index 0000000..2b76de2 --- /dev/null +++ b/service/things-manager/sdk/java/jni/tm/inc/jni_things_maintenance.h @@ -0,0 +1,81 @@ +/* ***************************************************************** + * + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ + +/** + * @file + * This file contains the declaration of Things Maintenance API's + * for JNI implementation. + */ + +#ifndef JNI_THINGS_MAINTENANCE_H_ +#define JNI_THINGS_MAINTENANCE_H_ + +#include +#include + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * API to let thing(device) reboot. + * The target thing could be a group of multiple things or a single thing. + * + * @param resource - resource type representing the target group + * + * @return OCStackResult - return value of this API. + * It returns OC_STACK_OK if success. + * + * NOTE: OCStackResult is defined in ocstack.h. + */ +JNIEXPORT jint JNICALL JNIThingsMaintenanceReboot +(JNIEnv *env, jobject interfaceObject, jobject resource); + +/** + * API for factory reset on thing(device). + * The target thing could be a group of multiple things or a single thing. + * + * @param resource - resource type representing the target group + * + * @return OCStackResult - return value of this API. + * It returns OC_STACK_OK if success. + * + * NOTE: OCStackResult is defined in ocstack.h. + */ +JNIEXPORT jint JNICALL JNIThingsMaintenanceFactoryReset +(JNIEnv *env, jobject interfaceObject, jobject resource); + + +/** + * API for showing the list of supported Maintenance units. + * + * @return std::string - return value of this API. + * It returns the list in JSON format + */ +JNIEXPORT jstring JNICALL JNIThingsMaintenanceGetListOfSupportedConfigurationUnits +(JNIEnv *env, jobject interfaceObject); + +#ifdef __cplusplus +} +#endif +#endif //JNI_THINGS_MAINTENANCE_H_ diff --git a/service/things-manager/sdk/java/jni/tm/inc/jni_things_maintenance_callbacks.h b/service/things-manager/sdk/java/jni/tm/inc/jni_things_maintenance_callbacks.h new file mode 100644 index 0000000..21b67e0 --- /dev/null +++ b/service/things-manager/sdk/java/jni/tm/inc/jni_things_maintenance_callbacks.h @@ -0,0 +1,83 @@ +/* ***************************************************************** + * + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ + +/** + * @file + * This file contains the declaration of ThingsMaintenanceCallbacks class. + */ + +#ifndef JNI_THINGS_MAINTENANCE_CALLBACKS_H_ +#define JNI_THINGS_MAINTENANCE_CALLBACKS_H_ + +#include + +#include "ThingsMaintenance.h" + +/** + * This class provides a set of callback functions for things maintenance. + */ +class ThingsMaintenanceCallbacks +{ + + public: + ThingsMaintenanceCallbacks() {} + virtual ~ThingsMaintenanceCallbacks() {} + + /** + * This callback method is called when a response for the reboot request + * just arrives. + * + * @param headerOptions - It comprises of optionID and optionData as members. + * @param rep - Configuration parameters are carried as a pair of attribute key and value + * in a form of OCRepresentation instance. + * @param eCode - error code. + */ + static void onRebootResponse(const OC::HeaderOptions &headerOptions, + const OC::OCRepresentation &rep, + const int eCode); + + /** + * This callback method is called when a response for the factoryReset request + * just arrives. + * + * @param headerOptions - It comprises of optionID and optionData as members. + * @param rep - Configuration parameters are carried as a pair of attribute key and value + * in a form of OCRepresentation instance. + * @param eCode - error code. + */ + static void onFactoryResetResponse(const OC::HeaderOptions &headerOptions, + const OC::OCRepresentation &rep, + const int eCode); + + /** + * This method invokes the Callback function with particular name and signature. + * + * @param headerOptions - It comprises of optionID and optionData as members. + * @param rep - Configuration parameters are carried as a pair of attribute key and value + * in a form of OCRepresentation instance. + * @param eCode - error code. + * @param callbackName - callbackName to be invoked. + * @param signature - Signature of the callback method to be called. + */ + static void invokeCallback(const OC::HeaderOptions &headerOptions, + const OC::OCRepresentation &rep, const int eCode, + const char *callbackName, const char *signature); +}; +#endif //JNI_THINGS_MAINTENANCE_CALLBACKS_H_ diff --git a/service/things-manager/sdk/java/jni/tm/inc/jni_things_manager.h b/service/things-manager/sdk/java/jni/tm/inc/jni_things_manager.h deleted file mode 100644 index 042de70..0000000 --- a/service/things-manager/sdk/java/jni/tm/inc/jni_things_manager.h +++ /dev/null @@ -1,372 +0,0 @@ -/****************************************************************** - * - * Copyright 2015 Samsung Electronics All Rights Reserved. - * - * - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************/ - -/** @file jni_things_manager.h - * - * @brief This file contains the declaration of Things Manager service API's - * for JNI implementation - */ - -#ifndef __JNI_THINGS_MANAGER_H_ -#define __JNI_THINGS_MANAGER_H_ - - -#include -#include - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * API for discoverying candidate resources. - * - * @param resourceTypes - required resource types(called "candidate") - * @param waitSec - Delay time in seconds to add before starting to find the resources in network. - * - * @return OCStackResult - return value of this API. - * It returns OC_STACK_OK if success. - * - * NOTE: OCStackResult is defined in ocstack.h. - */ -JNIEXPORT jint JNICALL JNIThingsManagerFindCandidateResource -(JNIEnv *env, jobject interfaceObject, jobject resourceTypes, jint waitSec); - -/** - * API for subscribing child's state. - * - * @param resource - collection resource for subscribing presence of all child resources. - * - * @return OCStackResult - return value of this API. - * It returns OC_STACK_OK if success. - * - * NOTE: OCStackResult is defined in ocstack.h. - */ -JNIEXPORT jint JNICALL JNIThingsManagerSubscribeCollectionPresence -(JNIEnv *env, jobject interfaceObject, jobject resource); - -/** - * API for register and bind resource to group. - * - * @param resource - resource for register and bind to group. It has all data. - * @param collectionHandle - collection resource handle. It will be added child resource. - * - * @return childHandle - child resource handle. - * - * NOTE: OCStackResult is defined in ocstack.h. - */ -JNIEXPORT jobject JNICALL JNIThingsManagerBindResourceToGroup -(JNIEnv *env, jobject interfaceObject, jobject resource, jobject collectionHandle); - -/** - * API for finding a specific remote group when a resource tries to join a group. - * Callback is called when a group is found or not. - * - * @param resourceTypes - resource types of a group to find and join - * - * @return OCStackResult - return value of this API. - * It returns OC_STACK_OK if success. - * - * NOTE: It return OC_STACK ERROR when It was finding a group. - * You should call this api when the group finding process has stopped. - * OCStackResult is defined in ocstack.h. - */ - -JNIEXPORT jint JNICALL JNIThingsManagerFindGroup -(JNIEnv *env, jobject interfaceObject, jobject resourceTypes); - -/** - * API for creating a new group. - * - * @param resourceType - resource type of a group to create - * - * @return OCStackResult - return value of this API. - * It returns OC_STACK_OK if success. - * - * NOTE: OCStackResult is defined in ocstack.h. - */ -JNIEXPORT jint JNICALL JNIThingsManagerCreateGroup -(JNIEnv *env, jobject interfaceObject, jstring resourceType); - -/** - * API for joining a group. This API is used when a resource that has a group tries - * to find a specific remote resource and makes it join a group - * - * @param resourceType - resource type of a group to join. - * @param resourceHandle - resource handle to join a group. - * - * @return OCStackResult - return value of this API. - * It returns OC_STACK_OK if success. - * - * NOTE: If you want to join the resource in the remote(other) process, use the API - * jniThingsManagerJoinGroupObject instead of this. - * OCStackResult is defined in ocstack.h. - */ -JNIEXPORT jint JNICALL JNIThingsManagerJoinGroupString -(JNIEnv *env, jobject interfaceObject, jstring resourceType, jobject resourceHandle); - -/** - * API for joining a group. This API is used when a resource that - * doesn't have a group tries to find and join a specific remote group. - * - * @param resource - group resource pointer to join. - * @param resourceHandle - resource handle to join a group. - * - * @return OCStackResult - return value of this API. - * It returns OC_STACK_OK if success. - * - * NOTE: NOTE: If you want to join the resource in the same process, use the API - * jniThingsManagerJoinGroupString instead of this. - * OCStackResult is defined in ocstack.h. - */ -JNIEXPORT jint JNICALL JNIThingsManagerJoinGroupObject -(JNIEnv *env, jobject interfaceObject, jobject resource, jobject resourceHandle); - -/** - * API for leaving a joined group. - * - * @param resourceType - resource type of a group to leave. - * @param resourceHandle - resource handle to join a group. - * - * @return OCStackResult - return value of this API. - * It returns OC_STACK_OK if success. - * - * NOTE: OCStackResult is defined in ocstack.h. - */ -JNIEXPORT jint JNICALL JNIThingsManagerLeaveGroup -(JNIEnv *env, jobject interfaceObject, jstring resourceType, jobject resourceHandle); - -/** - * API for leaving a joined group. - * - * @param resource - resource of a group to leave. - * @param resourceType - resource type of a group to leave. - * @param resourceHandle - resource handle to join a group. - * - * @return OCStackResult - return value of this API. - * It returns OC_STACK_OK if success. - * - * NOTE: OCStackResult is defined in ocstack.h. - */ -JNIEXPORT jint JNICALL JNIThingsManagerLeaveGroupForResource -(JNIEnv *env, jobject interfaceObject, jobject resource, jstring resourceType, - jobject resourceHandle); -/** - * API for deleting a group. - * - * @param collectionResourceType - resource type of a group to delete. - * - * @return void - */ -JNIEXPORT void JNICALL JNIThingsManagerDeleteGroup -(JNIEnv *env, jobject interfaceObject, jstring collectionResourceType); - -/** - * API for getting a list of joined groups. - * - * @return std::map - return value of this API. - * It returns group resource type and group resource handle as a map type. - */ -JNIEXPORT jobject JNICALL JNIThingsManagerGetGroupList -(JNIEnv *env, jobject interfaceObject); - -/** - * API for updating configuration value of multiple things of a target group - * or a single thing. - * Before using the below function, a developer should acquire a resource pointer of - * (collection) resource that he wants to send a request by calling findResource() function - * provided in OCPlatform. And he should also notice a "Configuration Name" term which - * represents a nickname of a target attribute of a resource that he wants to update. - * The base motivation to introduce the term is to avoid a usage of URI to access a resource - * from a developer. Thus, a developer should know which configuration names are supported - * by Things Configuration class and what the configuration name means. - * To get a list of supported configuration names, use getListOfSupportedConfigurationUnits() - * function, which provides the list in JSON format. - * - * @param resource - resource pointer representing the target group or the single thing. - * @param configurations - ConfigurationUnit: a nickname of attribute of target resource - * (e.g., installedlocation, currency, (IP)address) - * Value : a value to be updated - * - * @return OCStackResult - return value of this API. - * It returns OC_STACK_OK if success. - * - * NOTE: OCStackResult is defined in ocstack.h. - */ -JNIEXPORT jint JNICALL JNIThingsManagerUpdateConfigurations -(JNIEnv *env, jobject interfaceObject, jobject resource, jobject configurations); - -/** - * API for getting configuration value of multiple things of a target group - * or a single thing. - * - * @param resource - resource pointer representing the target group or the single thing. - * @param configurations - ConfigurationUnit: a nickname of attribute of target resource. - * - * @return OCStackResult - return value of this API. - * It returns OC_STACK_OK if success. - * - * NOTE: OCStackResult is defined in ocstack.h. - */ -JNIEXPORT jint JNICALL JNIThingsManagerGetConfigurations -(JNIEnv *env, jobject interfaceObject, jobject resource, jobject configurations); - -/** - * API for showing the list of supported configuration units (configurable parameters) - * - * @return std::string - return value of this API. - * It returns the list in JSON format - */ -JNIEXPORT jstring JNICALL JNIThingsManagerGetListOfSupportedConfigurationUnits -(JNIEnv *env, jobject interfaceObject); - -/** - * API for boostrapping system configuration parameters from a bootstrap server. - * - * @return OCStackResult - return value of this API. - * It returns OC_STACK_OK if success. - * - * NOTE: OCStackResult is defined in ocstack.h. - */ -JNIEXPORT jint JNICALL JNIThingsManagerDoBootstrap -(JNIEnv *env, jobject interfaceObject); - -/** - * API to let thing(device) reboot. - * The target thing could be a group of multiple things or a single thing. - * - * @param resource - resource type representing the target group - * - * @return OCStackResult - return value of this API. - * It returns OC_STACK_OK if success. - * - * NOTE: OCStackResult is defined in ocstack.h. - */ -JNIEXPORT jint JNICALL JNIThingsManagerReboot -(JNIEnv *env, jobject interfaceObject, jobject resource); - -/** - * API for factory reset on thing(device). - * The target thing could be a group of multiple things or a single thing. - * - * @param resource - resource type representing the target group - * - * @return OCStackResult - return value of this API. - * It returns OC_STACK_OK if success. - * - * NOTE: OCStackResult is defined in ocstack.h. - */ -JNIEXPORT jint JNICALL JNIThingsManagerFactoryReset -(JNIEnv *env, jobject interfaceObject, jobject resource); - -/** - * API for adding an Action Set. - * - * @param resource - resource type representing the target group - * @param newActionSet - list of Action Set to be added - * - * @return OCStackResult - return value of this API. - * It returns OC_STACK_OK if success. - * - * NOTE: OCStackResult is defined in ocstack.h. - */ - -JNIEXPORT jint JNICALL JNIThingsManagerAddActionSet -(JNIEnv *env, jobject interfaceObject, jobject resource, jobject newActionSet); - -/** - * API for executing the Action Set. - * - * @param resource - resource type representing the target group - * @param actionSetName - Action Set name for executing the Action set - * - * @return OCStackResult - return value of this API. - * It returns OC_STACK_OK if success. - * - * NOTE: OCStackResult is defined in ocstack.h. - */ -JNIEXPORT jint JNICALL JNIThingsManagerExecuteActionSet -(JNIEnv *env, jobject interfaceObject, jobject resource, jstring actionSetName); - -/** - * API for executing the Action Set. - * - * @param resource - resource type representing the target group - * @param actionSetName - Action Set name for executing the Action set - * @param delay - waiting time for until action set run. - * - * @return OCStackResult - return value of this API. - * It returns OC_STACK_OK if success. - * - * NOTE: OCStackResult is defined in ocstack.h. - */ -JNIEXPORT jint JNICALL JNIThingsManagerExecuteActionSetWithDelay -(JNIEnv *env, jobject interfaceObject, jobject resource, jstring actionSetName, jlong delay); - -/** - * API for cancelling the Action Set. - * - * @param resource - resource type representing the target group - * @param actionSetName - Action Set name for cancelling the Action set - * - * @return OCStackResult - return value of this API. - * It returns OC_STACK_OK if success. - * - * NOTE: OCStackResult is defined in ocstack.h. - */ -JNIEXPORT jint JNICALL JNIThingsManagerCancelActionSet -(JNIEnv *env, jobject interfaceObject, jobject resource, jstring actionSetName); - - -/** - * API for reading the Action Set. - * - * @param resource - resource type representing the target group - * @param actionSetName - Action Set name for reading the Action set - * - * @return OCStackResult - return value of this API. - * It returns OC_STACK_OK if success. - * - * NOTE: OCStackResult is defined in ocstack.h. - */ -JNIEXPORT jint JNICALL JNIThingsManagerGetActionSet -(JNIEnv *env, jobject interfaceObject, jobject resource, jstring actionSetName); - -/** - * API for removing the Action Set. - * - * @param resource - resource type representing the target group - * @param actionSetName - Action Set name for removing the Action set - * - * @return OCStackResult - return value of this API. - * It returns OC_STACK_OK if success. - * - * NOTE: OCStackResult is defined in ocstack.h. - */ -JNIEXPORT jint JNICALL JNIThingsManagerDeleteActionSet -(JNIEnv *env, jobject interfaceObject, jobject resource, jstring actionSetName); - -#ifdef __cplusplus -} -#endif -#endif //__JNI_THINGS_MANAGER_H_ \ No newline at end of file diff --git a/service/things-manager/sdk/java/jni/tm/inc/jni_things_manager_callbacks.h b/service/things-manager/sdk/java/jni/tm/inc/jni_things_manager_callbacks.h deleted file mode 100644 index 42cdc44..0000000 --- a/service/things-manager/sdk/java/jni/tm/inc/jni_things_manager_callbacks.h +++ /dev/null @@ -1,208 +0,0 @@ -/****************************************************************** - * - * Copyright 2015 Samsung Electronics All Rights Reserved. - * - * - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************/ - -/** @file jni_things_manager_callbacks.h - * - * @brief This file contains the declaration of ThingsManagerCallbacks class - * and its members related to ThingsManagerCallbacks. - */ - -#ifndef __JNI_THINGS_MANAGER_CALLBACKS_H_ -#define __JNI_THINGS_MANAGER_CALLBACKS_H_ - -#include - -#include "ThingsManager.h" - -/** - * @class ThingsManagerCallbacks - * @brief This class provides a set of callback functions for group management, - * synchronization of group, configuration of things, and diagnostics about things. - * - */ -class ThingsManagerCallbacks -{ - - public: - ThingsManagerCallbacks() {} - virtual ~ThingsManagerCallbacks() {} - - /** - * This callback method is called when resources are discovered in network. - * - * @param resourceVector - List of resources discovered in the network - * - * @return void - */ - static void onFoundCandidateResource(std::vector< std::shared_ptr > - resourceVector); - - /** - * This callback method is called to notify whether group is found or not. - * - * @param resource - Resource URI - * - * @return void - */ - static void onFoundGroup(std::shared_ptr resource); - - /** - * This callback method is called for child resource presence status. - * - * @param resource - URI of resource. - * @param result - error code. - * - * @return void - */ - static void onSubscribePresence(std::string resource, OCStackResult result); - - /** - * This callback method is called when a response for the updateConfigurations request - * just arrives. - * - * @param headerOptions - It comprises of optionID and optionData as members. - * @param rep - Configuration parameters are carried as a pair of attribute key and value - * in a form of OCRepresentation instance. - * @param eCode - error code. - * - * @return void - */ - static void onUpdateConfigurationsResponse(const OC::HeaderOptions &headerOptions, - const OC::OCRepresentation &rep, const int eCode); - - /** - * This callback method is called when a response for the getConfigurations request - * just arrives. - * - * @param headerOptions - It comprises of optionID and optionData as members. - * @param rep - Configuration parameters are carried as a pair of attribute key and value - * in a form of OCRepresentation instance. - * @param eCode - error code. - * - * @return void - */ - static void onGetConfigurationsResponse(const OC::HeaderOptions &headerOptions, - const OC::OCRepresentation &rep, const int eCode); - - /** - * This callback method is called when a response for the doBootstrap request - * just arrives. - * - * @param headerOptions - It comprises of optionID and optionData as members. - * @param rep - Configuration parameters are carried as a pair of attribute key and value - * in a form of OCRepresentation instance. - * @param eCode - error code. - * - * @return void - */ - static void onBootStrapResponse(const OC::HeaderOptions &headerOptions, - const OC::OCRepresentation &rep, - const int eCode); - - /** - * This callback method is called when a response for the reboot request - * just arrives. - * - * @param headerOptions - It comprises of optionID and optionData as members. - * @param rep - Configuration parameters are carried as a pair of attribute key and value - * in a form of OCRepresentation instance. - * @param eCode - error code. - * - * @return void - */ - static void onRebootResponse(const OC::HeaderOptions &headerOptions, - const OC::OCRepresentation &rep, - const int eCode); - - /** - * This callback method is called when a response for the factoryReset request - * just arrives. - * - * @param headerOptions - It comprises of optionID and optionData as members. - * @param rep - Configuration parameters are carried as a pair of attribute key and value - * in a form of OCRepresentation instance. - * @param eCode - error code. - * - * @return void - */ - static void onFactoryResetResponse(const OC::HeaderOptions &headerOptions, - const OC::OCRepresentation &rep, - const int eCode); - - /** - * This callback method is called when a response for the executeActionSet - * or deleteActionSet request just arrives. - * - * @param headerOptions - It comprises of optionID and optionData as members. - * @param rep - Configuration parameters are carried as a pair of attribute key and value - * in a form of OCRepresentation instance. - * @param eCode - error code. - * - * @return void - */ - static void onPostResponse(const OC::HeaderOptions &headerOptions, - const OC::OCRepresentation &rep, const int eCode); - - /** - * This callback method is called when a response for the addActionSet request - * just arrives. - * - * @param headerOptions - It comprises of optionID and optionData as members. - * @param rep - Configuration parameters are carried as a pair of attribute key and value - * in a form of OCRepresentation instance. - * @param eCode - error code. - * - * @return void - */ - static void onPutResponse(const OC::HeaderOptions &headerOptions, - const OC::OCRepresentation &rep, const int eCode); - - /** - * This callback method is called when a response for the getActionSet request - * just arrives. - * - * @param headerOptions - It comprises of optionID and optionData as members. - * @param rep - Configuration parameters are carried as a pair of attribute key and value - * in a form of OCRepresentation instance. - * @param eCode - error code. - * - * @return void - */ - static void onGetResponse(const OC::HeaderOptions &headerOptions, - const OC::OCRepresentation &rep, const int eCode); - - /** - * This method invokes the Callback function with particular name and signature. - * - * @param headerOptions - It comprises of optionID and optionData as members. - * @param rep - Configuration parameters are carried as a pair of attribute key and value - * in a form of OCRepresentation instance. - * @param eCode - error code. - * @param callbackName - callbackName to be invoked. - * @param signature - Signature of the callback method to be called. - * - * @return void - */ - static void invokeCallback(const OC::HeaderOptions &headerOptions, - const OC::OCRepresentation &rep, const int eCode, - const char *callbackName, const char *signature); - -}; -#endif //__JNI_THINGS_MANAGER_CALLBACKS_H_ \ No newline at end of file diff --git a/service/things-manager/sdk/java/jni/tm/inc/jni_things_manager_util.h b/service/things-manager/sdk/java/jni/tm/inc/jni_things_manager_util.h index cf89df8..6cf90f5 100644 --- a/service/things-manager/sdk/java/jni/tm/inc/jni_things_manager_util.h +++ b/service/things-manager/sdk/java/jni/tm/inc/jni_things_manager_util.h @@ -19,38 +19,62 @@ ******************************************************************/ /** - * @file jni_things_manager_util.h - * - * @brief This file contains the utility functions for conversions from java to CPP - * and viceversa + * @file + * This file contains the utility functions for conversions from java to CPP + * and viceversa. */ -#ifndef __JNI_THINGS_MANAGER_UTILS_H_ -#define __JNI_THINGS_MANAGER_UTILS_H_ - +#ifndef JNI_THINGS_MANAGER_UTILS_H_ +#define JNI_THINGS_MANAGER_UTILS_H_ #include #include +#include "JniOcResource.h" #include "jni_things_manager_jvm.h" /** - * Utility function for converting a Java Vector of Strings to CPP Vector of Strings + * Utility function for converting a Java Vector of Strings to CPP Vector of Strings. * - * @param env - Default JNI Environment pointer + * @param env - Default JNI Environment pointer * @param jVectorString - Java Vector of Strings - * - * @return void */ std::vector convertStringVector(JNIEnv *env, jobject jVectorString); /** - * Utility function for converting a Hash Map of Strings to CPP Map of Strings + * Utility function for converting a Hash Map of Strings to CPP Map of Strings. * - * @param env - Default JNI Environment pointer + * @param env - Default JNI Environment pointer * @param jMapString - Java Map of Strings - * - * @return void */ std::map convertStringMap(JNIEnv *env, jobject jMapString); -#endif //__JNI_THINGS_MANAGER_UTILS_H_ + +/** + * Utility function for converting ocResource Handle to java. + * @param env - Default JNI Environment pointer + * @param resourceHandle - Resource Handle + */ +jobject ocResourceHandleToJava(JNIEnv *env, jlong resourceHandle); + +/** + * Utility function for converting native ocResource to java ocResource. + * @param env - Default JNI Environment pointer + * @param resource - Native Resource + */ +jobject OcResourceToJava(JNIEnv *env, jlong resource); + +/** + * Utility function for converting native ocHeaderOption to java ocHeaderOption. + * @param env - Default JNI Environment pointer + * @param headerOption - Native headerOption + */ +jobject OcHeaderOptionToJava(JNIEnv *env, OC::HeaderOption::OCHeaderOption headerOption); + +/** + * Utility function for converting native ocRepresentation to java ocRepresentation. + * @param env - Default JNI Environment pointer + * @param ocRepresentation - Native ocRepresentation + */ +jobject OcRepresentationToJava(JNIEnv *env, jlong ocRepresentation); + +#endif //JNI_THINGS_MANAGER_UTILS_H_ diff --git a/service/things-manager/sdk/java/jni/tm/src/jni_action.cpp b/service/things-manager/sdk/java/jni/tm/src/jni_action.cpp index 45ea379..1b408a1 100644 --- a/service/things-manager/sdk/java/jni/tm/src/jni_action.cpp +++ b/service/things-manager/sdk/java/jni/tm/src/jni_action.cpp @@ -1,4 +1,4 @@ -/****************************************************************** +/* ***************************************************************** * * Copyright 2015 Samsung Electronics All Rights Reserved. * @@ -17,17 +17,17 @@ * limitations under the License. * ******************************************************************/ -#include "jni_action.h" -#include +#include "jni_action.h" #include "jni_things_manager_jvm.h" #include "jni_getter.h" #include "jni_setter.h" +#include + #define JACTION_TARGET ("target") #define JACTION_LISTOF_CAPABILITY ("listOfCapability") - JniAction::JniAction(JNIEnv *env, jobject obj) : JObject(env, obj) { } diff --git a/service/things-manager/sdk/java/jni/tm/src/jni_action_set.cpp b/service/things-manager/sdk/java/jni/tm/src/jni_action_set.cpp index d952f81..ad62102 100644 --- a/service/things-manager/sdk/java/jni/tm/src/jni_action_set.cpp +++ b/service/things-manager/sdk/java/jni/tm/src/jni_action_set.cpp @@ -1,4 +1,4 @@ -/****************************************************************** +/* ***************************************************************** * * Copyright 2015 Samsung Electronics All Rights Reserved. * @@ -17,8 +17,8 @@ * limitations under the License. * ******************************************************************/ -#include "jni_action_set.h" +#include "jni_action_set.h" #include "jni_things_manager_jvm.h" #include "jni_getter.h" #include "jni_setter.h" diff --git a/service/things-manager/sdk/java/jni/tm/src/jni_capability.cpp b/service/things-manager/sdk/java/jni/tm/src/jni_capability.cpp index 9a15496..6a428d0 100644 --- a/service/things-manager/sdk/java/jni/tm/src/jni_capability.cpp +++ b/service/things-manager/sdk/java/jni/tm/src/jni_capability.cpp @@ -1,4 +1,4 @@ -/****************************************************************** +/* ***************************************************************** * * Copyright 2015 Samsung Electronics All Rights Reserved. * @@ -17,8 +17,8 @@ * limitations under the License. * ******************************************************************/ -#include "jni_capability.h" +#include "jni_capability.h" #include "jni_things_manager_jvm.h" #include "jni_getter.h" #include "jni_setter.h" diff --git a/service/things-manager/sdk/java/jni/tm/src/jni_group_manager.cpp b/service/things-manager/sdk/java/jni/tm/src/jni_group_manager.cpp new file mode 100644 index 0000000..4678f5e --- /dev/null +++ b/service/things-manager/sdk/java/jni/tm/src/jni_group_manager.cpp @@ -0,0 +1,456 @@ +/* ***************************************************************** + * + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ + +#include "jni_group_manager.h" +#include "JniOcResource.h" +#include "JniOcResourceHandle.h" +#include "GroupManager.h" +#include "ActionSet.h" +#include "jni_things_manager_jvm.h" +#include "jni_things_manager_util.h" +#include "jni_group_manager_callbacks.h" +#include "jni_action_set.h" + +/** + * GroupManager static object + */ +static GroupManager g_GroupManager; + +JNIEXPORT jint JNICALL JNIGroupManagerFindCandidateResource(JNIEnv *env, jobject interfaceObject, + jobject jResourceTypes, jint waitSec) +{ + LOGI("JNIGroupManagerFindCandidateResource: Enter"); + + if (!jResourceTypes) + { + LOGE("JNIGroupManagerFindCandidateResource: jResourceTypes is NULL!"); + return OC_STACK_INVALID_PARAM; + } + + OCStackResult ocResult = OC_STACK_ERROR; + try + { + ocResult = g_GroupManager.findCandidateResources(convertStringVector(env, jResourceTypes), + &GroupManagerCallbacks::onFoundCandidateResource, (int)waitSec); + + if (OC_STACK_OK != ocResult) + { + LOGE("JNIGroupManagerFindCandidateResource: findCandidateResources failed!"); + return ocResult; + } + } + catch (InitializeException &e) + { + LOGE("JNIGroupManagerFindCandidateResource: Exception occurred! %s, %d", e.reason().c_str(), + e.code()); + return ocResult; + } + + LOGI("JNIGroupManagerFindCandidateResource: Exit"); + return ocResult; +} + +JNIEXPORT jint JNICALL JNIGroupManagerSubscribeCollectionPresence(JNIEnv *env, + jobject interfaceObject, + jobject jResource) +{ + LOGI("JNIGroupManagerSubscribeCollectionPresence: Enter"); + + if (!jResource) + { + LOGE("JNIGroupManagerSubscribeCollectionPresence: jResource is NULL!"); + return OC_STACK_INVALID_PARAM; + } + + OCStackResult ocResult = OC_STACK_ERROR; + + JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, jResource); + if (NULL == jniOcResource) + { + LOGE("JNIGroupManagerSubscribeCollectionPresence: Failed to get jni OcResource!"); + return ocResult; + } + + std::shared_ptr ocResource = jniOcResource->getOCResource(); + if (NULL == ocResource.get()) + { + LOGE("JNIGroupManagerSubscribeCollectionPresence: Failed to get OCResource object!"); + return ocResult; + } + + ocResult = g_GroupManager.subscribeCollectionPresence(ocResource, + &GroupManagerCallbacks::onSubscribePresence); + if (OC_STACK_OK != ocResult) + { + LOGE("JNIGroupManagerSubscribeCollectionPresence: subscribeCollectionPresence failed!"); + return ocResult; + } + + LOGI("JNIGroupManagerSubscribeCollectionPresence: Exit"); + return ocResult; +} + +JNIEXPORT jobject JNICALL JNIGroupManagerBindResourceToGroup(JNIEnv *env, jobject interfaceObject, + jobject jResource, jobject jCollectionHandle) +{ + LOGI("JNIGroupManagerBindResourceToGroup: Enter"); + + if (!jResource || !jCollectionHandle) + { + LOGE("JNIGroupManagerBindResourceToGroup: Invalid parameter!"); + return NULL; + } + + std::shared_ptr ocResource; + JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, jResource); + if (jniOcResource) + { + ocResource = jniOcResource->getOCResource(); + } + + if (NULL == ocResource.get()) + { + LOGE("JNIGroupManagerBindResourceToGroup: Failed to get OCResource object!"); + return NULL; + } + + JniOcResourceHandle *jniOcCollectionHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(env, + jCollectionHandle); + if (NULL == jniOcCollectionHandle) + { + LOGE("JNIGroupManagerBindResourceToGroup: collection handle is null!"); + return NULL; + } + + jobject jResourceHandle = NULL; + try + { + OCResourceHandle ocChildHandle = NULL; + OCResourceHandle ocCollectionHandle = jniOcCollectionHandle->getOCResourceHandle(); + OCStackResult ocResult = g_GroupManager.bindResourceToGroup(ocChildHandle, ocResource, + ocCollectionHandle); + if (OC_STACK_OK != ocResult) + { + LOGE("JNIGroupManagerBindResourceToGroup: bindResourceToGroup failed!"); + return NULL; + } + + // Convert OCResourceHandle to java type + JniOcResourceHandle *jniHandle = new JniOcResourceHandle(ocChildHandle); + jlong handle = reinterpret_cast(jniHandle); + jResourceHandle = env->NewObject(g_cls_OcResourceHandle, g_mid_OcResourceHandle_N_ctor, handle); + if (env->ExceptionCheck()) + { + LOGE("JNIGroupManagerBindResourceToGroup: Failed to create OcResourceHandle"); + delete jniHandle; + return NULL; + } + } + catch (InitializeException &e) + { + LOGE("JNIGroupManagerBindResourceToGroup: Exception occurred! %s, %d", e.reason().c_str(), + e.code()); + return NULL; + } + + LOGI("JNIGroupManagerBindResourceToGroup: Exit"); + return jResourceHandle; +} + +JNIEXPORT jint JNICALL JNIGroupManagerAddActionSet(JNIEnv *env, jobject interfaceObject, + jobject resource, + jobject newActionSet) +{ + LOGI("JNIGroupManagerAddActionSet: Entry"); + + if ((!resource) || (!newActionSet)) + { + LOGE("JNIGroupManagerAddActionSet: resource or newActionSet is NULL!"); + return OC_STACK_INVALID_PARAM; + } + + OCStackResult ocResult = OC_STACK_ERROR; + + std::shared_ptr ocResource; + JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, resource); + if (jniOcResource) + { + ocResource = jniOcResource->getOCResource(); + } + + if (NULL == ocResource.get()) + { + LOGE("JNIGroupManagerAddActionSet: Failed to get OCResource object!"); + return ocResult; + } + + JniActionSet *jActionSet = new JniActionSet(env, newActionSet); + ActionSet *pActionSet = jActionSet->getActionSet(env, newActionSet); + if (NULL == pActionSet) + { + LOGE("JNIGroupManagerAddActionSet: Failed to convert ActionSet!"); + return ocResult; + } + + ocResult = g_GroupManager.addActionSet(ocResource, pActionSet, + &GroupManagerCallbacks::onPutResponse); + if (OC_STACK_OK != ocResult) + { + LOGE("JNIGroupManagerAddActionSet: addActionSet is failed!"); + } + + delete pActionSet; + LOGI("JNIGroupManagerAddActionSet: Exit"); + return ocResult; +} + +JNIEXPORT jint JNICALL JNIGroupManagerExecuteActionSet(JNIEnv *env, jobject interfaceObject, + jobject resource, jstring jActionSetName) +{ + LOGI("JNIGroupManagerExecuteActionSet: Entry"); + + if ((!resource) || (!jActionSetName)) + { + LOGE("JNIGroupManagerExecuteActionSet: resource or jActionSetName is NULL!"); + return OC_STACK_INVALID_PARAM; + } + + OCStackResult ocResult = OC_STACK_ERROR; + + std::shared_ptr ocResource; + JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, resource); + if (jniOcResource) + { + ocResource = jniOcResource->getOCResource(); + } + + if (NULL == ocResource.get()) + { + LOGE("JNIGroupManagerExecuteActionSet: Failed to get OCResource object!"); + return ocResult; + } + + const char *actionSetNamePointer = env->GetStringUTFChars(jActionSetName, 0); + if (NULL == actionSetNamePointer) + { + LOGE("JNIGroupManagerExecuteActionSet: Failed to convert jstring to char string!"); + return OC_STACK_NO_MEMORY; + } + + std::string actionSetName(actionSetNamePointer); + + ocResult = g_GroupManager.executeActionSet(ocResource, actionSetName, + &GroupManagerCallbacks::onPostResponse); + if (OC_STACK_OK != ocResult) + { + LOGE("JNIGroupManagerExecuteActionSet: executeActionSet is failed!"); + } + + env->ReleaseStringUTFChars(jActionSetName, actionSetNamePointer); + LOGI("JNIGroupManagerExecuteActionSet: Exit"); + return ocResult; +} + +JNIEXPORT jint JNICALL JNIGroupManagerExecuteActionSetWithDelay(JNIEnv *env, + jobject interfaceObject, + jobject resource, jstring jActionSetName, jlong delay) +{ + LOGI("JNIGroupManagerExecuteActionSetWithDelay: Entry"); + + if ((!resource) || (!jActionSetName)) + { + LOGE("JNIGroupManagerExecuteActionSetWithDelay: resource or jActionSetName is NULL!"); + return OC_STACK_INVALID_PARAM; + } + + OCStackResult ocResult = OC_STACK_ERROR; + + std::shared_ptr ocResource; + JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, resource); + if (jniOcResource) + { + ocResource = jniOcResource->getOCResource(); + } + + if (NULL == ocResource.get()) + { + LOGE("JNIGroupManagerExecuteActionSetWithDelay: Failed to get OCResource object!"); + return ocResult; + } + + const char *actionSetNamePointer = env->GetStringUTFChars(jActionSetName, 0); + if (NULL == actionSetNamePointer) + { + LOGE("JNIGroupManagerExecuteActionSetWithDelay: Failed to convert jstring to char string!"); + return OC_STACK_NO_MEMORY; + } + + std::string actionSetName(actionSetNamePointer); + if (0 == delay) + { + ocResult = g_GroupManager.executeActionSet(ocResource, actionSetName, + &GroupManagerCallbacks::onPostResponse); + } + else + { + ocResult = g_GroupManager.executeActionSet(ocResource, actionSetName, + (long int)delay, + &GroupManagerCallbacks::onPostResponse); + } + if (OC_STACK_OK != ocResult) + { + LOGE("JNIGroupManagerExecuteActionSetWithDelay: executeActionSet is failed!"); + } + + env->ReleaseStringUTFChars(jActionSetName, actionSetNamePointer); + LOGI("JNIGroupManagerExecuteActionSetWithDelay: Exit"); + return ocResult; +} + +JNIEXPORT jint JNICALL JNIGroupManagerCancelActionSet(JNIEnv *env, jobject interfaceObject, + jobject resource, jstring jActionSetName) +{ + LOGI("JNIGroupManagerCancelActionSet: Entry"); + + if ((!resource) || (!jActionSetName)) + { + LOGE("JNIGroupManagerCancelActionSet: resource or jActionSetName is NULL!"); + return OC_STACK_INVALID_PARAM; + } + + OCStackResult ocResult = OC_STACK_ERROR; + + std::shared_ptr ocResource; + JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, resource); + if (jniOcResource) + { + ocResource = jniOcResource->getOCResource(); + } + + if (NULL == ocResource.get()) + { + LOGE("JNIGroupManagerCancelActionSet: Failed to get OCResource object!"); + return ocResult; + } + + const char *actionSetNamePointer = env->GetStringUTFChars(jActionSetName, 0); + if (NULL == actionSetNamePointer) + { + LOGE("JNIGroupManagerCancelActionSet: Failed to get character sequence from jstring!"); + return OC_STACK_NO_MEMORY; + } + + std::string actionSetName(actionSetNamePointer); + + ocResult = g_GroupManager.cancelActionSet(ocResource, actionSetName, + &GroupManagerCallbacks::onPostResponse); + if (OC_STACK_OK != ocResult) + { + LOGE("JNIGroupManagerCancelActionSet: cancelActionSet is failed!"); + } + + env->ReleaseStringUTFChars(jActionSetName, actionSetNamePointer); + LOGI("JNIGroupManagerCancelActionSet: Exit"); + return ocResult; +} + +JNIEXPORT jint JNICALL JNIGroupManagerGetActionSet(JNIEnv *env, jobject interfaceObject, + jobject resource, + jstring jActionSetName) +{ + LOGI("JNIGroupManagerGetActionSet: Entry"); + + if ((!resource) || (!jActionSetName)) + { + LOGE("JNIGroupManagerGetActionSet: resource or jActionSetName is NULL!"); + return OC_STACK_INVALID_PARAM; + } + + OCStackResult ocResult = OC_STACK_ERROR; + + std::shared_ptr ocResource; + JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, resource); + if (jniOcResource) + { + ocResource = jniOcResource->getOCResource(); + } + + if (NULL == ocResource.get()) + { + LOGE("JNIGroupManagerGetActionSet: Failed to get OCResource object!"); + return ocResult; + } + + const char *actionSetNamePointer = env->GetStringUTFChars(jActionSetName, 0); + std::string actionSetName(actionSetNamePointer); + + ocResult = g_GroupManager.getActionSet(ocResource, actionSetName, + &GroupManagerCallbacks::onGetResponse); + if (OC_STACK_OK != ocResult) + { + LOGE("JNIGroupManagerGetActionSet: getActionSet is failed!"); + } + + env->ReleaseStringUTFChars(jActionSetName, actionSetNamePointer); + LOGI("JNIGroupManagerGetActionSet: Exit"); + return ocResult; +} + +JNIEXPORT jint JNICALL JNIGroupManagerDeleteActionSet(JNIEnv *env, jobject interfaceObject, + jobject resource, + jstring jActionSetName) +{ + LOGI("JNIGroupManagerDeleteActionSet: Entry"); + + if ((!resource) || (!jActionSetName)) + { + LOGE("JNIGroupManagerDeleteActionSet: resource or jActionSetName is NULL!"); + return OC_STACK_INVALID_PARAM; + } + + OCStackResult ocResult = OC_STACK_ERROR; + + std::shared_ptr ocResource; + JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, resource); + if (jniOcResource) + { + ocResource = jniOcResource->getOCResource(); + } + + if (NULL == ocResource.get()) + { + LOGE("JNIGroupManagerDeleteActionSet: Failed to get OCResource object!"); + return ocResult; + } + + const char *actionSetNamePointer = env->GetStringUTFChars(jActionSetName, 0); + std::string actionSetName(actionSetNamePointer); + + ocResult = g_GroupManager.deleteActionSet(ocResource, actionSetName, + &GroupManagerCallbacks::onPutResponse); + if (OC_STACK_OK != ocResult) + { + LOGE("JNIGroupManagerDeleteActionSet: deleteActionSet is failed!"); + } + + env->ReleaseStringUTFChars(jActionSetName, actionSetNamePointer); + LOGI("JNIGroupManagerDeleteActionSet: Exit"); + return ocResult; +} diff --git a/service/things-manager/sdk/java/jni/tm/src/jni_group_manager_callbacks.cpp b/service/things-manager/sdk/java/jni/tm/src/jni_group_manager_callbacks.cpp new file mode 100644 index 0000000..13d8c10 --- /dev/null +++ b/service/things-manager/sdk/java/jni/tm/src/jni_group_manager_callbacks.cpp @@ -0,0 +1,335 @@ +/* ***************************************************************** + * + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ + +#include "jni_group_manager_callbacks.h" +#include "JniOcResource.h" +#include "GroupManager.h" +#include "jni_things_manager_jvm.h" +#include "jni_things_manager_util.h" +#include "jni_string.h" + +#define LOG_TAG "GroupManagerCallbacks" + +#define METHOD_ONRESOURCE_CALLBACK "(" TM_JAVA_VECTOR_TYPE")V" +#define METHOD_ONPRESENCE_CALLBACK "(" TM_JAVA_STRING_TYPE"I)V" +#define METHOD_ONPOST_CALLBACK "(" TM_JAVA_VECTOR_TYPE TM_SERVICE_OCREPRESENTATION_TYPE"I)V" +#define METHOD_ONPUT_CALLBACK "(" TM_JAVA_VECTOR_TYPE TM_SERVICE_OCREPRESENTATION_TYPE"I)V" +#define METHOD_ONGET_CALLBACK "(" TM_JAVA_VECTOR_TYPE TM_SERVICE_OCREPRESENTATION_TYPE"I)V" + +void GroupManagerCallbacks::onFoundCandidateResource( + std::vector< std::shared_ptr> resources) +{ + LOGI("onFoundCandidateResource : Enter"); + + if (resources.size() == 0) + { + LOGE("onFoundCandidateResource : found resources zero"); + return; + } + + JNIEnv *env = ThingsManagerJVM::getEnv(); + if (env == NULL) + { + LOGE("onFoundCandidateResource : Getting JNIEnv failed"); + return; + } + + // Get GroupManagerCallback class reference + jclass groupManagerCallbacks = GetJClass(TM_SERVICE_GROUP_MANAGER_CLASS_PATH); + + if (NULL == groupManagerCallbacks) + { + LOGE("onFoundCandidateResource : GetJClass TMServiceCallbackInterface failed"); + ThingsManagerJVM::releaseEnv(); + return; + } + + // Get onResourceCallback method reference + jmethodID method_id = env->GetStaticMethodID(groupManagerCallbacks, "onResourceFoundCallback", + METHOD_ONRESOURCE_CALLBACK); + if (NULL == method_id) + { + LOGE("findCandidateResource: onResourceCallback : GetMethodID failed"); + ThingsManagerJVM::releaseEnv(); + return; + } + + if ((env)->ExceptionCheck()) + { + LOGE("findCandidateResource : ExceptionCheck failed"); + ThingsManagerJVM::releaseEnv(); + return; + } + + jclass vectorCls = env->FindClass(TM_JAVA_VECTOR_CLASS_PATH); + if (!vectorCls) + { + LOGE("findCandidateResource: failed to get %s class reference", TM_JAVA_VECTOR_CLASS_PATH); + ThingsManagerJVM::releaseEnv(); + return; + } + + jmethodID constr = env->GetMethodID(vectorCls, "", "()V"); + if (!constr) + { + LOGE("findCandidateResource: failed to get %s constructor", TM_JAVA_VECTOR_CLASS_PATH); + ThingsManagerJVM::releaseEnv(); + return; + } + + jobject vectorObj = env->NewObject(vectorCls, constr); + if (!vectorObj) + { + LOGE("findCandidateResource: failed to create a %s object", TM_JAVA_VECTOR_CLASS_PATH); + ThingsManagerJVM::releaseEnv(); + return; + } + + jmethodID addElement = env->GetMethodID(vectorCls, "addElement", "(Ljava/lang/Object;)V"); + if (NULL == addElement) + { + LOGE("findCandidateResource: failed to create a addElement method"); + ThingsManagerJVM::releaseEnv(); + return; + } + + // Convert to java OCResource object + for (int i = 0; i < resources.size(); i++) + { + JniOcResource *jniOcResource = new JniOcResource(resources[i]); + if (!jniOcResource) + { + LOGE("findCandidateResource: failed to create a JniOcResource"); + ThingsManagerJVM::releaseEnv(); + return; + } + + jobject resource = OcResourceToJava(env, reinterpret_cast(jniOcResource)); + env->CallVoidMethod(vectorObj, addElement, resource); + } + + env->CallStaticVoidMethod(groupManagerCallbacks, method_id, vectorObj); + + if ((env)->ExceptionCheck()) + { + LOGE("findCandidateResource : CallVoidMethod failed"); + ThingsManagerJVM::releaseEnv(); + return; + } + + ThingsManagerJVM::releaseEnv(); + LOGI("findCandidateResource : Exit"); +} + +void GroupManagerCallbacks::onSubscribePresence(std::string resource, OCStackResult result) +{ + LOGI("SubscribePresence : Entry"); + + JNIEnv *env = ThingsManagerJVM::getEnv(); + if (env == NULL) + { + LOGE("SubscribePresence : Getting JNIEnv failed"); + return; + } + + // Get GroupManagerCallback class reference + jclass groupManagerCallbacks = GetJClass(TM_SERVICE_GROUP_MANAGER_CLASS_PATH); + + if (NULL == groupManagerCallbacks) + { + LOGE("SubscribePresence : GetJClass TMServiceCallbackInterface failed"); + ThingsManagerJVM::releaseEnv(); + return; + } + + jmethodID method_id = env->GetStaticMethodID(groupManagerCallbacks, + "onPresenceCallback", + METHOD_ONPRESENCE_CALLBACK); + if (NULL == method_id) + { + LOGE("SubscribePresence : GetMethodID failed"); + ThingsManagerJVM::releaseEnv(); + return; + } + + if ((env)->ExceptionCheck()) + { + LOGE("SubscribePresence : ExceptionCheck failed"); + ThingsManagerJVM::releaseEnv(); + return; + } + + JString *jresource = new JString(env, resource); + if (jresource == NULL) + { + LOGE("resource value is invalid"); + ThingsManagerJVM::releaseEnv(); + return; + } + + env->CallStaticVoidMethod(groupManagerCallbacks, method_id, jresource->getObject(), (jint)result); + + delete jresource; + + if ((env)->ExceptionCheck()) + { + LOGE("SubscribePresence : CallVoidMethod failed"); + ThingsManagerJVM::releaseEnv(); + return; + } + + LOGI("SubscribePresence : Exit"); + +//METHOD_FAILURE: + ThingsManagerJVM::releaseEnv(); +} + +void GroupManagerCallbacks::onPostResponse(const OC::HeaderOptions &headerOptions, + const OC::OCRepresentation &rep, const int eCode) +{ + LOGI("PostResponse : Enter"); + + GroupManagerCallbacks::invokeCallback(headerOptions, rep, eCode, "onPostResponseCallback", + METHOD_ONPOST_CALLBACK); + + LOGI("PostResponse : Exit"); +} + +void GroupManagerCallbacks::onPutResponse(const OC::HeaderOptions &headerOptions, + const OC::OCRepresentation &rep, const int eCode) +{ + LOGI("OnPutResponse : Enter"); + + GroupManagerCallbacks::invokeCallback(headerOptions, rep, eCode, "onPutResponseCallback", + METHOD_ONPUT_CALLBACK); + + LOGI("OnPutResponse : Exit"); +} + +void GroupManagerCallbacks::onGetResponse(const OC::HeaderOptions &headerOptions, + const OC::OCRepresentation &rep, const int eCode) +{ + LOGI("OnGetResponse : Enter"); + + GroupManagerCallbacks::invokeCallback(headerOptions, rep, eCode, "onGetResponseCallback", + METHOD_ONGET_CALLBACK); + + LOGI("OnGetResponse : Exit"); +} + +void GroupManagerCallbacks::invokeCallback(const OC::HeaderOptions &headerOptions, + const OC::OCRepresentation &rep, const int eCode, const char *callbackName, + const char *signature) +{ + LOGI("InvokeCallback : Enter %s", callbackName); + + JNIEnv *env = ThingsManagerJVM::getEnv(); + if (env == NULL) + { + LOGE("InvokeCallback : Getting JNIEnv failed"); + return; + } + + // Get ThingsManagerCallback class reference + jclass groupManagerCallbacks = GetJClass(TM_SERVICE_GROUP_MANAGER_CLASS_PATH); + if (NULL == groupManagerCallbacks) + { + LOGE("InvokeCallback : GetJClass TMServiceCallbackInterface failed"); + ThingsManagerJVM::releaseEnv(); + return; + } + + jmethodID method_id = env->GetStaticMethodID(groupManagerCallbacks, callbackName, signature); + if (!method_id) + { + LOGE("InvokeCallback : GetMethodID failed"); + ThingsManagerJVM::releaseEnv(); + return; + } + + if ((env)->ExceptionCheck()) + { + LOGE("InvokeCallback : ExceptionCheck failed"); + ThingsManagerJVM::releaseEnv(); + return; + } + + // Convert vector to java type + jclass vectorCls = env->FindClass(TM_JAVA_VECTOR_CLASS_PATH); + if (!vectorCls) + { + LOGE("InvokeCallback: failed to get %s class reference", TM_JAVA_VECTOR_CLASS_PATH); + ThingsManagerJVM::releaseEnv(); + return; + } + + jmethodID constr = env->GetMethodID(vectorCls, "", "()V"); + if (!constr) + { + LOGE("InvokeCallback: failed to get %s constructor", TM_JAVA_VECTOR_CLASS_PATH); + ThingsManagerJVM::releaseEnv(); + return; + } + + jobject vectorObj = env->NewObject(vectorCls, constr); + if (!vectorObj) + { + LOGE("InvokeCallback: failed to create a %s object", TM_JAVA_VECTOR_CLASS_PATH); + ThingsManagerJVM::releaseEnv(); + return; + } + + jmethodID addElement = env->GetMethodID(vectorCls, "addElement", "(Ljava/lang/Object;)V"); + if (NULL == addElement) + { + LOGE("InvokeCallback: failed to create a addElement method"); + ThingsManagerJVM::releaseEnv(); + return; + } + + jobject headerOptionTemp; + for (int i = 0; i < headerOptions.size(); i++) + { + headerOptionTemp = OcHeaderOptionToJava(env, headerOptions[i]); + env->CallVoidMethod(vectorObj, addElement, headerOptionTemp); + } + + // Convert OCRepresentation to java type + jobject jrepresentation = OcRepresentationToJava(env, (jlong) reinterpret_cast(&rep)); + if (!jrepresentation) + { + LOGE("InvokeCallback : cannot create OCRepresentation class"); + ThingsManagerJVM::releaseEnv(); + return; + } + + env->CallStaticVoidMethod(groupManagerCallbacks, method_id, vectorObj, jrepresentation, + (jint)eCode); + + if ((env)->ExceptionCheck()) + { + LOGE("InvokeCallback : CallVoidMethod failed"); + ThingsManagerJVM::releaseEnv(); + return; + } + + ThingsManagerJVM::releaseEnv(); + LOGI("InvokeCallback : Exit %s", callbackName); +} diff --git a/service/things-manager/sdk/java/jni/tm/src/jni_group_synchronization.cpp b/service/things-manager/sdk/java/jni/tm/src/jni_group_synchronization.cpp new file mode 100644 index 0000000..1ab32fe --- /dev/null +++ b/service/things-manager/sdk/java/jni/tm/src/jni_group_synchronization.cpp @@ -0,0 +1,375 @@ +/* ***************************************************************** + * + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ + +#include "jni_group_synchronization.h" +#include "JniOcResource.h" +#include "JniOcResourceHandle.h" +#include "GroupManager.h" +#include "ActionSet.h" +#include "jni_things_manager_jvm.h" +#include "jni_things_manager_util.h" +#include "jni_group_synchronization_callbacks.h" +#include "jni_action_set.h" + +using namespace OC; +using namespace OIC; + +/** + * GroupSynchronization static object + */ +static GroupSynchronization g_GroupSynchronization; + +JNIEXPORT jint JNICALL JNIGroupSynchronizationFindGroup(JNIEnv *env, jobject interfaceObject, + jobject jResourceTypes) +{ + LOGI("JNIGroupSynchronizationFindGroup: Enter"); + + if (!jResourceTypes) + { + LOGE("JNIGroupSynchronizationFindGroup: jResourceTypes is NULL!"); + return OC_STACK_INVALID_PARAM; + } + + OCStackResult ocResult = OC_STACK_ERROR; + try + { + ocResult = g_GroupSynchronization.findGroup((convertStringVector(env, jResourceTypes)), + &GroupSynchronizationCallbacks::onFoundGroup); + if (OC_STACK_OK != ocResult) + { + LOGE("JNIGroupSynchronizationFindGroup: findGroup failed!"); + return ocResult; + } + } + catch (InitializeException &e) + { + LOGE("JNIGroupSynchronizationFindGroup: Exception occurred! %s, %d", e.reason().c_str(), + e.code()); + return ocResult; + } + LOGI("JNIGroupSynchronizationFindGroup: Exit"); + return ocResult; +} + +JNIEXPORT jint JNICALL JNIGroupSynchronizationCreateGroup(JNIEnv *env, jobject interfaceObject, + jstring jResourceType) +{ + LOGI("JNIGroupSynchronizationCreateGroup: Enter"); + + if (!jResourceType) + { + LOGE("JNIGroupSynchronizationCreateGroup: jResourceType is NULL!"); + return OC_STACK_INVALID_PARAM; + } + + OCStackResult ocResult = OC_STACK_ERROR; + + const char *resourceTypePointer = env->GetStringUTFChars(jResourceType, NULL); + if (NULL == resourceTypePointer) + { + LOGE("JNIGroupSynchronizationCreateGroup: Failed to convert jstring to char string!"); + return OC_STACK_NO_MEMORY; + } + + std::string resourceType(resourceTypePointer); + try + { + ocResult = g_GroupSynchronization.createGroup(resourceType); + if (OC_STACK_OK != ocResult) + { + LOGE("JNIGroupSynchronizationCreateGroup: CreateGroup failed!"); + } + } + catch (InitializeException &e) + { + LOGE("JNIGroupSynchronizationCreateGroup: Exception occurred! %s, %d", e.reason().c_str(), + e.code()); + } + env->ReleaseStringUTFChars(jResourceType, resourceTypePointer); + LOGI("JNIGroupSynchronizationCreateGroup: Exit"); + return ocResult; +} + +JNIEXPORT jint JNICALL JNIGroupSynchronizationJoinGroupString(JNIEnv *env, jobject interfaceObject, + jstring jResourceType, jobject jResourceHandle) +{ + LOGI("JNIGroupSynchronizationJoinGroupString: Enter"); + + if ((!jResourceType) || (!jResourceHandle)) + { + LOGE("JNIGroupSynchronizationJoinGroupString: jResourceType or jResourceHandle is NULL!"); + return OC_STACK_INVALID_PARAM; + } + + OCStackResult ocResult = OC_STACK_ERROR; + + const char *resourceTypePointer = env->GetStringUTFChars(jResourceType, NULL); + if (NULL == resourceTypePointer) + { + LOGE("JNIGroupSynchronizationJoinGroupString: Failed to convert jstring to char string!"); + return OC_STACK_NO_MEMORY; + } + + std::string resourceType(resourceTypePointer); + + JniOcResourceHandle *jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(env, + jResourceHandle); + try + { + OCResourceHandle ocResourceHandle = jniOcResourceHandle->getOCResourceHandle(); + ocResult = g_GroupSynchronization.joinGroup(resourceType, ocResourceHandle); + if (OC_STACK_OK != ocResult) + { + LOGE("JNIGroupSynchronizationJoinGroupString: joinGroup failed!"); + } + } + catch (InitializeException &e) + { + LOGE("JNIGroupSynchronizationJoinGroupString: Exception occurred! %s, %d", e.reason().c_str(), + e.code()); + } + env->ReleaseStringUTFChars(jResourceType, resourceTypePointer); + LOGI("JNIGroupSynchronizationJoinGroupString: Exit"); + return ocResult; +} + +JNIEXPORT jint JNICALL JNIGroupSynchronizationJoinGroupObject(JNIEnv *env, jobject interfaceObject, + jobject jResource, jobject jResourceHandle) +{ + LOGI("JNIGroupSynchronizationJoinGroupObject: Enter"); + + if ((!jResource) || (!jResourceHandle)) + { + LOGE("JNIGroupSynchronizationJoinGroupObject: jResource or jResourceHandle is NULL!"); + return OC_STACK_INVALID_PARAM; + } + + OCStackResult ocResult = OC_STACK_ERROR; + + std::shared_ptr ocResource; + JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, jResource); + if (jniOcResource) + { + ocResource = jniOcResource->getOCResource(); + } + + if (NULL == ocResource.get()) + { + LOGE("JNIGroupSynchronizationJoinGroupObject: Failed to get OCResource object!"); + return ocResult; + } + + JniOcResourceHandle *jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(env, + jResourceHandle); + + try + { + OCResourceHandle resHandle = jniOcResourceHandle->getOCResourceHandle(); + + ocResult = g_GroupSynchronization.joinGroup(ocResource, resHandle); + if (OC_STACK_OK != ocResult) + { + LOGE("JNIGroupSynchronizationJoinGroupObject: joinGroup failed!"); + return ocResult; + } + } + catch (InitializeException &e) + { + LOGE("JNIGroupSynchronizationJoinGroupObject: Exception occurred! %s, %d", e.reason().c_str(), + e.code()); + return ocResult; + } + LOGI("JNIGroupSynchronizationJoinGroupObject: Exit"); + return ocResult; +} + +JNIEXPORT jint JNICALL JNIGroupSynchronizationLeaveGroup(JNIEnv *env, jobject interfaceObject, + jstring jResourceType, + jobject jResourceHandle) +{ + LOGI("JNIGroupSynchronizationLeaveGroup: Enter"); + + if ((!jResourceType) || (!jResourceHandle)) + { + LOGE("JNIGroupSynchronizationLeaveGroup: jResourceType or jResourceHandle is NULL!"); + return OC_STACK_INVALID_PARAM; + } + + OCStackResult ocResult = OC_STACK_ERROR; + + const char *resourceTypePointer = env->GetStringUTFChars(jResourceType, NULL); + if (NULL == resourceTypePointer) + { + LOGE("JNIGroupSynchronizationLeaveGroup: Failed to convert jstring to char string!"); + return OC_STACK_NO_MEMORY; + } + + std::string resourceType(resourceTypePointer); + JniOcResourceHandle *jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(env, + jResourceHandle); + + try + { + OCResourceHandle ocResourceHandle = jniOcResourceHandle->getOCResourceHandle(); + + ocResult = g_GroupSynchronization.leaveGroup(resourceType, ocResourceHandle); + if (OC_STACK_OK != ocResult) + { + LOGE("JNIGroupSynchronizationLeaveGroup: leaveGroup failed!"); + } + } + catch (InitializeException &e) + { + LOGE("JNIGroupSynchronizationLeaveGroup: Exception occurred! %s, %d", e.reason().c_str(), + e.code()); + } + env->ReleaseStringUTFChars(jResourceType, resourceTypePointer); + LOGI("JNIGroupSynchronizationLeaveGroup: Exit"); + return ocResult; +} + +JNIEXPORT jint JNICALL JNIGroupSynchronizationLeaveGroupForResource(JNIEnv *env, + jobject interfaceObject, + jobject jResource, + jstring jResourceType, + jobject jResourceHandle) +{ + LOGI("JNIGroupSynchronizationLeaveGroupForResource: Enter"); + + if ((!jResource) || (!jResourceType) || (!jResourceHandle)) + { + LOGE("JNIGroupSynchronizationLeaveGroupForResource: jResourceType or jResourceHandle is NULL!"); + return OC_STACK_INVALID_PARAM; + } + + OCStackResult ocResult = OC_STACK_ERROR; + + JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, jResource); + if (NULL == jniOcResource) + { + LOGE("JNIGroupSynchronizationLeaveGroupForResource: Failed to get jni OcResource!"); + return ocResult; + } + + std::shared_ptr ocResource = jniOcResource->getOCResource(); + if (NULL == ocResource.get()) + { + LOGE("JNIGroupSynchronizationLeaveGroupForResource: Failed to get OCResource object!"); + return ocResult; + } + + const char *resourceTypePointer = env->GetStringUTFChars(jResourceType, NULL); + if (NULL == resourceTypePointer) + { + LOGE("JNIGroupSynchronizationLeaveGroupForResource: Failed to convert jstring to char string!"); + return OC_STACK_NO_MEMORY; + } + + std::string resourceType(resourceTypePointer); + JniOcResourceHandle *jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(env, + jResourceHandle); + + try + { + OCResourceHandle ocResourceHandle = jniOcResourceHandle->getOCResourceHandle(); + + ocResult = g_GroupSynchronization.leaveGroup(ocResource, resourceType, ocResourceHandle); + if (OC_STACK_OK != ocResult) + { + LOGE("JNIGroupSynchronizationLeaveGroupForResource: leaveGroup failed!"); + } + } + catch (InitializeException &e) + { + LOGE("JNIGroupSynchronizationLeaveGroupForResource: Exception occurred! %s, %d", e.reason().c_str(), + e.code()); + } + + env->ReleaseStringUTFChars(jResourceType, resourceTypePointer); + LOGI("JNIGroupSynchronizationLeaveGroupForResource: Exit"); + return ocResult; +} + +JNIEXPORT void JNICALL JNIGroupSynchronizationDeleteGroup(JNIEnv *env, jobject interfaceObject, + jstring jcollectionResourceType) +{ + LOGI("JNIGroupSynchronizationDeleteGroup: Enter"); + + if (!jcollectionResourceType) + { + LOGE("JNIGroupSynchronizationDeleteGroup: jcollectionResourceType is NULL!"); + return; + } + + const char *collectionResourceTypePointer = env->GetStringUTFChars(jcollectionResourceType, NULL); + if (NULL == collectionResourceTypePointer) + { + LOGE("JNIGroupSynchronizationDeleteGroup: Failed to convert jstring to char string!"); + return; + } + + std::string collectionResourceType(collectionResourceTypePointer); + try + { + g_GroupSynchronization.deleteGroup(collectionResourceType); + } + catch (InitializeException &e) + { + LOGE("JNIGroupSynchronizationDeleteGroup: Exception occurred! %s, %d", e.reason().c_str(), + e.code()); + } + + env->ReleaseStringUTFChars(jcollectionResourceType, collectionResourceTypePointer); + LOGI("JNIGroupSynchronizationDeleteGroup: Exit"); +} + +JNIEXPORT jobject JNICALL JNIGroupSynchronizationGetGroupList(JNIEnv *env, jobject interfaceObject) +{ + LOGI("JNIGroupSynchronizationGetGroupList: Enter"); + + std::map< std::string, OCResourceHandle> groupListMap; + jobject jGroupListMap; + + groupListMap = g_GroupSynchronization.getGroupList(); + if (groupListMap.empty()) + { + LOGD("getGroupList Map is empty"); + return NULL; + } + + jclass clazz = env->FindClass("java/util/HashMap"); + jmethodID init = env->GetMethodID(clazz, "", "()V"); + jGroupListMap = env->NewObject(clazz, init); + jmethodID putMethod = env->GetMethodID(clazz, "put", + "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); + + for (auto it = groupListMap.begin(); it != groupListMap.end(); ++it) + { + jstring key = (*env).NewStringUTF( (*it).first.c_str() ); + JniOcResourceHandle *jniOcResourceHandle = new JniOcResourceHandle(((*it).second)); + jobject value = ocResourceHandleToJava(env, reinterpret_cast(jniOcResourceHandle)); + env->CallObjectMethod(jGroupListMap, putMethod, key, value); + } + + LOGI("JNIGroupSynchronizationGetGroupList: Exit"); + return jGroupListMap; +} + + diff --git a/service/things-manager/sdk/java/jni/tm/src/jni_group_synchronization_callbacks.cpp b/service/things-manager/sdk/java/jni/tm/src/jni_group_synchronization_callbacks.cpp new file mode 100644 index 0000000..867831b --- /dev/null +++ b/service/things-manager/sdk/java/jni/tm/src/jni_group_synchronization_callbacks.cpp @@ -0,0 +1,106 @@ +/* ***************************************************************** + * + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ + +#include "jni_group_synchronization_callbacks.h" +#include "JniOcResource.h" +#include "GroupSynchronization.h" +#include "jni_things_manager_jvm.h" +#include "jni_things_manager_util.h" +#include "jni_string.h" + +#define LOG_TAG "GroupSynchronizationCallbacks" + +#define METHOD_ONGROUP_FIND_CALLBACK "(" TM_SERVICE_OCRESOURCE_TYPE")V" + +void GroupSynchronizationCallbacks::onFoundGroup(std::shared_ptr groupResource) +{ + LOGI("FindGroup : Enter"); + + if (NULL == groupResource.get()) + { + LOGE("FindGroup : Invalid received GroupResource!"); + return; + } + + JNIEnv *env = ThingsManagerJVM::getEnv(); + if (env == NULL) + { + LOGE("FindGroup : Getting JNIEnv failed"); + return; + } + + // Get ThingsManagerCallback class reference + jclass groupSynchronizationCallbacks = GetJClass(TM_SERVICE_GROUP_SYNCHRONIZATION_CLASS_PATH); + if (NULL == groupSynchronizationCallbacks) + { + LOGE("FindGroup : GetJClass TMServiceCallbackInterface failed"); + ThingsManagerJVM::releaseEnv(); + return; + } + + // Get the ThingsManagerCallback class instance + jobject jobjectCallback = GetJObjectInstance(TM_SERVICE_GROUP_SYNCHRONIZATION_CLASS_PATH); + if (NULL == jobjectCallback) + { + LOGE("FindGroup: getInstance failed!"); + ThingsManagerJVM::releaseEnv(); + return; + } + + // Get onGroupFindCallback method reference + jmethodID method_id = env->GetMethodID(groupSynchronizationCallbacks, + "onGroupFindCallback", + METHOD_ONGROUP_FIND_CALLBACK); + if (NULL == method_id) + { + LOGE("FindGroup : GetMethodID failed"); + ThingsManagerJVM::releaseEnv(); + return; + } + + if ((env)->ExceptionCheck()) + { + LOGE("FindGroup : ExceptionCheck failed"); + ThingsManagerJVM::releaseEnv(); + return; + } + + JniOcResource *jniOcResource = new JniOcResource(groupResource); + if (!jniOcResource) + { + LOGE("FindGroup : groupResource is invalid!"); + ThingsManagerJVM::releaseEnv(); + return; + } + + jobject resource = OcResourceToJava(env, reinterpret_cast(jniOcResource)); + + env->CallVoidMethod(jobjectCallback, method_id, resource); + + if ((env)->ExceptionCheck()) + { + LOGE("FindGroup : CallVoidMethod failed"); + ThingsManagerJVM::releaseEnv(); + return; + } + + ThingsManagerJVM::releaseEnv(); + LOGI("FindGroup : Exit"); +} diff --git a/service/things-manager/sdk/java/jni/tm/src/jni_things_configuration.cpp b/service/things-manager/sdk/java/jni/tm/src/jni_things_configuration.cpp new file mode 100644 index 0000000..c5291d8 --- /dev/null +++ b/service/things-manager/sdk/java/jni/tm/src/jni_things_configuration.cpp @@ -0,0 +1,155 @@ +/* ***************************************************************** + * + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ +#include "jni_things_configuration.h" +#include "JniOcResource.h" +#include "JniOcResourceHandle.h" +#include "ThingsConfiguration.h" +#include "ActionSet.h" +#include "jni_things_manager_jvm.h" +#include "jni_things_manager_util.h" +#include "jni_things_configuration_callbacks.h" +#include "jni_action_set.h" + +using namespace OC; +using namespace OIC; + +/** + * ThingsConfiguration static object + */ +static ThingsConfiguration g_ThingsConfiguration; + +JNIEXPORT jint JNICALL JNIThingsConfigurationUpdateConfigurations(JNIEnv *env, + jobject interfaceObject, + jobject resource, jobject configurations) +{ + LOGI("JNIThingsConfigurationUpdateConfigurations: Enter"); + + if ((!resource) || (!configurations)) + { + LOGE("JNIThingsConfigurationUpdateConfigurations: resource or configurations is NULL!"); + return OC_STACK_INVALID_PARAM; + } + + OCStackResult ocResult = OC_STACK_ERROR; + + std::shared_ptr ocResource; + JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, resource); + if (jniOcResource) + { + ocResource = jniOcResource->getOCResource(); + } + + if (NULL == ocResource.get()) + { + LOGE("JNIThingsConfigurationUpdateConfigurations: Failed to get OCResource object!"); + return ocResult; + } + + std::map configurationsMap; + configurationsMap = convertStringMap(env, configurations); + ocResult = g_ThingsConfiguration.updateConfigurations(ocResource, configurationsMap, + &ThingsConfigurationCallbacks::onUpdateConfigurationsResponse); + if (OC_STACK_OK != ocResult) + { + LOGE("JNIThingsConfigurationUpdateConfigurations: updateConfigurations failed!"); + return ocResult; + } + + LOGI("JNIThingsConfigurationUpdateConfigurations: Exit"); + return ocResult; +} + +JNIEXPORT jint JNICALL JNIThingsConfigurationGetConfigurations(JNIEnv *env, jobject interfaceObject, + jobject resource, jobject configurations) +{ + LOGI("JNIThingsConfigurationGetConfigurations: Enter"); + + if ((!resource) || (!configurations)) + { + LOGE("JNIThingsConfigurationGetConfigurations: resource or configurations is NULL!"); + return OC_STACK_INVALID_PARAM; + } + + OCStackResult ocResult = OC_STACK_ERROR; + + std::shared_ptr ocResource; + JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, resource); + if (jniOcResource) + { + ocResource = jniOcResource->getOCResource(); + } + + if (NULL == ocResource.get()) + { + LOGE("JNIThingsConfigurationGetConfigurations: Failed to get OCResource object!"); + return ocResult; + } + + ocResult = g_ThingsConfiguration.getConfigurations(ocResource, + (convertStringVector(env, configurations)), + &ThingsConfigurationCallbacks::onGetConfigurationsResponse); + if (OC_STACK_OK != ocResult) + { + LOGE("JNIThingsConfigurationGetConfigurations: getConfigurations failed!"); + return ocResult; + } + + LOGI("JNIThingsConfigurationGetConfigurations: Exit"); + return ocResult; +} + +JNIEXPORT jstring JNICALL JNIThingsConfigurationGetListOfSupportedConfigurationUnits(JNIEnv *env, + jobject interfaceObject) +{ + LOGI("JNIThingsConfigurationGetListOfSupportedConfigurationUnits: Enter"); + + std::string configListString = g_ThingsConfiguration.getListOfSupportedConfigurationUnits(); + jstring jConfigListString = env->NewStringUTF(configListString.c_str()); + + LOGI("JNIThingsConfigurationGetListOfSupportedConfigurationUnits: Exit"); + return jConfigListString; +} + +JNIEXPORT jint JNICALL JNIThingsConfigurationDoBootstrap(JNIEnv *env, jobject interfaceObject) +{ + LOGI("JNIThingsConfigurationDoBootstrap: Enter"); + + OCStackResult ocResult = OC_STACK_ERROR; + try + { + ocResult = g_ThingsConfiguration.doBootstrap(&ThingsConfigurationCallbacks::onBootStrapResponse); + if (OC_STACK_OK != ocResult) + { + LOGE("JNIThingsConfigurationDoBootstrap: doBootstrap failed!"); + return ocResult; + } + } + catch (InitializeException &e) + { + LOGE("JNIThingsConfigurationDoBootstrap: Exception occurred! %s, %d", e.reason().c_str(), + e.code()); + return ocResult; + } + + LOGI("JNIThingsConfigurationDoBootstrap: Exit"); + return ocResult; +} + + diff --git a/service/things-manager/sdk/java/jni/tm/src/jni_things_configuration_callbacks.cpp b/service/things-manager/sdk/java/jni/tm/src/jni_things_configuration_callbacks.cpp new file mode 100644 index 0000000..3ac990d --- /dev/null +++ b/service/things-manager/sdk/java/jni/tm/src/jni_things_configuration_callbacks.cpp @@ -0,0 +1,179 @@ +/* ***************************************************************** + * + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ + +#include "jni_things_configuration_callbacks.h" +#include "JniOcResource.h" +#include "ThingsConfiguration.h" +#include "jni_things_manager_jvm.h" +#include "jni_things_manager_util.h" +#include "jni_string.h" + +#define LOG_TAG "ThingsConfigurationCallbacks" + +#define METHOD_ONUPDATE_CONF_CALLBACK "(" TM_JAVA_VECTOR_TYPE TM_SERVICE_OCREPRESENTATION_TYPE"I)V" +#define METHOD_ONGET_CONF_CALLBACK "(" TM_JAVA_VECTOR_TYPE TM_SERVICE_OCREPRESENTATION_TYPE"I)V" +#define METHOD_ONBOOT_STRAP_CALLBACK "(" TM_JAVA_VECTOR_TYPE TM_SERVICE_OCREPRESENTATION_TYPE"I)V" + +void ThingsConfigurationCallbacks::onUpdateConfigurationsResponse(const OC::HeaderOptions + &headerOptions, + const OC::OCRepresentation &rep, const int eCode) +{ + LOGI("UpdateConfigurations : Enter"); + + ThingsConfigurationCallbacks::invokeCallback(headerOptions, rep, eCode, + "onUpdateConfigurationsCallback", + METHOD_ONUPDATE_CONF_CALLBACK); + + LOGI("UpdateConfigurations : Exit"); +} + +void ThingsConfigurationCallbacks::onGetConfigurationsResponse(const OC::HeaderOptions + &headerOptions, + const OC::OCRepresentation &rep, const int eCode) +{ + LOGI("GetConfigurations : Enter"); + + ThingsConfigurationCallbacks::invokeCallback(headerOptions, rep, eCode, + "onGetConfigurationsCallback", + METHOD_ONGET_CONF_CALLBACK); + + LOGI("GetConfigurations : Exit"); +} + +void ThingsConfigurationCallbacks::onBootStrapResponse(const OC::HeaderOptions &headerOptions, + const OC::OCRepresentation &rep, const int eCode) +{ + LOGI("BootStrap : Enter"); + + ThingsConfigurationCallbacks::invokeCallback(headerOptions, rep, eCode, "onBootStrapCallback", + METHOD_ONBOOT_STRAP_CALLBACK); + + LOGI("BootStrap : Exit"); +} + +void ThingsConfigurationCallbacks::invokeCallback(const OC::HeaderOptions &headerOptions, + const OC::OCRepresentation &rep, const int eCode, const char *callbackName, + const char *signature) +{ + LOGI("InvokeCallback : Enter %s", callbackName); + + JNIEnv *env = ThingsManagerJVM::getEnv(); + if (env == NULL) + { + LOGE("InvokeCallback : Getting JNIEnv failed"); + return; + } + + // Get ThingsManagerCallback class reference + jclass thingsConfigurationCallbacks = GetJClass(TM_SERVICE_THINGS_CONFIGURATION_CLASS_PATH); + if (NULL == thingsConfigurationCallbacks) + { + LOGE("InvokeCallback : GetJClass TMServiceCallbackInterface failed"); + ThingsManagerJVM::releaseEnv(); + return; + } + + // Get the ThingsManagerCallback class instance + jobject jobjectCallback = GetJObjectInstance(TM_SERVICE_THINGS_CONFIGURATION_CLASS_PATH); + if (NULL == jobjectCallback) + { + LOGE("InvokeCallback: getInstance( %s) failed!", TM_SERVICE_THINGS_CONFIGURATION_CLASS_PATH); + ThingsManagerJVM::releaseEnv(); + return; + } + + jmethodID method_id = env->GetMethodID(thingsConfigurationCallbacks, callbackName, signature); + if (!method_id) + { + LOGE("InvokeCallback : GetMethodID failed"); + ThingsManagerJVM::releaseEnv(); + return; + } + + if ((env)->ExceptionCheck()) + { + LOGE("InvokeCallback : ExceptionCheck failed"); + ThingsManagerJVM::releaseEnv(); + return; + } + + // Convert vector to java type + jclass vectorCls = env->FindClass(TM_JAVA_VECTOR_CLASS_PATH); + if (!vectorCls) + { + LOGE("InvokeCallback: failed to get %s class reference", TM_JAVA_VECTOR_CLASS_PATH); + ThingsManagerJVM::releaseEnv(); + return; + } + + jmethodID constr = env->GetMethodID(vectorCls, "", "()V"); + if (!constr) + { + LOGE("InvokeCallback: failed to get %s constructor", TM_JAVA_VECTOR_CLASS_PATH); + ThingsManagerJVM::releaseEnv(); + return; + } + + jobject vectorObj = env->NewObject(vectorCls, constr); + if (!vectorObj) + { + LOGE("InvokeCallback: failed to create a %s object", TM_JAVA_VECTOR_CLASS_PATH); + ThingsManagerJVM::releaseEnv(); + return; + } + + jmethodID addElement = env->GetMethodID(vectorCls, "addElement", "(Ljava/lang/Object;)V"); + if (NULL == addElement) + { + LOGE("InvokeCallback: failed to create a addElement method"); + ThingsManagerJVM::releaseEnv(); + return; + } + + jobject headerOptionTemp; + for (int i = 0; i < headerOptions.size(); i++) + { + headerOptionTemp = OcHeaderOptionToJava(env, headerOptions[i]); + env->CallVoidMethod(vectorObj, addElement, headerOptionTemp); + } + + // Convert OCRepresentation to java type + jobject jrepresentation = OcRepresentationToJava(env, (jlong) reinterpret_cast(&rep)); + if (!jrepresentation) + { + LOGE("InvokeCallback : cannot create OCRepresentation class"); + ThingsManagerJVM::releaseEnv(); + return; + } + + env->CallVoidMethod(jobjectCallback, method_id, vectorObj, jrepresentation, (jint)eCode); + + if ((env)->ExceptionCheck()) + { + LOGE("InvokeCallback : CallVoidMethod failed"); + ThingsManagerJVM::releaseEnv(); + return; + } + + ThingsManagerJVM::releaseEnv(); + LOGI("InvokeCallback : Exit %s", callbackName); +} + + diff --git a/service/things-manager/sdk/java/jni/tm/src/jni_things_maintenance.cpp b/service/things-manager/sdk/java/jni/tm/src/jni_things_maintenance.cpp new file mode 100644 index 0000000..99f9417 --- /dev/null +++ b/service/things-manager/sdk/java/jni/tm/src/jni_things_maintenance.cpp @@ -0,0 +1,123 @@ +/* ***************************************************************** + * + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ +#include "jni_things_maintenance.h" +#include "JniOcResource.h" +#include "JniOcResourceHandle.h" +#include "ThingsMaintenance.h" +#include "ActionSet.h" +#include "jni_things_manager_jvm.h" +#include "jni_things_manager_util.h" +#include "jni_things_maintenance_callbacks.h" +#include "jni_action_set.h" + +using namespace OC; +using namespace OIC; + +/** + * ThingsMaintenance static object + */ +static ThingsMaintenance g_ThingsMaintenance; + +JNIEXPORT jint JNICALL JNIThingsMaintenanceReboot(JNIEnv *env, jobject interfaceObject, + jobject resource) +{ + LOGI("JNIThingsMaintenanceReboot: Enter"); + + if (!resource) + { + LOGE("JNIThingsMaintenanceReboot: resource is NULL!"); + return OC_STACK_INVALID_PARAM; + } + + OCStackResult ocResult = OC_STACK_ERROR; + + std::shared_ptr ocResource; + JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, resource); + if (jniOcResource) + { + ocResource = jniOcResource->getOCResource(); + } + + if (NULL == ocResource.get()) + { + LOGE("JNIThingsMaintenanceReboot: Failed to get OCResource object!"); + return ocResult; + } + + ocResult = g_ThingsMaintenance.reboot(ocResource, &ThingsMaintenanceCallbacks::onRebootResponse); + if (OC_STACK_OK != ocResult) + { + LOGE("JNIThingsMaintenanceReboot: reboot failed!"); + return ocResult; + } + + LOGI("JNIThingsMaintenanceReboot: Exit"); + return ocResult; +} + +JNIEXPORT jint JNICALL JNIThingsMaintenanceFactoryReset(JNIEnv *env, jobject interfaceObject, + jobject resource) +{ + LOGI("JNIThingsMaintenanceFactoryReset: Enter"); + + if (!resource) + { + LOGE("JNIThingsMaintenanceFactoryReset: resource is NULL!"); + return OC_STACK_INVALID_PARAM; + } + + OCStackResult ocResult = OC_STACK_ERROR; + + std::shared_ptr ocResource; + JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, resource); + if (jniOcResource) + { + ocResource = jniOcResource->getOCResource(); + } + + if (NULL == ocResource.get()) + { + LOGE("JNIThingsMaintenanceFactoryReset: Failed to get OCResource object!"); + return ocResult; + } + + ocResult = g_ThingsMaintenance.factoryReset(ocResource, + &ThingsMaintenanceCallbacks::onFactoryResetResponse); + if (OC_STACK_OK != ocResult) + { + LOGE("JNIThingsMaintenanceFactoryReset: factoryReset failed!"); + return ocResult; + } + + LOGI("JNIThingsMaintenanceFactoryReset: Exit"); + return ocResult; +} + +JNIEXPORT jstring JNICALL JNIThingsMaintenanceGetListOfSupportedConfigurationUnits +(JNIEnv *env, jobject interfaceObject) +{ + LOGI("JNIThingsMaintenanceGetListOfSupportedConfigurationUnits: Enter"); + + std::string configListString = g_ThingsMaintenance.getListOfSupportedMaintenanceUnits(); + jstring jConfigListString = env->NewStringUTF(configListString.c_str()); + + LOGI("JNIThingsMaintenanceGetListOfSupportedConfigurationUnits: Exit"); + return jConfigListString; +} diff --git a/service/things-manager/sdk/java/jni/tm/src/jni_things_maintenance_callbacks.cpp b/service/things-manager/sdk/java/jni/tm/src/jni_things_maintenance_callbacks.cpp new file mode 100644 index 0000000..ee290b5 --- /dev/null +++ b/service/things-manager/sdk/java/jni/tm/src/jni_things_maintenance_callbacks.cpp @@ -0,0 +1,161 @@ +/* ***************************************************************** + * + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ + +#include "jni_things_maintenance_callbacks.h" +#include "JniOcResource.h" +#include "ThingsMaintenance.h" +#include "jni_things_manager_jvm.h" +#include "jni_things_manager_util.h" +#include "jni_string.h" + +#define LOG_TAG "ThingsMaintenanceCallbacks" + +#define METHOD_ONFACTORY_RESET_CALLBACK "(" TM_JAVA_VECTOR_TYPE TM_SERVICE_OCREPRESENTATION_TYPE"I)V" +#define METHOD_ONREBOOT_CALLBACK "(" TM_JAVA_VECTOR_TYPE TM_SERVICE_OCREPRESENTATION_TYPE"I)V" + +void ThingsMaintenanceCallbacks::onRebootResponse(const OC::HeaderOptions &headerOptions, + const OC::OCRepresentation &rep, const int eCode) +{ + LOGI("OnReboot : Enter"); + + ThingsMaintenanceCallbacks::invokeCallback(headerOptions, rep, eCode, "onRebootCallback", + METHOD_ONREBOOT_CALLBACK); + + LOGI("OnReboot : Exit"); +} + +void ThingsMaintenanceCallbacks::onFactoryResetResponse(const OC::HeaderOptions &headerOptions, + const OC::OCRepresentation &rep, const int eCode) +{ + LOGI("OnFactoryReset : Enter"); + + ThingsMaintenanceCallbacks::invokeCallback(headerOptions, rep, eCode, "onFactoryResetCallback", + METHOD_ONFACTORY_RESET_CALLBACK); + + LOGI("OnFactoryReset : Exit"); +} + +void ThingsMaintenanceCallbacks::invokeCallback(const OC::HeaderOptions &headerOptions, + const OC::OCRepresentation &rep, const int eCode, const char *callbackName, + const char *signature) +{ + LOGI("InvokeCallback : Enter %s", callbackName); + + JNIEnv *env = ThingsManagerJVM::getEnv(); + if (env == NULL) + { + LOGE("InvokeCallback : Getting JNIEnv failed"); + return; + } + + // Get ThingsManagerCallback class reference + jclass thingsMaintenanceCallbacks = GetJClass(TM_SERVICE_THINGS_MAINTENANCE_CLASS_PATH); + if (NULL == thingsMaintenanceCallbacks) + { + LOGE("InvokeCallback : GetJClass TMServiceCallbackInterface failed"); + ThingsManagerJVM::releaseEnv(); + return; + } + + // Get the ThingsManagerCallback class instance + jobject jobjectCallback = GetJObjectInstance(TM_SERVICE_THINGS_MAINTENANCE_CLASS_PATH); + if (NULL == jobjectCallback) + { + LOGE("InvokeCallback: getInstance( %s) failed!", TM_SERVICE_THINGS_MAINTENANCE_CLASS_PATH); + ThingsManagerJVM::releaseEnv(); + return; + } + + jmethodID method_id = env->GetMethodID(thingsMaintenanceCallbacks, callbackName, signature); + if (!method_id) + { + LOGE("InvokeCallback : GetMethodID failed"); + ThingsManagerJVM::releaseEnv(); + return; + } + + if ((env)->ExceptionCheck()) + { + LOGE("InvokeCallback : ExceptionCheck failed"); + ThingsManagerJVM::releaseEnv(); + return; + } + + // Convert vector to java type + jclass vectorCls = env->FindClass(TM_JAVA_VECTOR_CLASS_PATH); + if (!vectorCls) + { + LOGE("InvokeCallback: failed to get %s class reference", TM_JAVA_VECTOR_CLASS_PATH); + ThingsManagerJVM::releaseEnv(); + return; + } + + jmethodID constr = env->GetMethodID(vectorCls, "", "()V"); + if (!constr) + { + LOGE("InvokeCallback: failed to get %s constructor", TM_JAVA_VECTOR_CLASS_PATH); + ThingsManagerJVM::releaseEnv(); + return; + } + + jobject vectorObj = env->NewObject(vectorCls, constr); + if (!vectorObj) + { + LOGE("InvokeCallback: failed to create a %s object", TM_JAVA_VECTOR_CLASS_PATH); + ThingsManagerJVM::releaseEnv(); + return; + } + + jmethodID addElement = env->GetMethodID(vectorCls, "addElement", "(Ljava/lang/Object;)V"); + if (NULL == addElement) + { + LOGE("InvokeCallback: failed to create a addElement method"); + ThingsManagerJVM::releaseEnv(); + return; + } + + jobject headerOptionTemp; + for (int i = 0; i < headerOptions.size(); i++) + { + headerOptionTemp = OcHeaderOptionToJava(env, headerOptions[i]); + env->CallVoidMethod(vectorObj, addElement, headerOptionTemp); + } + + // Convert OCRepresentation to java type + jobject jrepresentation = OcRepresentationToJava(env, (jlong) reinterpret_cast(&rep)); + if (!jrepresentation) + { + LOGE("InvokeCallback : cannot create OCRepresentation class"); + ThingsManagerJVM::releaseEnv(); + return; + } + + env->CallVoidMethod(jobjectCallback, method_id, vectorObj, jrepresentation, (jint)eCode); + + if ((env)->ExceptionCheck()) + { + LOGE("InvokeCallback : CallVoidMethod failed"); + ThingsManagerJVM::releaseEnv(); + return; + } + + ThingsManagerJVM::releaseEnv(); + LOGI("InvokeCallback : Exit %s", callbackName); +} diff --git a/service/things-manager/sdk/java/jni/tm/src/jni_things_manager.cpp b/service/things-manager/sdk/java/jni/tm/src/jni_things_manager.cpp deleted file mode 100644 index 6e66c54..0000000 --- a/service/things-manager/sdk/java/jni/tm/src/jni_things_manager.cpp +++ /dev/null @@ -1,1013 +0,0 @@ -/****************************************************************** - * - * Copyright 2015 Samsung Electronics All Rights Reserved. - * - * - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************/ -#include "jni_things_manager.h" - -#include "JniOcResource.h" -#include "JniOcResourceHandle.h" -#include "ThingsManager.h" -#include "ActionSet.h" -#include "jni_things_manager_jvm.h" -#include "jni_things_manager_util.h" -#include "jni_things_manager_callbacks.h" -#include "jni_action_set.h" - -using namespace OC; -using namespace OIC; - -/** - * @var g_ThingsManager - * @brief ThingsManager static object - */ -static ThingsManager g_ThingsManager; - -jobject ocResourceHandleToJava(JNIEnv *env, jlong resourceHandle); - -JNIEXPORT jint JNICALL JNIThingsManagerFindCandidateResource(JNIEnv *env, jobject interfaceObject, - jobject jResourceTypes, jint waitSec) -{ - LOGI("JNIThingsManagerFindCandidateResource: Enter"); - - if (!jResourceTypes) - { - LOGE("JNIThingsManagerFindCandidateResource: jResourceTypes is NULL!"); - return OC_STACK_INVALID_PARAM; - } - - OCStackResult ocResult = OC_STACK_ERROR; - try - { - ocResult = g_ThingsManager.findCandidateResources(convertStringVector(env, jResourceTypes), - &ThingsManagerCallbacks::onFoundCandidateResource, (int)waitSec); - - if (OC_STACK_OK != ocResult) - { - LOGE("JNIThingsManagerFindCandidateResource: findCandidateResources failed!"); - return ocResult; - } - } - catch (InitializeException &e) - { - LOGE("JNIThingsManagerFindCandidateResource: Exception occurred! %s, %d", e.reason().c_str(), - e.code()); - return ocResult; - } - - LOGI("JNIThingsManagerFindCandidateResource: Exit"); - return ocResult; -} - -JNIEXPORT jint JNICALL JNIThingsManagerSubscribeCollectionPresence(JNIEnv *env, - jobject interfaceObject, - jobject jResource) -{ - LOGI("JNIThingsManagerSubscribeCollectionPresence: Enter"); - - if (!jResource) - { - LOGE("JNIThingsManagerSubscribeCollectionPresence: jResource is NULL!"); - return OC_STACK_INVALID_PARAM; - } - - OCStackResult ocResult = OC_STACK_ERROR; - - JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, jResource); - if (NULL == jniOcResource) - { - LOGE("JNIThingsManagerSubscribeCollectionPresence: Failed to get jni OcResource!"); - return ocResult; - } - - std::shared_ptr ocResource = jniOcResource->getOCResource(); - if (NULL == ocResource.get()) - { - LOGE("JNIThingsManagerSubscribeCollectionPresence: Failed to get OCResource object!"); - return ocResult; - } - - ocResult = g_ThingsManager.subscribeCollectionPresence(ocResource, - &ThingsManagerCallbacks::onSubscribePresence); - if (OC_STACK_OK != ocResult) - { - LOGE("JNIThingsManagerSubscribeCollectionPresence: subscribeCollectionPresence failed!"); - return ocResult; - } - - LOGI("JNIThingsManagerSubscribeCollectionPresence: Exit"); - return ocResult; -} - -JNIEXPORT jobject JNICALL JNIThingsManagerBindResourceToGroup(JNIEnv *env, jobject interfaceObject, - jobject jResource, jobject jCollectionHandle) -{ - LOGI("JNIThingsManagerBindResourceToGroup: Enter"); - - if (!jResource || !jCollectionHandle) - { - LOGE("JNIThingsManagerBindResourceToGroup: Invalid parameter!"); - return NULL; - } - - std::shared_ptr ocResource; - JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, jResource); - if (jniOcResource) - { - ocResource = jniOcResource->getOCResource(); - } - - if (NULL == ocResource.get()) - { - LOGE("JNIThingsManagerBindResourceToGroup: Failed to get OCResource object!"); - return NULL; - } - - JniOcResourceHandle *jniOcCollectionHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(env, - jCollectionHandle); - if (NULL == jniOcCollectionHandle) - { - LOGE("JNIThingsManagerBindResourceToGroup: collection handle is null!"); - return NULL; - } - - jobject jResourceHandle = NULL; - try - { - OCResourceHandle ocChildHandle = NULL; - OCResourceHandle ocCollectionHandle = jniOcCollectionHandle->getOCResourceHandle(); - OCStackResult ocResult = g_ThingsManager.bindResourceToGroup(ocChildHandle, ocResource, ocCollectionHandle); - if (OC_STACK_OK != ocResult) - { - LOGE("JNIThingsManagerBindResourceToGroup: bindResourceToGroup failed!"); - return NULL; - } - - // Convert OCResourceHandle to java type - JniOcResourceHandle* jniHandle = new JniOcResourceHandle(ocChildHandle); - jlong handle = reinterpret_cast(jniHandle); - jResourceHandle = env->NewObject(g_cls_OcResourceHandle, g_mid_OcResourceHandle_N_ctor, handle); - if (env->ExceptionCheck()) - { - LOGE("JNIThingsManagerBindResourceToGroup: Failed to create OcResourceHandle"); - delete jniHandle; - return NULL; - } - } - catch (InitializeException &e) - { - LOGE("JNIThingsManagerBindResourceToGroup: Exception occurred! %s, %d", e.reason().c_str(), - e.code()); - return NULL; - } - - LOGI("JNIThingsManagerBindResourceToGroup: Exit"); - return jResourceHandle; -} - -JNIEXPORT jint JNICALL JNIThingsManagerFindGroup(JNIEnv *env, jobject interfaceObject, - jobject jResourceTypes) -{ - LOGI("JNIThingsManagerFindGroup: Enter"); - - if (!jResourceTypes) - { - LOGE("JNIThingsManagerFindGroup: jResourceTypes is NULL!"); - return OC_STACK_INVALID_PARAM; - } - - OCStackResult ocResult = OC_STACK_ERROR; - try - { - ocResult = g_ThingsManager.findGroup((convertStringVector(env, jResourceTypes)), - &ThingsManagerCallbacks::onFoundGroup); - if (OC_STACK_OK != ocResult) - { - LOGE("JNIThingsManagerFindGroup: findGroup failed!"); - return ocResult; - } - } - catch (InitializeException &e) - { - LOGE("JNIThingsManagerFindGroup: Exception occurred! %s, %d", e.reason().c_str(), - e.code()); - return ocResult; - } - LOGI("JNIThingsManagerFindGroup: Exit"); - return ocResult; -} - -JNIEXPORT jint JNICALL JNIThingsManagerCreateGroup(JNIEnv *env, jobject interfaceObject, - jstring jResourceType) -{ - LOGI("JNIThingsManagerCreateGroup: Enter"); - - if (!jResourceType) - { - LOGE("JNIThingsManagerCreateGroup: jResourceType is NULL!"); - return OC_STACK_INVALID_PARAM; - } - - OCStackResult ocResult = OC_STACK_ERROR; - - const char *resourceTypePointer = env->GetStringUTFChars(jResourceType, NULL); - if (NULL == resourceTypePointer) - { - LOGE("JNIThingsManagerCreateGroup: Failed to convert jstring to char string!"); - return OC_STACK_NO_MEMORY; - } - - std::string resourceType(resourceTypePointer); - try - { - ocResult = g_ThingsManager.createGroup(resourceType); - if (OC_STACK_OK != ocResult) - { - LOGE("JNIThingsManagerCreateGroup: CreateGroup failed!"); - } - } - catch (InitializeException &e) - { - LOGE("JNIThingsManagerCreateGroup: Exception occurred! %s, %d", e.reason().c_str(), - e.code()); - } - env->ReleaseStringUTFChars(jResourceType, resourceTypePointer); - LOGI("JNIThingsManagerCreateGroup: Exit"); - return ocResult; -} - -JNIEXPORT jint JNICALL JNIThingsManagerJoinGroupString(JNIEnv *env, jobject interfaceObject, - jstring jResourceType, jobject jResourceHandle) -{ - LOGI("JNIThingsManagerJoinGroupString: Enter"); - - if ((!jResourceType) || (!jResourceHandle)) - { - LOGE("JNIThingsManagerJoinGroupString: jResourceType or jResourceHandle is NULL!"); - return OC_STACK_INVALID_PARAM; - } - - OCStackResult ocResult = OC_STACK_ERROR; - - const char *resourceTypePointer = env->GetStringUTFChars(jResourceType, NULL); - if (NULL == resourceTypePointer) - { - LOGE("JNIThingsManagerJoinGroupString: Failed to convert jstring to char string!"); - return OC_STACK_NO_MEMORY; - } - - std::string resourceType(resourceTypePointer); - - JniOcResourceHandle *jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(env, - jResourceHandle); - try - { - OCResourceHandle ocResourceHandle = jniOcResourceHandle->getOCResourceHandle(); - ocResult = g_ThingsManager.joinGroup(resourceType, ocResourceHandle); - if (OC_STACK_OK != ocResult) - { - LOGE("JNIThingsManagerJoinGroupString: joinGroup failed!"); - } - } - catch (InitializeException &e) - { - LOGE("JNIThingsManagerJoinGroupString: Exception occurred! %s, %d", e.reason().c_str(), - e.code()); - } - env->ReleaseStringUTFChars(jResourceType, resourceTypePointer); - LOGI("JNIThingsManagerJoinGroupString: Exit"); - return ocResult; -} - -JNIEXPORT jint JNICALL JNIThingsManagerJoinGroupObject(JNIEnv *env, jobject interfaceObject, - jobject jResource, jobject jResourceHandle) -{ - LOGI("JNIThingsManagerJoinGroupObject: Enter"); - - if ((!jResource) || (!jResourceHandle)) - { - LOGE("JNIThingsManagerJoinGroupObject: jResource or jResourceHandle is NULL!"); - return OC_STACK_INVALID_PARAM; - } - - OCStackResult ocResult = OC_STACK_ERROR; - - std::shared_ptr ocResource; - JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, jResource); - if (jniOcResource) - { - ocResource = jniOcResource->getOCResource(); - } - - if (NULL == ocResource.get()) - { - LOGE("JNIThingsManagerJoinGroupObject: Failed to get OCResource object!"); - return ocResult; - } - - JniOcResourceHandle *jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(env, - jResourceHandle); - - try - { - OCResourceHandle resHandle = jniOcResourceHandle->getOCResourceHandle(); - - ocResult = g_ThingsManager.joinGroup(ocResource, resHandle); - if (OC_STACK_OK != ocResult) - { - LOGE("JNIThingsManagerJoinGroupObject: joinGroup failed!"); - return ocResult; - } - } - catch (InitializeException &e) - { - LOGE("JNIThingsManagerJoinGroupObject: Exception occurred! %s, %d", e.reason().c_str(), - e.code()); - return ocResult; - } - LOGI("JNIThingsManagerJoinGroupObject: Exit"); - return ocResult; -} - -JNIEXPORT jint JNICALL JNIThingsManagerLeaveGroup(JNIEnv *env, jobject interfaceObject, - jstring jResourceType, - jobject jResourceHandle) -{ - LOGI("JNIThingsManagerLeaveGroup: Enter"); - - if ((!jResourceType) || (!jResourceHandle)) - { - LOGE("JNIThingsManagerLeaveGroup: jResourceType or jResourceHandle is NULL!"); - return OC_STACK_INVALID_PARAM; - } - - OCStackResult ocResult = OC_STACK_ERROR; - - const char *resourceTypePointer = env->GetStringUTFChars(jResourceType, NULL); - if (NULL == resourceTypePointer) - { - LOGE("JNIThingsManagerLeaveGroup: Failed to convert jstring to char string!"); - return OC_STACK_NO_MEMORY; - } - - std::string resourceType(resourceTypePointer); - JniOcResourceHandle *jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(env, - jResourceHandle); - - try - { - OCResourceHandle ocResourceHandle = jniOcResourceHandle->getOCResourceHandle(); - - ocResult = g_ThingsManager.leaveGroup(resourceType, ocResourceHandle); - if (OC_STACK_OK != ocResult) - { - LOGE("JNIThingsManagerLeaveGroup: leaveGroup failed!"); - } - } - catch (InitializeException &e) - { - LOGE("JNIThingsManagerLeaveGroup: Exception occurred! %s, %d", e.reason().c_str(), - e.code()); - } - env->ReleaseStringUTFChars(jResourceType, resourceTypePointer); - LOGI("JNIThingsManagerLeaveGroup: Exit"); - return ocResult; -} - -JNIEXPORT jint JNICALL JNIThingsManagerLeaveGroupForResource(JNIEnv *env, jobject interfaceObject, - jobject jResource, - jstring jResourceType, - jobject jResourceHandle) -{ - LOGI("JNIThingsManagerLeaveGroupForResource: Enter"); - - if ((!jResource) || (!jResourceType) || (!jResourceHandle)) - { - LOGE("JNIThingsManagerLeaveGroupForResource: jResourceType or jResourceHandle is NULL!"); - return OC_STACK_INVALID_PARAM; - } - - OCStackResult ocResult = OC_STACK_ERROR; - - JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, jResource); - if (NULL == jniOcResource) - { - LOGE("JNIThingsManagerLeaveGroupForResource: Failed to get jni OcResource!"); - return ocResult; - } - - std::shared_ptr ocResource = jniOcResource->getOCResource(); - if (NULL == ocResource.get()) - { - LOGE("JNIThingsManagerLeaveGroupForResource: Failed to get OCResource object!"); - return ocResult; - } - - const char *resourceTypePointer = env->GetStringUTFChars(jResourceType, NULL); - if (NULL == resourceTypePointer) - { - LOGE("JNIThingsManagerLeaveGroupForResource: Failed to convert jstring to char string!"); - return OC_STACK_NO_MEMORY; - } - - std::string resourceType(resourceTypePointer); - JniOcResourceHandle *jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(env, - jResourceHandle); - - try - { - OCResourceHandle ocResourceHandle = jniOcResourceHandle->getOCResourceHandle(); - - ocResult = g_ThingsManager.leaveGroup(ocResource, resourceType, ocResourceHandle); - if (OC_STACK_OK != ocResult) - { - LOGE("JNIThingsManagerLeaveGroupForResource: leaveGroup failed!"); - } - } - catch (InitializeException &e) - { - LOGE("JNIThingsManagerLeaveGroupForResource: Exception occurred! %s, %d", e.reason().c_str(), - e.code()); - } - - env->ReleaseStringUTFChars(jResourceType, resourceTypePointer); - LOGI("JNIThingsManagerLeaveGroupForResource: Exit"); - return ocResult; -} - -JNIEXPORT void JNICALL JNIThingsManagerDeleteGroup(JNIEnv *env, jobject interfaceObject, - jstring jcollectionResourceType) -{ - LOGI("JNIThingsManagerDeleteGroup: Enter"); - - if (!jcollectionResourceType) - { - LOGE("JNIThingsManagerDeleteGroup: jcollectionResourceType is NULL!"); - return; - } - - const char *collectionResourceTypePointer = env->GetStringUTFChars(jcollectionResourceType, NULL); - if (NULL == collectionResourceTypePointer) - { - LOGE("JNIThingsManagerDeleteGroup: Failed to convert jstring to char string!"); - return; - } - - std::string collectionResourceType(collectionResourceTypePointer); - try - { - g_ThingsManager.deleteGroup(collectionResourceType); - } - catch (InitializeException &e) - { - LOGE("JNIThingsManagerDeleteGroup: Exception occurred! %s, %d", e.reason().c_str(), - e.code()); - } - - env->ReleaseStringUTFChars(jcollectionResourceType, collectionResourceTypePointer); - LOGI("JNIThingsManagerDeleteGroup: Exit"); -} - -JNIEXPORT jobject JNICALL JNIThingsManagerGetGroupList(JNIEnv *env, jobject interfaceObject) -{ - LOGI("JNIThingsManagerGetGroupList: Enter"); - - std::map< std::string, OCResourceHandle> groupListMap; - jobject jGroupListMap; - - groupListMap = g_ThingsManager.getGroupList(); - if (groupListMap.empty()) - { - LOGD("getGroupList Map is empty"); - return NULL; - } - - jclass clazz = env->FindClass("java/util/HashMap"); - jmethodID init = env->GetMethodID(clazz, "", "()V"); - jGroupListMap = env->NewObject(clazz, init); - jmethodID putMethod = env->GetMethodID(clazz, "put", - "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); - - for (auto it = groupListMap.begin(); it != groupListMap.end(); ++it) - { - jstring key = (*env).NewStringUTF( (*it).first.c_str() ); - JniOcResourceHandle *jniOcResourceHandle = new JniOcResourceHandle(((*it).second)); - jobject value = ocResourceHandleToJava(env, reinterpret_cast(jniOcResourceHandle)); - env->CallObjectMethod(jGroupListMap, putMethod, key, value); - } - - LOGI("JNIThingsManagerGetGroupList: Exit"); - return jGroupListMap; -} - -JNIEXPORT jint JNICALL JNIThingsManagerUpdateConfigurations(JNIEnv *env, jobject interfaceObject, - jobject resource, jobject configurations) -{ - LOGI("JNIThingsManagerUpdateConfigurations: Enter"); - - if ((!resource) || (!configurations)) - { - LOGE("JNIThingsManagerUpdateConfigurations: resource or configurations is NULL!"); - return OC_STACK_INVALID_PARAM; - } - - OCStackResult ocResult = OC_STACK_ERROR; - - std::shared_ptr ocResource; - JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, resource); - if (jniOcResource) - { - ocResource = jniOcResource->getOCResource(); - } - - if (NULL == ocResource.get()) - { - LOGE("JNIThingsManagerUpdateConfigurations: Failed to get OCResource object!"); - return ocResult; - } - - std::map configurationsMap; - configurationsMap = convertStringMap(env, configurations); - ocResult = g_ThingsManager.updateConfigurations(ocResource, configurationsMap, - &ThingsManagerCallbacks::onUpdateConfigurationsResponse); - if (OC_STACK_OK != ocResult) - { - LOGE("JNIThingsManagerUpdateConfigurations: updateConfigurations failed!"); - return ocResult; - } - - LOGI("JNIThingsManagerUpdateConfigurations: Exit"); - return ocResult; -} - -JNIEXPORT jint JNICALL JNIThingsManagerGetConfigurations(JNIEnv *env, jobject interfaceObject, - jobject resource, jobject configurations) -{ - LOGI("JNIThingsManagerGetConfigurations: Enter"); - - if ((!resource) || (!configurations)) - { - LOGE("JNIThingsManagerGetConfigurations: resource or configurations is NULL!"); - return OC_STACK_INVALID_PARAM; - } - - OCStackResult ocResult = OC_STACK_ERROR; - - std::shared_ptr ocResource; - JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, resource); - if (jniOcResource) - { - ocResource = jniOcResource->getOCResource(); - } - - if (NULL == ocResource.get()) - { - LOGE("JNIThingsManagerGetConfigurations: Failed to get OCResource object!"); - return ocResult; - } - - ocResult = g_ThingsManager.getConfigurations(ocResource, - (convertStringVector(env, configurations)), - &ThingsManagerCallbacks::onGetConfigurationsResponse); - if (OC_STACK_OK != ocResult) - { - LOGE("JNIThingsManagerGetConfigurations: getConfigurations failed!"); - return ocResult; - } - - LOGI("JNIThingsManagerGetConfigurations: Exit"); - return ocResult; -} - -JNIEXPORT jstring JNICALL JNIThingsManagerGetListOfSupportedConfigurationUnits(JNIEnv *env, - jobject interfaceObject) -{ - LOGI("JNIThingsManagerGetListOfSupportedConfigurationUnits: Enter"); - - std::string configListString = g_ThingsManager.getListOfSupportedConfigurationUnits(); - jstring jConfigListString = env->NewStringUTF(configListString.c_str()); - - LOGI("JNIThingsManagerGetListOfSupportedConfigurationUnits: Exit"); - return jConfigListString; -} - -JNIEXPORT jint JNICALL JNIThingsManagerDoBootstrap(JNIEnv *env, jobject interfaceObject) -{ - LOGI("JNIThingsManagerDoBootstrap: Enter"); - - OCStackResult ocResult = OC_STACK_ERROR; - try - { - ocResult = g_ThingsManager.doBootstrap(&ThingsManagerCallbacks::onBootStrapResponse); - if (OC_STACK_OK != ocResult) - { - LOGE("JNIThingsManagerDoBootstrap: doBootstrap failed!"); - return ocResult; - } - } - catch (InitializeException &e) - { - LOGE("JNIThingsManagerDoBootstrap: Exception occurred! %s, %d", e.reason().c_str(), - e.code()); - return ocResult; - } - - LOGI("JNIThingsManagerDoBootstrap: Exit"); - return ocResult; -} - -JNIEXPORT jint JNICALL JNIThingsManagerReboot(JNIEnv *env, jobject interfaceObject, - jobject resource) -{ - LOGI("JNIThingsManagerReboot: Enter"); - - if (!resource) - { - LOGE("JNIThingsManagerReboot: resource is NULL!"); - return OC_STACK_INVALID_PARAM; - } - - OCStackResult ocResult = OC_STACK_ERROR; - - std::shared_ptr ocResource; - JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, resource); - if (jniOcResource) - { - ocResource = jniOcResource->getOCResource(); - } - - if (NULL == ocResource.get()) - { - LOGE("JNIThingsManagerReboot: Failed to get OCResource object!"); - return ocResult; - } - - ocResult = g_ThingsManager.reboot(ocResource, &ThingsManagerCallbacks::onRebootResponse); - if (OC_STACK_OK != ocResult) - { - LOGE("JNIThingsManagerReboot: reboot failed!"); - return ocResult; - } - - LOGI("JNIThingsManagerReboot: Exit"); - return ocResult; -} - -JNIEXPORT jint JNICALL JNIThingsManagerFactoryReset(JNIEnv *env, jobject interfaceObject, - jobject resource) -{ - LOGI("JNIThingsManagerFactoryReset: Enter"); - - if (!resource) - { - LOGE("JNIThingsManagerFactoryReset: resource is NULL!"); - return OC_STACK_INVALID_PARAM; - } - - OCStackResult ocResult = OC_STACK_ERROR; - - std::shared_ptr ocResource; - JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, resource); - if (jniOcResource) - { - ocResource = jniOcResource->getOCResource(); - } - - if (NULL == ocResource.get()) - { - LOGE("JNIThingsManagerFactoryReset: Failed to get OCResource object!"); - return ocResult; - } - - ocResult = g_ThingsManager.factoryReset(ocResource, - &ThingsManagerCallbacks::onFactoryResetResponse); - if (OC_STACK_OK != ocResult) - { - LOGE("JNIThingsManagerFactoryReset: factoryReset failed!"); - return ocResult; - } - - LOGI("JNIThingsManagerFactoryReset: Exit"); - return ocResult; -} - -JNIEXPORT jint JNICALL JNIThingsManagerAddActionSet(JNIEnv *env, jobject interfaceObject, - jobject resource, - jobject newActionSet) -{ - LOGI("JNIThingsManagerAddActionSet: Entry"); - - if ((!resource) || (!newActionSet)) - { - LOGE("JNIThingsManagerAddActionSet: resource or newActionSet is NULL!"); - return OC_STACK_INVALID_PARAM; - } - - OCStackResult ocResult = OC_STACK_ERROR; - - std::shared_ptr ocResource; - JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, resource); - if (jniOcResource) - { - ocResource = jniOcResource->getOCResource(); - } - - if (NULL == ocResource.get()) - { - LOGE("JNIThingsManageraAdActionSet: Failed to get OCResource object!"); - return ocResult; - } - - JniActionSet *jActionSet = new JniActionSet(env, newActionSet); - ActionSet *pActionSet = jActionSet->getActionSet(env, newActionSet); - if (NULL == pActionSet) - { - LOGE("JNIThingsManageraAdActionSet: Failed to convert ActionSet!"); - return ocResult; - } - - ocResult = g_ThingsManager.addActionSet(ocResource, pActionSet, - &ThingsManagerCallbacks::onPutResponse); - if (OC_STACK_OK != ocResult) - { - LOGE("JNIThingsManagerAddActionSet: addActionSet is failed!"); - } - - delete pActionSet; - LOGI("JNIThingsManagerAddActionSet: Exit"); - return ocResult; -} - -JNIEXPORT jint JNICALL JNIThingsManagerExecuteActionSet(JNIEnv *env, jobject interfaceObject, - jobject resource, jstring jActionSetName) -{ - LOGI("JNIThingsManagerExecuteActionSet: Entry"); - - if ((!resource) || (!jActionSetName)) - { - LOGE("JNIThingsManagerExecuteActionSet: resource or jActionSetName is NULL!"); - return OC_STACK_INVALID_PARAM; - } - - OCStackResult ocResult = OC_STACK_ERROR; - - std::shared_ptr ocResource; - JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, resource); - if (jniOcResource) - { - ocResource = jniOcResource->getOCResource(); - } - - if (NULL == ocResource.get()) - { - LOGE("JNIThingsManagerExecuteActionSet: Failed to get OCResource object!"); - return ocResult; - } - - const char *actionSetNamePointer = env->GetStringUTFChars(jActionSetName, 0); - if (NULL == actionSetNamePointer) - { - LOGE("JNIThingsManagerExecuteActionSet: Failed to convert jstring to char string!"); - return OC_STACK_NO_MEMORY; - } - - std::string actionSetName(actionSetNamePointer); - - ocResult = g_ThingsManager.executeActionSet(ocResource, actionSetName, - &ThingsManagerCallbacks::onPostResponse); - if (OC_STACK_OK != ocResult) - { - LOGE("JNIThingsManagerExecuteActionSet: executeActionSet is failed!"); - } - - env->ReleaseStringUTFChars(jActionSetName, actionSetNamePointer); - LOGI("JNIThingsManagerExecuteActionSet: Exit"); - return ocResult; -} - -JNIEXPORT jint JNICALL JNIThingsManagerExecuteActionSetWithDelay(JNIEnv *env, - jobject interfaceObject, - jobject resource, jstring jActionSetName, jlong delay) -{ - LOGI("JNIThingsManagerExecuteActionSet: Entry"); - - if ((!resource) || (!jActionSetName)) - { - LOGE("JNIThingsManagerExecuteActionSet: resource or jActionSetName is NULL!"); - return OC_STACK_INVALID_PARAM; - } - - OCStackResult ocResult = OC_STACK_ERROR; - - std::shared_ptr ocResource; - JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, resource); - if (jniOcResource) - { - ocResource = jniOcResource->getOCResource(); - } - - if (NULL == ocResource.get()) - { - LOGE("JNIThingsManagerExecuteActionSet: Failed to get OCResource object!"); - return ocResult; - } - - const char *actionSetNamePointer = env->GetStringUTFChars(jActionSetName, 0); - if (NULL == actionSetNamePointer) - { - LOGE("JNIThingsManagerExecuteActionSet: Failed to convert jstring to char string!"); - return OC_STACK_NO_MEMORY; - } - - std::string actionSetName(actionSetNamePointer); - if (0 == delay) - { - ocResult = g_ThingsManager.executeActionSet(ocResource, actionSetName, - &ThingsManagerCallbacks::onPostResponse); - } - else - { - ocResult = g_ThingsManager.executeActionSet(ocResource, actionSetName, - (long int)delay, - &ThingsManagerCallbacks::onPostResponse); - } - if (OC_STACK_OK != ocResult) - { - LOGE("JNIThingsManagerExecuteActionSet: executeActionSet is failed!"); - } - - env->ReleaseStringUTFChars(jActionSetName, actionSetNamePointer); - LOGI("JNIThingsManagerExecuteActionSet: Exit"); - return ocResult; -} - -JNIEXPORT jint JNICALL JNIThingsManagerCancelActionSet(JNIEnv *env, jobject interfaceObject, - jobject resource, jstring jActionSetName) -{ - LOGI("JNIThingsManagerCancelActionSet: Entry"); - - if ((!resource) || (!jActionSetName)) - { - LOGE("JNIThingsManagerCancelActionSet: resource or jActionSetName is NULL!"); - return OC_STACK_INVALID_PARAM; - } - - OCStackResult ocResult = OC_STACK_ERROR; - - std::shared_ptr ocResource; - JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, resource); - if (jniOcResource) - { - ocResource = jniOcResource->getOCResource(); - } - - if (NULL == ocResource.get()) - { - LOGE("JNIThingsManagerCancelActionSet: Failed to get OCResource object!"); - return ocResult; - } - - const char *actionSetNamePointer = env->GetStringUTFChars(jActionSetName, 0); - if (NULL == actionSetNamePointer) - { - LOGE("JNIThingsManagerCancelActionSet: Failed to get character sequence from jstring!"); - return OC_STACK_NO_MEMORY; - } - - std::string actionSetName(actionSetNamePointer); - - ocResult = g_ThingsManager.cancelActionSet(ocResource, actionSetName, - &ThingsManagerCallbacks::onPostResponse); - if (OC_STACK_OK != ocResult) - { - LOGE("JNIThingsManagerCancelActionSet: cancelActionSet is failed!"); - } - - env->ReleaseStringUTFChars(jActionSetName, actionSetNamePointer); - LOGI("JNIThingsManagerCancelActionSet: Exit"); - return ocResult; -} - -JNIEXPORT jint JNICALL JNIThingsManagerGetActionSet(JNIEnv *env, jobject interfaceObject, - jobject resource, - jstring jActionSetName) -{ - LOGI("JNIThingsManagerGetActionSet: Entry"); - - if ((!resource) || (!jActionSetName)) - { - LOGE("JNIThingsManagerGetActionSet: resource or jActionSetName is NULL!"); - return OC_STACK_INVALID_PARAM; - } - - OCStackResult ocResult = OC_STACK_ERROR; - - std::shared_ptr ocResource; - JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, resource); - if (jniOcResource) - { - ocResource = jniOcResource->getOCResource(); - } - - if (NULL == ocResource.get()) - { - LOGE("JNIThingsManagerGetActionSet: Failed to get OCResource object!"); - return ocResult; - } - - const char *actionSetNamePointer = env->GetStringUTFChars(jActionSetName, 0); - std::string actionSetName(actionSetNamePointer); - - ocResult = g_ThingsManager.getActionSet(ocResource, actionSetName, - &ThingsManagerCallbacks::onGetResponse); - if (OC_STACK_OK != ocResult) - { - LOGE("JNIThingsManagerGetActionSet: getActionSet is failed!"); - } - - env->ReleaseStringUTFChars(jActionSetName, actionSetNamePointer); - LOGI("JNIThingsManagerGetActionSet: Exit"); - return ocResult; -} - -JNIEXPORT jint JNICALL JNIThingsManagerDeleteActionSet(JNIEnv *env, jobject interfaceObject, - jobject resource, - jstring jActionSetName) -{ - LOGI("JNIThingsManagerDeleteActionSet: Entry"); - - if ((!resource) || (!jActionSetName)) - { - LOGE("JNIThingsManagerDeleteActionSet: resource or jActionSetName is NULL!"); - return OC_STACK_INVALID_PARAM; - } - - OCStackResult ocResult = OC_STACK_ERROR; - - std::shared_ptr ocResource; - JniOcResource *jniOcResource = JniOcResource::getJniOcResourcePtr(env, resource); - if (jniOcResource) - { - ocResource = jniOcResource->getOCResource(); - } - - if (NULL == ocResource.get()) - { - LOGE("JNIThingsManagerDeleteActionSet: Failed to get OCResource object!"); - return ocResult; - } - - const char *actionSetNamePointer = env->GetStringUTFChars(jActionSetName, 0); - std::string actionSetName(actionSetNamePointer); - - ocResult = g_ThingsManager.deleteActionSet(ocResource, actionSetName, - &ThingsManagerCallbacks::onPutResponse); - if (OC_STACK_OK != ocResult) - { - LOGE("JNIThingsManagerDeleteActionSet: deleteActionSet is failed!"); - } - - env->ReleaseStringUTFChars(jActionSetName, actionSetNamePointer); - LOGI("JNIThingsManagerDeleteActionSet: Exit"); - return ocResult; -} - -jobject ocResourceHandleToJava(JNIEnv *env, jlong resourceHandle) -{ - jclass resourceClass = GetJClass(TM_SERVICE_OCRESOURCEHANDLE_PATH); - if (NULL == resourceClass) - { - LOGE("ocResourceHandleToJava : failed to find OCResourceHandle java class!"); - return NULL; - } - - jmethodID constructor = env->GetMethodID(resourceClass, "", "(J)V"); - if (NULL == constructor) - { - LOGE("ocResourceHandleToJava: Failed to get constructor method!"); - return NULL; - } - - jobject resourceObj = (jobject) env->NewObject(resourceClass, constructor, resourceHandle); - if (NULL == resourceObj) - { - LOGE("ocResourceHandleToJava: Failed to create OCResouceHandle java object!"); - return NULL; - } - - return resourceObj; -} diff --git a/service/things-manager/sdk/java/jni/tm/src/jni_things_manager_callbacks.cpp b/service/things-manager/sdk/java/jni/tm/src/jni_things_manager_callbacks.cpp deleted file mode 100644 index b24b2eb..0000000 --- a/service/things-manager/sdk/java/jni/tm/src/jni_things_manager_callbacks.cpp +++ /dev/null @@ -1,594 +0,0 @@ -/****************************************************************** - * - * Copyright 2015 Samsung Electronics All Rights Reserved. - * - * - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************/ -#include "jni_things_manager_callbacks.h" -#include "JniOcResource.h" -#include "ThingsManager.h" -#include "jni_things_manager_jvm.h" -#include "jni_string.h" - -#define LOG_TAG "ThingsManagerCallbacks" - -#define METHOD_ONRESOURCE_CALLBACK "(" TM_JAVA_VECTOR_TYPE")V" -#define METHOD_ONGROUP_FIND_CALLBACK "(" TM_SERVICE_OCRESOURCE_TYPE")V" -#define METHOD_ONPRESENCE_CALLBACK "(" TM_JAVA_STRING_TYPE"I)V" -#define METHOD_ONUPDATE_CONF_CALLBACK "(" TM_JAVA_VECTOR_TYPE TM_SERVICE_OCREPRESENTATION_TYPE"I)V" -#define METHOD_ONGET_CONF_CALLBACK "(" TM_JAVA_VECTOR_TYPE TM_SERVICE_OCREPRESENTATION_TYPE"I)V" -#define METHOD_ONBOOT_STRAP_CALLBACK "(" TM_JAVA_VECTOR_TYPE TM_SERVICE_OCREPRESENTATION_TYPE"I)V" -#define METHOD_ONFACTORY_RESET_CALLBACK "(" TM_JAVA_VECTOR_TYPE TM_SERVICE_OCREPRESENTATION_TYPE"I)V" -#define METHOD_ONREBOOT_CALLBACK "(" TM_JAVA_VECTOR_TYPE TM_SERVICE_OCREPRESENTATION_TYPE"I)V" -#define METHOD_ONPOST_CALLBACK "(" TM_JAVA_VECTOR_TYPE TM_SERVICE_OCREPRESENTATION_TYPE"I)V" -#define METHOD_ONPUT_CALLBACK "(" TM_JAVA_VECTOR_TYPE TM_SERVICE_OCREPRESENTATION_TYPE"I)V" -#define METHOD_ONGET_CALLBACK "(" TM_JAVA_VECTOR_TYPE TM_SERVICE_OCREPRESENTATION_TYPE"I)V" -#define METHOD_TMCALLBACK_GETINSTANCE "()" TM_SERVICE_CALLBACK_CLASS_TYPE - -jobject OcResourceToJava(JNIEnv *env, jlong resource) -{ - jclass resourceClass = GetJClass(TM_SERVICE_OCRESOURCE_PATH); - if (NULL == resourceClass) - { - LOGE("OcResourceToJava : failed to find OCResouce java class!"); - return NULL; - } - - jmethodID constructor = env->GetMethodID(resourceClass, "", "(J)V"); - if (NULL == constructor) - { - LOGE("OcResourceToJava: Failed to get constructor method!"); - return NULL; - } - - jobject resourceObj = (jobject) env->NewObject(resourceClass, constructor, resource); - if (NULL == resourceObj) - { - LOGE("OcResourceToJava: Failed to create OCResouce java object!"); - return NULL; - } - - return resourceObj; -} - -jobject OcHeaderOptionToJava(JNIEnv *env, OC::HeaderOption::OCHeaderOption headerOption) -{ - JString *optionData = new JString(env, headerOption.getOptionData()); - if (!optionData) - { - LOGE("OcHeaderOptionToJava : failed to get JString!"); - return NULL; - } - - jclass headerOptionClass = GetJClass(TM_SERVICE_HEADER_OPTION_PATH); - if (NULL == headerOptionClass) - { - LOGE("OcHeaderOptionToJava : failed to find OCRepresentation java class!"); - return NULL; - } - - jmethodID constructor = env->GetMethodID(headerOptionClass, "", "(JLjava/lang/String;)V"); - if (NULL == constructor) - { - LOGE("OcHeaderOptionToJava: Failed to get constructor method!"); - return NULL; - } - - jobject headerOptionObj = (jobject) env->NewObject(headerOptionClass, constructor, - (jlong)headerOption.getOptionID(), optionData); - if (NULL == headerOptionObj) - { - LOGE("OcHeaderOptionToJava: Failed to create OCRepresentation java object!"); - return NULL; - } - - return headerOptionObj; -} - -jobject OcRepresentationToJava(JNIEnv *env, jlong ocRepresentation) -{ - jclass ocRepresentationClass = GetJClass(TM_SERVICE_OCREPRESENTATION_PATH); - if (NULL == ocRepresentationClass) - { - LOGE("OcRepresentationToJava : failed to find OCRepresentation java class!"); - return NULL; - } - - jmethodID constructor = env->GetMethodID(ocRepresentationClass, "", "(J)V"); - if (NULL == constructor) - { - LOGE("OcRepresentationToJava: Failed to get constructor method!"); - return NULL; - } - - jobject ocRepresentationObj = (jobject) env->NewObject(ocRepresentationClass, constructor, - ocRepresentation); - if (NULL == ocRepresentationObj) - { - LOGE("OcRepresentationToJava: Failed to create OCRepresentation java object!"); - return NULL; - } - - return ocRepresentationObj; -} - -void ThingsManagerCallbacks::onFoundCandidateResource( - std::vector< std::shared_ptr> resources) -{ - LOGI("findCandidateResource : Enter"); - - if (resources.size() == 0) - { - LOGE("findCandidateResource : found resources zero"); - return; - } - - JNIEnv *env = ThingsManagerJVM::getEnv(); - if (env == NULL) - { - LOGE("findCandidateResource : Getting JNIEnv failed"); - return; - } - - // Get ThingsManagerCallback class reference - jclass thingsManagerCallbacks = GetJClass(TM_SERVICE_CALLBACK_CLASS_PATH); - if (NULL == thingsManagerCallbacks) - { - LOGE("findCandidateResource : GetJClass TMServiceCallbackInterface failed"); - ThingsManagerJVM::releaseEnv(); - return; - } - - // Get the ThingsManagerCallback class instance - jobject jobjectCallback = GetJObjectInstance(TM_SERVICE_CALLBACK_CLASS_PATH); - if (NULL == jobjectCallback) - { - LOGE("getInstance( %s) failed!", TM_SERVICE_CALLBACK_CLASS_PATH); - ThingsManagerJVM::releaseEnv(); - return; - } - - // Get onResourceCallback method reference - jmethodID method_id = env->GetMethodID(thingsManagerCallbacks, - "onResourceCallback", METHOD_ONRESOURCE_CALLBACK); - if (NULL == method_id) - { - LOGE("findCandidateResource: onResourceCallback : GetMethodID failed"); - ThingsManagerJVM::releaseEnv(); - return; - } - - if ((env)->ExceptionCheck()) - { - LOGE("findCandidateResource : ExceptionCheck failed"); - ThingsManagerJVM::releaseEnv(); - return; - } - - jclass vectorCls = env->FindClass(TM_JAVA_VECTOR_CLASS_PATH); - if (!vectorCls) - { - LOGE("findCandidateResource: failed to get %s class reference", TM_JAVA_VECTOR_CLASS_PATH); - ThingsManagerJVM::releaseEnv(); - return; - } - - jmethodID constr = env->GetMethodID(vectorCls, "", "()V"); - if (!constr) - { - LOGE("findCandidateResource: failed to get %s constructor", TM_JAVA_VECTOR_CLASS_PATH); - ThingsManagerJVM::releaseEnv(); - return; - } - - jobject vectorObj = env->NewObject(vectorCls, constr); - if (!vectorObj) - { - LOGE("findCandidateResource: failed to create a %s object", TM_JAVA_VECTOR_CLASS_PATH); - ThingsManagerJVM::releaseEnv(); - return; - } - - jmethodID addElement = env->GetMethodID(vectorCls, "addElement", "(Ljava/lang/Object;)V"); - if (NULL == addElement) - { - LOGE("findCandidateResource: failed to create a addElement method"); - ThingsManagerJVM::releaseEnv(); - return; - } - - // Convert to java OCResource object - for (int i = 0; i < resources.size(); i++) - { - JniOcResource *jniOcResource = new JniOcResource(resources[i]); - if (!jniOcResource) - { - LOGE("findCandidateResource: failed to create a JniOcResource"); - ThingsManagerJVM::releaseEnv(); - return; - } - - jobject resource = OcResourceToJava(env, reinterpret_cast(jniOcResource)); - env->CallVoidMethod(vectorObj, addElement, resource); - } - - env->CallVoidMethod(jobjectCallback, method_id, vectorObj); - - if ((env)->ExceptionCheck()) - { - LOGE("findCandidateResource : CallVoidMethod failed"); - ThingsManagerJVM::releaseEnv(); - return; - } - - ThingsManagerJVM::releaseEnv(); - LOGI("findCandidateResource : Exit"); -} - -void ThingsManagerCallbacks::onFoundGroup(std::shared_ptr groupResource) -{ - LOGI("FindGroup : Enter"); - - if (NULL == groupResource.get()) - { - LOGE("FindGroup : Invalid received GroupResource!"); - return; - } - - JNIEnv *env = ThingsManagerJVM::getEnv(); - if (env == NULL) - { - LOGE("FindGroup : Getting JNIEnv failed"); - return; - } - - // Get ThingsManagerCallback class reference - jclass thingsManagerCallbacks = GetJClass(TM_SERVICE_CALLBACK_CLASS_PATH); - if (NULL == thingsManagerCallbacks) - { - LOGE("FindGroup : GetJClass TMServiceCallbackInterface failed"); - ThingsManagerJVM::releaseEnv(); - return; - } - - // Get the ThingsManagerCallback class instance - jobject jobjectCallback = GetJObjectInstance(TM_SERVICE_CALLBACK_CLASS_PATH); - if (NULL == jobjectCallback) - { - LOGE("FindGroup: getInstance( %s) failed!", TM_SERVICE_CALLBACK_CLASS_PATH); - ThingsManagerJVM::releaseEnv(); - return; - } - - // Get onGroupFindCallback method reference - jmethodID method_id = env->GetMethodID(thingsManagerCallbacks, - "onGroupFindCallback", - METHOD_ONGROUP_FIND_CALLBACK); - if (NULL == method_id) - { - LOGE("FindGroup : GetMethodID failed"); - ThingsManagerJVM::releaseEnv(); - return; - } - - if ((env)->ExceptionCheck()) - { - LOGE("FindGroup : ExceptionCheck failed"); - ThingsManagerJVM::releaseEnv(); - return; - } - - JniOcResource *jniOcResource = new JniOcResource(groupResource); - if (!jniOcResource) - { - LOGE("FindGroup : groupResource is invalid!"); - ThingsManagerJVM::releaseEnv(); - return; - } - - jobject resource = OcResourceToJava(env, reinterpret_cast(jniOcResource)); - - env->CallVoidMethod(jobjectCallback, method_id, resource); - - if ((env)->ExceptionCheck()) - { - LOGE("FindGroup : CallVoidMethod failed"); - ThingsManagerJVM::releaseEnv(); - return; - } - - ThingsManagerJVM::releaseEnv(); - LOGI("FindGroup : Exit"); -} - -void ThingsManagerCallbacks::onSubscribePresence(std::string resource, OCStackResult result) -{ - LOGI("SubscribePresence : Entry"); - - JNIEnv *env = ThingsManagerJVM::getEnv(); - if (env == NULL) - { - LOGE("SubscribePresence : Getting JNIEnv failed"); - return; - } - - // Get ThingsManagerCallback class reference - jclass thingsManagerCallbacks = GetJClass(TM_SERVICE_CALLBACK_CLASS_PATH); - if (NULL == thingsManagerCallbacks) - { - LOGE("findCandidateResource : GetJClass TMServiceCallbackInterface failed"); - ThingsManagerJVM::releaseEnv(); - return; - } - - // Get getInstance method reference - jmethodID getinstance_method_id = env->GetStaticMethodID(thingsManagerCallbacks, - "getInstance", METHOD_TMCALLBACK_GETINSTANCE); - if (NULL == getinstance_method_id) - { - LOGE("getInstance : GetMethodID failed"); - ThingsManagerJVM::releaseEnv(); - return; - } - - // Get the ThingsManagerCallback class instance - jobject jobjectCallback = env->CallStaticObjectMethod(thingsManagerCallbacks, - getinstance_method_id); - if (NULL == jobjectCallback) - { - LOGE("getInstance( %s) failed!", TM_SERVICE_CALLBACK_CLASS_PATH); - ThingsManagerJVM::releaseEnv(); - return; - } - - jmethodID method_id = env->GetMethodID(thingsManagerCallbacks, - "onPresenceCallback", - METHOD_ONPRESENCE_CALLBACK); - if (NULL == method_id) - { - LOGE("SubscribePresence : GetMethodID failed"); - ThingsManagerJVM::releaseEnv(); - return; - } - - if ((env)->ExceptionCheck()) - { - LOGE("SubscribePresence : ExceptionCheck failed"); - ThingsManagerJVM::releaseEnv(); - return; - } - - JString *jresource = new JString(env, resource); - if (jresource == NULL) - { - LOGE("resource value is invalid"); - ThingsManagerJVM::releaseEnv(); - return; - } - - env->CallVoidMethod(jobjectCallback, method_id, jresource->getObject(), (jint)result); - - delete jresource; - - if ((env)->ExceptionCheck()) - { - LOGE("SubscribePresence : CallVoidMethod failed"); - ThingsManagerJVM::releaseEnv(); - return; - } - - LOGI("SubscribePresence : Exit"); - -//METHOD_FAILURE: - ThingsManagerJVM::releaseEnv(); -} - -void ThingsManagerCallbacks::onUpdateConfigurationsResponse(const OC::HeaderOptions &headerOptions, - const OC::OCRepresentation &rep, const int eCode) -{ - LOGI("UpdateConfigurations : Enter"); - - ThingsManagerCallbacks::invokeCallback(headerOptions, rep, eCode, "onUpdateConfigurationsCallback", - METHOD_ONUPDATE_CONF_CALLBACK); - - LOGI("UpdateConfigurations : Exit"); -} - -void ThingsManagerCallbacks::onGetConfigurationsResponse(const OC::HeaderOptions &headerOptions, - const OC::OCRepresentation &rep, const int eCode) -{ - LOGI("GetConfigurations : Enter"); - - ThingsManagerCallbacks::invokeCallback(headerOptions, rep, eCode, "onGetConfigurationsCallback", - METHOD_ONGET_CONF_CALLBACK); - - LOGI("GetConfigurations : Exit"); -} - -void ThingsManagerCallbacks::onBootStrapResponse(const OC::HeaderOptions &headerOptions, - const OC::OCRepresentation &rep, const int eCode) -{ - LOGI("BootStrap : Enter"); - - ThingsManagerCallbacks::invokeCallback(headerOptions, rep, eCode, "onBootStrapCallback", - METHOD_ONBOOT_STRAP_CALLBACK); - - LOGI("BootStrap : Exit"); -} - -void ThingsManagerCallbacks::onRebootResponse(const OC::HeaderOptions &headerOptions, - const OC::OCRepresentation &rep, const int eCode) -{ - LOGI("OnReboot : Enter"); - - ThingsManagerCallbacks::invokeCallback(headerOptions, rep, eCode, "onRebootCallback", - METHOD_ONREBOOT_CALLBACK); - - LOGI("OnReboot : Exit"); -} - -void ThingsManagerCallbacks::onFactoryResetResponse(const OC::HeaderOptions &headerOptions, - const OC::OCRepresentation &rep, const int eCode) -{ - LOGI("OnFactoryReset : Enter"); - - ThingsManagerCallbacks::invokeCallback(headerOptions, rep, eCode, "onFactoryResetCallback", - METHOD_ONFACTORY_RESET_CALLBACK); - - LOGI("OnFactoryReset : Exit"); -} - -void ThingsManagerCallbacks::onPostResponse(const OC::HeaderOptions &headerOptions, - const OC::OCRepresentation &rep, const int eCode) -{ - LOGI("PostResponse : Enter"); - - ThingsManagerCallbacks::invokeCallback(headerOptions, rep, eCode, "onPostResponseCallback", - METHOD_ONPOST_CALLBACK); - - LOGI("PostResponse : Exit"); -} - -void ThingsManagerCallbacks::onPutResponse(const OC::HeaderOptions &headerOptions, - const OC::OCRepresentation &rep, const int eCode) -{ - LOGI("OnPutResponse : Enter"); - - ThingsManagerCallbacks::invokeCallback(headerOptions, rep, eCode, "onPutResponseCallback", - METHOD_ONPUT_CALLBACK); - - LOGI("OnPutResponse : Exit"); -} - - -void ThingsManagerCallbacks::onGetResponse(const OC::HeaderOptions &headerOptions, - const OC::OCRepresentation &rep, const int eCode) -{ - LOGI("OnGetResponse : Enter"); - - ThingsManagerCallbacks::invokeCallback(headerOptions, rep, eCode, "onGetResponseCallback", - METHOD_ONGET_CALLBACK); - - LOGI("OnGetResponse : Exit"); -} - -void ThingsManagerCallbacks::invokeCallback(const OC::HeaderOptions &headerOptions, - const OC::OCRepresentation &rep, const int eCode, const char *callbackName, - const char *signature) -{ - LOGI("InvokeCallback : Enter %s", callbackName); - - JNIEnv *env = ThingsManagerJVM::getEnv(); - if (env == NULL) - { - LOGE("InvokeCallback : Getting JNIEnv failed"); - return; - } - - // Get ThingsManagerCallback class reference - jclass thingsManagerCallbacks = GetJClass(TM_SERVICE_CALLBACK_CLASS_PATH); - if (NULL == thingsManagerCallbacks) - { - LOGE("InvokeCallback : GetJClass TMServiceCallbackInterface failed"); - ThingsManagerJVM::releaseEnv(); - return; - } - - // Get the ThingsManagerCallback class instance - jobject jobjectCallback = GetJObjectInstance(TM_SERVICE_CALLBACK_CLASS_PATH); - if (NULL == jobjectCallback) - { - LOGE("InvokeCallback: getInstance( %s) failed!", TM_SERVICE_CALLBACK_CLASS_PATH); - ThingsManagerJVM::releaseEnv(); - return; - } - - jmethodID method_id = env->GetMethodID(thingsManagerCallbacks, callbackName, signature); - if (!method_id) - { - LOGE("InvokeCallback : GetMethodID failed"); - ThingsManagerJVM::releaseEnv(); - return; - } - - if ((env)->ExceptionCheck()) - { - LOGE("InvokeCallback : ExceptionCheck failed"); - ThingsManagerJVM::releaseEnv(); - return; - } - - // Convert vector to java type - jclass vectorCls = env->FindClass(TM_JAVA_VECTOR_CLASS_PATH); - if (!vectorCls) - { - LOGE("InvokeCallback: failed to get %s class reference", TM_JAVA_VECTOR_CLASS_PATH); - ThingsManagerJVM::releaseEnv(); - return; - } - - jmethodID constr = env->GetMethodID(vectorCls, "", "()V"); - if (!constr) - { - LOGE("InvokeCallback: failed to get %s constructor", TM_JAVA_VECTOR_CLASS_PATH); - ThingsManagerJVM::releaseEnv(); - return; - } - - jobject vectorObj = env->NewObject(vectorCls, constr); - if (!vectorObj) - { - LOGE("InvokeCallback: failed to create a %s object", TM_JAVA_VECTOR_CLASS_PATH); - ThingsManagerJVM::releaseEnv(); - return; - } - - jmethodID addElement = env->GetMethodID(vectorCls, "addElement", "(Ljava/lang/Object;)V"); - if (NULL == addElement) - { - LOGE("InvokeCallback: failed to create a addElement method"); - ThingsManagerJVM::releaseEnv(); - return; - } - - jobject headerOptionTemp; - for (int i = 0; i < headerOptions.size(); i++) - { - headerOptionTemp = OcHeaderOptionToJava(env, headerOptions[i]); - env->CallVoidMethod(vectorObj, addElement, headerOptionTemp); - } - - // Convert OCRepresentation to java type - jobject jrepresentation = OcRepresentationToJava(env, (jlong) reinterpret_cast(&rep)); - if (!jrepresentation) - { - LOGE("InvokeCallback : cannot create OCRepresentation class"); - ThingsManagerJVM::releaseEnv(); - return; - } - - env->CallVoidMethod(jobjectCallback, method_id, vectorObj, jrepresentation, (jint)eCode); - - if ((env)->ExceptionCheck()) - { - LOGE("InvokeCallback : CallVoidMethod failed"); - ThingsManagerJVM::releaseEnv(); - return; - } - - ThingsManagerJVM::releaseEnv(); - LOGI("InvokeCallback : Exit %s", callbackName); -} \ No newline at end of file diff --git a/service/things-manager/sdk/java/jni/tm/src/jni_things_manager_util.cpp b/service/things-manager/sdk/java/jni/tm/src/jni_things_manager_util.cpp index 5adb8c6..3147d5b 100644 --- a/service/things-manager/sdk/java/jni/tm/src/jni_things_manager_util.cpp +++ b/service/things-manager/sdk/java/jni/tm/src/jni_things_manager_util.cpp @@ -1,4 +1,4 @@ -/****************************************************************** +/* ***************************************************************** * * Copyright 2015 Samsung Electronics All Rights Reserved. * @@ -17,8 +17,119 @@ * limitations under the License. * ******************************************************************/ + #include "jni_things_manager_util.h" #include "JniOcResource.h" +#include "jni_string.h" + +jobject ocResourceHandleToJava(JNIEnv *env, jlong resourceHandle) +{ + jclass resourceClass = GetJClass(TM_SERVICE_OCRESOURCEHANDLE_PATH); + if (NULL == resourceClass) + { + LOGE("ocResourceHandleToJava : failed to find OCResourceHandle java class!"); + return NULL; + } + + jmethodID constructor = env->GetMethodID(resourceClass, "", "(J)V"); + if (NULL == constructor) + { + LOGE("ocResourceHandleToJava: Failed to get constructor method!"); + return NULL; + } + + jobject resourceObj = (jobject) env->NewObject(resourceClass, constructor, resourceHandle); + if (NULL == resourceObj) + { + LOGE("ocResourceHandleToJava: Failed to create OCResouceHandle java object!"); + return NULL; + } + return resourceObj; +} + +jobject OcResourceToJava(JNIEnv *env, jlong resource) +{ + jclass resourceClass = GetJClass(TM_SERVICE_OCRESOURCE_PATH); + if (NULL == resourceClass) + { + LOGE("OcResourceToJava : failed to find OCResouce java class!"); + return NULL; + } + + jmethodID constructor = env->GetMethodID(resourceClass, "", "(J)V"); + if (NULL == constructor) + { + LOGE("OcResourceToJava: Failed to get constructor method!"); + return NULL; + } + + jobject resourceObj = (jobject) env->NewObject(resourceClass, constructor, resource); + if (NULL == resourceObj) + { + LOGE("OcResourceToJava: Failed to create OCResouce java object!"); + return NULL; + } + return resourceObj; +} + +jobject OcHeaderOptionToJava(JNIEnv *env, OC::HeaderOption::OCHeaderOption headerOption) +{ + JString *optionData = new JString(env, headerOption.getOptionData()); + if (!optionData) + { + LOGE("OcHeaderOptionToJava : failed to get JString!"); + return NULL; + } + + jclass headerOptionClass = GetJClass(TM_SERVICE_HEADER_OPTION_PATH); + if (NULL == headerOptionClass) + { + LOGE("OcHeaderOptionToJava : failed to find OCRepresentation java class!"); + return NULL; + } + + jmethodID constructor = env->GetMethodID(headerOptionClass, "", "(JLjava/lang/String;)V"); + if (NULL == constructor) + { + LOGE("OcHeaderOptionToJava: Failed to get constructor method!"); + return NULL; + } + + jobject headerOptionObj = (jobject) env->NewObject(headerOptionClass, constructor, + (jlong)headerOption.getOptionID(), optionData); + if (NULL == headerOptionObj) + { + LOGE("OcHeaderOptionToJava: Failed to create OCRepresentation java object!"); + return NULL; + } + return headerOptionObj; +} + +jobject OcRepresentationToJava(JNIEnv *env, jlong ocRepresentation) +{ + jclass ocRepresentationClass = GetJClass(TM_SERVICE_OCREPRESENTATION_PATH); + if (NULL == ocRepresentationClass) + { + LOGE("OcRepresentationToJava : failed to find OCRepresentation java class!"); + return NULL; + } + + jmethodID constructor = env->GetMethodID(ocRepresentationClass, "", "(J)V"); + if (NULL == constructor) + { + LOGE("OcRepresentationToJava: Failed to get constructor method!"); + return NULL; + } + + jobject ocRepresentationObj = (jobject) env->NewObject(ocRepresentationClass, constructor, + ocRepresentation); + if (NULL == ocRepresentationObj) + { + LOGE("OcRepresentationToJava: Failed to create OCRepresentation java object!"); + return NULL; + } + return ocRepresentationObj; +} std::vector convertStringVector(JNIEnv *env, jobject jVectorString) { @@ -66,7 +177,6 @@ std::vector convertStringVector(JNIEnv *env, jobject jVectorString) env->ReleaseStringUTFChars(jContactInfoObj, buff); } - return vectorString; } @@ -126,6 +236,5 @@ std::map convertStringMap(JNIEnv *env, jobject jMapStr env->ReleaseStringUTFChars(jMapKeyStr, key); env->ReleaseStringUTFChars(jMapValueStr, value); } - return mapString; } diff --git a/service/things-manager/sdk/java/src/org/iotivity/service/tm/Action.java b/service/things-manager/sdk/java/src/org/iotivity/service/tm/Action.java index 15cf5c1..c7c3c9c 100644 --- a/service/things-manager/sdk/java/src/org/iotivity/service/tm/Action.java +++ b/service/things-manager/sdk/java/src/org/iotivity/service/tm/Action.java @@ -1,4 +1,4 @@ -/****************************************************************** +/* ***************************************************************** * * Copyright 2015 Samsung Electronics All Rights Reserved. * @@ -19,10 +19,9 @@ ******************************************************************/ /** - * @file Action.java - * - * @brief This file contains class which provides functions to retrieve the Action details from a - * Segment. + * @file + * This file contains class which provides functions to retrieve the Action + * details from a Segment. */ package org.iotivity.service.tm; @@ -33,9 +32,7 @@ import java.util.Vector; import android.util.Log; /** - * This class provides functions to retrieve the Action details from a - * Segment. - * + * This class provides functions to retrieve the Action details from a Segment. */ public class Action { private static final String LOG_TAG = "Action"; @@ -54,7 +51,6 @@ public class Action { * uri=coap://10.251.44.228:49858/a/light|power=10) * * @return String for a specific action. - * */ public String toString() { StringBuilder result = new StringBuilder(); @@ -71,13 +67,12 @@ public class Action { /** * This function parses the Segment value to retrieve sub segments separated - * by a vertical bar(|): URI and a pair of attribute key and value + * by a vertical bar(|): URI and a pair of attribute key and value. * * @param actionString * Segment String * * @return Action needed by remote devices as members of a specific group - * */ public static Action toAction(String actionString) { Action result = new Action(); @@ -112,7 +107,6 @@ public class Action { result.listOfCapability.add(capability); } } - return result; } } diff --git a/service/things-manager/sdk/java/src/org/iotivity/service/tm/ActionSet.java b/service/things-manager/sdk/java/src/org/iotivity/service/tm/ActionSet.java index c234210..2abec72 100644 --- a/service/things-manager/sdk/java/src/org/iotivity/service/tm/ActionSet.java +++ b/service/things-manager/sdk/java/src/org/iotivity/service/tm/ActionSet.java @@ -17,11 +17,10 @@ * limitations under the License. * ******************************************************************/ + /** - * @file ActionSet.java - * - * @brief This file contains class which provides functions to retrieve ActionSet from plain text. - * + * @file + * This file contains class which provides functions to retrieve ActionSet from plain text. */ package org.iotivity.service.tm; @@ -31,11 +30,10 @@ import java.util.Vector; import android.util.Log; /** - * This class provides functions to retrieve ActionSet from plain text. - * An ActionSet is a set of descriptions of actions needed by remote - * devices as members of a specific group. To create an ActionSet, one - * needs to know the Delimeter serialization. - * + * This class provides functions to retrieve ActionSet from plain text. An + * ActionSet is a set of descriptions of actions needed by remote devices as + * members of a specific group. To create an ActionSet, one needs to know the + * Delimeter serialization. */ public class ActionSet extends Time { /** @@ -68,7 +66,6 @@ public class ActionSet extends Time { * and a pair of attribute key and value. * * @return String for a specific action. - * */ @Override public String toString() { @@ -110,7 +107,6 @@ public class ActionSet extends Time { * * @return ActionSet which is a set of descriptions of actions needed by * remote devices as members of a specific group. - * */ public static ActionSet toActionSet(String actionsetString) { if (0 == actionsetString.length()) { @@ -141,7 +137,6 @@ public class ActionSet extends Time { result.listOfAction.add(action); } } - return result; } } diff --git a/service/things-manager/sdk/java/src/org/iotivity/service/tm/Capability.java b/service/things-manager/sdk/java/src/org/iotivity/service/tm/Capability.java index 850fee9..93ce271 100644 --- a/service/things-manager/sdk/java/src/org/iotivity/service/tm/Capability.java +++ b/service/things-manager/sdk/java/src/org/iotivity/service/tm/Capability.java @@ -17,11 +17,11 @@ * limitations under the License. * ******************************************************************/ + /** - * @file Capability.java - * - * @brief This file contains class which provides functions to specify an attribute key and value - * of the target resource + * @file + * This file contains class which provides functions to specify an attribute key and value + * of the target resource. * */ @@ -32,12 +32,11 @@ import java.util.StringTokenizer; import android.util.Log; /** - * This class needs to be created to specify an attribute key and value - * of the target resource. The attribute key and value are written in - * capability and status variables of Capability instance class, - * respectively. After filling the Capability instance, store it to - * listOfCapability vector variable of Action instance. - * + * This class needs to be created to specify an attribute key and value of the + * target resource. The attribute key and value are written in capability and + * status variables of Capability instance class, respectively. After filling + * the Capability instance, store it to listOfCapability vector variable of + * Action instance. */ public class Capability { /** @@ -57,7 +56,6 @@ public class Capability { * This function generates a Capability String. * * @return String for a specific Capability. - * */ public String toString() { StringBuilder result = new StringBuilder(); @@ -72,7 +70,6 @@ public class Capability { * Capability in String format. * * @return Capability class. - * */ public static Capability toCapability(String capabilityString) { StringTokenizer tokenizer = new StringTokenizer(capabilityString, "="); diff --git a/service/things-manager/sdk/java/src/org/iotivity/service/tm/GroupManager.java b/service/things-manager/sdk/java/src/org/iotivity/service/tm/GroupManager.java new file mode 100644 index 0000000..14e487c --- /dev/null +++ b/service/things-manager/sdk/java/src/org/iotivity/service/tm/GroupManager.java @@ -0,0 +1,535 @@ +/* ***************************************************************** + * + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ + +/** + * @file + * This file contains class which provides functions + * for group management. + */ + +package org.iotivity.service.tm; + +import java.util.Vector; + +import org.iotivity.base.OcException; +import org.iotivity.base.OcHeaderOption; +import org.iotivity.base.OcRepresentation; +import org.iotivity.base.OcResource; +import org.iotivity.base.OcResourceHandle; + +import android.util.Log; + +/** + * This class provides a set of APIs relating to Group Management. + */ +public class GroupManager { + + private static IFindCandidateResourceListener s_resourceListener; + private static ISubscribePresenceListener s_presenceListener; + private static IActionListener actionListener; + + private final String LOG_TAG = this.getClass() + .getSimpleName(); + + // Native methods + private static native int nativeFindCandidateResource( + Vector resourceTypes, int waitTime); + + private static native int nativeSubscribeCollectionPresence( + OcResource resource); + + public static native OcResourceHandle nativeBindResourceToGroup( + OcResource resource, OcResourceHandle collectionHandle); + + public static native int nativeAddActionSet(OcResource resource, + ActionSet actionSet); + + public static native int nativeExecuteActionSet(OcResource resource, + String actionsetName); + + public static native int nativeExecuteActionSetWithDelay( + OcResource resource, String actionsetName, long delay); + + public static native int nativeCancelActionSet(OcResource resource, + String actionsetName); + + public static native int nativeGetActionSet(OcResource resource, + String actionsetName); + + public static native int nativeDeleteActionSet(OcResource resource, + String actionsetName); + + static { + System.loadLibrary("gnustl_shared"); + System.loadLibrary("oc_logger"); + System.loadLibrary("connectivity_abstraction"); + System.loadLibrary("ca-interface"); + System.loadLibrary("octbstack"); + System.loadLibrary("oc"); + System.loadLibrary("TGMSDKLibrary"); + System.loadLibrary("ocstack-jni"); + System.loadLibrary("things-manager-jni"); + } + + /** + * Provides interface for getting notification when resources are discovered + * in network. + */ + public interface IFindCandidateResourceListener { + + /** + * This callback method will be called whenever resource is discovered + * in the network. + * + * @param resources + * List of resources discovered in the network + */ + public void onResourceFoundCallback(Vector resources); + } + + /** + * Provides interface for getting child resource presence status. + */ + public interface ISubscribePresenceListener { + + /** + * This callback method will be called for child resource presence + * status. + * + * @param resource + * URI of resource. + * @param result + * error code. + */ + public void onPresenceCallback(String resource, int result); + } + + /** + * Provides interface for receiving the callback for the GET, PUT and POST + * requested actions. + */ + public interface IActionListener { + + /** + * This callback method is called when a asynchronous response for the + * getActionSet request is received. + * + * @param headerOptions + * It comprises of optionID and optionData as members. + * @param rep + * Configuration parameters are carried as a pair of + * attribute key and value in a form of OCRepresentation + * instance. + * @param errorValue + * error code. + */ + public void onGetResponseCallback(Vector headerOptions, + OcRepresentation rep, int errorValue); + + /** + * This callback method is called when a asynchronous response for the + * addActionSet request is received. + * + * @param headerOptions + * It comprises of optionID and optionData as members. + * @param rep + * Configuration parameters are carried as a pair of + * attribute key and value in a form of OCRepresentation + * instance. + * @param errorValue + * error code. + */ + public void onPutResponseCallback(Vector headerOptions, + OcRepresentation rep, int errorValue); + + /** + * This callback method is called when a asynchronous response for the + * executeActionSet or deleteActionSet request is received. + * + * @param headerOptions + * It comprises of optionID and optionData as members. + * @param rep + * Configuration parameters are carried as a pair of + * attribute key and value in a form of OCRepresentation + * instance. + * @param errorValue + * error code. + */ + public void onPostResponseCallback( + Vector headerOptions, OcRepresentation rep, + int errorValue); + } + + /** + * Set listener for receiving notification of resource discovery. + * + * @param listener + * IFindCandidateResourceListener to receive the discovered + * resources. + */ + public void setFindCandidateResourceListener( + IFindCandidateResourceListener listener) { + s_resourceListener = listener; + } + + /** + * Set listener for receiving responses of Get, PUT and POST requests. + * + * @param listener + * IActionListener to receive Get, PUT and POST request + * responses. + */ + public void setActionListener(IActionListener listener) { + actionListener = listener; + } + + /** + * Set listener for receiving child resource presence notifications. + * + * @param listener + * ISubscribePresenceListener to receive child resource presence + * state. + */ + public void setSubscribePresenceListener(ISubscribePresenceListener listener) { + s_presenceListener = listener; + } + + /** + * API for discovering candidate resources with waiting delay. This + * operation returns all resources of given type on the network service. + * This operation is sent via multicast to all services. However, the filter + * limits the responders to just those that support the resource type in the + * query. Currently only exact matches are supported. + *

+ * Listener should be set using setFindCandidateResourceListener API + *

+ * Listener IFindCandidateResourceListener::onResourceCallback will be + * notified when resource is discovered in network. + * + * @param resourceTypes + * required resource types(called "candidate") + * @param waitTime + * Delay time to add in seconds before starting to find the + * resources in network. + * + * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error + * code. + */ + public OCStackResult findCandidateResources(Vector resourceTypes, + int waitTime) { + OCStackResult result; + if (null == s_resourceListener) { + result = OCStackResult.OC_STACK_ERROR; + } else { + int ordinal = nativeFindCandidateResource(resourceTypes, waitTime); + result = OCStackResult.conversion(ordinal); + } + return result; + } + + /** + * API for subscribing child's state. Listener + *

+ * ISubscribePresenceListener::onPresenceCallback will be notified for + * resource presence status + *

+ * + * @param resource + * collection resource for subscribing presence of all child + * resources + * + * @return OCStackResult - return value of this API. It returns OC_STACK_OK + * if success. + */ + public OCStackResult subscribeCollectionPresence(OcResource resource) + throws OcException { + String LOG_TAG = this.getClass().getSimpleName(); + + OCStackResult result; + if (null == s_presenceListener) { + result = OCStackResult.OC_STACK_ERROR; + } else { + + int ordinal = nativeSubscribeCollectionPresence(resource); + Log.i(LOG_TAG, "Ordinal value = : " + ordinal); + result = OCStackResult.conversion(ordinal); + } + return result; + } + + /** + * API for register and bind resource to group. + * + * @param resource + * resource for register and bind to group. It has all data. + * @param collectionHandle + * collection resource handle. It will be added child resource. + * + * @return OcResourceHandle - Child resource handle. + */ + public OcResourceHandle bindResourceToGroup(OcResource resource, + OcResourceHandle collectionHandle) throws OcException { + return nativeBindResourceToGroup(resource, collectionHandle); + } + + /** + * API for adding a new ActionSet onto a specific resource. + * + *

+ * Listener should be set using setActionListener API. + *

+ * Listener IActionListener::onPutResponseCallback will be notified when the + * response of PUT operation arrives. + * + * @param resource + * resource pointer of the group resource + * @param actionSet + * pointer of ActionSet + * + * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error + * code. + */ + public OCStackResult addActionSet(OcResource resource, ActionSet actionSet) + throws OcException { + if (null == actionListener) { + Log.e(LOG_TAG, "addActionSet: listener not set!"); + return OCStackResult.OC_STACK_LISTENER_NOT_SET; + } + int ordinal = nativeAddActionSet(resource, actionSet); + + return OCStackResult.conversion(ordinal); + } + + /** + * API for executing a specific ActionSet belonging to a specific resource. + * + *

+ * Listener should be set using setActionListener API. + *

+ * Listener IActionListener::onPostResponseCallback will be notified when + * the response of POST operation arrives. + * + * @param resource + * resource pointer of the group resource + * @param actionsetName + * ActionSet name for removing the ActionSet + * + * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error + * code. + */ + public OCStackResult executeActionSet(OcResource resource, + String actionsetName) throws OcException { + if (null == actionListener) { + Log.e(LOG_TAG, "executeActionSet: listener not set!"); + return OCStackResult.OC_STACK_LISTENER_NOT_SET; + } + + int ordinal = nativeExecuteActionSet(resource, actionsetName); + + return OCStackResult.conversion(ordinal); + } + + /** + * API for executing a specific ActionSet belonging to a specific resource. + * + *

+ * Listener should be set using setActionListener API. + *

+ * Listener IActionListener::onPostResponseCallback will be notified when + * the response of POST operation arrives. + * + * @param resource + * resource pointer of the group resource + * @param actionsetName + * ActionSet name for removing the ActionSet + * @param delay + * Wait time for the ActionSet execution + * + * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error + * code. + */ + public OCStackResult executeActionSet(OcResource resource, + String actionsetName, long delay) throws OcException { + if (null == actionListener) { + Log.e(LOG_TAG, "executeActionSet: listener not set!"); + return OCStackResult.OC_STACK_LISTENER_NOT_SET; + } + + OCStackResult result; + int ordinal = nativeExecuteActionSetWithDelay(resource, actionsetName, + delay); + result = OCStackResult.conversion(ordinal); + + return result; + } + + /** + * API to cancel the existing ActionSet. + * + *

+ * Listener should be set using setActionListener API. + *

+ * Listener IActionListener::onPostResponseCallback will be notified when + * the response of POST operation arrives. + * + * @param resource + * resource pointer of the group resource. + * @param actionsetName + * ActionSet name that has to be cancelled. + * + * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error + * code. + */ + + public OCStackResult cancelActionSet(OcResource resource, + String actionsetName) throws OcException { + if (null == actionListener) { + Log.e(LOG_TAG, "cancelActionSet: listener not set!"); + return OCStackResult.OC_STACK_LISTENER_NOT_SET; + } + + OCStackResult result; + int ordinal = nativeCancelActionSet(resource, actionsetName); + result = OCStackResult.conversion(ordinal); + + return result; + } + + /** + * API to to get an existing ActionSet belonging to a specific resource. + * + *

+ * Listener should be set using setActionListener API. + *

+ * Listener IActionListener::onPostResponseCallback will be notified when + * the response of POST operation arrives. + * + * @param resource + * resource pointer of the group resource + * @param actionsetName + * ActionSet name for removing the ActionSet + * + * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error + * code. + */ + public OCStackResult getActionSet(OcResource resource, String actionsetName) + throws OcException { + if (null == actionListener) { + Log.e(LOG_TAG, "getActionSet: listener not set!"); + return OCStackResult.OC_STACK_LISTENER_NOT_SET; + } + + OCStackResult result; + int ordinal = nativeGetActionSet(resource, actionsetName); + result = OCStackResult.conversion(ordinal); + + return result; + } + + /** + * API to delete an existing ActionSet belonging to a specific resource. + * + *

+ * Listener should be set using setActionListener API. + *

+ * Listener IActionListener::onPutResponseCallback will be notified when the + * response of PUT operation arrives. + * + * @param resource + * resource pointer of the group resource + * @param actionsetName + * ActionSet name for removing the ActionSet + * + * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error + * code. + */ + public OCStackResult deleteActionSet(OcResource resource, + String actionsetName) throws OcException { + if (null == actionListener) { + Log.e(LOG_TAG, "deleteActionSet: listener not set!"); + return OCStackResult.OC_STACK_LISTENER_NOT_SET; + } + + OCStackResult result; + int ordinal = nativeDeleteActionSet(resource, actionsetName); + result = OCStackResult.conversion(ordinal); + + return result; + } + + // ******** JNI UTILITY FUNCTIONS **********// + + /* + * This callback method will be called from JNI whenever resource is + * discovered in the network. + */ + private static void onResourceFoundCallback(Vector resources) { + if (null != s_resourceListener) + s_resourceListener.onResourceFoundCallback(resources); + } + + /* + * This callback method is called from JNI for child resource presence + * status. + */ + private static void onPresenceCallback(String resource, int errorValue) { + if (null != s_presenceListener) { + Log.i("ThingsManagerCallback : onPresenceCallback", + "Received Callback from JNI"); + s_presenceListener.onPresenceCallback(resource, errorValue); + } + } + + /* + * This callback method is called from JNI when a response for the + * executeActionSet or deleteActionSet request just arrives. + */ + private static void onPostResponseCallback( + Vector headerOptions, OcRepresentation rep, + int errorValue) { + if (null != actionListener) + actionListener.onPostResponseCallback(headerOptions, rep, + errorValue); + } + + /* + * This callback method is called from JNI when a response for the + * addActionSet request just arrives. + */ + private static void onPutResponseCallback( + Vector headerOptions, OcRepresentation rep, + int errorValue) { + if (null != actionListener) + actionListener + .onPutResponseCallback(headerOptions, rep, errorValue); + } + + /* + * This callback method is called from JNI when a response for the + * getActionSet request just arrives. + */ + private static void onGetResponseCallback( + Vector headerOptions, OcRepresentation rep, + int errorValue) { + if (null != actionListener) + actionListener + .onGetResponseCallback(headerOptions, rep, errorValue); + } +} diff --git a/service/things-manager/sdk/java/src/org/iotivity/service/tm/GroupSynchronization.java b/service/things-manager/sdk/java/src/org/iotivity/service/tm/GroupSynchronization.java new file mode 100644 index 0000000..2d461bb --- /dev/null +++ b/service/things-manager/sdk/java/src/org/iotivity/service/tm/GroupSynchronization.java @@ -0,0 +1,283 @@ +/* ***************************************************************** + * + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ + +/** + * @file + * This file contains class which provides functions + * related to Group Synchronization. + */ + +package org.iotivity.service.tm; + +import java.util.Map; +import java.util.Vector; + +import org.iotivity.base.OcException; +import org.iotivity.base.OcResource; +import org.iotivity.base.OcResourceHandle; + +import android.util.Log; + +/** + * This class provides a set of APIs relating to Group Synchronization. + */ +public class GroupSynchronization { + + private IFindGroupListener groupListener; + private final String LOG_TAG = this.getClass() + .getSimpleName(); + + private static GroupSynchronization s_groupSynchronizationInstance; + + // Native methods + private static native int nativeFindGroup( + Vector collectionResourceTypes); + + private static native int nativeCreateGroup(String collectionResourceType); + + private static native int nativeJoinGroupString( + String collectionResourceType, OcResourceHandle resourceHandle); + + private static native int nativeJoinGroupObject(OcResource resource, + OcResourceHandle resourceHandle); + + private static native int nativeLeaveGroup(String collectionResourceType, + OcResourceHandle resourceHandle); + + private static native int nativeLeaveGroupForResource(OcResource resource, + String collectionResourceType, OcResourceHandle resourceHandle); + + private static native void nativeDeleteGroup(String collectionResourceType); + + private static native Map nativeGetGroupList(); + + static { + System.loadLibrary("gnustl_shared"); + System.loadLibrary("oc_logger"); + System.loadLibrary("connectivity_abstraction"); + System.loadLibrary("ca-interface"); + System.loadLibrary("octbstack"); + System.loadLibrary("oc"); + System.loadLibrary("TGMSDKLibrary"); + System.loadLibrary("ocstack-jni"); + System.loadLibrary("things-manager-jni"); + } + + /** + * Function for Getting instance of GroupSynchronization object. + * + * @return GroupSynchronization instance. + */ + public static GroupSynchronization getInstance() { + if (null == s_groupSynchronizationInstance) { + s_groupSynchronizationInstance = new GroupSynchronization(); + } + return s_groupSynchronizationInstance; + } + + /** + * Provides interface for getting group discovery status. + */ + public interface IFindGroupListener { + /** + * This callback method will be called to notify whether group is found + * or not. + * + * @param resource + * URI of resource. + */ + public void onGroupFindCallback(OcResource resource); + } + + /** + * Set listener for receiving notification on whether the requested group is + * found or not. + * + * @param listener + * IFindGroupListener to receive group discovery status. + */ + public void setGroupListener(IFindGroupListener listener) { + groupListener = listener; + } + + /** + * API for finding a specific remote group when a resource tries to join a + * group. + *

+ * IFindGroupListener::onGroupFindCallback will be called to notify whether + * requested group found or not. + *

+ * + * @param resourceTypes + * resource types of a group to find and join + * + * @return OCStackResult - return value of this API. It returns OC_STACK_OK + * if success. + */ + public OCStackResult findGroup(Vector resourceTypes) { + OCStackResult result; + if (null == groupListener) { + result = OCStackResult.OC_STACK_ERROR; + } else { + int ordinal = nativeFindGroup(resourceTypes); + result = OCStackResult.conversion(ordinal); + } + return result; + } + + /** + * API for creating a new group. + * + * @param resourceType + * resource type of a group to create + * + * @return OCStackResult - return value of this API. It returns OC_STACK_OK + * if success. + */ + public OCStackResult createGroup(String resourceType) { + OCStackResult result; + int ordinal = nativeCreateGroup(resourceType); + result = OCStackResult.conversion(ordinal); + return result; + } + + /** + * API for joining a group. This API is used when a resource that has a + * group tries to find a specific remote resource and makes it join a group. + * + * @param resourceType + * resource type of a group to join. + * @param resourceHandle + * resource handle to join a group. + * + * @return OCStackResult - return value of this API. It returns OC_STACK_OK + * if success. + */ + public OCStackResult joinGroup(String resourceType, + OcResourceHandle resourceHandle) { + OCStackResult result; + + int ordinal = nativeJoinGroupString(resourceType, resourceHandle); + result = OCStackResult.conversion(ordinal); + + return result; + } + + /** + * API for joining a group. This API is used when a resource that doesn't + * have a group tries to find and join a specific remote group. + * + * @param resource + * group resource to join. + * @param resourceHandle + * resource handle to join a group. + * + * @return OCStackResult - return value of this API. It returns OC_STACK_OK + * if success. + */ + public OCStackResult joinGroup(OcResource resource, + OcResourceHandle resourceHandle) throws OcException { + + OCStackResult result; + int ordinal = nativeJoinGroupObject(resource, resourceHandle); + result = OCStackResult.conversion(ordinal); + + return result; + } + + /** + * API for leaving a joined group. + * + * @param resourceType + * resource type of a group to leave. + * @param resourceHandle + * resource handle to leave a group. + * + * @return OCStackResult - return value of this API. It returns OC_STACK_OK + * if success. + */ + public OCStackResult leaveGroup(String resourceType, + OcResourceHandle resourceHandle) { + + OCStackResult result; + int ordinal = nativeLeaveGroup(resourceType, resourceHandle); + result = OCStackResult.conversion(ordinal); + + return result; + } + + /** + * API for leaving a joined group. + * + * @param resource + * resource of a group to leave. + * @param resourceType + * resource type of a group to leave. + * @param resourceHandle + * resource handle to leave a group. + * + * @return OCStackResult - return value of this API. It returns OC_STACK_OK + * if success. + */ + public OCStackResult leaveGroup(OcResource resource, String resourceType, + OcResourceHandle resourceHandle) { + + OCStackResult result; + int ordinal = nativeLeaveGroupForResource(resource, resourceType, + resourceHandle); + result = OCStackResult.conversion(ordinal); + + return result; + } + + /** + * API for deleting a group. + * + * @param collectionResourceType + * resource type of a group to delete. + */ + public void deleteGroup(String collectionResourceType) { + nativeDeleteGroup(collectionResourceType); + } + + /** + * API for getting a list of joined groups. + * + * @return Returns group resource type and group resource handle as a map + * table. + */ + public Map getGroupList() { + return nativeGetGroupList(); + } + + // ******** JNI UTILITY FUNCTION **********// + + /* + * This callback method is called from JNI to notify whether group is found + * or not. + */ + public void onGroupFindCallback(OcResource resource) { + if (null != groupListener) { + Log.i("ThingsManagerCallback : onGroupFindCallback", + "Received Callback from JNI"); + groupListener.onGroupFindCallback(resource); + } + } +} diff --git a/service/things-manager/sdk/java/src/org/iotivity/service/tm/IActionListener.java b/service/things-manager/sdk/java/src/org/iotivity/service/tm/IActionListener.java deleted file mode 100644 index 974dfee..0000000 --- a/service/things-manager/sdk/java/src/org/iotivity/service/tm/IActionListener.java +++ /dev/null @@ -1,88 +0,0 @@ -/****************************************************************** - * - * Copyright 2015 Samsung Electronics All Rights Reserved. - * - * - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************/ - -/** - * @file IActionListener.java - * - * @brief This file provides interface for receiving the callback for the GET, PUT and POST requested - * actions. - * - */ - -package org.iotivity.service.tm; - -import java.util.Vector; - -import org.iotivity.base.OcHeaderOption; -import org.iotivity.base.OcRepresentation; - -/** - * Provides interface for receiving the callback for the GET, PUT and - * POST requested actions. - */ -public interface IActionListener { - /** - * This callback method is called when a asynchronous response for the getActionSet - * request is received. - * - * @param headerOptions - * It comprises of optionID and optionData as members. - * @param rep - * Configuration parameters are carried as a pair of attribute - * key and value in a form of OCRepresentation instance. - * @param errorValue - * error code. - * - */ - public void onGetResponseCallback(Vector headerOptions, - OcRepresentation rep, int errorValue); - - /** - * This callback method is called when a asynchronous response for the addActionSet - * request is received. - * - * @param headerOptions - * It comprises of optionID and optionData as members. - * @param rep - * Configuration parameters are carried as a pair of attribute - * key and value in a form of OCRepresentation instance. - * @param errorValue - * error code. - * - */ - public void onPutResponseCallback(Vector headerOptions, - OcRepresentation rep, int errorValue); - - /** - * This callback method is called when a asynchronous response for the executeActionSet - * or deleteActionSet request is received. - * - * @param headerOptions - * It comprises of optionID and optionData as members. - * @param rep - * Configuration parameters are carried as a pair of attribute - * key and value in a form of OCRepresentation instance. - * @param errorValue - * error code. - * - */ - public void onPostResponseCallback(Vector headerOptions, - OcRepresentation rep, int errorValue); -} diff --git a/service/things-manager/sdk/java/src/org/iotivity/service/tm/IConfigurationListener.java b/service/things-manager/sdk/java/src/org/iotivity/service/tm/IConfigurationListener.java deleted file mode 100644 index 49d91dc..0000000 --- a/service/things-manager/sdk/java/src/org/iotivity/service/tm/IConfigurationListener.java +++ /dev/null @@ -1,60 +0,0 @@ -/****************************************************************** - * - * Copyright 2015 Samsung Electronics All Rights Reserved. - * - * - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************/ - -/** - * @file IConfigurationListener.java - * - * @brief This file provides interface for receiving asynchronous response for - * configuration APIs. - */ - -package org.iotivity.service.tm; - -import java.util.Vector; - -import org.iotivity.base.OcHeaderOption; -import org.iotivity.base.OcRepresentation; - -/** - * Provides interface for receiving asynchronous response for - * configuration APIs. - */ -public interface IConfigurationListener { - /** - * Asynchronous response callback for ThingsManager::doBootstrap API. - */ - public void onBootStrapCallback(Vector headerOptions, - OcRepresentation rep, int errorValue); - - /** - * Asynchronous response callback for ThingsManager::updateConfigurations - * API. - */ - public void onUpdateConfigurationsCallback( - Vector headerOptions, OcRepresentation rep, - int errorValue); - - /** - * Asynchronous response callback for ThingsManager::getConfigurations API. - */ - public void onGetConfigurationsCallback( - Vector headerOptions, OcRepresentation rep, - int errorValue); -} diff --git a/service/things-manager/sdk/java/src/org/iotivity/service/tm/IDiagnosticsListener.java b/service/things-manager/sdk/java/src/org/iotivity/service/tm/IDiagnosticsListener.java deleted file mode 100644 index 499b111..0000000 --- a/service/things-manager/sdk/java/src/org/iotivity/service/tm/IDiagnosticsListener.java +++ /dev/null @@ -1,51 +0,0 @@ -/****************************************************************** - * - * Copyright 2015 Samsung Electronics All Rights Reserved. - * - * - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************/ - -/** - * @file IDiagnosticsListener.java - * - * @brief This file provides interface for receiving asynchronous response for - * diagnostic feature APIs. - */ - -package org.iotivity.service.tm; - -import java.util.Vector; - -import org.iotivity.base.OcHeaderOption; -import org.iotivity.base.OcRepresentation; - -/** - * Provides interface for receiving asynchronous response for diagnostic - * feature APIs. - */ -public interface IDiagnosticsListener { - /** - * Asynchronous response callback for ThingsManager::reboot API. - */ - public void onRebootCallback(Vector headerOptions, - OcRepresentation rep, int errorValue); - - /** - * Asynchronous response callback for ThingsManager::factoryReset API. - */ - public void onFactoryResetCallback(Vector headerOptions, - OcRepresentation rep, int errorValue); -} diff --git a/service/things-manager/sdk/java/src/org/iotivity/service/tm/IFindCandidateResourceListener.java b/service/things-manager/sdk/java/src/org/iotivity/service/tm/IFindCandidateResourceListener.java deleted file mode 100644 index 74472b6..0000000 --- a/service/things-manager/sdk/java/src/org/iotivity/service/tm/IFindCandidateResourceListener.java +++ /dev/null @@ -1,46 +0,0 @@ -/****************************************************************** - * - * Copyright 2015 Samsung Electronics All Rights Reserved. - * - * - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************/ -/** - * @file IFindCandidateResourceListener.java - * - * @brief This file provides interface for getting notification when resources are - * discovered in network. - */ - -package org.iotivity.service.tm; - -import java.util.Vector; - -import org.iotivity.base.OcResource; - -/** - * Provides interface for getting notification when resources are - * discovered in network. - */ -public interface IFindCandidateResourceListener { - /** - * This callback method will be called whenever resource is discovered in - * the network. - * - * @param resources - * List of resources discovered in the network - */ - public void onResourceCallback(Vector resources); -} diff --git a/service/things-manager/sdk/java/src/org/iotivity/service/tm/IFindGroupListener.java b/service/things-manager/sdk/java/src/org/iotivity/service/tm/IFindGroupListener.java deleted file mode 100644 index 232cf57..0000000 --- a/service/things-manager/sdk/java/src/org/iotivity/service/tm/IFindGroupListener.java +++ /dev/null @@ -1,43 +0,0 @@ -/****************************************************************** - * - * Copyright 2015 Samsung Electronics All Rights Reserved. - * - * - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************/ -/** - * @file IFindGroupListener.java - * - * @brief This file provides interface for getting group discovery status. - * - */ - -package org.iotivity.service.tm; - -import org.iotivity.base.OcResource; - -/** - * Provides interface for getting group discovery status. - */ -public interface IFindGroupListener { - /** - * This callback method will be called to notify whether group is found or - * not. - * - * @param resource - * URI of resource. - */ - public void onGroupFindCallback(OcResource resource); -} \ No newline at end of file diff --git a/service/things-manager/sdk/java/src/org/iotivity/service/tm/ISubscribePresenceListener.java b/service/things-manager/sdk/java/src/org/iotivity/service/tm/ISubscribePresenceListener.java deleted file mode 100644 index a1e2541..0000000 --- a/service/things-manager/sdk/java/src/org/iotivity/service/tm/ISubscribePresenceListener.java +++ /dev/null @@ -1,42 +0,0 @@ -/****************************************************************** - * - * Copyright 2015 Samsung Electronics All Rights Reserved. - * - * - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************/ -/** - * @file ISubscribePresenceListener.java - * - * @brief This file provides interface for getting child resource presence status. - * - */ - -package org.iotivity.service.tm; - -/** - * Provides interface for getting child resource presence status. - */ -public interface ISubscribePresenceListener { - /** - * This callback method will be called for child resource presence status. - * - * @param resource - * URI of resource. - * @param result - * error code. - */ - public void onPresenceCallback(String resource, int result); -} diff --git a/service/things-manager/sdk/java/src/org/iotivity/service/tm/OCStackResult.java b/service/things-manager/sdk/java/src/org/iotivity/service/tm/OCStackResult.java index 241eb11..d64efb0 100644 --- a/service/things-manager/sdk/java/src/org/iotivity/service/tm/OCStackResult.java +++ b/service/things-manager/sdk/java/src/org/iotivity/service/tm/OCStackResult.java @@ -1,4 +1,4 @@ -/****************************************************************** +/* ***************************************************************** * * Copyright 2015 Samsung Electronics All Rights Reserved. * @@ -17,11 +17,11 @@ * limitations under the License. * ******************************************************************/ + /** - * @file OCStackResult.java - * - * @brief This file provides a Enum which contains Status codes for Success and Errors - * + * @file + * This file provides a Enum which contains Status codes + * for Success and Errors */ package org.iotivity.service.tm; @@ -30,6 +30,7 @@ package org.iotivity.service.tm; * This Enum contains Status codes for Success and Errors */ public enum OCStackResult { + OC_STACK_OK, OC_STACK_RESOURCE_CREATED, OC_STACK_RESOURCE_DELETED, diff --git a/service/things-manager/sdk/java/src/org/iotivity/service/tm/ThingsConfiguration.java b/service/things-manager/sdk/java/src/org/iotivity/service/tm/ThingsConfiguration.java new file mode 100644 index 0000000..deddcb5 --- /dev/null +++ b/service/things-manager/sdk/java/src/org/iotivity/service/tm/ThingsConfiguration.java @@ -0,0 +1,289 @@ +/* ***************************************************************** + * + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ + +/** + * @file + * This file contains class which provides functions for + * things configuration. + */ + +package org.iotivity.service.tm; + +import java.util.Map; +import java.util.Vector; + +import org.iotivity.base.OcException; +import org.iotivity.base.OcHeaderOption; +import org.iotivity.base.OcRepresentation; +import org.iotivity.base.OcResource; + +import android.util.Log; + +/** + * This class provides a set of APIs relating to Things Configuration. + */ +public class ThingsConfiguration { + + private IConfigurationListener configurationListener; + private static ThingsConfiguration s_thingsConfigurationInstance; + private final String LOG_TAG = this.getClass() + .getSimpleName(); + + // Native Methods + private static native int nativeUpdateConfigurations(OcResource resource, + Map configurations); + + private static native int nativeGetConfigurations(OcResource resource, + Vector configurations); + + private static native String nativeGetListOfSupportedConfigurationUnits(); + + private static native int nativeDoBootstrap(); + + /** + * Function for Getting instance of ThingsConfiguration object. + * + * @return ThingsConfiguration instance. + * + */ + public static ThingsConfiguration getInstance() { + if (null == s_thingsConfigurationInstance) { + s_thingsConfigurationInstance = new ThingsConfiguration(); + } + return s_thingsConfigurationInstance; + } + + /** + * Provides interface for receiving asynchronous response for configuration + * APIs. + */ + public interface IConfigurationListener { + /** + * Asynchronous response callback for doBootstrap API. + * + * @param headerOptions + * It comprises of optionID and optionData as members. + * @param rep + * Configuration parameters are carried as a pair of + * attribute key and value in a form of OCRepresentation + * instance. + * @param errorValue + * error code. + */ + public void onBootStrapCallback(Vector headerOptions, + OcRepresentation rep, int errorValue); + + /** + * Asynchronous response callback for updateConfigurations API. + * + * @param headerOptions + * It comprises of optionID and optionData as members. + * @param rep + * Configuration parameters are carried as a pair of + * attribute key and value in a form of OCRepresentation + * instance. + * @param errorValue + * error code. + */ + public void onUpdateConfigurationsCallback( + Vector headerOptions, OcRepresentation rep, + int errorValue); + + /** + * Asynchronous response callback for getConfigurations API. + * + * @param headerOptions + * It comprises of optionID and optionData as members. + * @param rep + * Configuration parameters are carried as a pair of + * attribute key and value in a form of OCRepresentation + * instance. + * @param errorValue + * error code. + */ + public void onGetConfigurationsCallback( + Vector headerOptions, OcRepresentation rep, + int errorValue); + } + + /** + * Set listener for receiving asynchronous response for configuration APIs. + * + * @param listener + * IConfigurationListener to receive asynchronous response for + * configuration APIs. + */ + public void setConfigurationListener(IConfigurationListener listener) { + configurationListener = listener; + } + + /** + * API for updating configuration value of multiple things of a target group + * or a single thing to a resource server(s). + * + *

+ * Listener should be set using setConfigurationListener API. + *

+ * Listener IConfigurationListener::onUpdateConfigurationsCallback will be + * notified when the response of update configuration arrives. + * + * @param resource + * resource representing the target group or the single thing. It + * is a pointer of resource instance of Configuration resource. + * The resource pointer can be acquired by performing + * findResource() function with a dedicated resource type, + * "oic.con". Note that, the resource pointer represents not only + * a single simple resource but also a collection resource + * composing multiple simple resources. In other words, using + * these APIs, developers can send a series of requests to + * multiple things by calling the corresponding function at once. + * @param configurations + * ConfigurationUnit: a nickname of attribute of target resource + * (e.g., installed location, currency, (IP)address) Value : a + * value to be updated. It represents an indicator of which + * resource developers want to access and which value developers + * want to update. Basically, developers could use a resource URI + * to access a specific resource but a resource URI might be hard + * for all developers to memorize lots of URIs, especially in the + * case of long URIs. To relieve the problem, Things + * Configuration introduces a easy-memorizing name, called + * ConfigurationName, instead of URI. And ConfigurationValue used + * in updateConfiguration() function indicates a value to be + * updated. Note that, only one configuration parameter is + * supported in this release. Multiple configuration parameters + * will be supported in future release. + * + * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error + * code. + */ + public OCStackResult updateConfigurations(OcResource resource, + Map configurations) throws OcException { + OCStackResult result; + if (null == configurationListener) { + result = OCStackResult.OC_STACK_ERROR; + } else { + int ordinal = nativeUpdateConfigurations(resource, configurations); + result = OCStackResult.conversion(ordinal); + } + return result; + } + + /** + * API for getting configuration value of multiple things of a target group + * or a single thing.To get a value, users need to know a Configuration Name + * indicating the target resource. In this release, the Configuration Name + * is "configuration".An update value is not needed. After that, users store + * them in form of a Vector and then use a getConfigurations() function. + * + * @param resource + * resource representing the target group or the single thing. + * @param configurations + * ConfigurationUnit: a nickname of attribute of target resource. + * + * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error + * code. + */ + public OCStackResult getConfigurations(OcResource resource, + Vector configurations) throws OcException { + OCStackResult result; + if (null == configurationListener) { + result = OCStackResult.OC_STACK_ERROR; + } else { + int ordinal = nativeGetConfigurations(resource, configurations); + result = OCStackResult.conversion(ordinal); + } + return result; + } + + /** + * API for getting the list of supported configuration units (configurable + * parameters). It shows which Configuration Names are supported and their + * brief descriptions. This information is provided in JSON format. + * + * @return Returns the configuration list in JSON format. + */ + public String getListOfSupportedConfigurationUnits() { + return nativeGetListOfSupportedConfigurationUnits(); + } + + /** + * API for bootstrapping system configuration parameters from a bootstrap + * server. + *

+ * Listener should be set using setConfigurationListener API. + *

+ * Listener IConfigurationListener::onBootStrapCallback will be notified + * when the response arrives. + * + * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error + * code. + */ + public OCStackResult doBootstrap() { + if (null == configurationListener) { + Log.e(LOG_TAG, "doBootstrap: listener not set!"); + return OCStackResult.OC_STACK_LISTENER_NOT_SET; + } + + OCStackResult result; + int ordinal = nativeDoBootstrap(); + result = OCStackResult.conversion(ordinal); + return result; + } + + // ******** JNI UTILITY FUNCTIONS **********// + + /* + * This callback method is called from JNI when a response for the + * updateConfigurations request just arrives. + */ + public void onUpdateConfigurationsCallback( + Vector headerOptions, OcRepresentation rep, + int errorValue) { + if (null != configurationListener) + configurationListener.onUpdateConfigurationsCallback(headerOptions, + rep, errorValue); + } + + /* + * This callback method is called from JNI when a response for the + * getConfigurations request just arrives. + */ + public void onGetConfigurationsCallback( + Vector headerOptions, OcRepresentation rep, + int errorValue) { + if (null != configurationListener) + configurationListener.onGetConfigurationsCallback(headerOptions, + rep, errorValue); + } + + /* + * This callback method is called from JNI when a response for the + * doBootstrap request just arrives. + */ + public void onBootStrapCallback(Vector headerOptions, + OcRepresentation rep, int errorValue) { + if (null != configurationListener) { + Log.i("ThingsManagerCallback : onBootStrapCallback", + "Received Callback from JNI"); + configurationListener.onBootStrapCallback(headerOptions, rep, + errorValue); + } + } +} diff --git a/service/things-manager/sdk/java/src/org/iotivity/service/tm/ThingsMaintenance.java b/service/things-manager/sdk/java/src/org/iotivity/service/tm/ThingsMaintenance.java new file mode 100644 index 0000000..dc948a0 --- /dev/null +++ b/service/things-manager/sdk/java/src/org/iotivity/service/tm/ThingsMaintenance.java @@ -0,0 +1,225 @@ +/* ***************************************************************** + * + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ + +/** + * @file + * This file contains class which provides functions + * for things maintenance. + */ + +package org.iotivity.service.tm; + +import java.util.Vector; + +import org.iotivity.base.OcException; +import org.iotivity.base.OcHeaderOption; +import org.iotivity.base.OcRepresentation; +import org.iotivity.base.OcResource; + +import android.util.Log; + +/** + * This class provides a set of APIs relating to Things Maintenance. + */ +public class ThingsMaintenance { + + private IThingsMaintenanceListener thingsMaintenanceListener; + private static ThingsMaintenance s_thingsMaintenanceInstance; + private final String LOG_TAG = this.getClass() + .getSimpleName(); + + // Native methods + private static native int nativeReboot(OcResource resource); + + private static native int nativeFactoryReset(OcResource resource); + + private static native String nativeGetListOfSupportedMaintenanceUnits(); + + /** + * Function for Getting instance of ThingsMaintenance object. + * + * @return ThingsMaintenance instance. + */ + public static ThingsMaintenance getInstance() { + if (null == s_thingsMaintenanceInstance) { + s_thingsMaintenanceInstance = new ThingsMaintenance(); + } + return s_thingsMaintenanceInstance; + } + + /** + * Provides interface for receiving asynchronous response for Things + * Maintenance feature APIs. + */ + public interface IThingsMaintenanceListener { + /** + * Asynchronous response callback for reboot API. + * + * @param headerOptions + * It comprises of optionID and optionData as members. + * @param rep + * Configuration parameters are carried as a pair of + * attribute key and value in a form of OCRepresentation + * instance. + * @param errorValue + * error code. + */ + public void onRebootCallback(Vector headerOptions, + OcRepresentation rep, int errorValue); + + /** + * Asynchronous response callback for factoryReset API. + * + * @param headerOptions + * It comprises of optionID and optionData as members. + * @param rep + * Configuration parameters are carried as a pair of + * attribute key and value in a form of OCRepresentation + * instance. + * @param errorValue + * error code. + */ + public void onFactoryResetCallback( + Vector headerOptions, OcRepresentation rep, + int errorValue); + } + + /** + * Set listener for receiving asynchronous response for Things Maintenance + * APIs. + * + * @param listener + * IThingsMaintenanceListener to receive asynchronous response + * for diagnostic feature APIs. + */ + public void setThingsMaintenanceListener(IThingsMaintenanceListener listener) { + thingsMaintenanceListener = listener; + } + + /** + * API to is used to send a request to a server(thing or device) to be + * rebooted. On receiving the request, the server attempts to reboot itself + * in a deterministic time. The target thing could be a group of multiple + * things or a single thing. + *

+ * Listener should be set using setDiagnosticsListener API. + *

+ * Listener IThingsMaintenanceListener::onRebootCallback will be notified + * when the response arrives. + * + * @param resource + * resource pointer representing the target group + * + * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error + * code. + */ + public OCStackResult reboot(OcResource resource) throws OcException { + + OCStackResult result; + int ordinal = nativeReboot(resource); + result = OCStackResult.conversion(ordinal); + + return result; + } + + /** + * API to restore all configuration parameters to default one on + * thing(device). All configuration parameters refers Configuration + * resource, which they could have been modified for various reasons (e.g., + * for a request to update a value). If developers on the client want to + * restore the parameters, just use the factoryReset function.The target + * thing could be a group of multiple things or a single thing. + * + *

+ * Listener should be set using setDiagnosticsListener API. + *

+ * Listener IThingsMaintenanceListener::onFactoryResetCallback will be + * notified when the response arrives. + * + * @param resource + * resource pointer representing the target group + * + * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error + * code. + */ + public OCStackResult factoryReset(OcResource resource) throws OcException { + + OCStackResult result; + int ordinal = nativeFactoryReset(resource); + result = OCStackResult.conversion(ordinal); + + return result; + } + + /** + * This callback method is called when a response for the reboot request + * just arrives. + * + * @param headerOptions + * It comprises of optionID and optionData as members. + * @param rep + * Configuration parameters are carried as a pair of attribute + * key and value in a form of OCRepresentation instance. + * @param errorValue + * error code. + */ + public void onRebootCallback(Vector headerOptions, + OcRepresentation rep, int errorValue) { + if (null != thingsMaintenanceListener) { + Log.i("ThingsManagerCallback : onRebootCallback", + "Received Callback from JNI"); + thingsMaintenanceListener.onRebootCallback(headerOptions, rep, + errorValue); + } + } + + /** + * This callback method is called when a response for the factoryReset + * request just arrives. + * + * @param headerOptions + * It comprises of optionID and optionData as members. + * @param rep + * Configuration parameters are carried as a pair of attribute + * key and value in a form of OCRepresentation instance. + * @param errorValue + * error code. + */ + public void onFactoryResetCallback(Vector headerOptions, + OcRepresentation rep, int errorValue) { + if (null != thingsMaintenanceListener) { + Log.i("ThingsManagerCallback : onFactoryResetCallback", + "Received Callback from JNI"); + thingsMaintenanceListener.onFactoryResetCallback(headerOptions, + rep, errorValue); + } + } + + /** + * API for getting the list of supported Maintenance units. It shows which + * Maintenance Names are supported and their brief descriptions. This + * information is provided in JSON format. + * + * @return Returns the configuration list in JSON format. + */ + public String getListOfSupportedMaintenanceUnits() { + return nativeGetListOfSupportedMaintenanceUnits(); + } +} diff --git a/service/things-manager/sdk/java/src/org/iotivity/service/tm/ThingsManager.java b/service/things-manager/sdk/java/src/org/iotivity/service/tm/ThingsManager.java deleted file mode 100644 index a506305..0000000 --- a/service/things-manager/sdk/java/src/org/iotivity/service/tm/ThingsManager.java +++ /dev/null @@ -1,819 +0,0 @@ -/****************************************************************** - * - * Copyright 2015 Samsung Electronics All Rights Reserved. - * - * - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************/ -/** - * @file ThingsManager.java - * - * @brief This file provides a class for a set of APIs relating to group management, - * synchronization of group, configuration of things, and diagnostics - * about things. - * - */ - -package org.iotivity.service.tm; - -import java.util.Map; -import java.util.Vector; - -import org.iotivity.base.OcException; -import org.iotivity.base.OcResource; -import org.iotivity.base.OcResourceHandle; - -import android.util.Log; - -/** - * This class provides a set of APIs relating to group management, - * synchronization of group, configuration of things, and diagnostics - * about things. - * - */ -public class ThingsManager { - - private IFindCandidateResourceListener resourceListener; - private ISubscribePresenceListener presenceListener; - private IFindGroupListener groupListener; - private IConfigurationListener configurationListener; - private IDiagnosticsListener diagnosticsListener; - private IActionListener actionListener; - private final String LOG_TAG = this.getClass() - .getSimpleName(); - - private final ThingsManagerCallback thingsManagerCallbackInterfaceObj; - private final ThingsManagerInterface thingsManagerInterfaceObj; - - static { - System.loadLibrary("gnustl_shared"); - System.loadLibrary("oc_logger"); - System.loadLibrary("connectivity_abstraction"); - System.loadLibrary("ca-interface"); - System.loadLibrary("octbstack"); - System.loadLibrary("oc"); - System.loadLibrary("TGMSDKLibrary"); - System.loadLibrary("ocstack-jni"); - System.loadLibrary("things-manager-jni"); - } - - /** - * Constructor for ThingsManager. Constructs a new ThingsManager. - */ - public ThingsManager() { - thingsManagerCallbackInterfaceObj = ThingsManagerCallback.getInstance(); - thingsManagerInterfaceObj = ThingsManagerInterface.getInstance(); - } - - /** - * Set listener for receiving notification of resource discovery. - * - * @param listener - * IFindCandidateResourceListener to receive the - * discovered resources. - */ - public void setFindCandidateResourceListener( - IFindCandidateResourceListener listener) { - resourceListener = listener; - thingsManagerCallbackInterfaceObj - .registerFindCandidateResourceListener(listener); - thingsManagerInterfaceObj - .registerFindCandidateResourceListener(listener); - } - - /** - * Set listener for receiving child resource presence notifications. - * - * @param listener - * ISubscribePresenceListener to receive child resource - * presence state. - */ - public void setSubscribePresenceListener(ISubscribePresenceListener listener) { - presenceListener = listener; - thingsManagerCallbackInterfaceObj - .registerSubscribePresenceListener(listener); - thingsManagerInterfaceObj.registerSubscribePresenceListener(listener); - } - - /** - * Set listener for receiving notification on whether the requested group is - * found or not. - * - * @param listener - * IFindGroupListener to receive group discovery status. - */ - public void setGroupListener(IFindGroupListener listener) { - groupListener = listener; - thingsManagerCallbackInterfaceObj.registerGroupListener(listener); - thingsManagerInterfaceObj.registerGroupListener(listener); - } - - /** - * Set listener for receiving asynchronous response for configuration APIs. - * - * @param listener - * IConfigurationListener to receive asynchronous response - * for configuration APIs. - */ - public void setConfigurationListener(IConfigurationListener listener) { - configurationListener = listener; - thingsManagerCallbackInterfaceObj - .registerConfigurationListener(listener); - thingsManagerInterfaceObj.registerConfigurationListener(listener); - } - - /** - * Set listener for receiving asynchronous response for diagnostic feature - * APIs. - * - * @param listener - * IDiagnosticsListener to receive asynchronous response - * for diagnostic feature APIs. - */ - public void setDiagnosticsListener(IDiagnosticsListener listener) { - diagnosticsListener = listener; - thingsManagerCallbackInterfaceObj.registerDiagnosticsListener(listener); - } - - /** - * Set listener for receiving responses of Get, PUT and POST requests. - * - * @param listener - * IActionListener to receive Get, PUT and POST request - * responses. - */ - public void setActionListener(IActionListener listener) { - actionListener = listener; - thingsManagerCallbackInterfaceObj.registerActionListener(listener); - } - - /** - * API for discovering candidate resources with waiting delay. This - * operation returns all resources of given type on the network service. - * This operation is sent via multicast to all services. However, the filter - * limits the responders to just those that support the resource type in the - * query. Currently only exact matches are supported. - *

- * Listener should be set using setFindCandidateResourceListener API - *

- * Listener IFindCandidateResourceListener::onResourceCallback - * will be notified when resource is discovered in network. - * - * @param resourceTypes - * required resource types(called "candidate") - * @param waitTime - * Delay time to add in seconds before starting to find the - * resources in network. - * - * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error - * code. - * - */ - public OCStackResult findCandidateResources(Vector resourceTypes, - int waitTime) { - if (null == resourceListener) { - Log.e(LOG_TAG,"findCandidateResources: listener not set!"); - return OCStackResult.OC_STACK_LISTENER_NOT_SET; - } - - OCStackResult result = thingsManagerInterfaceObj.findCandidateResources( - resourceTypes, waitTime); - if (OCStackResult.OC_STACK_OK != result) { - Log.e(LOG_TAG, "findCandidateResources: returned error: " + result.name()); - } - - return result; - } - - /** - * API for subscribing child's state. It subscribes the presence state of - * the resource. By making this subscription, every time a server - * adds/removes/alters a resource, starts or is intentionally stopped, a - * notification is sent to subscriber. - * - *

- * Listener should be set using setSubscribePresenceListener API. - *

- * Listener ISubscribePresenceListener::onPresenceCallback will - * be notified for resource presence status - * - * @param resource - * collection resource for subscribing presence of all child - * resources - * - * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error - * code. - * - */ - public OCStackResult subscribeCollectionPresence(OcResource resource) - throws OcException { - if (null == presenceListener) { - Log.e(LOG_TAG,"subscribeCollectionPresence: listener not set!"); - return OCStackResult.OC_STACK_LISTENER_NOT_SET; - } - - OCStackResult result = thingsManagerInterfaceObj - .subscribeCollectionPresence(resource); - if (OCStackResult.OC_STACK_OK != result) { - Log.e(LOG_TAG, "subscribeCollectionPresence: returned error: " + result.name()); - } - - return result; - } - - /** - * API for finding a specific remote group when a resource tries to join a - * group. - *

- * Listener should be set using setGroupListener API - *

- * Listener IFindGroupListener::onGroupFindCallback will be - * called to notify whenever a requested group is found. - * - * @param collectionResourceTypes - * resource types of a group to find and join - * - * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error - * code. - * - * - */ - public OCStackResult findGroup(Vector collectionResourceTypes) { - if (null == groupListener) { - Log.e(LOG_TAG,"findGroup: listener not set!"); - return OCStackResult.OC_STACK_LISTENER_NOT_SET; - } - - OCStackResult result = result = thingsManagerInterfaceObj.findGroup(collectionResourceTypes); - if (OCStackResult.OC_STACK_OK != result) { - Log.e(LOG_TAG, "findGroup: returned error: " + result.name()); - } - - return result; - } - - /** - * API for creating a new group. - * - * @param collectionResourceType - * resource type of a group to create - * - * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error - * code. - */ - public OCStackResult createGroup(String collectionResourceType) { - OCStackResult result = thingsManagerInterfaceObj.createGroup(collectionResourceType); - if (OCStackResult.OC_STACK_OK != result) { - Log.e(LOG_TAG, "createGroup: returned error: " + result.name()); - } - - return result; - } - - /** - * API for joining a group. This API is used for joining the resource - * to local group which is created using @createGroup API. - * - * @param collectionResourceType - * resource type of a group to join. - * @param resourceHandle - * resource handle to join a group. - * - * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error - * code. - * - */ - public OCStackResult joinGroup(String collectionResourceType, - OcResourceHandle resourceHandle) { - OCStackResult result = thingsManagerInterfaceObj.joinGroup(collectionResourceType, - resourceHandle); - if (OCStackResult.OC_STACK_OK != result) { - Log.e(LOG_TAG, "joinGroup: returned error: " + result.name()); - } - - return result; - } - - /** - * API for joining a group. This API is used for joining the resource to - * remote group. - * - * @param resource - * group resource to join. - * @param resourceHandle - * resource handle to join a group. - * - * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error - * code. - * - */ - public OCStackResult joinGroup(OcResource resource, - OcResourceHandle resourceHandle) throws OcException { - OCStackResult result = thingsManagerInterfaceObj.joinGroup(resource, resourceHandle); - if (OCStackResult.OC_STACK_OK != result) { - Log.e(LOG_TAG, "joinGroup: returned error: " + result.name()); - } - - return result; - } - - /** - * API for leaving a joined local group. - * - * @param collectionResourceType - * resource type of a group to leave. - * @param resourceHandle - * resource handle to leave a group. - * - * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error - * code. - * - */ - public OCStackResult leaveGroup(String collectionResourceType, - OcResourceHandle resourceHandle) { - OCStackResult result = thingsManagerInterfaceObj.leaveGroup(collectionResourceType, - resourceHandle); - if (OCStackResult.OC_STACK_OK != result) { - Log.e(LOG_TAG, "leaveGroup: returned error: " + result.name()); - } - - return result; - } - - /** - * API for leaving a joined remote group. - * - * @param resource - * resource of a group to leave. - * @param collectionResourceType - * resource type of a group to leave. - * @param resourceHandle - * resource handle to leave a group. - * - * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error - * code. - * - */ - public OCStackResult leaveGroup(OcResource resource, String collectionResourceType, - OcResourceHandle resourceHandle) { - OCStackResult result = thingsManagerInterfaceObj.leaveGroup(resource, collectionResourceType, - resourceHandle); - if (OCStackResult.OC_STACK_OK != result) { - Log.e(LOG_TAG, "leaveGroup: returned error: " + result.name()); - } - - return result; - } - - /** - * API for deleting a created group. - * - * @param collectionResourceType - * resource type of a group to delete. - * - */ - public void deleteGroup(String collectionResourceType) { - thingsManagerInterfaceObj.deleteGroup(collectionResourceType); - } - - /** - * API for getting a list of local groups. - * - * @return Returns the map with the group resource type and group - * resource handle on successs otherwise null. - * - */ - public Map getGroupList() { - return thingsManagerInterfaceObj.getGroupList(); - } - - /** - * API for registering and binding a resource to group. - * - * @param resource - * resource for register and bind to group. It has all data. - * @param collectionHandle - * collection resource handle. It will be the added child - * resource. - * - * @return OcResourceHandle - Child resource handle. - * - */ - public OcResourceHandle bindResourceToGroup(OcResource resource, - OcResourceHandle collectionHandle) - throws OcException { - return thingsManagerInterfaceObj.bindResourceToGroup(resource, - collectionHandle); - } - - /** - * API for updating configuration value of multiple things of a target group - * or a single thing to a resource server(s). - * - *

- * Listener should be set using setConfigurationListener API. - *

- * Listener IConfigurationListener::onUpdateConfigurationsCallback will be - * notified when the response of update configuration arrives. - * - * @param resource - * resource representing the target group or the single thing. - * It is a pointer of resource instance of Configuration - * resource. The resource pointer can be acquired by performing - * findResource() function with a dedicated resource type, - * "oic.con". Note that, the resource pointer represents not only - * a single simple resource but also a collection resource - * composing multiple simple resources. In other words, using - * these APIs, developers can send a series of requests to - * multiple things by calling the corresponding function at once. - * @param configurations - * ConfigurationUnit: a nickname of attribute of target - * resource (e.g., installed location, currency, (IP)address) - * Value : a value to be updated. It represents an indicator of - * which resource developers want to access and which value - * developers want to update. Basically, developers could use a - * resource URI to access a specific resource but a resource URI - * might be hard for all developers to memorize lots of URIs, - * especially in the case of long URIs. To relieve the problem, - * Things Configuration introduces a easy-memorizing name, called - * ConfigurationName, instead of URI. And ConfigurationValue used - * in updateConfiguration() function indicates a value to be - * updated. Note that, only one configuration parameter is - * supported in this release. Multiple configuration parameters - * will be supported in future release. - * - * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error - * code. - * - */ - public OCStackResult updateConfigurations(OcResource resource, - Map configurations) throws OcException { - if (null == configurationListener) { - Log.e(LOG_TAG,"updateConfigurations: listener not set!"); - return OCStackResult.OC_STACK_LISTENER_NOT_SET; - } - - OCStackResult result = thingsManagerInterfaceObj.updateConfigurations(resource, - configurations); - if (OCStackResult.OC_STACK_OK != result) { - Log.e(LOG_TAG, "updateConfigurations: returned error: " + result.name()); - } - - return result; - } - - /** - * API for getting configuration value of multiple things of a target group - * or a single thing.To get a value, users need to know a Configuration Name - * indicating the target resource. In this release, the Configuration Name - * is "configuration".An update value is not needed. After that, users store - * them in form of a Vector and then use a getConfigurations() function. - * - * @param resource - * resource representing the target group or the single thing. - * @param configurations - * ConfigurationUnit: a nickname of attribute of target - * resource. - * - * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error - * code. - * - */ - public OCStackResult getConfigurations(OcResource resource, - Vector configurations) throws OcException { - if (null == configurationListener) { - Log.e(LOG_TAG,"getConfigurations: listener not set!"); - return OCStackResult.OC_STACK_LISTENER_NOT_SET; - } - - OCStackResult result = thingsManagerInterfaceObj.getConfigurations(resource, - configurations); - if (OCStackResult.OC_STACK_OK != result) { - Log.e(LOG_TAG, "getConfigurations: returned error: " + result.name()); - } - - return result; - } - - /** - * API for getting the list of supported configuration units (configurable - * parameters). It shows which Configuration Names are supported and their - * brief descriptions. This information is provided in JSON format. - * - * @return Returns the configuration list in JSON format. - * - */ - public String getListOfSupportedConfigurationUnits() { - return thingsManagerInterfaceObj.getListOfSupportedConfigurationUnits(); - } - - /** - * API for bootstrapping system configuration parameters from a bootstrap - * server. - *

- * Listener should be set using setConfigurationListener API. - *

- * Listener IConfigurationListener::onBootStrapCallback will be - * notified when the response arrives. - * - * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error - * code. - * - */ - public OCStackResult doBootstrap() { - if (null == configurationListener) { - Log.e(LOG_TAG,"doBootstrap: listener not set!"); - return OCStackResult.OC_STACK_LISTENER_NOT_SET; - } - - OCStackResult result = thingsManagerInterfaceObj.doBootstrap(); - if (OCStackResult.OC_STACK_OK != result) { - Log.e(LOG_TAG, "doBootstrap: returned error: " + result.name()); - } - - return result; - } - - /** - * API to is used to send a request to a server(thing or device) to be - * rebooted. On receiving the request, the server attempts to reboot itself - * in a deterministic time. The target thing could be a group of multiple - * things or a single thing. - *

- * Listener should be set using setDiagnosticsListener API. - *

- * Listener IDiagnosticsListener::onRebootCallback will be - * notified when the response arrives. - * @param resource - * resource pointer representing the target group - * - * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error - * code. - * - */ - public OCStackResult reboot(OcResource resource) throws OcException { - if (null == diagnosticsListener) { - Log.e(LOG_TAG,"reboot: listener not set!"); - return OCStackResult.OC_STACK_LISTENER_NOT_SET; - } - - OCStackResult result = thingsManagerInterfaceObj.reboot(resource); - if (OCStackResult.OC_STACK_OK != result) { - Log.e(LOG_TAG, "reboot: returned error: " + result.name()); - } - - return result; - } - - /** - * API to restore all configuration parameters to default one on - * thing(device). All configuration parameters refers Configuration - * resource, which they could have been modified for various reasons (e.g., - * for a request to update a value). If developers on the client want to - * restore the parameters, just use the factoryReset function.The target - * thing could be a group of multiple things or a single thing. - * - *

- * Listener should be set using setDiagnosticsListener API. - *

- * Listener IDiagnosticsListener::onFactoryResetCallback will be - * notified when the response arrives. - * - * @param resource - * resource pointer representing the target group - * - * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error - * code. - * - */ - public OCStackResult factoryReset(OcResource resource) throws OcException { - if (null == diagnosticsListener) { - Log.e(LOG_TAG,"factoryReset: listener not set!"); - return OCStackResult.OC_STACK_LISTENER_NOT_SET; - } - - OCStackResult result = thingsManagerInterfaceObj.factoryReset(resource); - if (OCStackResult.OC_STACK_OK != result) { - Log.e(LOG_TAG, "factoryReset: returned error: " + result.name()); - } - - return result; - } - - /** - * API for adding a new ActionSet onto a specific resource. - * - *

- * Listener should be set using setActionListener API. - *

- * Listener IActionListener::onPutResponseCallback will be - * notified when the response of PUT operation arrives. - * @param resource - * resource pointer of the group resource - * @param actionSet - * pointer of ActionSet - * - * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error - * code. - * - */ - public OCStackResult addActionSet(OcResource resource, ActionSet actionSet) - throws OcException { - if (null == actionListener) { - Log.e(LOG_TAG,"addActionSet: listener not set!"); - return OCStackResult.OC_STACK_LISTENER_NOT_SET; - } - - OCStackResult result = thingsManagerInterfaceObj - .addActionSet(resource, actionSet); - if (OCStackResult.OC_STACK_OK != result) { - Log.e(LOG_TAG, "addActionSet: returned error: " + result.name()); - } - - return result; - } - - /** - * API for executing a specific ActionSet belonging to a specific resource. - * - *

- * Listener should be set using setActionListener API. - *

- * Listener IActionListener::onPostResponseCallback will be - * notified when the response of POST operation arrives. - * - * @param resource - * resource pointer of the group resource - * @param actionsetName - * ActionSet name for removing the ActionSet - * - * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error - * code. - * - */ - public OCStackResult executeActionSet(OcResource resource, - String actionsetName) throws OcException { - if (null == actionListener) { - Log.e(LOG_TAG,"executeActionSet: listener not set!"); - return OCStackResult.OC_STACK_LISTENER_NOT_SET; - } - - OCStackResult result = thingsManagerInterfaceObj - .executeActionSet(resource, actionsetName); - if (OCStackResult.OC_STACK_OK != result) { - Log.e(LOG_TAG, "executeActionSet: returned error: " + result.name()); - } - - return result; - } - - /** - * API for executing a specific ActionSet belonging to a specific resource. - * - *

- * Listener should be set using setActionListener API. - *

- * Listener IActionListener::onPostResponseCallback will be - * notified when the response of POST operation arrives. - * - * @param resource - * resource pointer of the group resource - * @param actionsetName - * ActionSet name for removing the ActionSet - * @param delay - * Wait time for the ActionSet execution - * - * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error - * code. - * - */ - public OCStackResult executeActionSet(OcResource resource, - String actionsetName, long delay) throws OcException { - if (null == actionListener) { - Log.e(LOG_TAG,"executeActionSet: listener not set!"); - return OCStackResult.OC_STACK_LISTENER_NOT_SET; - } - - OCStackResult result = thingsManagerInterfaceObj - .executeActionSet(resource, actionsetName, delay); - if (OCStackResult.OC_STACK_OK != result) { - Log.e(LOG_TAG, "executeActionSet: returned error: " + result.name()); - } - - return result; - } - - /** - * API to cancel the existing ActionSet. - * - *

- * Listener should be set using setActionListener API. - *

- * Listener IActionListener::onPostResponseCallback will be - * notified when the response of POST operation arrives. - * @param resource - * resource pointer of the group resource. - * @param actionsetName - * ActionSet name that has to be cancelled. - * - * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error - * code. - * - */ - - public OCStackResult cancelActionSet(OcResource resource, - String actionsetName) throws OcException { - if (null == actionListener) { - Log.e(LOG_TAG,"cancelActionSet: listener not set!"); - return OCStackResult.OC_STACK_LISTENER_NOT_SET; - } - - OCStackResult result = thingsManagerInterfaceObj.cancelActionSet(resource, - actionsetName); - if (OCStackResult.OC_STACK_OK != result) { - Log.e(LOG_TAG, "cancelActionSet: returned error: " + result.name()); - } - - return result; - } - - /** - * API to to get an existing ActionSet belonging to a specific resource. - * - *

- * Listener should be set using setActionListener API. - *

- * Listener IActionListener::onPostResponseCallback will be - * notified when the response of POST operation arrives. - * @param resource - * resource pointer of the group resource - * @param actionsetName - * ActionSet name for removing the ActionSet - * - * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error - * code. - * - */ - public OCStackResult getActionSet(OcResource resource, String actionsetName) - throws OcException { - if (null == actionListener) { - Log.e(LOG_TAG,"getActionSet: listener not set!"); - return OCStackResult.OC_STACK_LISTENER_NOT_SET; - } - - OCStackResult result = thingsManagerInterfaceObj.getActionSet(resource, - actionsetName); - if (OCStackResult.OC_STACK_OK != result) { - Log.e(LOG_TAG, "getActionSet: returned error: " + result.name()); - } - - return result; - } - - /** - * API to delete an existing ActionSet belonging to a specific resource. - * - *

- * Listener should be set using setActionListener API. - *

- * Listener IActionListener::onPutResponseCallback will be - * notified when the response of PUT operation arrives. - * - * @param resource - * resource pointer of the group resource - * @param actionsetName - * ActionSet name for removing the ActionSet - * - * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error - * code. - * - */ - public OCStackResult deleteActionSet(OcResource resource, - String actionsetName) throws OcException { - if (null == actionListener) { - Log.e(LOG_TAG,"deleteActionSet: listener not set!"); - return OCStackResult.OC_STACK_LISTENER_NOT_SET; - } - - OCStackResult result = thingsManagerInterfaceObj.deleteActionSet(resource, - actionsetName); - if (OCStackResult.OC_STACK_OK != result) { - Log.e(LOG_TAG, "deleteActionSet: returned error: " + result.name()); - } - - return result; - } - -} diff --git a/service/things-manager/sdk/java/src/org/iotivity/service/tm/ThingsManagerCallback.java b/service/things-manager/sdk/java/src/org/iotivity/service/tm/ThingsManagerCallback.java deleted file mode 100644 index 36456dc..0000000 --- a/service/things-manager/sdk/java/src/org/iotivity/service/tm/ThingsManagerCallback.java +++ /dev/null @@ -1,415 +0,0 @@ -/****************************************************************** - * - * Copyright 2015 Samsung Electronics All Rights Reserved. - * - * - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************/ - -/** - * @file ThingsManagerCallback.java - * - * @brief This file provides a class for a set of callback functions for group management, - * synchronization of group, configuration of things, and diagnostics - * about things. - * - */ - -package org.iotivity.service.tm; - -import java.util.Vector; - -import org.iotivity.base.OcHeaderOption; -import org.iotivity.base.OcRepresentation; -import org.iotivity.base.OcResource; - -import android.util.Log; - -/** - * This class provides a set of callback functions for group management, - * synchronization of group, configuration of things, and diagnostics - * about things. - * - */ -class ThingsManagerCallback { - - private IFindCandidateResourceListener resourceListener; - private ISubscribePresenceListener presenceListener; - private IFindGroupListener groupListener; - private IConfigurationListener configurationListener; - private IDiagnosticsListener diagnosticsListener; - private IActionListener actionListener; - private static ThingsManagerCallback thingsManagerCallbackInterfaceObj; - - private ThingsManagerCallback() { - } - - /** - * Function for Getting instance of ThingsManagerCallback object. - * - * @return ThingsManagerCallback instance. - * - */ - public static synchronized ThingsManagerCallback getInstance() { - if (null == thingsManagerCallbackInterfaceObj) { - thingsManagerCallbackInterfaceObj = new ThingsManagerCallback(); - } - return thingsManagerCallbackInterfaceObj; - } - - /** - * Register listener for findCandidateResource callback. - * - * @param listener - * interface for getting notification when resources are - * discovered in network. - * - */ - public void registerFindCandidateResourceListener( - IFindCandidateResourceListener listener) { - resourceListener = listener; - } - - /** - * Register listener for subscribeCollectionPresence callback. - * - * @param listener - * interface for getting notification regarding child resource - * presence status. - * - */ - public void registerSubscribePresenceListener( - ISubscribePresenceListener listener) { - presenceListener = listener; - } - - /** - * Register listener for find group callback. - * - * @param listener - * interface for getting notification on whether the group is - * found or not. - * - */ - public void registerGroupListener(IFindGroupListener listener) { - groupListener = listener; - } - - /** - * Register listener for updateConfigurations and getConfigurations - * callback. - * - * @param listener - * interface for getting notification on configuration values - * information or when configuration value is updated for - * multiple things of a target group or a single thing. - * - */ - public void registerConfigurationListener(IConfigurationListener listener) { - configurationListener = listener; - } - - /** - * Register listener for doBootstrap, reboot and factoryReset callbacks. - * - * @param listener - * interface for receiving asynchronous response for diagnostic - * feature APIs. - * - */ - public void registerDiagnosticsListener(IDiagnosticsListener listener) { - diagnosticsListener = listener; - } - - /** - * Register listener for getActionSet, executeActionSet and deleteActionSet - * callback. - * - * @param listener - * interface for receiving the callback for the GET, PUT and - * POST requested actions. - * - */ - public void registerActionListener(IActionListener listener) { - actionListener = listener; - } - - /** - * Unregister listener for findCandidateResource callback. - * - */ - public void unregisterFindCandidateResourceListener() { - resourceListener = null; - } - - /** - * Unregister listener for subscribeCollectionPresence callback. - * - */ - public void unregisterSubscribePresenceListener() { - presenceListener = null; - } - - /** - * Unregister listener for find group callback. - * - */ - public void unregisterGroupListener() { - groupListener = null; - } - - /** - * Unregister listener for updateConfigurations and getConfigurations - * callback. - * - */ - public void unregisterConfigurationListener() { - configurationListener = null; - } - - /** - * Unregister listener for doBootstrap, reboot and factoryReset callbacks. - * - */ - public void unregisterDiagnosticsListener() { - diagnosticsListener = null; - } - - /** - * Unregister listener for getActionSet, executeActionSet and - * deleteActionSet callback. - * - */ - public void unregisterActionListener() { - actionListener = null; - } - - /** - * This callback method will be called whenever resource is discovered in - * the network. - * - * @param resources - * List of resources discovered in the network - * - */ - public void onResourceCallback(Vector resources) { - if (null != resourceListener) - resourceListener.onResourceCallback(resources); - } - - /** - * This callback method is called when a response for the executeActionSet - * or deleteActionSet request just arrives. - * - * @param headerOptions - * It comprises of optionID and optionData as members. - * @param rep - * Configuration parameters are carried as a pair of attribute - * key and value in a form of OCRepresentation instance. - * @param errorValue - * error code. - * - */ - public void onPostResponseCallback(Vector headerOptions, - OcRepresentation rep, int errorValue) { - if (null != actionListener) - actionListener.onPostResponseCallback(headerOptions, rep, - errorValue); - } - - /** - * This callback method is called when a response for the addActionSet - * request just arrives. - * - * @param headerOptions - * It comprises of optionID and optionData as members. - * @param rep - * Configuration parameters are carried as a pair of attribute - * key and value in a form of OCRepresentation instance. - * @param errorValue - * error code. - * - */ - public void onPutResponseCallback(Vector headerOptions, - OcRepresentation rep, int errorValue) { - if (null != actionListener) - actionListener - .onPutResponseCallback(headerOptions, rep, errorValue); - } - - /** - * This callback method is called when a response for the getActionSet - * request just arrives. - * - * @param headerOptions - * It comprises of optionID and optionData as members. - * @param rep - * Configuration parameters are carried as a pair of attribute - * key and value in a form of OCRepresentation instance. - * @param errorValue - * error code. - * - */ - public void onGetResponseCallback(Vector headerOptions, - OcRepresentation rep, int errorValue) { - if (null != actionListener) - actionListener - .onGetResponseCallback(headerOptions, rep, errorValue); - } - - /** - * This callback method is called when a response for the - * updateConfigurations request just arrives. - * - * @param headerOptions - * It comprises of optionID and optionData as members. - * @param rep - * Configuration parameters are carried as a pair of attribute - * key and value in a form of OCRepresentation instance. - * @param errorValue - * error code. - * - */ - public void onUpdateConfigurationsCallback( - Vector headerOptions, OcRepresentation rep, - int errorValue) { - if (null != configurationListener) - configurationListener.onUpdateConfigurationsCallback(headerOptions, - rep, errorValue); - } - - /** - * This callback method is called when a response for the getConfigurations - * request just arrives. - * - * @param headerOptions - * It comprises of optionID and optionData as members. - * @param rep - * Configuration parameters are carried as a pair of attribute - * key and value in a form of OCRepresentation instance. - * @param errorValue - * error code. - * - */ - public void onGetConfigurationsCallback( - Vector headerOptions, OcRepresentation rep, - int errorValue) { - if (null != configurationListener) - configurationListener.onGetConfigurationsCallback(headerOptions, - rep, errorValue); - } - - /** - * This callback method is called when a response for the doBootstrap - * request just arrives. - * - * @param headerOptions - * It comprises of optionID and optionData as members. - * @param rep - * Configuration parameters are carried as a pair of attribute - * key and value in a form of OCRepresentation instance. - * @param errorValue - * error code. - * - */ - public void onBootStrapCallback(Vector headerOptions, - OcRepresentation rep, int errorValue) { - if (null != configurationListener) { - Log.i("ThingsManagerCallback : onBootStrapCallback", - "Received Callback from JNI"); - configurationListener.onBootStrapCallback(headerOptions, rep, - errorValue); - } - } - - /** - * This callback method is called when a response for the reboot request - * just arrives. - * - * @param headerOptions - * It comprises of optionID and optionData as members. - * @param rep - * Configuration parameters are carried as a pair of attribute - * key and value in a form of OCRepresentation instance. - * @param errorValue - * error code. - * - */ - public void onRebootCallback(Vector headerOptions, - OcRepresentation rep, int errorValue) { - if (null != diagnosticsListener) { - Log.i("ThingsManagerCallback : onRebootCallback", - "Received Callback from JNI"); - diagnosticsListener - .onRebootCallback(headerOptions, rep, errorValue); - } - } - - /** - * This callback method is called when a response for the factoryReset - * request just arrives. - * - * @param headerOptions - * It comprises of optionID and optionData as members. - * @param rep - * Configuration parameters are carried as a pair of attribute - * key and value in a form of OCRepresentation instance. - * @param errorValue - * error code. - * - */ - public void onFactoryResetCallback(Vector headerOptions, - OcRepresentation rep, int errorValue) { - if (null != diagnosticsListener) { - Log.i("ThingsManagerCallback : onFactoryResetCallback", - "Received Callback from JNI"); - diagnosticsListener.onFactoryResetCallback(headerOptions, rep, - errorValue); - } - } - - /** - * This callback method is called to notify whether group is found or not. - * - * @param resource - * Resource URI - * - */ - public void onGroupFindCallback(OcResource resource) { - if (null != groupListener) { - Log.i("ThingsManagerCallback : onGroupFindCallback", - "Received Callback from JNI"); - groupListener.onGroupFindCallback(resource); - } - } - - /** - * This callback method is called for child resource presence status. - * - * @param resource - * URI of resource. - * @param errorValue - * error code. - * - */ - public void onPresenceCallback(String resource, int errorValue) { - if (null != presenceListener) { - Log.i("ThingsManagerCallback : onPresenceCallback", - "Received Callback from JNI"); - presenceListener.onPresenceCallback(resource, errorValue); - } - } - -} diff --git a/service/things-manager/sdk/java/src/org/iotivity/service/tm/ThingsManagerInterface.java b/service/things-manager/sdk/java/src/org/iotivity/service/tm/ThingsManagerInterface.java deleted file mode 100644 index 0f1d2cd..0000000 --- a/service/things-manager/sdk/java/src/org/iotivity/service/tm/ThingsManagerInterface.java +++ /dev/null @@ -1,652 +0,0 @@ -/****************************************************************** - * - * Copyright 2015 Samsung Electronics All Rights Reserved. - * - * - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************/ -/** - * @file ThingsManagerInterface.java - * - * @brief This file provides a class which acts as an interface for Things Manager API calls between - * ThingsManager and ThingsManagerNativeInterface - * - */ - -package org.iotivity.service.tm; - -import java.util.Iterator; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Vector; - -import org.iotivity.base.OcException; -import org.iotivity.base.OcResource; -import org.iotivity.base.OcResourceHandle; - -import android.util.Log; - -/** - * This class acts as an interface for Things Manager API calls between - * ThingsManager and ThingsManagerNativeInterface - * - */ -class ThingsManagerInterface { - - private IFindCandidateResourceListener resourceListener; - private ISubscribePresenceListener presenceListener; - private IFindGroupListener groupListener; - private IConfigurationListener configurationListener; - private static ThingsManagerInterface thingsManagerInterfaceObj; - - private ThingsManagerInterface() { - } - - /** - * Function for Getting instance of ThingsManagerInterface object. - * - * @return ThingsManagerInterface instance. - * - */ - public static synchronized ThingsManagerInterface getInstance() { - if (null == thingsManagerInterfaceObj) { - thingsManagerInterfaceObj = new ThingsManagerInterface(); - } - return thingsManagerInterfaceObj; - } - - /** - * Register listener for findCandidateResource callback. - * - * @param listener - * interface for getting notification when resources are - * discovered in network. - * - */ - public void registerFindCandidateResourceListener( - IFindCandidateResourceListener listener) { - resourceListener = listener; - } - - /** - * Register listener for subscribeCollectionPresence callback. - * - * @param listener - * interface for getting notification regarding child resource - * presence status. - * - */ - public void registerSubscribePresenceListener( - ISubscribePresenceListener listener) { - presenceListener = listener; - } - - /** - * Register listener for register group and find group callback. - * - * @param listener - * interface for getting notification on whether the group is - * found or not. - * - */ - public void registerGroupListener(IFindGroupListener listener) { - groupListener = listener; - } - - /** - * Register listener for updateConfigurations and getConfigurations - * callback. - * - * @param listener - * interface for getting notification on configuration values - * information or when configuration value is updated for - * multiple things of a target group or a single thing. - * - */ - public void registerConfigurationListener(IConfigurationListener listener) { - configurationListener = listener; - } - - /** - * Unregister listener for findCandidateResource callback. - * - */ - public void unregisterFindCandidateResourceListener() { - resourceListener = null; - } - - /** - * Unregister listener for subscribeCollectionPresence callback. - * - */ - public void unregisterSubscribePresenceListener() { - presenceListener = null; - } - - /** - * Unregister listener for registerGroup and findGroup callback. - * - */ - public void unregisterGroupListener() { - groupListener = null; - } - - /** - * Unregister listener for updateConfigurations and getConfigurations - * callback. - * - */ - public void unregisterConfigurationListener() { - configurationListener = null; - } - - /** - * API for discovering candidate resources with waiting delay. Listener - *

- * IFindCandidateResourceListener::onResourceCallback will be notified - * when resource is discovered in network. - *

- * - * @param resourceTypes - * required resource types(called "candidate") - * @param waitTime - * Time duration in seconds to find the resources in network - * - * @return OCStackResult - return value of this API. It returns OC_STACK_OK - * if success. - * - */ - public OCStackResult findCandidateResources(Vector resourceTypes, - int waitTime) { - OCStackResult result; - if (null == resourceListener) { - result = OCStackResult.OC_STACK_ERROR; - } else { - int ordinal = ThingsManagerNativeInterface.findCandidateResources( - resourceTypes, waitTime); - result = OCStackResult.conversion(ordinal); - } - return result; - } - - /** - * API for subscribing child's state. Listener - *

- * ISubscribePresenceListener::onPresenceCallback will be notified for - * resource presence status - *

- * - * @param resource - * collection resource for subscribing presence of all child - * resources - * - * @return OCStackResult - return value of this API. It returns OC_STACK_OK - * if success. - * - */ - public OCStackResult subscribeCollectionPresence(OcResource resource) - throws OcException { - String LOG_TAG = this.getClass().getSimpleName(); - - OCStackResult result; - if (null == presenceListener) { - result = OCStackResult.OC_STACK_ERROR; - } else { - - int ordinal = ThingsManagerNativeInterface - .subscribeCollectionPresence(resource); - Log.i(LOG_TAG, "Ordinal value = : " + ordinal); - result = OCStackResult.conversion(ordinal); - } - return result; - } - - /** - * API for finding a specific remote group when a resource tries to join a - * group. - *

- * IFindGroupListener::onGroupFindCallback will be called to notify - * whether requested group found or not. - *

- * - * @param resourceTypes - * resource types of a group to find and join - * - * @return OCStackResult - return value of this API. It returns OC_STACK_OK - * if success. - * - */ - public OCStackResult findGroup(Vector resourceTypes) { - OCStackResult result; - if (null == groupListener) { - result = OCStackResult.OC_STACK_ERROR; - } else { - int ordinal = ThingsManagerNativeInterface.findGroup(resourceTypes); - result = OCStackResult.conversion(ordinal); - } - return result; - } - - /** - * API for creating a new group. - * - * @param resourceType - * resource type of a group to create - * - * @return OCStackResult - return value of this API. It returns OC_STACK_OK - * if success. - * - */ - public OCStackResult createGroup(String resourceType) { - OCStackResult result; - int ordinal = ThingsManagerNativeInterface.createGroup(resourceType); - result = OCStackResult.conversion(ordinal); - return result; - } - - /** - * API for joining a group. This API is used when a resource that has a - * group tries to find a specific remote resource and makes it join a group. - * - * @param resourceType - * resource type of a group to join. - * @param resourceHandle - * resource handle to join a group. - * - * @return OCStackResult - return value of this API. It returns OC_STACK_OK - * if success. - * - */ - public OCStackResult joinGroup(String resourceType, - OcResourceHandle resourceHandle) { - OCStackResult result; - - int ordinal = ThingsManagerNativeInterface.joinGroup(resourceType, - resourceHandle); - result = OCStackResult.conversion(ordinal); - - return result; - } - - /** - * API for joining a group. This API is used when a resource that doesn't - * have a group tries to find and join a specific remote group. - * - * @param resource - * group resource to join. - * @param resourceHandle - * resource handle to join a group. - * - * @return OCStackResult - return value of this API. It returns OC_STACK_OK - * if success. - * - */ - public OCStackResult joinGroup(OcResource resource, - OcResourceHandle resourceHandle) throws OcException { - - OCStackResult result; - int ordinal = ThingsManagerNativeInterface.joinGroup(resource, - resourceHandle); - result = OCStackResult.conversion(ordinal); - - return result; - } - - /** - * API for leaving a joined group. - * - * @param resourceType - * resource type of a group to leave. - * @param resourceHandle - * resource handle to leave a group. - * - * @return OCStackResult - return value of this API. It returns OC_STACK_OK - * if success. - * - */ - public OCStackResult leaveGroup(String resourceType, - OcResourceHandle resourceHandle) { - - OCStackResult result; - int ordinal = ThingsManagerNativeInterface.leaveGroup(resourceType, - resourceHandle); - result = OCStackResult.conversion(ordinal); - - return result; - } - - /** - * API for leaving a joined group. - * - * @param resource - * resource of a group to leave. - * @param resourceType - * resource type of a group to leave. - * @param resourceHandle - * resource handle to leave a group. - * - * @return OCStackResult - return value of this API. It returns OC_STACK_OK - * if success. - * - */ - public OCStackResult leaveGroup(OcResource resource, String resourceType, - OcResourceHandle resourceHandle) { - - OCStackResult result; - int ordinal = ThingsManagerNativeInterface.leaveGroup(resource, - resourceType, resourceHandle); - result = OCStackResult.conversion(ordinal); - - return result; - } - - /** - * API for deleting a group. - * - * @param collectionResourceType - * resource type of a group to delete. - * - */ - public void deleteGroup(String collectionResourceType) { - ThingsManagerNativeInterface.deleteGroup(collectionResourceType); - } - - /** - * API for getting a list of joined groups. - * - * @return Returns group resource type and group resource handle as a map - * table. - * - */ - public Map getGroupList() { - return ThingsManagerNativeInterface.getGroupList(); - } - - /** - * API for register and bind resource to group. - * - * @param resource - * resource for register and bind to group. It has all data. - * @param collectionHandle - * collection resource handle. It will be added child resource. - * - * @return OcResourceHandle - Child resource handle. - */ - public OcResourceHandle bindResourceToGroup(OcResource resource, - OcResourceHandle collectionHandle) - throws OcException { - return ThingsManagerNativeInterface.bindResourceToGroup( - resource, collectionHandle); - } - - /** - * API for updating configuration value of multiple things of a target group - * or a single thing. - * - * @param resource - * resource representing the target group or the single thing. - * @param configurations - * ConfigurationUnit: a nickname of attribute of target - * resource (e.g., installed location, currency, (IP)address) - * Value : a value to be updated - * - * @return OCStackResult - return value of this API. It returns OC_STACK_OK - * if success. - * - */ - public OCStackResult updateConfigurations(OcResource resource, - Map configurations) throws OcException { - OCStackResult result; - if (null == configurationListener) { - result = OCStackResult.OC_STACK_ERROR; - } else { - int ordinal = ThingsManagerNativeInterface.updateConfigurations( - resource, configurations); - result = OCStackResult.conversion(ordinal); - } - return result; - - } - - /** - * API for getting configuration value of multiple things of a target group - * or a single thing. - * - * @param resource - * resource representing the target group or the single thing. - * @param configurations - * ConfigurationUnit: a nickname of attribute of target - * resource. - * - * @return OCStackResult - return value of this API. It returns OC_STACK_OK - * if success. - * - */ - public OCStackResult getConfigurations(OcResource resource, - Vector configurations) throws OcException { - OCStackResult result; - if (null == configurationListener) { - result = OCStackResult.OC_STACK_ERROR; - } else { - int ordinal = ThingsManagerNativeInterface.getConfigurations( - resource, configurations); - result = OCStackResult.conversion(ordinal); - } - return result; - } - - /** - * API for showing the list of supported configuration units (configurable - * parameters) - * - * @return Returns the configuration list in JSON format. - * - */ - public String getListOfSupportedConfigurationUnits() { - - return ThingsManagerNativeInterface - .getListOfSupportedConfigurationUnits(); - } - - /** - * API for bootstrapping system configuration parameters from a bootstrap - * server. - * - * @return OCStackResult - return value of this API. It returns OC_STACK_OK - * if success. - */ - public OCStackResult doBootstrap() { - - OCStackResult result; - int ordinal = ThingsManagerNativeInterface.doBootstrap(); - result = OCStackResult.conversion(ordinal); - - return result; - } - - /** - * API to let thing(device) reboot. The target thing could be a group of - * multiple things or a single thing. - * - * @param resource - * resource pointer representing the target group - * - * @return OCStackResult - return value of this API. It returns OC_STACK_OK - * if success - */ - public OCStackResult reboot(OcResource resource) throws OcException { - - OCStackResult result; - int ordinal = ThingsManagerNativeInterface.reboot(resource); - result = OCStackResult.conversion(ordinal); - - return result; - } - - /** - * API for factory reset on thing(device). The target thing could be a group - * of multiple things or a single thing. - * - * @param resource - * resource pointer representing the target group - * - * @return OCStackResult - return value of this API. It returns OC_STACK_OK - * if success. - */ - public OCStackResult factoryReset(OcResource resource) throws OcException { - - OCStackResult result; - int ordinal = ThingsManagerNativeInterface.factoryReset(resource); - result = OCStackResult.conversion(ordinal); - - return result; - } - - /** - * API for adding an Action Set. Callback is called when the response of PUT - * operation arrives. - * - * @param resource - * resource pointer of the group resource - * @param actionSet - * pointer of Action Set - * - * @return OCStackResult - return value of this API. It returns OC_STACK_OK - * if success. - */ - public OCStackResult addActionSet(OcResource resource, ActionSet actionSet) - throws OcException { - - int ordinal = ThingsManagerNativeInterface.addActionSet(resource, - actionSet); - - return OCStackResult.conversion(ordinal); - } - - /** - * API for executing the Action Set. Callback is called when the response of - * POST operation arrives. - * - * @param resource - * resource pointer of the group resource - * @param actionsetName - * Action Set name for removing the Action set - * - * @return OCStackResult - return value of this API. It returns OC_STACK_OK - * if success. - */ - public OCStackResult executeActionSet(OcResource resource, - String actionsetName) throws OcException { - - int ordinal = ThingsManagerNativeInterface.executeActionSet(resource, - actionsetName); - - return OCStackResult.conversion(ordinal); - } - - /** - * API for executing the Action Set. Callback is called when the response of - * POST operation arrives. - * - * @param resource - * resource pointer of the group resource - * @param actionsetName - * Action Set name for removing the Action set - * @param delay - * waiting time for until action set run. - * - * @return OCStackResult - return value of this API. It returns OC_STACK_OK - * if success. - */ - public OCStackResult executeActionSet(OcResource resource, - String actionsetName, long delay) throws OcException { - - OCStackResult result; - int ordinal = ThingsManagerNativeInterface.executeActionSet(resource, - actionsetName, delay); - result = OCStackResult.conversion(ordinal); - - return result; - } - - /** - * API for cancelling the Action Set. Callback is called when the response - * of POST operation arrives. - * - * @param resource - * resource pointer of the group resource - * @param actionsetName - * Action Set name for removing the Action set - * - * @return OCStackResult - return value of this API. It returns OC_STACK_OK - * if success. - */ - public OCStackResult cancelActionSet(OcResource resource, - String actionsetName) throws OcException { - - OCStackResult result; - int ordinal = ThingsManagerNativeInterface.cancelActionSet(resource, - actionsetName); - result = OCStackResult.conversion(ordinal); - - return result; - } - - /** - * API for reading the Action Set. Callback is called when the response of - * GET operation arrives. - * - * @param resource - * resource pointer of the group resource - * @param actionsetName - * Action Set name for removing the Action set - * - * @return OCStackResult - return value of this API. It returns OC_STACK_OK - * if success. - */ - public OCStackResult getActionSet(OcResource resource, String actionsetName) - throws OcException { - - OCStackResult result; - int ordinal = ThingsManagerNativeInterface.getActionSet(resource, - actionsetName); - result = OCStackResult.conversion(ordinal); - - return result; - } - - /** - * API for removing the action set. Callback is called when the response of - * POST operation arrives. - * - * @param resource - * resource pointer of the group resource - * @param actionsetName - * Action Set name for removing the Action set - * - * @return OCStackResult - return value of this API. It returns OC_STACK_OK - * if success. - */ - public OCStackResult deleteActionSet(OcResource resource, - String actionsetName) throws OcException { - - OCStackResult result; - int ordinal = ThingsManagerNativeInterface.deleteActionSet(resource, - actionsetName); - result = OCStackResult.conversion(ordinal); - - return result; - } -} diff --git a/service/things-manager/sdk/java/src/org/iotivity/service/tm/ThingsManagerNativeInterface.java b/service/things-manager/sdk/java/src/org/iotivity/service/tm/ThingsManagerNativeInterface.java deleted file mode 100644 index cd598c0..0000000 --- a/service/things-manager/sdk/java/src/org/iotivity/service/tm/ThingsManagerNativeInterface.java +++ /dev/null @@ -1,362 +0,0 @@ -/****************************************************************** - * - * Copyright 2015 Samsung Electronics All Rights Reserved. - * - * - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************/ -/** - * @file ThingsManagerNativeInterface.java - * - * @brief This file provides a class which provides a set of native functions relating to group - * management, synchronization of group, configuration of things, and - * diagnostics about things. - */ - -package org.iotivity.service.tm; - -import java.util.Map; -import java.util.Vector; - -import org.iotivity.base.OcResource; -import org.iotivity.base.OcResourceHandle; - -/** - * This class provides a set of native functions relating to group - * management, synchronization of group, configuration of things, and - * diagnostics about things. - * - */ -class ThingsManagerNativeInterface { - /** - * Native function for discoverying candidate resources. - * - * @param resourceTypes - * - required resource types(called "candidate") - * @param waitTime - * - Delay time in seconds to add before starting to find the - * resources in network. - * - * @return OCStackResult - return value of this API. It returns OC_STACK_OK - * if success. - * - */ - public static native int findCandidateResources( - Vector resourceTypes, int waitTime); - - /** - * Native function for subscribing child's state. - * - * @param resource - * - collection resource for subscribing presence of all child - * resources. - * - * @return OCStackResult - return value of this API. It returns OC_STACK_OK - * if success. - * - */ - public static native int subscribeCollectionPresence(OcResource resource); - - /** - * Native function for register and bind resource to group. - * - * @param resource - * - resource for register and bind to group. It has all data. - * @param collectionHandle - * - collection resource handle. It will be added child resource. - * - * @return OcResourceHandle - Child resource handle. - * - */ - public static native OcResourceHandle bindResourceToGroup(OcResource resource, - OcResourceHandle collectionHandle); - - /** - * Native function for finding a specific remote group when a resource tries - * to join a group. Callback is called when a group is found or not. - * - * @param collectionResourceTypes - * - resource types of a group to find and join - * - * @return OCStackResult - return value of this API. It returns OC_STACK_OK - * if success. - * - */ - public static native int findGroup(Vector collectionResourceTypes); - - /** - * Native function for creating a new group. - * - * @param collectionResourceType - * - resource type of a group to create - * - * @return OCStackResult - return value of this API. It returns OC_STACK_OK - * if success. - */ - public static native int createGroup(String collectionResourceType); - - /** - * Native function for joining a group. This API is used when a resource - * that has a group tries to find a specific remote resource and makes it - * join a group. - * - * @param collectionResourceType - * - resource type of a group to join. - * @param resourceHandle - * - resource handle to join a group. - * - * @return OCStackResult - return value of this API. It returns OC_STACK_OK - * if success. - * - */ - public static native int joinGroup(String collectionResourceType, - OcResourceHandle resourceHandle); - - /** - * Native function for joining a group. This is used when a resource that - * doesn't have a group tries to find and join a specific remote group. - * - * @param resource - * - group resource to join. - * @param resourceHandle - * - resource handle to join a group. - * - * @return OCStackResult - return value of this API. It returns OC_STACK_OK - * if success. - * - */ - public static native int joinGroup(OcResource resource, - OcResourceHandle resourceHandle); - - /** - * Native function for leaving a joined group. - * - * @param collectionResourceType - * - resource type of a group to leave. - * @param resourceHandle - * - resource handle to leave a group. - * - * @return OCStackResult - return value of this API. It returns OC_STACK_OK - * if success. - * - */ - public static native int leaveGroup(String collectionResourceType, - OcResourceHandle resourceHandle); - - /** - * Native function for leaving a joined group. - * - * @param resource - * - resource of a group to leave. - * @param collectionResourceType - * - resource type of a group to leave. - * @param resourceHandle - * - resource handle to leave a group. - * - * @return OCStackResult - return value of this API. It returns OC_STACK_OK - * if success. - * - */ - public static native int leaveGroup(OcResource resource, - String collectionResourceType, OcResourceHandle resourceHandle); - - /** - * Native function for deleting a group. - * - * @param collectionResourceType - * - resource type of a group to delete. - * - * - */ - public static native void deleteGroup(String collectionResourceType); - - /** - * Native function for getting a list of joined groups. - * - * @return Returns group resource type and group resource handle as a map - * table. - * - */ - public static native Map getGroupList(); - - /** - * Native function for updating configuration value of multiple things of a - * target group or a single thing. - * - * @param resource - * - resource representing the target group or the single thing. - * @param configurations - * - ConfigurationUnit: a nickname of attribute of target - * resource (e.g., installed location, currency, (IP)address) - * Value : a value to be updated - * - * @return OCStackResult - return value of this API. It returns OC_STACK_OK - * if success. - * - */ - public static native int updateConfigurations(OcResource resource, - Map configurations); - - /** - * Native function for getting configuration value of multiple things of a - * target group or a single thing. - * - * @param resource - * - resource representing the target group or the single thing. - * @param configurations - * - ConfigurationUnit: a nickname of attribute of target - * resource. - * - * @return OCStackResult - return value of this API. It returns OC_STACK_OK - * if success. - * - */ - public static native int getConfigurations(OcResource resource, - Vector configurations); - - /** - * Native function for showing the list of supported configuration units - * (configurable parameters) - * - * @return Returns the configuration list in JSON format. - * - */ - public static native String getListOfSupportedConfigurationUnits(); - - /** - * Native function for bootstrapping system configuration parameters from a - * bootstrap server. - * - * @return OCStackResult - return value of this API. It returns OC_STACK_OK - * if success. - */ - public static native int doBootstrap(); - - /** - * Native function to let thing(device) reboot. The target thing could be a - * group of multiple things or a single thing. - * - * @param resource - * - resource pointer representing the target group - * - * @return OCStackResult - return value of this API. It returns OC_STACK_OK - * if success - */ - public static native int reboot(OcResource resource); - - /** - * Native function for factory reset on thing(device). The target thing - * could be a group of multiple things or a single thing. - * - * @param resource - * - resource pointer representing the target group - * - * @return OCStackResult - return value of this API. It returns OC_STACK_OK - * if success. - */ - public static native int factoryReset(OcResource resource); - - /** - * Native function for adding an Action Set. Callback is called when the - * response of PUT operation arrives. - * - * @param resource - * - resource pointer of the group resource - * @param actionSet - * - pointer of Action Set - * - * @return OCStackResult - return value of this API. It returns OC_STACK_OK - * if success. - */ - public static native int addActionSet(OcResource resource, - ActionSet actionSet); - - /** - * Native function for executing the Action Set. Callback is called when the - * response of POST operation arrives. - * - * @param resource - * - resource pointer of the group resource - * @param actionsetName - * - Action Set name for removing the Action set - * - * @return OCStackResult - return value of this API. It returns OC_STACK_OK - * if success. - */ - public static native int executeActionSet(OcResource resource, - String actionsetName); - - /** - * Native function for executing the Action Set. Callback is called when the - * response of POST operation arrives. - * - * @param resource - * - resource pointer of the group resource - * @param actionsetName - * - Action Set name for removing the Action set - * @param delay - * - waiting time for until action set run. - * - * @return OCStackResult - return value of this API. It returns OC_STACK_OK - * if success. - */ - public static native int executeActionSet(OcResource resource, - String actionsetName, long delay); - - /** - * Native function for cancelling the Action Set. Callback is called when - * the response of POST operation arrives. - * - * @param resource - * - resource pointer of the group resource - * @param actionsetName - * - Action Set name for removing the Action set - * - * @return OCStackResult - return value of this API. It returns OC_STACK_OK - * if success. - */ - public static native int cancelActionSet(OcResource resource, - String actionsetName); - - /** - * Native function for reading the Action Set. Callback is called when the - * response of GET operation arrives. - * - * @param resource - * - resource pointer of the group resource - * @param actionsetName - * - Action Set name for removing the Action set - * - * @return OCStackResult - return value of this API. It returns OC_STACK_OK - * if success. - */ - public static native int getActionSet(OcResource resource, - String actionsetName); - - /** - * Native function for removing the action set. Callback is called when the - * response of POST operation arrives. - * - * @param resource - * - resource pointer of the group resource - * @param actionsetName - * - Action Set name for removing the Action set - * - * @return OCStackResult - return value of this API. It returns OC_STACK_OK - * if success. - */ - public static native int deleteActionSet(OcResource resource, - String actionsetName); -} diff --git a/service/things-manager/sdk/java/src/org/iotivity/service/tm/Time.java b/service/things-manager/sdk/java/src/org/iotivity/service/tm/Time.java index dc28d8b..7ae50ae 100644 --- a/service/things-manager/sdk/java/src/org/iotivity/service/tm/Time.java +++ b/service/things-manager/sdk/java/src/org/iotivity/service/tm/Time.java @@ -1,12 +1,31 @@ +/* ***************************************************************** + * + * 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. + * + ******************************************************************/ + package org.iotivity.service.tm; import android.util.Log; /** - * This class provides time-related information used for - * scheduled/recursive group action features. Along with time-related - * variables, it also provides various useful functionality including - * translating time to second unit + * This class provides time-related information used for scheduled/recursive + * group action features. Along with time-related variables, it also provides + * various useful functionality including translating time to second unit */ public class Time { @@ -44,7 +63,6 @@ public class Time { * Second to be set * @param dayOfTheWeek * Day of the week to be set - * */ public void setTime(int year, int month, int day, int hour, int min, int sec, int dayOfTheWeek) { @@ -96,7 +114,6 @@ public class Time { * * @param seconds * time delay in seconds - * */ public void setDelay(long seconds) { if (mType != ActionSetType.NONE) { @@ -108,7 +125,6 @@ public class Time { * Get absolute time in seconds. * * @return long - Absolute time in seconds. - * */ public long getSecAbsTime() { long interval; @@ -124,7 +140,6 @@ public class Time { * Get the type of ActionSet. * * @return ActionSetType - Type of ActionSet. - * */ public ActionSetType getType() { return mType; @@ -134,7 +149,6 @@ public class Time { * Get the time delay in seconds set in the ActionSet. * * @return long - Delay in seconds. - * */ public long getDelay() { return mDelay; -- 2.7.4