-Before run make,
-
-you have to modify Soft Sensor repository path
-
-that Soft Sensor Manager can find assets while it starts.
-
-
-If you want to build THSensorApp for Arduino, let's install follow.
-$ sudo apt-get install arduino
+/******************************************************************
+*
+* Copyright 2014 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.
+*
+******************************************************************/
-Download Time library(Time.zip) from http://playground.arduino.cc/Code/Time
-Unzip Time.zip to /usr/share/arduino/libraries/Time.
-$ sudo cp -Rdp THSensorApp/Time /usr/share/arduino/libraries/
+===============================================================================
+== How to Build SoftSensorManager ==
+===============================================================================
-Open the file located at "THSensorApp/build/Makefile"
+Once the source code is downloaded in your local specific folder, you may follow
+the steps to build and execute Soft Sensor Manager and its applications.
+In this context, we assume that the code was downloaded into 'oic' folder.
-Line 9, ARDUINO_PORT is the serial port path,
-which has to be aligned on your system.
+=======================================
+1. Download source code download
+=======================================
+Once you download the codes, please make sure that the downloaded code structure is as follows;
-If you type "make" at SoftSensorManager folder.
+oic/resource
+oic/service
+oic/utilities
+
+
+The path for Soft Sensor Manager is as following;
+
+oic/service/soft-sensor-manager
+
+The SoftSensorManager directory includes following sub directories;
+
+Directories Description
+oic/service/soft-sensor-manager/build : There are makefiles for different platform; Linux, Tizen, and Arduino.
+oic/service/soft-sensor-manager/doc : SSM developer's guide and Getting started documents
+oic/service/soft-sensor-manager/SampleApp : There are two types of sample applications; application for UI, and application for physical sensors.
+ For UI application, there are SSMTesterApp in /linux, and /Tizen.
+ For physical sensors,
+ 1) Temperature and Humidity sensors, THSensorApp, in \linux and \arduino.
+ In the two directories, in \linux and \arduino , there are two TemperaterHumiditySensor applications,
+ THSensorApp and THSensorApp1, and they are for DiscomfortSoftSensor which aggregates
+ two TemperaterHumiditySensors to calculate current discomfort index in the given room.
+ 2) Trackee_Thing for IndoorTrajectorySensor in \linux and \arduino
+
+oic/service/soft-sensor-manager/SDK : The SDK APIs for applications is located.
+oic/service/soft-sensor-manager/SSMCore : The SSM service codes
+oic/service/soft-sensor-manager/SoftSensorPlugin : The source codes for soft sensors can be located in this folder.
+ Examples of soft sensors are DiscomfortIndexSensor and IndoorTrajectorySensor.
+
+
+=======================================
+2. Refer readme files in each build
+ directory for each module.
+=======================================
+There are readme files in the build directories for each module (e.g. \SDK, \ SSMCore, \SampleApp).
+Please refer the files for specific setup.
+
+
+=======================================
+3. Run make
+=======================================
+
+3.1 Run make for SoftSensorManager & App in Ubuntu.
+
+3.1.1 Before running make for SoftSensorManager & App in Ubuntu, resource should be built in advance.
+ Please refer to ¡®Build the IoTivity project for Linux¡¯ in previous section
+
+3.1.2 If you type "make" at ¡°soft-sensor-manager/build/linux¡±, all packages will be pushed to "/soft-sensor-manager/build/linux/release".
+ You can also found other packages in the folder
++--------------------------------------------------------------+
+| ~/oic/service/soft-sensor-manager/build/linux$ make |
++--------------------------------------------------------------+
+
+3.2 Run make for App in Arduino
+
+3.2.1 If you want to build for Arduino, download Arduino IDE (Arduino 1.0.6) from following url.
+ Extract ¡®arduino-1.0.6-linux32.tgz¡¯ and change folder name from ¡®arduino-1.0.6¡¯ to ¡®arduino¡¯ and then move to "/usr/share/".
+ url: http://arduino.cc/en/Main/Software
+
++--------------------------------------------------------------------+
+| $ mv arduino-1.0.6 arduino |
+| $ sudo cp -Rdp ./arduino /usr/share/ |
++--------------------------------------------------------------------+
+
+3.2.2 Download Time library (Time.zip, Click ¡°The download¡±) from following url.
+ Unzip Time.zip and move them to /usr/share/arduino/libraries.
+ url: http://playground.arduino.cc/Code/Time
+
++--------------------------------------------------------------------+
+| $ sudo cp -Rdp ./Time /usr/share/arduino/libraries/ |
++--------------------------------------------------------------------+
+
+3.2.3 Create file named ¡®local.properties¡¯ in ¡°/oic/resource/csdk/¡± with the following definitions.
+
++------------------------------------------------------------------------------------+
+| < local.properties > |
+| ARDUINO_DIR = /usr/share/arduino |
+| ARDUINO_TOOLS_DIR = $(ARDUINO_DIR)/hardware/tools/avr/bin |
++------------------------------------------------------------------------------------+
+ If you have a problem with compiling ¡®resource¡¯ when you compile arduino application,
+ you may need to check 'local.properties' which is written in the readme file, '/oic/resource/csdk/README'.
+
+3.2.4 Before running make for application, you need to build resource with arduino platform first.
+ Please refer to below example.
+
++------------------------------------------------------------------------------------------+
+| ~/oic/resource/csdk$ make PLATFORM=arduinomega ARDUINOWIFI=1 |
++------------------------------------------------------------------------------------------+
+ PLATFORM : arduinomega or arduinodue.
+ ARDUINOWIFI : 0 (Ethernet), 1(Wifi)
+
+3.2.5 Now, you are ready to build sample arduino application.
+ To build all sample applications for arduino, just do as below.
+
++------------------------------------------------------------------------------------------------+
+|~/oic/service/soft-sensor-manager/ build/Arduino$ make PLATFORM=arduinomega ARDUINOWIFI=1 | |
++------------------------------------------------------------------------------------------------+
+
+ If you want to build each sample application separately, go to build directory for sample application.
+ Belowing is example for THSensor App.
++-------------------------------------------------------------------------------------------------------------------+
+|~/oic/service/soft-sensor-manager/SampleApp/arduino/THSensorApp/build$ make PLATFORM=arduinomega ARDUINOWIFI=1 | |
++-------------------------------------------------------------------------------------------------------------------+
+
+3.2.6. To build and deploy the binary into the target hardware board, Aruino in this case, you need 'install' option.
+ Please refer to below example for THSensorApp ;
+
++--------------------------------------------------------------------------------------------------------------------------+
+|~/oic/service/soft-sensor-manager/SampleApp/arduino/THSensorApp/build$ make install PLATFORM=arduinomega ARDUINOWIFI=1 | |
++--------------------------------------------------------------------------------------------------------------------------+
+ Before ¡®make install¡¯, you need to check the file located at "/oic/service/soft-sensor-manager/SampleApp/arduino/THSensorApp/build/Makefile".
+ Line 26, ARDUINO_PORT is the serial port path, which has to be aligned on your system.
+
+
+=======================================
+5. Execute THSensorApp and SSMTesterApp
+=======================================
+If you want to check how soft-sensor-manager is working, you can run simple applications - THSensorApp and SSMTesterApp
+
+5.1 To initiate THSensorApp, please enter as following;
+
++------------------------------------------------------------------------+
+|~/oic/service/soft-sensor-manager/build/linux/release$ ./THSensorApp | |
+|~/oic/service/soft-sensor-manager/build/linux/release$ ./THSensorApp1 |
++------------------------------------------------------------------------+
+
+5.2 To initiate SSMTesterApp , please enter as following;
+
++--------------------------------------------------------------------------+
+|~/oic/service/soft-sensor-manager/build/linux/release$ ./SSMTesterApp |
++--------------------------------------------------------------------------+
+
+Note that the sequence of process initiations should be followed due to the process dependencies.
-All packages will be pushed to "Outputs" folder.
-You can also found other packages from their.
sdk_env = soft_sensor_manager_env.Clone()
sdk_env.AppendUnique(CPPPATH = ['SSMCore/include'])
sdk_env.AppendUnique(CPPPATH = ['SSMCore/src'])
-sdk_env.AppendUnique(CPPPATH = ['SDK/include'])
+sdk_env.AppendUnique(CPPPATH = ['SDK/cpp/include'])
ssm_sdk_cpp_src = [
- Glob('SDK/src/*.cpp')
+ Glob('SDK/cpp/src/*.cpp')
]
env.AppendTarget('libSSMSDK')
--include ../../../build/linux/root_path.inc
--include ../../../build/linux/environment.mk
+-include ../../../../build/linux/root_path.inc
+-include ../../../../build/linux/environment.mk
BOOST=${BOOST_BASE}
SRC_PATH=../../src
CXX=g++
CXX_FLAGS=-std=c++0x -Wall -pthread -DLINUX
-CXX_INC=-I../../ -I${INC_PATH}/ -I${FD_SSMCORE}/include -I${FD_SSMCORE}/src -I${IOT_BASE}/include/ -I${IOT_LOG_DIR}/include -I${IOT_BASE}/csdk/stack/include -I${IOT_BASE}/csdk/ocsocket/include -I${IOT_BASE}/csdk/ocrandom/include -I${IOT_BASE}/csdk/logger/include -I${BOOST}
+CXX_INC=-I../../ -I${INC_PATH}/ -I${FD_SSMCORE}/include -I${FD_SSMCORE}/src -I${BOOST}
CXX_LIB=
SRCLIST=${wildcard ${SRC_PATH}/*.cpp}
--- /dev/null
+#ifndef _SSMInterface_H_
+#define _SSMInterface_H_
+
+#include <string>
+#include <vector>
+
+enum SSMRESULT
+{
+ SSM_S_OK
+ , SSM_S_FALSE
+ , SSM_E_POINTER
+ , SSM_E_OUTOFMEMORY
+ , SSM_E_FAIL
+ , SSM_E_NOINTERFACE
+ , SSM_E_NOTIMPL
+};
+
+/**
+* @class IModelData
+* @brief IModelData Interface
+* This class represents context model data package
+*
+* @see
+*/
+class IModelData
+{
+ public:
+ /**
+ * @fn getDataId
+ * @brief Get affected DataId. ContextModel has plenty of data so \n
+ * returned data is matched from given condition
+ *
+ * @param None
+ *
+ * @return int
+ * @warning
+ * @exception
+ * @see
+ */
+ virtual int getDataId() = 0;
+
+ /**
+ * @fn GetPropertyCount
+ * @brief ContextModel has at least one property that contains data \n
+ * property is described from its specification.
+ *
+ * @param None
+ *
+ * @return int
+ * @warning
+ * @exception
+ * @see
+ */
+ virtual int getPropertyCount() = 0;
+
+ /**
+ * @fn getPropertyName
+ * @brief Retrieve propertyName
+ *
+ * @param [in] int propertyIndex - index of property to read
+ *
+ * @return std::string
+ * @warning
+ * @exception
+ * @see
+ */
+ virtual std::string getPropertyName(int propertyIndex) = 0;
+
+ /**
+ * @fn getPropertyValue
+ * @brief Retrieve propertyValue
+ *
+ * @param [in] int propertyIndex - index of property to read
+ *
+ * @return std::string
+ * @warning
+ * @exception
+ * @see
+ */
+ virtual std::string getPropertyValue(int propertyIndex) = 0;
+
+ /**
+ * @fn getPropertyValueByName
+ * @brief Retrieve propertyValue using given name
+ *
+ * @param [in] std::string propertyName - property name looking for
+ *
+ * @return std::string
+ * @warning
+ * @exception
+ * @see
+ */
+ virtual std::string getPropertyValueByName(std::string propertyName) = 0;
+ protected:
+ virtual ~IModelData() {};
+};
+
+/**
+* @class IDataReader
+* @brief IDataReader Interface
+* This class represents context model data package's reader
+*
+* @see
+*/
+class IDataReader
+{
+ public:
+ /**
+ * @fn getAffectedModels
+ * @brief Get affected ContextModels. The CQL can specify multiple ContextModels for retrieving data.
+ *
+ * @param [in, out] std::vector<std::string> *pAffectedModels - affected ContextModel list
+ *
+ * @return SSMRESULT
+ * @warning
+ * @exception
+ * @see
+ */
+ virtual SSMRESULT getAffectedModels(std::vector<std::string> *pAffectedModels) = 0;
+
+ /**
+ * @fn getModelDataCount
+ * @brief Get affected data count. There are multiple data can exist from given condition.
+ *
+ * @param [in] std::string modelName - affected ContextModel name
+ *
+ * @param [in, out] int *pDataCount - affected dataId count
+ *
+ * @return SSMRESULT
+ * @warning
+ * @exception
+ * @see
+ */
+ virtual SSMRESULT getModelDataCount(std::string modelName, int *pDataCount) = 0;
+
+ /**
+ * @fn getModelData
+ * @brief Get actual Context Model data
+ *
+ * @param [in] std::string modelName - affected ContextModel name
+ *
+ *
+ * @param [in] int dataIndex - affected dataId index
+ *
+ *
+ * @param [out] IModelData **ppModelData - affected ContextModel data reader
+ *
+ * @return SSMRESULT
+ * @warning
+ * @exception
+ * @see
+ */
+ virtual SSMRESULT getModelData(std::string modelName, int dataIndex, IModelData **ppModelData) = 0;
+ protected:
+ virtual ~IDataReader() {};
+};
+
+/**
+* @class IQueryEngineEvent
+* @brief IQueryEngineEvent Interface
+* This class represents Query Engine's event that contains results
+*
+* @see
+*/
+class IQueryEngineEvent
+{
+ public:
+ /**
+ * @fn onQueryEngineEvent
+ * @brief Transmit result of SSMCore to Application layer
+ *
+ * @param [in] int cqid - entered ContextQuery ID
+ *
+ * @param [in] IDataReader *pResult - result of SSMCore
+ *
+ * @return SSMRESULT
+ * @warning
+ * @exception
+ * @see
+ */
+ virtual SSMRESULT onQueryEngineEvent(int cqid, IDataReader *pResult) = 0;
+ protected:
+ virtual ~IQueryEngineEvent() {};
+};
+
+/**
+* @class SSMInterface
+* @brief SSMInterface class
+* This class represents main class for querying Soft Sensors
+*
+* @see
+*/
+class SSMInterface
+{
+ public:
+ SSMInterface();
+ ~SSMInterface();
+
+ /**
+ * @fn registerQuery
+ * @brief Execute ContextQuery and return ContextQuery ID
+ *
+ * @param [in] std::string queryString - query for requesting data
+ *
+ * @param [in] IQueryEngineEvent listener - listener for receiving data related to query
+ *
+ * @param [in, out] int &cqid - ID of ContextQuery
+ *
+ * @return SSMRESULT
+ * @warning
+ * @exception
+ * @see
+ */
+ SSMRESULT registerQuery(std::string queryString, IQueryEngineEvent *listener, int &cqid);
+
+ /**
+ * @fn unregisterQuery
+ * @brief unregister registered ContextQuery according to cqid
+ *
+ * @param [in] int cqid - Context query corresponding to the cqid will be terminated
+ *
+ * @return SSMRESULT
+ * @warning
+ * @exception
+ * @see
+ */
+ SSMRESULT unregisterQuery(int cqid);
+};
+#endif
\ No newline at end of file
+++ /dev/null
-/******************************************************************
- *
- * Copyright 2014 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 ISSMClientListener.h
- * @brief This file contains client listener interfaces.
- */
-
-#ifndef ISSMCLIENTLISTENER_H_
-#define ISSMCLIENTLISTENER_H_
-#include <string>
-#include "OCPlatform.h"
-
-/**
- * @brief This enum defines Soft Sensor return types
- */
-typedef enum
-{
- SSM_SUCCESS, SSM_ERROR, SSM_ERROR_QUERY_PARSING, SSM_ERROR_NO_QUERY, SSM_ERROR_NETWORK
-} SSMReturn;
-
-using namespace OC;
-/**
- * @brief ISSMClientListener is a listener interface from which application is derived to get callback from SoftSensorManager service
- */
-class ISSMClientListener
-{
- public:
- /**
- * @brief onRegisterQuery is a pure virtual operation which should be implemented in applications to get callback messages.
- * @param [in] jsonData - A data map in which SoftSensorManager service sends sensor data with cqid.
- * @param [in] eCode - The address of listener class. When an application which inherits the ISSMClientListener calls this operation, it sends its address for the listener so that
- * SSMClient can callback message to the appication.
- * @param [out] cqid - A query id generated from SoftSensorManager service for the queryString request.
- * @return SSMReturn
-
- */
- virtual void onRegisterQuery(const std::string &jsonData, SSMReturn &eCode) = 0;
- virtual ~ISSMClientListener()
- {
- }
-};
-
-#endif /* ISSMCLIENTLISTENER_H_ */
+++ /dev/null
-//******************************************************************
-//
-// Copyright 2014 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 SSMClient.h
- * @brief This file contains the declaration of classes and its members related to SSMClient.
- */
-
-#ifndef RESOURCECLIENT_H_
-#define RESOURCECLIENT_H_
-
-#include <string>
-
-#include "OCResource.h"
-#include "OCPlatform.h"
-#include "ISSMClientListener.h"
-
-using namespace OC;
-
-#if defined(WIN32)
-class CSemaphore
-{
- private:
- HANDLE hSemaphore;
- int m_MaxTimeOut;
-
- public:
- /**
- * This is CSemaphore constructor.
- */
- CSemaphore()
- {
- m_MaxTimeOut = 0;
- }
- /**
- *This is CSemaphore destructor.
- */
- ~CSemaphore()
- {
- }
-
- /**
- * This is a function to creat a semaphore
- * This is syncronus call.
- * @param maximumRequestTimeOut
- * [IN] Request Time out.
- *
- * @return None
- *
- */
- void create(int maximumRequestTimeOut)
- {
- hSemaphore = CreateSemaphore(NULL, 1, 1, NULL);
- m_MaxTimeOut = maximumRequestTimeOut;
- }
-
- /**
- * This is a function to wait for semaphore
- *
- * @return None
- *
- */
- void wait()
- {
- WaitForSingleObject(hSemaphore, m_MaxTimeOut);
- }
-
- /**
- * This is a function to release semaphore
- *
- * @return None
- *
- */
- void release()
- {
- ReleaseSemaphore(hSemaphore, 1, NULL);
- }
-
-};
-
-#elif defined(LINUX)
-#include <semaphore.h>
-
-#define SEM_SUCCESS 0
-
-class CSemaphore
-{
- private:
- sem_t hSemaphore;
- timespec m_MaxTimeOut;
-
- public:
- /**
- * This is CSemaphore constructor.
- */
- CSemaphore()
- {
- m_MaxTimeOut.tv_sec = 0;
- m_MaxTimeOut.tv_nsec = 0;
- }
- /**
- *This is CSemaphore destructor.
- */
- ~CSemaphore()
- {
- }
- /**
- * This is a function to creat a semaphore
- * This is syncronus call.
- * @param maximumRequestTimeOut
- * [IN] Request Time out.
- *
- * @return None
- *
- */
- void create(int maximumRequestTimeOut)
- {
- if ( sem_init(&hSemaphore, 1, 0) < SEM_SUCCESS )
- {
- perror("Error : sem_init.");
- exit(0);
- }
- m_MaxTimeOut.tv_sec = maximumRequestTimeOut;
- }
-
- void wait()
- {
- sem_wait( &hSemaphore );
- }
-
- /**
- * This is a function to release semaphore
- *
- * @return None
- *
- */
- void release()
- {
- sem_post(&hSemaphore);
- }
-
-};
-#endif
-
-/**
- * @brief SSMClient is a wrapper class to provide SoftSensorManager functionality to Application.
- * Basically, SoftSensorManager is developed in Resource model (i.e. messaging with basic functions of put, get, and post).
- * SSMClient abstracts the resource based operations from client applications and provides c++ style functions.
- */
-class SSMClient
-{
- private:
- SSMReturn m_retResponse;
- CSemaphore m_sem;
- /**
- * @brief SoftSensorManager Resource.
- */
- std::shared_ptr< OCResource > m_SSMResource;
- /**
- * @brief attribute map .
- */
- std::map<std::string, std::string> m_responseAttributeMap;
- /**
- * @brief query engine.
- */
- std::string m_queryEngineId;
- /**
- * @brief app listener
- */
- ISSMClientListener *m_appListener;
-
- /**
- * @brief internal find resource function
- */
- void _findResource(void);
-
- /**
- * @brief internal Query engine function
- */
- void _createQueryEngine(void);
-
- /**
- * @brief internal release query function
- */
- void _releaseQueryEngine(std::string queryEngineId);
-
- public:
- /**
- * Constructor for SSMClient.
- */
- SSMClient();
- ~SSMClient();
-
- /**
- * This API sends query strings of applications to SoftSensorManager on Iotivity Base messaging.
- *
- * @param [in] queryString - A conditions query statement where the caller application specifies sensors for required data and conditions when the caller wants to get the data.
- * @param [in] listener - The address of listener class. When an application which inherits the ISSMClientListener calls this operation, it sends its address for the listener so that
- * SSMClient can callback message to the application.
- * @param [out] cqid - A query id generated from SoftSensorManager service for the queryString request.
- * @return SSMReturn
-
- */
- SSMReturn registerQuery(std::string queryString, ISSMClientListener *listener,
- std::string &cqid);
- /**
- * This API is to cancel the registered sends query strings of applications to SoftSensorManager on Iotivity Base messaging.
- *
- * @param [in] listener - The address of listener class. When an application which inherits the ISSMClientListener calls this operation, it sends its address for the listener so that
- * SSMClient can callback message to the application.
- * @param [in] cqid - A query id generated from SoftSensorManager service for the queryString request.
- * @return SSMReturn
- */
- SSMReturn unregisterQuery(std::string cqid);
-
- // friend option. for callback from SSMResource
- void onFoundResource(std::shared_ptr< OCResource > resource);
- void onCreateQueryEngine(const HeaderOptions &headerOptions, const OCRepresentation &rep,
- const int eCode);
- void onReleaseQueryEngine(const HeaderOptions &headerOptions, const OCRepresentation &rep,
- const int eCode);
- void onRegisterQuery(const HeaderOptions &headerOptions, const OCRepresentation &rep,
- const int eCode);
- void onUnregisterQuery(const HeaderOptions &headerOptions, const OCRepresentation &rep,
- const int eCode);
- void onObserve(const HeaderOptions &headerOptions, const OCRepresentation &rep, const int &eCode,
- const int &sequenceNumber);
-};
-
-#endif /* RESOURCECLIENT_H_ */
--- /dev/null
+package org.iotivity.service.ssm;
+
+import java.util.List;
+
+import android.util.Log;
+
+public class CoreController
+{
+ static
+ {
+ try
+ {
+ String workingPath = System.getProperty( "user.dir" );
+
+ Log.i("SSMTester", "loading ssm lib");
+
+ // for android: not complete method
+ if(System.getProperty("os.name").toLowerCase().equals("linux"))
+ {
+ //System.out.println("System load Android library");
+ System.loadLibrary("SSMCore_Android");
+ }
+ else
+ {
+ //System.out.println("System load 32bit library");
+ workingPath += "/../Outputs/";
+ System.load( workingPath + "SSMCore_Windows.dll");
+ }
+
+ Log.i("SSMTester", "loading done");
+ }
+ catch(UnsatisfiedLinkError e)
+ {
+ System.out.println(e.getMessage());
+ }
+ }
+
+ static private CoreController coreController;
+
+ public static CoreController getInstance()
+ {
+ if(coreController == null)
+ coreController = new CoreController();
+
+ return coreController;
+ }
+
+ public native void InitializeSSMCore(String xmlDescription);
+ public native void StartSSMCore();
+ public native void StopSSMCore();
+ public native void TerminateSSMCore();
+ public native QueryEngine CreateQueryEngine();
+ public native int ReleaseQueryEngine(QueryEngine queryEngine);
+
+ // QueryEngine
+ public native int ExecuteContextQuery(int pQueryEngineInstance, String contextQuery);
+ public native void RegisterQueryEvent(int pQueryEngineInstance, IQueryEngineEvent queryEngineEvent);
+ public native void KillContextQuery(int pQueryEngineInstance, int cqid);
+
+ //public native void UnregiterQueryEvent(int pQueryEngineInstance, IQueryEngineEvent queryEngineEvent);
+
+ //IModelData
+ public native int GetDataId(int pIModelDataInstance);
+ public native int GetPropertyCount(int pIModelDataInstance);
+ public native String GetPropertyName(int pIModelDataInstance, int propertyIndex);
+ public native String GetPropertyValue(int pIModelDataInstance, int propertyIndex);
+
+ //IDataReader
+ public native List<String> GetAffectedModels(int pDataReaderInstance);
+ public native int GetModelDataCount(int pDataReaderInstance, String modelName);
+ public native ModelData GetModelData(int pDataReaderInstance, String modelName, int dataIndex);
+
+ public native void RegisterReportReceiver(IReportReceiver reportReceiver);
+}
\ No newline at end of file
--- /dev/null
+package org.iotivity.service.ssm;
+
+import java.util.List;
+
+public class DataReader {
+
+ private int pDataReaderInstance;
+
+ public DataReader(int dataReaderInstance)
+ {
+ pDataReaderInstance = dataReaderInstance;
+ }
+
+ public List<String> GetAffectedModels()
+ {
+ return CoreController.getInstance().GetAffectedModels(pDataReaderInstance);
+ }
+
+ public int GetModelDataCount(String modelName)
+ {
+ return CoreController.getInstance().GetModelDataCount(pDataReaderInstance, modelName);
+ }
+
+ public ModelData GetModelData(String modelName, int dataIndex)
+ {
+ return CoreController.getInstance().GetModelData(pDataReaderInstance, modelName, dataIndex);
+ }
+}
--- /dev/null
+package org.iotivity.service.ssm;
+
+public interface IQueryEngineEvent {
+ public void OnQueryEngineEvent(int cqid, DataReader result);
+}
\ No newline at end of file
--- /dev/null
+package org.iotivity.service.ssm;
+
+public interface IReportReceiver {
+ public void OnMessageReceived(String tag, String msg);
+}
--- /dev/null
+package org.iotivity.service.ssm;
+
+public class ModelData {
+
+ private int pIModelDataInstance;
+
+ public ModelData(int iModelDataInstance)
+ {
+ pIModelDataInstance = iModelDataInstance;
+ }
+
+ public int GetDataId()
+ {
+ return CoreController.getInstance().GetDataId(pIModelDataInstance);
+ }
+
+ public int GetPropertyCount()
+ {
+ return CoreController.getInstance().GetPropertyCount(pIModelDataInstance);
+ }
+
+ public String GetPropertyName(int propertyIndex)
+ {
+ return CoreController.getInstance().GetPropertyName(pIModelDataInstance, propertyIndex);
+ }
+
+ public String GetPropertyValue(int propertyIndex)
+ {
+ return CoreController.getInstance().GetPropertyValue(pIModelDataInstance, propertyIndex);
+ }
+}
\ No newline at end of file
--- /dev/null
+package org.iotivity.service.ssm;
+
+public class QueryEngine
+{
+ private int pQueryEngineInstance;
+
+ public QueryEngine(int queryEngineInstance)
+ {
+ pQueryEngineInstance = queryEngineInstance;
+ }
+
+ public int GetQueryEngineInstance()
+ {
+ return pQueryEngineInstance;
+ }
+
+ public int ExecuteContextQuery(String contextQuery)
+ {
+ return CoreController.getInstance().ExecuteContextQuery(pQueryEngineInstance, contextQuery);
+ }
+
+ public void RegisterQueryEvent(IQueryEngineEvent queryEngineEvent)
+ {
+ CoreController.getInstance().RegisterQueryEvent(pQueryEngineInstance, queryEngineEvent);
+ }
+
+ public void KillContextQuery(int cqid)
+ {
+ CoreController.getInstance().KillContextQuery(pQueryEngineInstance, cqid);
+ }
+}
\ No newline at end of file
--- /dev/null
+package org.iotivity.service.ssm;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+public class SSMInterface {
+ private class QueryEngineEventReceiver implements IQueryEngineEvent
+ {
+ private Lock mMtxListener = new ReentrantLock();
+ private Map<Integer, IQueryEngineEvent> mMapListener = new HashMap<Integer, IQueryEngineEvent>();
+
+ public void OnQueryEngineEvent(int cqid, DataReader result)
+ {
+ mMtxListener.lock();
+
+ mMapListener.get(cqid).OnQueryEngineEvent(cqid, result);
+
+ mMtxListener.unlock();
+ }
+ void lockListener()
+ {
+ mMtxListener.lock();
+ }
+
+ void unlockListener()
+ {
+ mMtxListener.unlock();
+ }
+
+ void addListener(int cqid, IQueryEngineEvent engineEvent)
+ {
+ mMapListener.put(cqid, engineEvent);
+ }
+
+ void removeListener(int cqid)
+ {
+ mMapListener.remove(cqid);
+ }
+ };
+
+ private CoreController mSSMCore = null;
+ private QueryEngine mQueryEngine = null;
+ private QueryEngineEventReceiver mQueryEngineEventListenerReceiver = new QueryEngineEventReceiver();
+ private List<Integer> mRunningCQLs = new ArrayList<Integer>();
+
+ public SSMInterface()
+ {
+ }
+
+ public void startSSMCore(String initConfig) throws Exception
+ {
+ mSSMCore = CoreController.getInstance();
+ mSSMCore.InitializeSSMCore(initConfig);
+ mSSMCore.StartSSMCore();
+
+ mQueryEngine = mSSMCore.CreateQueryEngine();
+
+ if(mQueryEngine == null)
+ throw new Exception("Create Query Engine failed");
+
+ mQueryEngine.RegisterQueryEvent(mQueryEngineEventListenerReceiver);
+ }
+
+ public void stopSSMCore()
+ {
+ mQueryEngine.RegisterQueryEvent(null);
+ mSSMCore.ReleaseQueryEngine(mQueryEngine);
+ mQueryEngineEventListenerReceiver = null;
+ mQueryEngine = null;
+ mSSMCore.StopSSMCore();
+ mSSMCore.TerminateSSMCore();
+ }
+
+ public int registerQuery(String contextQuery, IQueryEngineEvent listener)
+ {
+ int cqid;
+
+ mQueryEngineEventListenerReceiver.lockListener();
+ cqid = mQueryEngine.ExecuteContextQuery(contextQuery);
+ mQueryEngineEventListenerReceiver.addListener(cqid, listener);
+ mRunningCQLs.add(cqid);
+ mQueryEngineEventListenerReceiver.unlockListener();
+
+ return cqid;
+ }
+
+ public void unregisterQuery(int cqid)
+ {
+ mQueryEngineEventListenerReceiver.lockListener();
+ mQueryEngine.KillContextQuery(cqid);
+ mQueryEngineEventListenerReceiver.removeListener(cqid);
+ mRunningCQLs.remove(cqid);
+ mQueryEngineEventListenerReceiver.unlockListener();
+ }
+}
\ No newline at end of file
+++ /dev/null
-//******************************************************************
-//
-// Copyright 2014 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 <iostream>
-#include <string>
-
-#include "SSMClient.h"
-#include "OCPlatform.h"
-#include "OCApi.h"
-
-const char *SSM_RESOURCE_URI = "/service/SoftSensorManager";
-
-#define SSM_RESOURCE_TYPE = "core.SoftSensorManager"
-
-#define COAP_SERVER_ADDR "coap://224.0.1.187/oc/core?rt=core.SoftSensorManager"
-
-SSMClient::SSMClient()
-{
- m_sem.create(100000);
- m_appListener = NULL;
- m_retResponse = SSM_ERROR;
- _findResource();
- _createQueryEngine();
-}
-
-SSMClient::~SSMClient()
-{
- _releaseQueryEngine(m_queryEngineId);
-}
-
-void SSMClient::_findResource()
-{
- // Create PlatformConfig object
- PlatformConfig cfg(OC::ServiceType::InProc, OC::ModeType::Both,
- "0.0.0.0", 0, OC::QualityOfService::LowQos);
-
- // Create a OCPlatform instance.
- // Note: Platform creation is synchronous call.
- try
- {
- OCPlatform::Configure(cfg);
-
- // Find all resources
- OCStackResult result;
- if ((result = OCPlatform::findResource("", COAP_SERVER_ADDR,
- std::bind(&SSMClient::onFoundResource, this, std::placeholders::_1)))
- != OC_STACK_OK)
- {
- std::cout << "Faile to Find Resource... " << std::endl;
- return;
- }
- std::cout << "Find Resource... " << std::endl;
-
- m_sem.wait();
-
- }
- catch (OCException e)
- {
- //log(e.what());
- }
-}
-
-void SSMClient::_createQueryEngine(void)
-{
- OCRepresentation rep;
-
- QueryParamsMap queryParamsMap;
-
- rep.setValue("command", std::string("CreateQueryEngine"));
-
- if (m_SSMResource->put(rep, queryParamsMap,
- std::bind(&SSMClient::onCreateQueryEngine, this, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3)) != OC_STACK_OK)
- {
- return;
- }
-
- m_sem.wait();
-}
-
-void SSMClient::_releaseQueryEngine(std::string queryEngineId)
-{
- OCRepresentation rep;
-
- QueryParamsMap queryParamsMap;
-
- rep.setValue("command", std::string("ReleaseQueryEngine"));
- rep.setValue("queryEngineId", queryEngineId);
-
- m_SSMResource->put(rep, queryParamsMap,
- std::bind(&SSMClient::onReleaseQueryEngine, this, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3));
-
- m_sem.wait();
-}
-
-SSMReturn SSMClient::registerQuery(std::string queryString, ISSMClientListener *listener,
- std::string &cqid)
-{
- OCRepresentation rep;
-
- QueryParamsMap queryParamsMap;
-
-
- rep.setValue("command", std::string("ExecuteContextQuery"));
- rep.setValue("queryEngineId", m_queryEngineId);
- rep.setValue("contextQuery", queryString);
-
- m_appListener = listener;
-
- if (m_SSMResource->put(rep, queryParamsMap,
- std::bind(&SSMClient::onRegisterQuery, this, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3)) != OC_STACK_OK)
- return SSM_ERROR_NETWORK;
-
- m_sem.wait();
-
- if (m_retResponse == SSM_SUCCESS)
- {
- cqid = m_responseAttributeMap["CQID"];
- }
-
- return m_retResponse;
-}
-
-SSMReturn SSMClient::unregisterQuery(std::string cqid)
-{
- OCRepresentation rep;
-
- QueryParamsMap queryParamsMap;
-
- rep.setValue("command", std::string("KillContextQuery"));
- rep.setValue("queryEngineId", m_queryEngineId);
- rep.setValue("CQID", cqid);
-
- if (m_SSMResource->put(rep, queryParamsMap,
- std::bind(&SSMClient::onUnregisterQuery, this, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3)) != OC_STACK_OK)
- return SSM_ERROR_NETWORK;
-
- m_sem.wait();
-
- return m_retResponse;
-}
-
-/**
- * Callback Function List.
- */
-// Callback to found resources
-void SSMClient::onFoundResource(std::shared_ptr< OCResource > resource)
-{
- std::string resourceURI;
- try
- {
- // Do some operations with resource object.
- if (resource)
- {
- // Get the resource URI
- resourceURI = resource->uri();
-
- if (resourceURI.compare(SSM_RESOURCE_URI) == 0)
- {
- m_SSMResource = resource;
- }
- }
- }
- catch (std::exception &e)
- {
- //log(e.what());
- }
-
- m_sem.release();
-}
-
-void SSMClient::onCreateQueryEngine(const HeaderOptions &headerOptions, const OCRepresentation &rep,
- const int eCode)
-{
- if (eCode != 0)
- {
- m_retResponse = SSM_ERROR_NETWORK;
- goto CLEANUP;
- }
-
- m_queryEngineId = rep.getValue<std::string>("queryEngineId");
- m_retResponse = SSM_SUCCESS;
-
-CLEANUP: m_sem.release();
-}
-
-void SSMClient::onRegisterQuery(const HeaderOptions &headerOptions, const OCRepresentation &rep,
- const int eCode)
-{
- QueryParamsMap queryParamsMap;
-
- if (eCode != 0)
- {
- m_retResponse = SSM_ERROR_NETWORK;
- goto CLEANUP;
- }
-
- if (rep.hasAttribute("error"))
- {
- m_retResponse = SSM_ERROR_QUERY_PARSING;
- goto CLEANUP;
- }
-
- m_SSMResource->observe(ObserveType::Observe, queryParamsMap,
- std::bind(&SSMClient::onObserve, this, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
-
- m_responseAttributeMap.clear();
-
- m_responseAttributeMap["CQID"] = rep.getValue<std::string>("CQID");
-
- m_retResponse = SSM_SUCCESS;
-
-CLEANUP: m_sem.release();
-}
-
-void SSMClient::onUnregisterQuery(const HeaderOptions &headerOptions, const OCRepresentation &rep,
- const int eCode)
-{
- if (eCode != 0)
- {
- m_retResponse = SSM_ERROR_NETWORK;
- goto CLEANUP;
- }
-
- if (rep.hasAttribute("error"))
- {
- m_retResponse = SSM_ERROR_NO_QUERY;
- goto CLEANUP;
- }
-
- m_responseAttributeMap.clear();
-
- m_retResponse = SSM_SUCCESS;
-
-CLEANUP: m_sem.release();
-}
-
-void SSMClient::onReleaseQueryEngine(const HeaderOptions &headerOptions,
- const OCRepresentation &rep, const int eCode)
-{
- if (eCode != 0)
- {
- m_retResponse = SSM_ERROR_NETWORK;
- goto CLEANUP;
- }
-
- m_retResponse = SSM_SUCCESS;
-
-CLEANUP: m_sem.release();
-}
-
-void SSMClient::onObserve(const HeaderOptions &headerOptions, const OCRepresentation &rep,
- const int &eCode, const int &sequenceNumber)
-{
- SSMReturn ret = SSM_SUCCESS;
-
- if (eCode != 0)
- {
- ret = SSM_ERROR_NETWORK;
- }
-
- m_appListener->onRegisterQuery(rep.getJSONRepresentation(), ret);
-}
post_job:
@echo " "
+ cp -Rdp ${INC_PATH}/SSMInterface.h ${FD_SDK}/include/
cp -Rdp ./${RST_NAME}/${TARGET} ${OUTPUTS_DIR}/
cp -Rdp ${INC_PATH}/SSMInterface.h ${OUTPUTS_DIR}/
cp -Rdp ${SRC_PATH}/SSMInterface/SSMModelDefinition.h ${OUTPUTS_DIR}/
* @fn getAffectedModels
* @brief Get affected ContextModels. The CQL can specify multiple ContextModels for retrieving data.
*
- * @param [out] std::vector<std::string> *pAffectedModels - affected ContextModel list
+ * @param [in, out] std::vector<std::string> *pAffectedModels - affected ContextModel list
*
* @return SSMRESULT
* @warning
*
* @param [in] std::string modelName - affected ContextModel name
*
- * @param [out] int *pDataCount - affected dataId count
+ * @param [in, out] int *pDataCount - affected dataId count
*
* @return SSMRESULT
* @warning
virtual ~IQueryEngineEvent() {};
};
+/**
+* @class SSMInterface
+* @brief SSMInterface class
+* This class represents main class for querying Soft Sensors
+*
+* @see
+*/
class SSMInterface
{
public:
SSMInterface();
~SSMInterface();
+ /**
+ * @fn registerQuery
+ * @brief Execute ContextQuery and return ContextQuery ID
+ *
+ * @param [in] std::string queryString - query for requesting data
+ *
+ * @param [in] IQueryEngineEvent listener - listener for receiving data related to query
+ *
+ * @param [in, out] int &cqid - ID of ContextQuery
+ *
+ * @return SSMRESULT
+ * @warning
+ * @exception
+ * @see
+ */
SSMRESULT registerQuery(std::string queryString, IQueryEngineEvent *listener, int &cqid);
+
+ /**
+ * @fn unregisterQuery
+ * @brief unregister registered ContextQuery according to cqid
+ *
+ * @param [in] int cqid - Context query corresponding to the cqid will be terminated
+ *
+ * @return SSMRESULT
+ * @warning
+ * @exception
+ * @see
+ */
SSMRESULT unregisterQuery(int cqid);
};
#endif
\ No newline at end of file
# Build flags
######################################################################
linux_sample_env.AppendUnique(CPPPATH = ['include'])
-linux_sample_env.AppendUnique(CPPPATH = ['../../../SSMCore/include'])
-linux_sample_env.AppendUnique(CPPPATH = ['../../../SSMCore/src'])
-linux_sample_env.AppendUnique(CPPPATH = ['../../../SDK/include'])
+linux_sample_env.AppendUnique(CPPPATH = ['../../../SDK/cpp/include'])
linux_sample_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread'])
linux_sample_env.AppendUnique(CPPDEFINES = ['LINUX'])
linux_sample_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
linux_sample_env.AppendUnique(LIBS = ['libSSMSDK'])
-linux_sample_env.AppendUnique(LIBS = ['libSSMCORE'])
+#linux_sample_env.AppendUnique(LIBS = ['libSSMCORE'])
+linux_sample_env.AppendUnique(LIBS = ['libSSMCore'])
linux_sample_env.AppendUnique(LIBS = ['oc'])
linux_sample_env.AppendUnique(LIBS = ['octbstack'])
linux_sample_env.AppendUnique(LIBS = ['libcoap'])
CXX=g++
CXX_FLAGS=-std=c++0x -Wall -DLINUX
-CXX_INC=-I${SRC_PATH}/ -I${INC_PATH}/ -I${OUTPUTS_DIR} -I${IOT_BASE}/include/ -I${IOT_LOG_DIR}/include/ -I${IOT_BASE}/csdk/stack/include -I${IOT_BASE}/csdk/ocsocket/include -I${IOT_BASE}/csdk/ocrandom/include -I${IOT_BASE}/csdk/logger/include -I${BOOST}
+CXX_INC=-I${SRC_PATH}/ -I${INC_PATH}/ -I${OUTPUTS_DIR} -I${BOOST}
CXX_LIB+=${OUTPUTS_DIR}/${SSM_LIB}
#include <string>
-#include "OCResource.h"
-#include "OCPlatform.h"
#include "SSMInterface.h"
-#include "SSMClient.h"
-#include "ISSMClientListener.h"
namespace APPMenu
{
ALL_DISCOMPORT = 2, HALF_DISCOMPORT, LITTLE_DISCOMPORT, ALL_COMPORT
} DIResult;
-class SSMTestApp: public ISSMClientListener
- , public IQueryEngineEvent
+class SSMTestApp: public IQueryEngineEvent
{
private:
- //SSMClient m_SSMClient;
SSMInterface m_SSMClient;
public:
void unregisterQuery();
/* operations from listener interface */
- void onRegisterQuery(const std::string &jsonData, SSMReturn &eCode);
SSMRESULT onQueryEngineEvent(int cqid, IDataReader *pResult);
};
#include "SSMTestApp.h"
+using namespace std;
+
SSMTestApp::SSMTestApp()
{
}
}
/* APP. Level Callback Function for Observer of client. */
-void SSMTestApp::onRegisterQuery(const std::string &jsonData, SSMReturn &eCode)
-{
- if (eCode == SSM_SUCCESS)
- {
- std::cout << jsonData << std::endl;
- }
- else
- {
- std::cout << "Response error: " << eCode << std::endl;
- }
-}
-
SSMRESULT SSMTestApp::onQueryEngineEvent(int cqid, IDataReader *pResult)
{
int dataCount = 0;
# service folder path.
FD_SSM=${ROOT_DIR}/service/soft-sensor-manager
-FD_SDK=${FD_SSM}/SDK
+FD_SDK=${FD_SSM}/SDK/cpp
FD_SSMCORE=${FD_SSM}/SSMCore
FD_SAMPLEAPP=${FD_SSM}/SampleApp
FD_SOFTSENSOR=${FD_SSM}/SoftSensorPlugin
OUTPUTS_DIR=${FD_BUILD}/linux/release
EXEC_DIR=${OUTPUTS_DIR}
SSXML_NAME="SoftSensorDescription.xml"
-SSM_LIB = libSSM.a
+SSM_LIB = libSSMSDK.a
SSMCORE_LIB=libSSMCore.a
# SoftSensorManager makefile path