iotivity 0.9.0
[platform/upstream/iotivity.git] / service / soft-sensor-manager / SSMCore / src / QueryProcessor / ConditionedQuery.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 _ConditionedQuery_H_
21 #define _ConditionedQuery_H_
22
23 #include "SSMInterface/SSMCore.h"
24 #include "Common/PlatformLayer.h"
25 #include "Common/InternalInterface.h"
26 #include "ConditionedQueryResult.h"
27 /**
28 * @class    CConditionedQuery
29 * @brief    CConditionedQuery Interface
30 *            This class represents parsed CQL for data retrieving
31 *
32 * @see
33 */
34 class CConditionedQuery :
35     public CObjectRoot<CObjectMultiThreadModel>
36     , public IConditionedQuery
37     , public IThreadClient
38     , public IConditionedModelEvent
39 {
40     private:
41         CObjectPtr<ITasker>                     m_pTasker;
42         //CObjectPtr<IPropagationEngine>            m_PropagationEngine;
43         CObject<CConditionedQueryResult>        *m_pConditionedQueryResult;
44         std::vector<IConditionedModel *>         m_conditionedModels;
45         CSimpleMutex                            m_mtxConditionCount;
46         IConditionedQueryEvent                  *m_conditionedQueryEvent;
47         int                                     m_untrackedConditionsCount;
48         bool                                    m_reservedForActivate;
49         int                                     m_userTriggerId;
50         IContextModel::ActivationType           m_activationType;
51         int                                     m_targetDeviceDataId;
52
53     public:
54         SSMRESULT finalConstruct();
55
56         void finalRelease();
57
58         /**
59         * @fn     create
60         * @brief Create Conditioned Query for multiple data searching or triggering
61         *
62         * @param [in] IContextModel::ActivationType activationType - Specify ContextModel's working type
63         * @param [in] int totalConditionsCount - Specify total condition's count each condition is related to each ContextModel
64         *
65         * @return SSMRESULT
66         * @warning
67         * @exception
68         * @see
69         */
70         SSMRESULT create(IN IContextModel::ActivationType activationType, IN int totalConditionsCount);
71
72         /**
73         * @fn     registerQueryConditionEvent
74         * @brief Register IConditionedQueryEvent interface for listening events
75         *
76         * @param [in] IConditionedQueryEvent *pConditionedQueryEvent - Interface pointer for listening
77         *
78         * @return SSMRESULT
79         * @warning
80         * @exception
81         * @see
82         */
83         SSMRESULT registerQueryConditionEvent(IN IConditionedQueryEvent *pConditionedQueryEvent);
84
85         /**
86         * @fn     onConditionedModelTriggered
87         * @brief Called when each Conditioned Model meets the conditions
88         *
89         * @param [in] int triggerId - trigger id that which Conditioned Model triggered
90         *
91         * @return SSMRESULT
92         * @warning
93         * @exception
94         * @see
95         */
96         SSMRESULT onConditionedModelTriggered(IN int triggerId);
97
98         void onExecute(IN void *pArg);
99
100         void onTerminate(IN void *pArg);
101
102         SSMRESULT queryInterface(const OID &objectID, IBase **ppObject)
103         {
104             if (ppObject == NULL)
105                 return SSM_E_POINTER;
106
107             if (IsEqualOID(objectID, OID_IConditionedQuery))
108             {
109                 IBase *pBase = (IConditionedQuery *)this;
110                 pBase->addRef();
111                 *ppObject = pBase;
112                 return SSM_S_OK;
113             }
114
115             return SSM_E_NOINTERFACE;
116         }
117
118         /**
119         * @fn     registerConditionedModel
120         * @brief Register Conditioned Model for tracking triggers
121         *
122         * @param [in] IConditionedModel *pConditionedModel - Interface of Conditioned Model
123         *
124         * @return SSMRESULT
125         * @warning
126         * @exception
127         * @see
128         */
129         SSMRESULT registerConditionedModel(IN IConditionedModel *pConditionedModel);
130
131         /**
132         * @fn     activateTriggers
133         * @brief Activate triggers for data evaluating. This changed related ContextModel's status to running
134         *
135         * @param [in] int userTriggerId - Specify TriggerId for event listening
136         *
137         * @return SSMRESULT
138         * @warning
139         * @exception
140         * @see
141         */
142         SSMRESULT activateTriggers(IN int userTriggerId);
143
144         /**
145         * @fn     deactivateTriggers
146         * @brief Deactivate triggers for data evaluating.
147         *
148         * @param [in] int userTriggerId - Specify TriggerId for event listening
149         *
150         * @return SSMRESULT
151         * @warning
152         * @exception
153         * @see
154         */
155         SSMRESULT deactivateTriggers();
156
157         /**
158         * @fn     getConditionedQueryResult
159         * @brief Retrieves conditioned data from current cached data
160         *
161         * @param [out] IConditionedQueryResult **ppConditionedQueryResult - Interface of result reader
162         *
163         * @return SSMRESULT
164         * @warning
165         * @exception
166         * @see
167         */
168         SSMRESULT getConditionedQueryResult(OUT IConditionedQueryResult **ppConditionedQueryResult);
169
170         /**
171         * @fn     hasAllConditionedModels
172         * @brief Retrieves current conditioned query has all Conditioned ContextModels for evaluating
173         *
174         * @param NONE
175         *
176         * @return bool
177         * @warning
178         * @exception
179         * @see
180         */
181         bool hasAllConditionedModels();
182 };
183
184 #endif