Imported Upstream version 0.9.1
[platform/upstream/iotivity.git] / service / soft-sensor-manager / SSMCore / src / SensorProcessor / SensingEngine.h
1 /******************************************************************
2 *
3 * Copyright 2014 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 #ifndef _ResponseReactor_H_
21 #define _ResponseReactor_H_
22
23 #include "SSMInterface/SSMCore.h"
24 #include "Common/PlatformLayer.h"
25 #include "Common/InternalInterface.h"
26
27 /**
28  * @class    CSensingEngine
29  * @brief    Class for implementing main abstration of SensorProcessor
30  *
31  *
32  * @see
33  */
34 class CSensingEngine :
35     public CObjectRoot<CObjectMultiThreadModel>
36     , public ISensingEngine
37 {
38     private:
39         CObjectPtr<IContextRepository>  m_pContextRepository;
40         CObjectPtr<IContextExecutor>    m_pContextExecutor;
41
42         /**
43         * @brief requested high layer's callback data.(IEvent instance, deviceId, call type)
44         */
45         std::map<std::string, CallbackData > m_requestedCallbackData;
46
47         /**
48         * @brief Context model data from lower layer(OnEvent Callback)
49         */
50         std::map<std::string, std::vector<ContextData> > m_storedLowerContextData;
51
52         CSimpleMutex                        m_mtxRequestedContextData;
53         CSimpleMutex                        m_mtxUnregisterContext;
54
55     public:
56         SSMRESULT finalConstruct();
57         void finalRelease();
58
59         SSMRESULT queryInterface(const OID &objectID, IBase **ppObject)
60         {
61             if (ppObject == NULL)
62                 return SSM_E_POINTER;
63
64             if (IsEqualOID(objectID, OID_ISensingEngine))
65             {
66                 IBase *pBase = this;
67                 pBase->addRef();
68                 *ppObject = pBase;
69                 return SSM_S_OK;
70             }
71             else if (IsEqualOID(objectID, OID_IContextRepository))
72             {
73                 IBase *pBase = this;
74                 pBase->addRef();
75                 *ppObject = m_pContextRepository;
76                 return SSM_S_OK;
77             }
78
79             return SSM_E_NOINTERFACE;
80         }
81
82         /**
83         * @fn           registerContext
84         * @brief        Register context model request.
85         *
86         * @param        [in]  TypeofEvent callType -  Type of event. SSM_ONCE or SSM_REPEAT
87         * @param        [in]  ISSMResource *pSSMResource -  Requested context model resource.
88         * @param        [in]  IEvent *pEvent -  IEvent class for callback.
89         *
90         * @return       SSMRESULT
91         *
92         * @warning
93         * @exception
94         * @see
95         */
96         SSMRESULT registerContext(TypeofEvent callType, ISSMResource *pSSMResource,
97                                   IEvent *pEvent);
98
99         /**
100         * @fn           unregisterContext
101         * @brief        Unregister context model request.
102         *
103         * @param        [in]  TypeofEvent callType -  Type of event. SSM_ONCE or SSM_REPEAT
104         * @param        [in]  ISSMResource *pSSMResource -  Requested context model resource.
105         * @param        [in]  IEvent *pEvent -  IEvent class for callback.
106         *
107         * @return       SSMRESULT
108         *
109         * @warning
110         * @exception
111         * @see
112         */
113         SSMRESULT  unregisterContext(TypeofEvent callType, ISSMResource *pSSMResource,
114                                      IEvent *pEvent);
115
116         /**
117         * @fn           getList
118         * @brief        Get context model list
119         *
120         * @param        [out]  std::vector<ISSMResource> *pList - ISSMResource vector of low level context models or high level context models.
121         *
122         * @return       SSMRESULT
123         *
124         * @warning
125         * @exception
126         * @see
127         */
128         SSMRESULT getList(std::vector<ISSMResource *> *pList);
129
130         /**
131         * @fn           onEvent
132         * @brief        IEvent Interface.
133         *               Call from executor when context model data generated.
134         *
135         * @param        [in]  std::string name - caller Resource name.
136         * @param        [in]  TypeofEvent callType -  context event type.
137         * @param        [in]  std::vector<ContextData> ctxData -  context data
138         *
139         * @return       int - function result status
140         *
141         * @warning
142         * @exception
143         * @see
144         */
145         int onEvent(std::string name, TypeofEvent callType, std::vector<ContextData> ctxData);
146 };
147 #endif