1 /******************************************************************
3 * Copyright 2014 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 ******************************************************************/
20 #ifndef _EvaluationEngine_H_
21 #define _EvaluationEngine_H_
23 #include "SSMInterface/SSMCore.h"
24 #include "Common/PlatformLayer.h"
25 #include "Common/sqlite3.h"
26 #include "Common/InternalInterface.h"
29 * @class CEvaluationEngine
30 * @brief CEvaluationEngine Interface
31 * This class represents Evaluation Engine
35 class CEvaluationEngine :
36 public CObjectRoot<CObjectMultiThreadModel>
37 , public IEvaluationEngine
38 , public IThreadClient
43 CSimpleMutex m_mtxTriggerId;
44 std::map<int, IEvaluationEngineEvent *> m_mapTriggers;
45 CSimpleMutex m_mtxDataRelation;
46 CObjectPtr<ITasker> m_pTasker;
48 SSMRESULT executeSQL_NoReturn(IN std::string strSQL);
50 SSMRESULT executeSQL_IntReturn(IN std::string strSQL, OUT int *pResult);
52 static void onSQLTrigger(IN sqlite3_context *context, IN int argc, IN sqlite3_value **argv);
54 SSMRESULT initializeEngine();
56 void terminateEngine();
59 SSMRESULT finalConstruct();
63 void onExecute(IN void *pArg);
65 void onTerminate(IN void *pArg);
68 * @fn onWatcherTriggered
69 * @brief Called when newly added data meets the conditions
71 * @param [in] int triggerId - Trigger id, which condition is triggered
72 * @param [in] int dataId - Data id, which data meets the conditions
79 SSMRESULT onWatcherTriggered(IN int triggerId, IN int dataId);
81 SSMRESULT queryInterface(const OID &objectID, IBase **ppObject)
86 if (IsEqualOID(objectID, OID_IEvaluationEngine))
88 IBase *pBase = (IEvaluationEngine *)this;
94 return SSM_E_NOINTERFACE;
99 * @brief Create new context model
101 * @param [in] int parentModelId - Parent Context Model id that related to Model hierarchy.
102 * @param [in] const char *newModelName - Represent model's name
103 * @param [in] ModelPropertyVec *pModelProperties - Represent model's properties that exposed to CQL
104 * @param [out] int *pModelId - Created model's id
111 SSMRESULT createModel(IN int parentModelId, IN const char *newModelName,
112 IN ModelPropertyVec *pModelDescs, OUT int *pModelId);
116 * @brief Add model data to Context Model
118 * @param [in] int modelId - model id that created CreateModel's execution.
119 * @param [in] int parentModelId - parent model id that created CreateModel's execution.
120 * @param [in] int parentDataId - Specify current model's parent Context Model's dataId
121 * @param [in] ModelPropertyVec *pData - Packed data for adding
122 * @param [out] int *pDataId - Returned dataId that newly added
129 SSMRESULT addModelData(IN int modelId, IN int parentModelId, IN int parentDataId,
130 IN ModelPropertyVec *pModelValues, OUT int *pDataId);
133 * @fn updateModelData
134 * @brief Update model data to Context Model
136 * @param [in] int modelId - model id that created CreateModel's execution.
137 * @param [in] int dataId - DataId that provided AddModelData's execution
138 * @param [in] ModelPropertyVec *pData - Packed data for updating
145 SSMRESULT updateModelData(IN int modelId, IN int dataId, IN ModelPropertyVec *pModelValues);
147 //SSMRESULT DeleteModel(IN int modelId);
150 * @fn deleteModelData
151 * @brief Delete model data using given index
153 * @param [in] int modelId - model id that created CreateModel's execution.
154 * @param [in] int dataId - DataId that provided AddModelData's execution
161 SSMRESULT deleteModelData(IN int modelId, IN int dataId);
165 * @brief Get model data
167 * @param [in] int modelId - model id that created CreateModel's execution.
168 * @param [in] int dataId - DataId that provided AddModelData's execution
169 * @param [out] ModelPropertyVec *pData - Packed data
176 SSMRESULT getModelData(IN int modelId, IN int dataId, OUT ModelPropertyVec *pModelProperties);
179 * @fn getModelDataSet
180 * @brief Get model data set
182 * @param [in] int modelId - model id that created CreateModel's execution.
183 * @param [in] int startIndex - Starting index of model data
184 * @param [in] int count - Number of data to retrieve
185 * @param [out] vector<ModelPropertyVec> *pDataSet - Packed data
186 * @param [out] int *pLastIndex - Index of last data
193 SSMRESULT getModelDataSet(IN int modelId, IN int startIndex, IN int count,
194 OUT std::vector<ModelPropertyVec> *pDataSet, OUT int *pLastIndex);
196 //SSMRESULT GetModelSchema(IN int modelId, OUT ModelPropertyVec *pModelProperties);
199 * @fn getConditionedModelData
200 * @brief Get affected data from given conditions
202 * @param [in] int modelId - model id that created CreateModel's execution.
203 * @param [in] ModelConditionVec *pModelConditions - Conditions for data retrieving
204 * @param [out] IntVec *pDataIds - Searched dataId sets.
211 SSMRESULT getConditionedModelData(IN int modelId, IN ModelConditionVec *pModelConditions,
212 OUT IntVec *pDataIds);
216 * @brief Watching data from given conditions
218 * @param [in] int modelId - model id that created CreateModel's execution.
219 * @param [in] ModelConditionVec *pModelConditions - Conditions for data triggering
220 * @param [in] IEvaluationEngineEvent *pEvaluationEngineEvent - Event interface where triggered event listening
221 * @param [out] int *pTriggerId - Identifier which trigger is activated
228 SSMRESULT watchModelData(IN int modelId, IN ModelConditionVec *pModelConditions,
229 IN IEvaluationEngineEvent *pEvaluationEngineEvent, OUT int *pTriggerId);
232 * @fn dropWatchModelData
233 * @brief Stop watching data
235 * @param [in] int triggerId - Identifier which trigger to drop
242 SSMRESULT dropWatchModelData(IN int triggerId);
245 * @fn getParentDataId
246 * @brief Get parent dataId related to model hierarchy
248 * @param [in] int modelId - model id that created CreateModel's execution.
249 * @param [in] int dataId - DataId that current model's
250 * @param [in] int parentModelId - Designated parent Context Model's id
251 * @param [out] int *pParentDataId - Designated parent Context Model's data's Id
258 SSMRESULT getParentDataId(IN int modelId, IN int dataId, IN int parentModelId,
259 OUT int *pParentDataId);
263 * @brief Get child dataId related to model hierarchy
265 * @param [in] int modelId - model id that created CreateModel's execution.
266 * @param [in] int dataId - DataId that current model's
267 * @param [in] int childModelId - Designated child Context Model's id
268 * @param [out] IntVec *pChildDataIds - Designated child Context Model's data's Id
275 SSMRESULT getChildDataId(IN int modelId, IN int dataId, IN int childModelId,
276 OUT IntVec *pChildDataIds);
278 //SSMRESULT GetPathToRoot(IN int currentModelId, OUT IntVec *pPath);
280 //SSMRESULT GetModelId(IN const char *modelName, OUT int *pModelId);
282 //SSMRESULT GetModelHierarchy(IN int rootModelId, OUT StringVec *pPath);
284 //SSMRESULT GetDataHierarchy(IN int rootModelId, IN int dataId, OUT StringVec *pPath);