Fix SSM JNI wrapper and android app
authorjk13 <jihyeok13.kim@samsung.com>
Fri, 24 Apr 2015 04:42:13 +0000 (13:42 +0900)
committerUze Choi <uzchoi@samsung.com>
Wed, 29 Apr 2015 00:57:03 +0000 (00:57 +0000)
This commit is for master branch
1. Fix JNI wrapper which includes invalid signature and load seqeuence
2. Fix android app ui

Change-Id: I75e0ebe98000340f75987fc9e707f542ef8ea18c
Signed-off-by: jk13 <jihyeok13.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/824
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/soft-sensor-manager/SDK/java/org/iotivity/service/ssm/CoreController.java
service/soft-sensor-manager/SSMCore/src/SSMInterface/SSMCore_JNI.cpp
service/soft-sensor-manager/SampleApp/android/SSMTesterApp/jni/Application.mk
service/soft-sensor-manager/SampleApp/android/SSMTesterApp/src/org/iotivity/service/ssm/sample/MainActivity.java

index 3c03303..0acf7e7 100644 (file)
@@ -31,282 +31,249 @@ import java.util.List;
 
 /**
  * @class CoreController
- * @brief This class provides a set of APIs relating to soft sensor manager
- *         It contains utility API's  for DataReader, QueryEngine and SSMInterface classes.
- *
- *
+ * @brief This class provides a set of APIs relating to soft sensor manager It
+ *        contains utility API's for DataReader, QueryEngine and SSMInterface
+ *        classes.
  */
