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 _PropagationEngine_H_
21 #define _PropagationEngine_H_
23 #include "SSMInterface/SSMCore.h"
24 #include "Common/PlatformLayer.h"
25 #include "Common/InternalInterface.h"
26 #include "ConditionedQuery.h"
28 typedef std::map< std::string, std::vector< std::pair<ModelConditionVec, IConditionedQuery *> > >
32 * @class CPropagationEngine
33 * @brief CPropagationEngine Interface
34 * This class represents propagation engine that manages ContextModel's automation
38 class CPropagationEngine :
39 public CObjectRoot<CObjectMultiThreadModel>
40 , public IPropagationEngine
41 , public IContextModelAccessor
42 , public IThreadClient
43 , public IContextModelEvent
44 , public IResourceEvent
47 CObjectPtr<ITasker> m_pTasker;
48 CObjectPtr<IEvaluationEngine> m_pEvaluationEngine;
49 CObjectPtr<IContextModel> m_pRootModel;
51 CObjectPtr<IContextDataReader> m_pContextDataReader;
52 CObjectPtr<IContextRepository> m_pContextRepository;
54 std::map<std::string, IContextModel *> m_installedContextModel;
55 VirtualModelMap m_lookUpContextModel;
56 CSimpleMutex m_mtxContextModelList;
57 CSimpleMutex m_mtxLookUpList;
59 CObjectPtr<ISensingEngine> m_pSensingEngine;
61 CObjectPtr<IContextModel> m_pDeviceModel;
63 std::map<std::string, int> m_searchedSensorDataId;
65 SSMRESULT findContextModel(std::string modelName, IContextModel **ppContextModel);
67 SSMRESULT registerCondition(IContextModel *pContextModel, ModelConditionVec *pConditions,
68 IConditionedQuery *pConditionedQuery);
70 SSMRESULT registerVirtualCondition(std::string virtualContextModelName,
71 ModelConditionVec *pConditions, IConditionedQuery *pConditionedQuery);
73 SSMRESULT propagateNewModel(std::string newModelName, IContextModel *pContextModel);
75 SSMRESULT addResourceFromGetList();
77 //TODO: Install Context model from SSMResource
78 SSMRESULT installCurrentSensors();
80 SSMRESULT installContextModelFromISSMResource(ISSMResource *pSSMResource);
82 SSMRESULT installContextModel(IContextModel *pParentModel,
83 IContextModel::ConstructionType constructionType,
84 const char *modelName, ModelPropertyVec *pModelDescs, IContextModel **ppContextModel);
86 SSMRESULT recoverEngineFromDatabase();
88 SSMRESULT cleanUpRemoteDeviceInfo();
90 SSMRESULT initializeEngine();
92 void terminateEngine();
94 SSMRESULT updateDeviceInfo(ISSMResource *pSSMResource, int *deviceId);
97 SSMRESULT finalConstruct();
101 void onExecute(void *pArg);
103 void onTerminate(void *pArg);
106 * @fn onResourceEvent
107 * @brief Called when new device has discovered
109 * @param [in] RESOURCE_EVENT_TYPE eventType - Enumerator that represents Device's status
110 * @param [in] ISSMResource *pSSMResouce - NULL
111 * @param [in] std::string info - NULL
118 int onResourceEvent(RESOURCE_EVENT_TYPE eventType, ISSMResource *pSSMResource,
121 SSMRESULT queryInterface(const OID &objectID, IBase **ppObject)
123 if (ppObject == NULL)
124 return SSM_E_POINTER;
126 if (IsEqualOID(objectID, OID_IPropagationEngine))
128 IBase *pBase = (IPropagationEngine *)this;
134 return SSM_E_NOINTERFACE;
138 * @fn getContextModel
139 * @brief Retrieve ContextModel interface specified name
141 * @param [in] std::string modelName - ContextModel's name that looking for
142 * @param [out] IContextModel **ppContextModel - Interface pointer for retrieving
149 SSMRESULT getContextModel(std::string modelName, IContextModel **ppContextModel);
152 * @fn createConditionedQuery
153 * @brief Create Conditioned Query using conditions
155 * @param [in] IContextModel::ActivationType activationType - ActivationType for ContextModel's working strategy
156 * @param [in] QueryCondition *pQueryCondition - Conditions for data retrieving
157 * @param [in] IConditionedQueryEvent *pEvent - Event interface for Conditioned Result listening
158 * @param [out] IConditionedQuery **ppConditionedQuery - Interface for retrieving Conditioned Query
165 SSMRESULT createConditionedQuery(IContextModel::ActivationType activationType,
166 QueryCondition *pQueryCondition,
167 IConditionedQueryEvent *pEvent, IConditionedQuery **ppConditionedQuery);
170 * @fn onModelStatusChange
171 * @brief Called when ContextModel wants to activate or deactivate
173 * @param [in] IContextModel::Status newStatus - Context Model's new status
174 * @param [in] ISSMResource *pSSMResource - Instance of actual resource
175 * @param [in] IContextModel *pModel - Affected Context Model
182 SSMRESULT onModelStatusChange(IContextModel::Status newStatus, ISSMResource *pSSMResource,
183 IContextModel *pModel);
186 * @fn onQueryContextModel
187 * @brief Called when ContextModelAccessor wants to query installed ContextModel
189 * @param [in] std::string modelName - ContextModel name to find out
190 * @param [out] IContextModel **ppContextModel - Interface of quried ContextModel
197 SSMRESULT onQueryContextModel(std::string modelName, IContextModel **ppContextModel);