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 _ContextExecutor_H_
21 #define _ContextExecutor_H_
23 #include "SSMInterface/SSMCore.h"
24 #include "SSMInterface/SSMModelDefinition.h"
25 #include "Common/PlatformLayer.h"
26 #include "Common/InternalInterface.h"
28 #include "ContextRepository.h"
31 * @class CContextExecutor
32 * @brief Class for execute context model.
33 * Delegate requested context to lower layer.
34 * Execute context model.
38 class CContextExecutor :
39 public CObjectRoot<CObjectMultiThreadModel>
40 , public IContextExecutor
41 , public IResourceEvent
42 , public IThreadClient
45 CObjectPtr<ITasker> m_pTasker;
47 CObjectPtr<IContextRepository> m_pContextRepository;
49 CObjectPtr<IContextDataReader> m_pContextDataReader;
52 * @brief Sensor data from primitive sensors
54 std::map<std::string, std::vector<ContextData> > m_storedPrimitiveSensorData;
57 * @brief key = primitive, soft sensor / values = soft sensors that has key in the input list
59 std::map<std::string, std::vector<std::string> > m_relatedSoftSensor;
62 * @brief requested high layer's callback data.(IEvent instance, deviceId, call type)
64 std::map<std::string, CallbackData> m_requestedContextCallback;
67 * @brief registered high layer's context resource data.
69 std::map<std::string, ISSMResource *> m_registeredResources;
72 * @brief context model event of context model library
74 std::map<std::string, ICtxEvent *> m_ctxEventList;
77 * @brief context model library list
79 std::map<std::string, void *> m_libraryList;
82 //CSimpleMutex m_mtxRequestedContextCallback;
84 CSimpleMutex m_mtxLibraryIO, m_mtxUserDataIO;
86 std::map<std::string, std::vector<CallbackData> > m_mapResourceLookup;
90 SSMRESULT finalConstruct();
93 SSMRESULT queryInterface(const OID &objectID, IBase **ppObject)
98 if (IsEqualOID(objectID, OID_IContextExecutor))
100 IBase *pBase = (IContextExecutor *)this;
106 return SSM_E_NOINTERFACE;
110 * @fn registerCallback
111 * @brief ICtxDelegate Interface.
112 * If context model call this function, then get model's instance
114 * @param [in] ICtxEvent *pEvent - context model's ICtxEvent instance.
122 void registerCallback(ICtxEvent *pEvent);
126 * @brief ICtxDelegate Interface.
127 * Get context model's result and delegate to upper layer.
129 * @param [in] std::vector<ContextData> contextData - context model's result
136 void addOutput(std::vector<ContextData> contextData);
139 * @fn getDataFromDatabase
140 * @brief ICtxDelegate Interface.
141 * Get context model's historical data
143 * @param [in] std::string modelName - Model name that looking for
144 * @param [in] int startIndex - Starting index of model data
145 * @param [in] int count - Number of data to retrieve
146 * @param [out] std::vector<ContextData> *data - data from database
147 * @param [out] int *pLastIndex - Index of last data
154 void getDataFromDatabase(std::string modelName, int startIndex, int count,
155 std::vector<ContextData> *data, int *pLastIndex);
159 * @brief IEvent Interface.
160 * Call from lower layer when lower context data generated.
162 * @param [in] std::string deviceID - caller device UUID.
163 * @param [in] TypeofEvent callType - context event type.
164 * @param [in] std::vector<ContextData> ctxData - context data
166 * @return int - function result status
172 int onEvent(std::string deviceID, TypeofEvent callType, std::vector<ContextData> ctxData);
175 * @fn registerContext
176 * @brief Register context model request.
178 * @param [in] TypeofEvent callType - Type of event. SSM_ONCE or SSM_REPEAT
179 * @param [in] ISSMResource *pSSMResource - Requested context model resource.
180 * @param [in] IEvent *pEvent - IEvent class for callback.
188 void registerContext(TypeofEvent callType, ISSMResource *pSSMResouce, IEvent *pEvent);
191 * @fn unregisterContext
192 * @brief Unregister context model request.
194 * @param [in] TypeofEvent callType - Type of event. SSM_ONCE or SSM_REPEAT
195 * @param [in] ISSMResource *pSSMResource - Requested context model resource.
196 * @param [in] IEvent *pEvent - IEvent class for callback.
204 void unregisterContext(TypeofEvent callType, ISSMResource *pSSMResource, IEvent *pEvent);
206 void onExecute(void *pArg);
207 void onTerminate(void *pArg);
208 int onResourceEvent(RESOURCE_EVENT_TYPE eventType, ISSMResource *pSSMResource,
212 SSMRESULT findString(std::vector<ISSMResource *> *sList, const std::string str,
213 ISSMResource **ppResource);
214 std::map<std::string, std::vector<ContextData> > getPreparedContextList(
215 std::string primitiveSensor);
216 void runLogic(std::vector<ContextData> inputData, std::string softSensor);