-public class CoreController
-{
-        static
-        {
-            try {
-                String workingPath = System.getProperty("user.dir");
+public class CoreController {
+    static {
+        try {
+            String workingPath = System.getProperty("user.dir");
 
-                // for android: not complete method
-                if (System.getProperty("os.name").toLowerCase().equals("linux"))
-                {
-                    // System.out.println("System load Android library");
-                    System.loadLibrary("oc_logger");
-                    System.loadLibrary("coap");
-                    System.loadLibrary("octbstack");
-                    System.loadLibrary("oc");
-                    System.loadLibrary("SSMCore");
-                }
-                else {
-                    // System.out.println("System load 32bit library");
-                    System.load(workingPath + "SSMCore_Windows.dll");
-                }
-            }
-            catch (UnsatisfiedLinkError e)
-            {
-                System.out.println(e.getMessage());
+            // for android: not complete method
+            if (System.getProperty("os.name").toLowerCase().equals("linux")) {
+                System.loadLibrary("oc_logger");
+                System.loadLibrary("octbstack");
+                System.loadLibrary("coap");
+                System.loadLibrary("oc");
+                System.loadLibrary("SSMCore");
+            } else {
+                System.load(workingPath + "SSMCore_Windows.dll");
             }
+        } catch (UnsatisfiedLinkError e) {
+            System.out.println(e.getMessage());
         }
+    }
 
-        static private CoreController coreController;
-        
-        /**
-         * Return instance of this class.
-         *
-         * @return CoreController - instance of this class
-         * 
-         */
-        public static CoreController getInstance()
-        {
-            if (coreController == null)
-                coreController = new CoreController();
-
-            return coreController;
-        }
+    static private CoreController coreController;
 
-        /**
-         * Initialize a framework using the given configuration
-         *
-         * @param xmlDescription 
-         *               - Framework specifications described in XML format
-         *
-         * @return void
-         * 
-         */
-        public native void initializeSSMCore(String xmlDescription)
-        throws Exception;
+    /**
+     * Return instance of CoreController.
+     * 
+     * @return CoreController - instance of this class
+     */
+    public static CoreController getInstance() {
+        if (coreController == null)
+            coreController = new CoreController();
 
-        /**
-         * Starts the framework that allows other devices to discover and communicate
-         *     with the SSMCore and underlying query engine.
-         *
-         * @return void
-         * 
-         */
-        public native void startSSMCore() throws Exception;
+        return coreController;
+    }
 
-        /**
-         * Stops the framework and terminate all communications.
-         *
-         * @return void
-         * 
-         */
-        public native void stopSSMCore() throws Exception;
+    /**
+     * Initialize a framework using the given configuration
+     * 
+     * @param xmlDescription
+     *            - Framework specifications described in XML format
+     * 
+     * @return void
+     */
+    public native void initializeSSMCore(String xmlDescription)
+            throws Exception;
 
-        /**
-         * Terminate the framework, return all allocated resources
-         *
-         * @return void
-         * 
-         */
-        public native void terminateSSMCore() throws Exception;
+    /**
+     * Starts the framework that allows other devices to discover and
+     * communicate with the SSMCore and underlying query engine.
+     * 
+     * @return void
+     */
+    public native void startSSMCore() throws Exception;
 
-        /**
-         * Creates an instance of the Query Engine
-         *
-         * @return QueryEngine - QueryEngine object created
-         *               
-         */
-        public native QueryEngine createQueryEngine() throws Exception;
+    /**
+     * Stops the framework and terminate all communications.
+     * 
+     * @return void
+     */
+    public native void stopSSMCore() throws Exception;
 
-        /**
-         * Release the QueryEngine object.
-         *
-         * @param queryEngine 
-         *               - QueryEngine instance to be released
-         *
-         * @return int - success or failure result
-         * 
-         */
-        public native int releaseQueryEngine(QueryEngine queryEngine);
+    /**
+     * Terminate the framework, return all allocated resources
+     * 
+     * @return void
+     */
+    public native void terminateSSMCore() throws Exception;
 
-        // QueryEngine
-        /**
-         * Execute the query with the QueryEngine and return ContextQuery ID
-         *            for the query
-         *
-         * @param pQueryEngineInstance 
-         *               - instance(created on creation of the QueryEngine)
-         *               of the query engine with which the query is to be executed
-         *
-         * @param contextQuery 
-         *               - query string to be executed
-         *
-         * @return int - ID of context query executed
-         * 
-         */
-        public native int executeContextQuery(int pQueryEngineInstance,
-                                              String contextQuery) throws Exception;
+    /**
+     * Creates an instance of the Query Engine
+     * 
+     * @return QueryEngine - QueryEngine object created
+     */
+    public native QueryEngine createQueryEngine() throws Exception;
 
-        /**
-         * Register QueryEngineEvent to QueryEngine.
-         *
-         * @param pQueryEngineInstance 
-         *               - instance(created on creation of the QueryEngine)
-         *               of the query engine with which the query is to be registered
-         *
-         * @param queryEngineEvent 
-         *               - the event class to receive QueryEngine events
-         *
-         * @return void
-         * 
-         */
-        public native void registerQueryEvent(int pQueryEngineInstance,
-                                              IQueryEngineEvent queryEngineEvent);
+    /**
+     * Release the QueryEngine object.
+     * 
+     * @param queryEngine
+     *            - QueryEngine instance to be released
+     * 
+     * @return int - success or failure result
+     */
+    public native int releaseQueryEngine(QueryEngine queryEngine);
 
+    /**
+     * Execute the query with the QueryEngine and return ContextQuery ID for the
+     * query
+     * 
+     * @param pQueryEngineInstance
+     *            - instance(created on creation of the QueryEngine) of the
+     *            query engine with which the query is to be executed
+     * 
+     * @param contextQuery
+     *            - query string to be executed
+     * 
+     * @return int - ID of context query executed
+     */
+    public native int executeContextQuery(int pQueryEngineInstance,
+            String contextQuery) throws Exception;
 
-        /**
-         * Kill the registered ContextQuery corresponding to the cqid
-         *
-         * @param pQueryEngineInstance 
-         *              - instance(created on creation of the QueryEngine)
-         *              of the query engine with which the query is to be terminated
-         *
-         * @param cqid 
-         *              - ContextQuery ID of the query to be terminated
-         *
-         * @return void
-         * 
-         */
-        public native void killContextQuery(int pQueryEngineInstance, int cqid)
-        throws Exception;
+    /**
+     * Register QueryEngineEvent to QueryEngine.
+     * 
+     * @param pQueryEngineInstance
+     *            - instance(created on creation of the QueryEngine) of the
+     *            query engine with which the query is to be registered
+     * 
+     * @param queryEngineEvent
+     *            - the event class to receive QueryEngine events
+     * 
+     * @return void
+     */
+    public native void registerQueryEvent(int pQueryEngineInstance,
+            IQueryEngineEvent queryEngineEvent);
 
-        // public native void UnregiterQueryEvent(int pQueryEngineInstance,
-        // IQueryEngineEvent queryEngineEvent);
+    /**
+     * Kill the registered ContextQuery corresponding to the cqid
+     * 
+     * @param pQueryEngineInstance
+     *            - instance(created on creation of the QueryEngine) of the
+     *            query engine with which the query is to be terminated
+     * 
+     * @param cqid
+     *            - ContextQuery ID of the query to be terminated
+     * 
+     * @return void
+     */
+    public native void killContextQuery(int pQueryEngineInstance, int cqid)
+            throws Exception;
 
-        // IModelData
-        /**
-         * Get the affected DataId. ContextModel has plenty of data so returned data is matched 
-         *               from given condition which in this case is the model data object instance
-         *
-         * @param pIModelDataInstance 
-         *               - instance(created on creation of the ModelData)
-         *                of the model data for which Data ID is to be returned
-         *
-         * @return int - the affected DataId
-         * 
-         */
-        public native int getDataId(int pIModelDataInstance);
+    /**
+     * Get the affected DataId. ContextModel has plenty of data so returned data
+     * is matched from given condition which in this case is the model data
+     * object instance
+     * 
+     * @param pIModelDataInstance
+     *            - instance(created on creation of the ModelData) of the model
+     *            data for which Data ID is to be returned
+     * 
+     * @return int - the affected DataId
+     */
+    public native int getDataId(int pIModelDataInstance);
 
-        /**
-         * ContextModel has at least one property that contains data \n
-         *           property is described from its specification.
-         *
-         * @param pIModelDataInstance - instance(created on creation of the ModelData)
-         *                of the model data for which property count is to be returned
-         *
-         * @return @return int - number of properties
-         * 
-         */
-        public native int getPropertyCount(int pIModelDataInstance);
+    /**
+     * ContextModel has at least one property that contains data \n property is
+     * described from its specification.
+     * 
+     * @param pIModelDataInstance
+     *            - instance(created on creation of the ModelData) of the model
+     *            data for which property count is to be returned
+     * 
+     * @return @return int - number of properties
+     */
+    public native int getPropertyCount(int pIModelDataInstance);
 
-        /**
-         * Retrieve the name of the property using the given index
-         *
-         * @param pIModelDataInstance 
-         *               - instance(created on creation of the ModelData)
-         *                of the model data for which property name is to be returned
-         *
-         * @param propertyIndex 
-         *               - index of property to read
-         *
-         * @return String - property name
-         * 
-         */
-        public native String getPropertyName(int pIModelDataInstance,
-                                             int propertyIndex);
+    /**
+     * Retrieve the name of the property using the given index
+     * 
+     * @param pIModelDataInstance
+     *            - instance(created on creation of the ModelData) of the model
+     *            data for which property name is to be returned
+     * 
+     * @param propertyIndex
+     *            - index of property to read
+     * 
+     * @return String - property name
+     */
+    public native String getPropertyName(int pIModelDataInstance,
+            int propertyIndex);
 
-        /**
-         * Retrieve the value of the property using the given index
-         *
-         * @param pIModelDataInstance 
-         *               - instance(created on creation of the ModelData)
-         *                of the model data for which property value is to be returned
-         *
-         * @param propertyIndex 
-         *               - index of property to read
-         *
-         * @return String - property value
-         * 
-         */
-        public native String getPropertyValue(int pIModelDataInstance,
-                                              int propertyIndex);
+    /**
+     * Retrieve the value of the property using the given index
+     * 
+     * @param pIModelDataInstance
+     *            - instance(created on creation of the ModelData) of the model
+     *            data for which property value is to be returned
+     * 
+     * @param propertyIndex
+     *            - index of property to read
+     * 
+     * @return String - property value
+     */
+    public native String getPropertyValue(int pIModelDataInstance,
+            int propertyIndex);
 
-        // IDataReader
-        /**
-         * Get affected context models. The CQL(context query language) can specify
-         *       multiple ContextModels for retrieving data so a list of string of affected
-         *       context models is returned
-         *
-         * @param pDataReaderInstance 
-         *              - instance(created on creation of the DataReader)
-         *                of the data reader class object
-         *
-         * @return List<String> - affected ContextModel list
-         * 
-         */
-        public native List<String> getAffectedModels(int pDataReaderInstance);
+    /**
+     * Get affected context models. The CQL(context query language) can specify
+     * multiple ContextModels for retrieving data so a list of string of
+     * affected context models is returned
+     * 
+     * @param pDataReaderInstance
+     *            - instance(created on creation of the DataReader) of the data
+     *            reader class object
+     * 
+     * @return List<String> - affected ContextModel list
+     */
+    public native List<String> getAffectedModels(int pDataReaderInstance);
 
-        /**
-         * Get affected model data count. There can be multiple data models existing
-         *       from the given condition, return the count.
-         *
-         * @param pDataReaderInstance 
-         *              - instance(created on creation of the DataReader)
-         *                of the data reader class object
-         *
-         * @param modelName 
-         *              - affected ContextModel name
-         *
-         * @return int  - affected dataId count
-         * 
-         */
-        public native int getModelDataCount(int pDataReaderInstance,
-                                            String modelName) throws Exception;
+    /**
+     * Get affected model data count. There can be multiple data models existing
+     * from the given condition, return the count.
+     * 
+     * @param pDataReaderInstance
+     *            - instance(created on creation of the DataReader) of the data
+     *            reader class object
+     * 
+     * @param modelName
+     *            - affected ContextModel name
+     * 
+     * @return int - affected dataId count
+     */
+    public native int getModelDataCount(int pDataReaderInstance,
+            String modelName) throws Exception;
 
-        /**
-         * Get actual Context Model data
-         *
-         * @param pDataReaderInstance 
-         *              - instance(created on creation of the DataReader)
-         *                of the data reader class object
-         *
-         * @param modelName 
-         *              - affected ContextModel name
-         *
-         * @param dataIndex 
-         *              - affected dataId index
-         *
-         * @return ModelData  - affected ContextModel data reader
-         * 
-         */
-        public native ModelData getModelData(int pDataReaderInstance,
-                                             String modelName, int dataIndex) throws Exception;
+    /**
+     * Get actual Context Model data
+     * 
+     * @param pDataReaderInstance
+     *            - instance(created on creation of the DataReader) of the data
+     *            reader class object
+     * 
+     * @param modelName
+     *            - affected ContextModel name
+     * 
+     * @param dataIndex
+     *            - affected dataId index
+     * 
+     * @return ModelData - affected ContextModel data reader
+     */
+    public native ModelData getModelData(int pDataReaderInstance,
+            String modelName, int dataIndex) throws Exception;
 
-        /**
-         * To register the report receiver to receive messages
-         *
-         * @param reportReceiver 
-         *              - report receiver instance
-         *
-         * @return void
-         * 
-         */
-        public native void registerReportReceiver(IReportReceiver reportReceiver);
+    /**
+     * To register the report receiver to receive messages
+     * 
+     * @param reportReceiver
+     *            - report receiver instance
+     * 
+     * @return void
+     */
+    public native void registerReportReceiver(IReportReceiver reportReceiver);
 }
\ No newline at end of file
index b5d33f4..f088ed2 100644 (file)
@@ -17,8 +17,9 @@
 * limitations under the License.
 *
 ******************************************************************/
-#include "SSMCore.h"
 #include "SSMInterface/SSMCore_JNI.h"
+
+#include "SSMCore.h"
 #include "Common/PlatformLayer.h"
 
 #define JNI_E_INVALIDARG -1001
@@ -37,7 +38,6 @@ jclass                      g_ClassQueryEngine = NULL;
 jclass                      g_ClassDataReader = NULL;
 jclass                      g_ClassModelData = NULL;
 jclass                      g_ClassQueryEngineEvent = NULL;
-
 jclass                      g_ClassReportReceiver = NULL;
 jobject                     g_objReportReceiver = NULL;
 
@@ -190,6 +190,13 @@ JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *jvm, void *reserved)
 JNIEXPORT void JNICALL Java_org_iotivity_service_ssm_CoreController_initializeSSMCore
 (JNIEnv *env, jclass clz, jstring jstrXmlDescription)
 {
+    if (jstrXmlDescription == NULL)
+    {
+        env->ThrowNew(env->FindClass("java/lang/IllegalArgumentException"),
+                      "InitializeSSMCore failed with Invalid parameter");
+        return;
+    }
+
     SSMRESULT res = SSM_E_FAIL;
     const char *xmlDescription = env->GetStringUTFChars(jstrXmlDescription, NULL);
 
@@ -247,7 +254,7 @@ JNIEXPORT jint JNICALL Java_org_iotivity_service_ssm_CoreController_releaseQuery
     IQueryEngine        *pQueryEngine = NULL;
 
     jmethodID mid_GetQueryEngineInstance = env->GetMethodID(g_ClassQueryEngine,
-                                           "GetQueryEngineInstance", "()I");
+                                           "getQueryEngineInstance", "()I");
 
     if (mid_GetQueryEngineInstance == NULL)
         return JNI_E_METHODID;
@@ -260,7 +267,14 @@ JNIEXPORT jint JNICALL Java_org_iotivity_service_ssm_CoreController_releaseQuery
 JNIEXPORT jint JNICALL Java_org_iotivity_service_ssm_CoreController_executeContextQuery
 (JNIEnv *env, jclass clz, jint pQueryEngineInstance, jstring jstrContextQuery)
 {
-    int                 cqid = 0;
+    int                 cqid = -1;
+    if (jstrContextQuery == NULL)
+    {
+        env->ThrowNew(env->FindClass("java/lang/IllegalArgumentException"),
+                      "ExecuteContextQuery with Invalid context query");
+        return cqid;
+    }
+
     IQueryEngine        *pQueryEngine = (IQueryEngine *)pQueryEngineInstance;
 
     const char *contextQuery = env->GetStringUTFChars(jstrContextQuery, NULL);
index 05aa46d..653b294 100644 (file)
@@ -74,15 +74,6 @@ public class MainActivity extends Activity {
         edtQuery = (EditText) findViewById(R.id.editQuery);
         edtUnregisterQuery = (EditText) findViewById(R.id.editUnregisterQuery);
 
-        findViewById(R.id.btnRegisterQuery).setOnClickListener(clickHandler);
-        findViewById(R.id.btnUnregisterQuery).setOnClickListener(clickHandler);
-        findViewById(R.id.btFullDevice).setOnClickListener(textAddHandler);
-        findViewById(R.id.btDiscomfortIndex).setOnClickListener(textAddHandler);
-        findViewById(R.id.btPlus).setOnClickListener(clickHandler);
-        findViewById(R.id.btMinus).setOnClickListener(clickHandler);
-        findViewById(R.id.btClear).setOnClickListener(textAddHandler);
-        findViewById(R.id.btLogClear).setOnClickListener(textAddHandler);
-
         mQueryEngineEventListener = new IQueryEngineEvent() {
             @Override
             public void onQueryEngineEvent(int cqid, DataReader result) {
@@ -231,6 +222,15 @@ public class MainActivity extends Activity {
         } catch (Exception e) {
             e.printStackTrace();
         }
+
+        findViewById(R.id.btnRegisterQuery).setOnClickListener(clickHandler);
+        findViewById(R.id.btnUnregisterQuery).setOnClickListener(clickHandler);
+        findViewById(R.id.btFullDevice).setOnClickListener(textAddHandler);
+        findViewById(R.id.btDiscomfortIndex).setOnClickListener(textAddHandler);
+        findViewById(R.id.btPlus).setOnClickListener(clickHandler);
+        findViewById(R.id.btMinus).setOnClickListener(clickHandler);
+        findViewById(R.id.btClear).setOnClickListener(textAddHandler);
+        findViewById(R.id.btLogClear).setOnClickListener(textAddHandler);
     }
 
     @Override