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 _ConditionedQuery_H_
21 #define _ConditionedQuery_H_
23 #include "SSMInterface/SSMCore.h"
24 #include "Common/PlatformLayer.h"
25 #include "Common/InternalInterface.h"
26 #include "ConditionedQueryResult.h"
28 * @class CConditionedQuery
29 * @brief CConditionedQuery Interface
30 * This class represents parsed CQL for data retrieving
34 class CConditionedQuery :
35 public CObjectRoot<CObjectMultiThreadModel>
36 , public IConditionedQuery
37 , public IThreadClient
38 , public IConditionedModelEvent
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;
50 IContextModel::ActivationType m_activationType;
51 int m_targetDeviceDataId;
54 SSMRESULT finalConstruct();
60 * @brief Create Conditioned Query for multiple data searching or triggering
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
70 SSMRESULT create(IN IContextModel::ActivationType activationType, IN int totalConditionsCount);
73 * @fn registerQueryConditionEvent
74 * @brief Register IConditionedQueryEvent interface for listening events
76 * @param [in] IConditionedQueryEvent *pConditionedQueryEvent - Interface pointer for listening
83 SSMRESULT registerQueryConditionEvent(IN IConditionedQueryEvent *pConditionedQueryEvent);
86 * @fn onConditionedModelTriggered
87 * @brief Called when each Conditioned Model meets the conditions
89 * @param [in] int triggerId - trigger id that which Conditioned Model triggered
96 SSMRESULT onConditionedModelTriggered(IN int triggerId);
98 void onExecute(IN void *pArg);
100 void onTerminate(IN void *pArg);
102 SSMRESULT queryInterface(const OID &objectID, IBase **ppObject)
104 if (ppObject == NULL)
105 return SSM_E_POINTER;
107 if (IsEqualOID(objectID, OID_IConditionedQuery))
109 IBase *pBase = (IConditionedQuery *)this;
115 return SSM_E_NOINTERFACE;
119 * @fn registerConditionedModel
120 * @brief Register Conditioned Model for tracking triggers
122 * @param [in] IConditionedModel *pConditionedModel - Interface of Conditioned Model
129 SSMRESULT registerConditionedModel(IN IConditionedModel *pConditionedModel);
132 * @fn activateTriggers
133 * @brief Activate triggers for data evaluating. This changed related ContextModel's status to running
135 * @param [in] int userTriggerId - Specify TriggerId for event listening
142 SSMRESULT activateTriggers(IN int userTriggerId);
145 * @fn deactivateTriggers
146 * @brief Deactivate triggers for data evaluating.
148 * @param [in] int userTriggerId - Specify TriggerId for event listening
155 SSMRESULT deactivateTriggers();
158 * @fn getConditionedQueryResult
159 * @brief Retrieves conditioned data from current cached data
161 * @param [out] IConditionedQueryResult **ppConditionedQueryResult - Interface of result reader
168 SSMRESULT getConditionedQueryResult(OUT IConditionedQueryResult **ppConditionedQueryResult);
171 * @fn hasAllConditionedModels
172 * @brief Retrieves current conditioned query has all Conditioned ContextModels for evaluating
181 bool hasAllConditionedModels();