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 #include "ConditionedModel.h"
22 SSMRESULT CConditionedModel::finalConstruct()
24 SSMRESULT res = SSM_E_FAIL;
28 m_pConditionedModelEvent = NULL;
30 SSM_CLEANUP_ASSERT(CreateGlobalInstance(OID_IEvaluationEngine, (IBase **)&m_pEvaluationEngine));
36 void CConditionedModel::finalRelease()
38 m_pConditionedModelEvent = NULL;
48 SSMRESULT CConditionedModel::create(IN IContextModel *pBaseModel,
49 IN ModelConditionVec *pModelConditions)
51 m_watchCondition = *pModelConditions;
52 return pBaseModel->queryInterface(OID_IContextModel, (IBase **)&m_pBaseModel);
55 SSMRESULT CConditionedModel::getBaseContextModel(OUT IContextModel **ppBaseContextModel)
57 SSMRESULT res = SSM_E_FAIL;
59 SSM_CLEANUP_ASSERT(m_pBaseModel->queryInterface(OID_IContextModel, (IBase **)ppBaseContextModel));
65 SSMRESULT CConditionedModel::registerConditionedModelEvent(IN IConditionedModelEvent
66 *pConditionedModelEvent)
68 m_pConditionedModelEvent = pConditionedModelEvent;
72 SSMRESULT CConditionedModel::onWatchModelData(IN int triggerId, IN int dataId)
74 SSMRESULT res = SSM_E_FAIL;
76 m_mtxConditionedData.lock();
77 m_triggeredDataIds.push_back(dataId);
78 m_mtxConditionedData.unlock();
80 if (m_pConditionedModelEvent)
82 res = m_pConditionedModelEvent->onConditionedModelTriggered(triggerId);
88 SSMRESULT CConditionedModel::activateTrigger(OUT int *pTriggerId)
90 SSMRESULT res = SSM_E_FAIL;
92 SSM_CLEANUP_ASSERT(m_pEvaluationEngine->watchModelData(m_pBaseModel->getModelId(),
93 &m_watchCondition, this, &m_triggerId));
95 *pTriggerId = m_triggerId;
101 SSMRESULT CConditionedModel::deactivateTrigger()
103 SSMRESULT res = SSM_S_OK;
105 if (m_triggerId > -1)
107 SSM_CLEANUP_ASSERT(m_pEvaluationEngine->dropWatchModelData(m_triggerId));
116 bool CConditionedModel::hasAffectedData()
120 m_mtxConditionedData.lock();
122 if (m_triggeredDataIds.size() > 0 || m_affectedDataIds.size() > 0)
128 if (m_pEvaluationEngine->getConditionedModelData(m_pBaseModel->getModelId(),
129 &m_watchCondition, &m_affectedDataIds) != SSM_S_OK)
135 if (m_affectedDataIds.size() > 0)
142 m_mtxConditionedData.unlock();
146 SSMRESULT CConditionedModel::getAffectedData(OUT IntVec *pDataIds)
148 SSMRESULT res = SSM_E_FAIL;
150 m_mtxConditionedData.lock();
152 if (m_triggeredDataIds.size() > 0)
154 pDataIds->push_back(m_triggeredDataIds.front());
155 m_triggeredDataIds.pop_front();
156 SSM_CLEANUP_ASSERT(SSM_S_OK);
160 m_affectedDataIds.clear();
161 SSM_CLEANUP_ASSERT(m_pEvaluationEngine->getConditionedModelData(m_pBaseModel->getModelId(),
162 &m_watchCondition, &m_affectedDataIds));
163 *pDataIds = m_affectedDataIds;
167 m_mtxConditionedData.unlock();
171 SSMRESULT CConditionedModel::getWatchCondition(OUT ModelConditionVec *pModelConditions)
173 *pModelConditions = m_watchCondition;