iotivity 0.9.0
[platform/upstream/iotivity.git] / service / soft-sensor-manager / SSMCore / src / QueryProcessor / ConditionedModel.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 _ConditionedModel_H_
21 #define _ConditionedModel_H_
22
23 #include "SSMInterface/SSMCore.h"
24 #include "Common/PlatformLayer.h"
25 #include "Common/InternalInterface.h"
26
27 /**
28 * @class    CConditionedModel
29 * @brief    CConditionedModel Interface
30 *            This class represents Context Model's data search from given conditions
31 *
32 * @see
33 */
34 class CConditionedModel :
35     public CObjectRoot<CObjectMultiThreadModel>
36     , public IConditionedModel
37     , public IEvaluationEngineEvent
38 {
39     private:
40         CObjectPtr<IEvaluationEngine>           m_pEvaluationEngine;
41         CObjectPtr<IContextModel>               m_pBaseModel;
42         ModelConditionVec                       m_watchCondition;
43         IConditionedModelEvent                  *m_pConditionedModelEvent;
44         int                                     m_triggerId;
45         CSimpleMutex                            m_mtxConditionedData;
46         std::list<int>                          m_triggeredDataIds;
47         IntVec                                  m_affectedDataIds;
48
49     public:
50         SSMRESULT finalConstruct();
51
52         void finalRelease();
53
54         /**
55         * @fn     create
56         * @brief Create Conditioned Model class using conditions.
57         *
58         * @param [in] IContextModel *pBaseModel - Base Context Model interface for Conditioned data reading
59         * @param [in] ModelConditionVec *pModelConditions - Conditions for data retrieving
60         *
61         * @return SSMRESULT
62         * @warning
63         * @exception
64         * @see
65         */
66         SSMRESULT create(IN IContextModel *pBaseModel, IN ModelConditionVec *pModelConditions);
67
68         /**
69         * @fn     onWatchModelData
70         * @brief Called when Model data meets given conditions.
71         *
72         * @param [in] int triggerId - Trigger id.
73         * @param [in] int dataId - Affected data's Id
74         *
75         * @return SSMRESULT
76         * @warning
77         * @exception
78         * @see
79         */
80         SSMRESULT onWatchModelData(IN int triggerId, IN int dataId);
81
82         SSMRESULT queryInterface(const OID &objectID, IBase **ppObject)
83         {
84             if (ppObject == NULL)
85                 return SSM_E_POINTER;
86
87             if (IsEqualOID(objectID, OID_IConditionedModel))
88             {
89                 IBase *pBase = (IConditionedModel *)this;
90                 pBase->addRef();
91                 *ppObject = pBase;
92                 return SSM_S_OK;
93             }
94
95             return SSM_E_NOINTERFACE;
96         }
97
98         /**
99         * @fn     getBaseContextModel
100         * @brief Get base Context Model interface
101         *
102         * @param [out] IContextModel **ppBaseContextModel - Interface pointer for retrieving base Context Model interface.
103         *
104         * @return SSMRESULT
105         * @warning
106         * @exception
107         * @see
108         */
109         SSMRESULT getBaseContextModel(OUT IContextModel **ppBaseContextModel);
110
111         /**
112         * @fn     registerConditionedModelEvent
113         * @brief Register for receiving triggered event from given conditions
114         *
115         * @param [in] IConditionedModelEvent *pConditionedModelEvent - Interface for listening events.
116         *
117         * @return SSMRESULT
118         * @warning
119         * @exception
120         * @see
121         */
122         SSMRESULT registerConditionedModelEvent(IN IConditionedModelEvent *pConditionedModelEvent);
123
124         /**
125         * @fn     activateTrigger
126         * @brief Activate trigger using given conditions
127         *
128         * @param [out] int *pTriggerId - Activated trigger id.
129         *
130         * @return SSMRESULT
131         * @warning
132         * @exception
133         * @see
134         */
135         SSMRESULT activateTrigger(OUT int *pTriggerId);
136
137         /**
138         * @fn     deactivateTrigger
139         * @brief Deactivate trigger that activated
140         *
141         * @param NONE
142         *
143         * @return SSMRESULT
144         * @warning
145         * @exception
146         * @see
147         */
148         SSMRESULT deactivateTrigger();
149
150         /**
151         * @fn     hasAffectedData
152         * @brief Quries if current Conditioned Model has affected data
153         *
154         * @param NONE
155         *
156         * @return bool
157         * @warning
158         * @exception
159         * @see
160         */
161         bool hasAffectedData();
162
163         /**
164         * @fn     getAffectedData
165         * @brief Get affected data from given conditions includes triggered data
166         *
167         * @param [out] IntVec   *pDataIds - Affected dataId sets.
168         *
169         * @return SSMRESULT
170         * @warning
171         * @exception
172         * @see
173         */
174         SSMRESULT getAffectedData(OUT IntVec *pDataIds);
175
176         /**
177         * @fn     getWatchCondition
178         * @brief Get watching conditions created from Context Model
179         *
180         * @param [out] ModelConditionVec *pModelConditions - Affected dataId sets.
181         *
182         * @return SSMRESULT
183         * @warning
184         * @exception
185         * @see
186         */
187         SSMRESULT getWatchCondition(OUT ModelConditionVec *pModelConditions);
188 };
189
190 #endif