1 /******************************************************************
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ******************************************************************/
21 * @file CoreController.java
23 * @brief This file provides a class containing a set of APIs for soft sensor manager
28 package org.iotivity.service.ssm;
30 import java.util.List;
33 * @class CoreController
34 * @brief This class provides a set of APIs relating to soft sensor manager It
35 * contains utility API's for DataReader, QueryEngine and SSMInterface
38 public class CoreController {
41 String workingPath = System.getProperty("user.dir");
43 // for android: not complete method
44 if (System.getProperty("os.name").toLowerCase().equals("linux")) {
45 System.loadLibrary("gnustl_shared");
46 System.loadLibrary("oc_logger");
47 System.loadLibrary("connectivity_abstraction");
48 System.loadLibrary("octbstack");
49 System.loadLibrary("oc");
50 System.loadLibrary("SSMCore");
52 System.load(workingPath + "SSMCore_Windows.dll");
54 } catch (UnsatisfiedLinkError e) {
55 System.out.println(e.getMessage());
59 static private CoreController coreController;
62 * Return instance of CoreController.
64 * @return CoreController - instance of this class
66 public static CoreController getInstance() {
67 if (coreController == null)
68 coreController = new CoreController();
70 return coreController;
74 * Initialize a framework using the given configuration
76 * @param xmlDescription
77 * - Framework specifications described in XML format
81 public native void initializeSSMCore(String xmlDescription)
85 * Starts the framework that allows other devices to discover and
86 * communicate with the SSMCore and underlying query engine.
90 public native void startSSMCore() throws Exception;
93 * Stops the framework and terminate all communications.
97 public native void stopSSMCore() throws Exception;
100 * Terminate the framework, return all allocated resources
104 public native void terminateSSMCore() throws Exception;
107 * Creates an instance of the Query Engine
109 * @return QueryEngine - QueryEngine object created
111 public native QueryEngine createQueryEngine() throws Exception;
114 * Release the QueryEngine object.
117 * - QueryEngine instance to be released
119 * @return int - success or failure result
121 public native int releaseQueryEngine(QueryEngine queryEngine);
124 * Execute the query with the QueryEngine and return ContextQuery ID for the
127 * @param pQueryEngineInstance
128 * - instance(created on creation of the QueryEngine) of the
129 * query engine with which the query is to be executed
131 * @param contextQuery
132 * - query string to be executed
134 * @return int - ID of context query executed
136 public native int executeContextQuery(int pQueryEngineInstance,
137 String contextQuery) throws Exception;
140 * Register QueryEngineEvent to QueryEngine.
142 * @param pQueryEngineInstance
143 * - instance(created on creation of the QueryEngine) of the
144 * query engine with which the query is to be registered
146 * @param queryEngineEvent
147 * - the event class to receive QueryEngine events
151 public native void registerQueryEvent(int pQueryEngineInstance,
152 IQueryEngineEvent queryEngineEvent);
155 * Kill the registered ContextQuery corresponding to the cqid
157 * @param pQueryEngineInstance
158 * - instance(created on creation of the QueryEngine) of the
159 * query engine with which the query is to be terminated
162 * - ContextQuery ID of the query to be terminated
166 public native void killContextQuery(int pQueryEngineInstance, int cqid)
170 * Get the affected DataId. ContextModel has plenty of data so returned data
171 * is matched from given condition which in this case is the model data
174 * @param pIModelDataInstance
175 * - instance(created on creation of the ModelData) of the model
176 * data for which Data ID is to be returned
178 * @return int - the affected DataId
180 public native int getDataId(int pIModelDataInstance);
183 * ContextModel has at least one property that contains data \n property is
184 * described from its specification.
186 * @param pIModelDataInstance
187 * - instance(created on creation of the ModelData) of the model
188 * data for which property count is to be returned
190 * @return @return int - number of properties
192 public native int getPropertyCount(int pIModelDataInstance);
195 * Retrieve the name of the property using the given index
197 * @param pIModelDataInstance
198 * - instance(created on creation of the ModelData) of the model
199 * data for which property name is to be returned
201 * @param propertyIndex
202 * - index of property to read
204 * @return String - property name
206 public native String getPropertyName(int pIModelDataInstance,
210 * Retrieve the value of the property using the given index
212 * @param pIModelDataInstance
213 * - instance(created on creation of the ModelData) of the model
214 * data for which property value is to be returned
216 * @param propertyIndex
217 * - index of property to read
219 * @return String - property value
221 public native String getPropertyValue(int pIModelDataInstance,
225 * Get affected context models. The CQL(context query language) can specify
226 * multiple ContextModels for retrieving data so a list of string of
227 * affected context models is returned
229 * @param pDataReaderInstance
230 * - instance(created on creation of the DataReader) of the data
231 * reader class object
233 * @return List<String> - affected ContextModel list
235 public native List<String> getAffectedModels(int pDataReaderInstance);
238 * Get affected model data count. There can be multiple data models existing
239 * from the given condition, return the count.
241 * @param pDataReaderInstance
242 * - instance(created on creation of the DataReader) of the data
243 * reader class object
246 * - affected ContextModel name
248 * @return int - affected dataId count
250 public native int getModelDataCount(int pDataReaderInstance,
251 String modelName) throws Exception;
254 * Get actual Context Model data
256 * @param pDataReaderInstance
257 * - instance(created on creation of the DataReader) of the data
258 * reader class object
261 * - affected ContextModel name
264 * - affected dataId index
266 * @return ModelData - affected ContextModel data reader
268 public native ModelData getModelData(int pDataReaderInstance,
269 String modelName, int dataIndex) throws Exception;
272 * To register the report receiver to receive messages
274 * @param reportReceiver
275 * - report receiver instance
279 public native void registerReportReceiver(IReportReceiver reportReceiver);