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 "ContextDataReader.h"
22 SSMRESULT CContextDataReader::finalConstruct()
24 m_pContextModelAccessor = NULL;
28 void CContextDataReader::finalRelease()
30 m_pContextModelAccessor = NULL;
33 SSMRESULT CContextDataReader::registerContextModelAccessor(IContextModelAccessor
34 *pContextModelAccessor)
36 m_pContextModelAccessor = pContextModelAccessor;
41 SSMRESULT CContextDataReader::getContextData(std::string modelName, int startIndex,
42 int count, std::vector<ContextData> *data, int *pLastIndex)
44 SSMRESULT res = SSM_E_FAIL;
45 std::vector<ModelPropertyVec> modelDataSet;
46 CObjectPtr<IContextModel> pContextModel;
48 SSM_CLEANUP_ASSERT(m_pContextModelAccessor->onQueryContextModel(modelName, &pContextModel));
50 SSM_CLEANUP_ASSERT(pContextModel->getModelDataSet(startIndex, count, &modelDataSet, pLastIndex));
52 for (std::vector<ModelPropertyVec>::iterator itorModelPropertyVec = modelDataSet.begin();
53 itorModelPropertyVec != modelDataSet.end(); ++itorModelPropertyVec)
55 ContextData contextData;
57 contextData.rootName = pContextModel->getModelName();
58 contextData.outputPropertyCount = (int)itorModelPropertyVec->size();
60 for (ModelPropertyVec::iterator itor = itorModelPropertyVec->begin();
61 itor != itorModelPropertyVec->end(); ++itor)
63 std::map<std::string, std::string> propertySet;
65 switch (itor->propertyType)
67 case ModelProperty::TYPE_INTEGER:
68 case ModelProperty::TYPE_NUMERIC:
69 propertySet["type"] = "int";
72 case ModelProperty::TYPE_REAL:
73 propertySet["type"] = "double";
76 case ModelProperty::TYPE_TEXT:
77 propertySet["type"] = "string";
81 propertySet["type"] = "string";
84 propertySet["name"] = itor->propertyName;
85 propertySet["value"] = itor->propertyValue;
87 contextData.outputProperty.push_back(propertySet);
90 data->push_back(contextData);