Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / service / soft-sensor-manager / SDK / java / org / iotivity / service / ssm / CoreController.java
1 /******************************************************************
2  *
3  * Copyright 2015 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  ******************************************************************/
20 /**
21  * @file    CoreController.java
22  *
23  * @brief    This file provides a class containing a set of APIs for soft sensor manager
24  *          application.
25  *
26  */
27
28 package org.iotivity.service.ssm;
29
30 import java.util.List;
31
32 /**
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
36  *        classes.
37  */
38 public class CoreController {
39     static {
40         try {
41             String workingPath = System.getProperty("user.dir");
42
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");
51             } else {
52                 System.load(workingPath + "SSMCore_Windows.dll");
53             }
54         } catch (UnsatisfiedLinkError e) {
55             System.out.println(e.getMessage());
56         }
57     }
58
59     static private CoreController coreController;
60
61     /**
62      * Return instance of CoreController.
63      * 
64      * @return CoreController - instance of this class
65      */
66     public static CoreController getInstance() {
67         if (coreController == null)
68             coreController = new CoreController();
69
70         return coreController;
71     }
72
73     /**
74      * Initialize a framework using the given configuration
75      * 
76      * @param xmlDescription
77      *            - Framework specifications described in XML format
78      * 
79      * @return void
80      */
81     public native void initializeSSMCore(String xmlDescription)
82             throws Exception;
83
84     /**
85      * Starts the framework that allows other devices to discover and
86      * communicate with the SSMCore and underlying query engine.
87      * 
88      * @return void
89      */
90     public native void startSSMCore() throws Exception;
91
92     /**
93      * Stops the framework and terminate all communications.
94      * 
95      * @return void
96      */
97     public native void stopSSMCore() throws Exception;
98
99     /**
100      * Terminate the framework, return all allocated resources
101      * 
102      * @return void
103      */
104     public native void terminateSSMCore() throws Exception;
105
106     /**
107      * Creates an instance of the Query Engine
108      * 
109      * @return QueryEngine - QueryEngine object created
110      */
111     public native QueryEngine createQueryEngine() throws Exception;
112
113     /**
114      * Release the QueryEngine object.
115      * 
116      * @param queryEngine
117      *            - QueryEngine instance to be released
118      * 
119      * @return int - success or failure result
120      */
121     public native int releaseQueryEngine(QueryEngine queryEngine);
122
123     /**
124      * Execute the query with the QueryEngine and return ContextQuery ID for the
125      * query
126      * 
127      * @param pQueryEngineInstance
128      *            - instance(created on creation of the QueryEngine) of the
129      *            query engine with which the query is to be executed
130      * 
131      * @param contextQuery
132      *            - query string to be executed
133      * 
134      * @return int - ID of context query executed
135      */
136     public native int executeContextQuery(int pQueryEngineInstance,
137             String contextQuery) throws Exception;
138
139     /**
140      * Register QueryEngineEvent to QueryEngine.
141      * 
142      * @param pQueryEngineInstance
143      *            - instance(created on creation of the QueryEngine) of the
144      *            query engine with which the query is to be registered
145      * 
146      * @param queryEngineEvent
147      *            - the event class to receive QueryEngine events
148      * 
149      * @return void
150      */
151     public native void registerQueryEvent(int pQueryEngineInstance,
152             IQueryEngineEvent queryEngineEvent);
153
154     /**
155      * Kill the registered ContextQuery corresponding to the cqid
156      * 
157      * @param pQueryEngineInstance
158      *            - instance(created on creation of the QueryEngine) of the
159      *            query engine with which the query is to be terminated
160      * 
161      * @param cqid
162      *            - ContextQuery ID of the query to be terminated
163      * 
164      * @return void
165      */
166     public native void killContextQuery(int pQueryEngineInstance, int cqid)
167             throws Exception;
168
169     /**
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
172      * object instance
173      * 
174      * @param pIModelDataInstance
175      *            - instance(created on creation of the ModelData) of the model
176      *            data for which Data ID is to be returned
177      * 
178      * @return int - the affected DataId
179      */
180     public native int getDataId(int pIModelDataInstance);
181
182     /**
183      * ContextModel has at least one property that contains data \n property is
184      * described from its specification.
185      * 
186      * @param pIModelDataInstance
187      *            - instance(created on creation of the ModelData) of the model
188      *            data for which property count is to be returned
189      * 
190      * @return @return int - number of properties
191      */
192     public native int getPropertyCount(int pIModelDataInstance);
193
194     /**
195      * Retrieve the name of the property using the given index
196      * 
197      * @param pIModelDataInstance
198      *            - instance(created on creation of the ModelData) of the model
199      *            data for which property name is to be returned
200      * 
201      * @param propertyIndex
202      *            - index of property to read
203      * 
204      * @return String - property name
205      */
206     public native String getPropertyName(int pIModelDataInstance,
207             int propertyIndex);
208
209     /**
210      * Retrieve the value of the property using the given index
211      * 
212      * @param pIModelDataInstance
213      *            - instance(created on creation of the ModelData) of the model
214      *            data for which property value is to be returned
215      * 
216      * @param propertyIndex
217      *            - index of property to read
218      * 
219      * @return String - property value
220      */
221     public native String getPropertyValue(int pIModelDataInstance,
222             int propertyIndex);
223
224     /**
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
228      * 
229      * @param pDataReaderInstance
230      *            - instance(created on creation of the DataReader) of the data
231      *            reader class object
232      * 
233      * @return List<String> - affected ContextModel list
234      */
235     public native List<String> getAffectedModels(int pDataReaderInstance);
236
237     /**
238      * Get affected model data count. There can be multiple data models existing
239      * from the given condition, return the count.
240      * 
241      * @param pDataReaderInstance
242      *            - instance(created on creation of the DataReader) of the data
243      *            reader class object
244      * 
245      * @param modelName
246      *            - affected ContextModel name
247      * 
248      * @return int - affected dataId count
249      */
250     public native int getModelDataCount(int pDataReaderInstance,
251             String modelName) throws Exception;
252
253     /**
254      * Get actual Context Model data
255      * 
256      * @param pDataReaderInstance
257      *            - instance(created on creation of the DataReader) of the data
258      *            reader class object
259      * 
260      * @param modelName
261      *            - affected ContextModel name
262      * 
263      * @param dataIndex
264      *            - affected dataId index
265      * 
266      * @return ModelData - affected ContextModel data reader
267      */
268     public native ModelData getModelData(int pDataReaderInstance,
269             String modelName, int dataIndex) throws Exception;
270
271     /**
272      * To register the report receiver to receive messages
273      * 
274      * @param reportReceiver
275      *            - report receiver instance
276      * 
277      * @return void
278      */
279     public native void registerReportReceiver(IReportReceiver reportReceiver);
280 }