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 _ContextModel_H_
21 #define _ContextModel_H_
23 #include "SSMInterface/SSMCore.h"
24 #include "Common/PlatformLayer.h"
25 #include "Common/InternalInterface.h"
28 * @class CContextModel
29 * @brief CContextModel Interface
30 * This class represents Context Model
35 public CObjectRoot<CObjectMultiThreadModel>
36 , public IContextModel
37 , public IThreadClient
41 CObjectPtr<ITasker> m_pTasker;
42 CObjectPtr<IEvaluationEngine> m_pEvaluationEngine;
43 CObjectPtr<IContextModel> m_pParentModel;
44 ModelPropertyVec m_modelProperties;
45 //std::vector<IConditionedModel*> m_ConditionedModels;
47 std::string m_modelName;
48 IContextModelEvent *m_pContextModelEvent;
49 CSimpleMutex m_mtxActivationCount;
50 int m_activationCount;
52 std::map<std::string, std::pair<int, ISSMResource> > m_mapSSM;
53 std::map<int, IntVec> m_mapDeviceDataIds;
55 //DeviceDataId, RefCount
56 std::map<int, int> m_mapSubscribedDevice;
57 std::map<int, int> m_mapGetDevice;
59 ConstructionType m_constructionType;
61 std::string m_secLifeTime;
63 void registerSSMResource(IN ActivationType activationType, IN int targetDeviceDataId,
64 IN ISSMResource *pSSMResource);
66 void unregisterSSMResource(IN ActivationType activationType, IN int targetDeviceDataId,
67 IN ISSMResource *pSSMResource);
70 SSMRESULT finalConstruct();
76 * @brief Create new Context Model
78 * @param [in] ConstructionType constructionType - Construction Type that current model is created from external modules or internally created.
79 * @param [in] IContextModel *pParentModel - Parent Context Model that related to Model hierarchy.
80 * @param [in] std::string modelName - Represent model's name
81 * @param [in] ModelPropertyVec *pModelProperties - Represent model's properties that exposed to CQL
88 SSMRESULT create(IN ConstructionType constructionType, IN IContextModel *pParentModel,
89 IN std::string modelName, IN ModelPropertyVec *pModelProperties);
92 * @fn registerContextModelEvent
93 * @brief Register ContextModel's events like Activate or Deactivate
95 * @param [in] IContextModelEvent *pContextModelEvent - Event interface.
102 SSMRESULT registerContextModelEvent(IN IContextModelEvent *pContextModelEvent);
104 void onExecute(IN void *pArg);
106 void onTerminate(IN void *pArg);
110 * @brief Called when new context model data arrived
112 * @param [in] std::string deviceID - DeviceID that represents where the data comes.
113 * @param [in] TypeofEvent callType - Represent received data's type, streamed or single
114 * @param [in] std::vector<ContextData> ctxData - Context data
121 int onEvent(IN std::string deviceID, IN TypeofEvent callType, IN std::vector<ContextData> ctxData);
123 SSMRESULT queryInterface(const OID &objectID, IBase **ppObject)
125 if (ppObject == NULL)
126 return SSM_E_POINTER;
128 if (IsEqualOID(objectID, OID_IContextModel))
130 IBase *pBase = (IContextModel *)this;
136 return SSM_E_NOINTERFACE;
141 * @brief Get current model's id used for Evaluation Engine
154 * @brief Get current model's name
158 * @return std::string
163 std::string getModelName();
166 * @fn getConstructionType
167 * @brief Get current model's constructionType defined when created
171 * @return IContextModel::ConstructionType
176 ConstructionType getConstructionType();
179 * @fn getParentDataId
180 * @brief Get parent dataId related to model hierarchy
182 * @param [in] int dataId - DataId that current model's
183 * @param [in] IContextModel *pParentModel - Designated parent Context Model
184 * @param [out] int *pParentDataId - Designated parent Context Model's data's Id
191 SSMRESULT getParentDataId(IN int dataId, IN IContextModel *pParentModel, OUT int *pParentDataId);
195 * @brief Get child dataId related to model hierarchy
197 * @param [in] int dataId - DataId that current model's
198 * @param [in] IContextModel *pChildModel - Designated child Context Model
199 * @param [out] int *pParentDataId - Designated child Context Model's data's Id
206 SSMRESULT getChildDataId(IN int dataId, IN IContextModel *pChildModel, OUT IntVec *pChildDataIds);
210 * @brief Activate current model's working. Each call to activate will increase internal reference counter
212 * @param [in] ActivationType activationType - Specify current model's working type
213 * @param [in] int targetDeviceDataId - Specify target device's dataId
220 SSMRESULT activate(IN ActivationType activationType, IN int targetDeviceDataId);
224 * @brief Deactivate current model's working. Each call to deactivate will decrease internal reference counter\n
225 * and finally deactivated when counter is 0
227 * @param [in] ActivationType activationType - Specify current model's working type
228 * @param [in] int targetDeviceDataId - Specify target device's dataId
235 SSMRESULT deactivate(IN ActivationType activationType, IN int targetDeviceDataId);
237 //SSMRESULT GetModelSchema(OUT ModelPropertyVec *pModelProperties);
241 * @brief Add model data to Context Model
243 * @param [in] int parentDataId - Specify current model's parent Context Model's dataId
244 * @param [in] ModelPropertyVec *pData - Packed data for adding
245 * @param [out] int *pDataId - Returned dataId that newly added
252 SSMRESULT addModelData(IN int parentDataId, IN ModelPropertyVec *pData, OUT int *pDataId);
255 * @fn updateModelData
256 * @brief Update model data to Context Model
258 * @param [in] int dataId - DataId that provided AddModelData's execution
259 * @param [in] ModelPropertyVec *pData - Packed data for updating
266 SSMRESULT updateModelData(IN int dataId, IN ModelPropertyVec *pData);
269 * @fn deleteModelData
270 * @brief Delete model data using given index
272 * @param [in] int dataId - DataId that provided AddModelData's execution
279 SSMRESULT deleteModelData(IN int dataId);
283 * @brief Get model data
285 * @param [in] int dataId - DataId that provided AddModelData's execution
286 * @param [out] ModelPropertyVec *pData - Packed data
293 SSMRESULT getModelData(IN int dataId, OUT ModelPropertyVec *pData);
296 * @fn getModelDataSet
297 * @brief Get model data set
299 * @param [in] int startIndex - Starting index of model data
300 * @param [in] int count - Number of data to retrieve
301 * @param [out] vector<ModelPropertyVec> *pData - Packed data
302 * @param [out] int *pLastIndex - Index of last data
309 SSMRESULT getModelDataSet(IN int startIndex, IN int count,
310 OUT std::vector<ModelPropertyVec> *pDataSet, OUT int *pLastIndex);
313 * @fn createConditionedModel
314 * @brief Create Conditioned Model for data searching or triggering
316 * @param [in] ModelConditionVec *pModelConditionVec - Conditions that searching or triggering
317 * @param [out] IConditionedModel **ppConditionedModel - Created Conditioned Model interface
324 SSMRESULT createConditionedModel(IN ModelConditionVec *pModelConditionVec,
325 OUT IConditionedModel **ppConditionedModel);
327 //SSMRESULT CleanUpModelData();
330 * @fn addSSMResourceAndDeviceDataId
331 * @brief Add SSM resources with other informations - Internal use only
333 * @param [in] std::string deviceId - deviceId that used D2D communication
334 * @param [in] int deviceDataId - Device's dataId that where SSMResource come from
335 * @param [in] ISSMResource *pSSMResource - SSMResource for adding
342 void addSSMResourceAndDeviceDataId(IN std::string deviceId, IN int deviceDataId,
343 IN ISSMResource *pSSMResource);
347 * @brief Sets current model data's lifeTime
349 * @param [in] int seconds - model data's lifeTime
356 void setLifeTime(std::string seconds);