Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / service / soft-sensor-manager / SSMCore / src / SensorProcessor / ContextDataReader.cpp
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 #include "ContextDataReader.h"
21
22 SSMRESULT CContextDataReader::finalConstruct()
23 {
24     m_pContextModelAccessor = NULL;
25     return SSM_S_OK;
26 }
27
28 void CContextDataReader::finalRelease()
29 {
30     m_pContextModelAccessor = NULL;
31 }
32
33 SSMRESULT CContextDataReader::registerContextModelAccessor(IContextModelAccessor
34         *pContextModelAccessor)
35 {
36     m_pContextModelAccessor = pContextModelAccessor;
37
38     return SSM_S_OK;
39 }
40
41 SSMRESULT CContextDataReader::getContextData(std::string modelName, int startIndex,
42         int count, std::vector<ContextData> *data, int *pLastIndex)
43 {
44     SSMRESULT res = SSM_E_FAIL;
45     std::vector<ModelPropertyVec>   modelDataSet;
46     CObjectPtr<IContextModel>   pContextModel;
47
48     SSM_CLEANUP_ASSERT(m_pContextModelAccessor->onQueryContextModel(modelName, &pContextModel));
49
50     SSM_CLEANUP_ASSERT(pContextModel->getModelDataSet(startIndex, count, &modelDataSet, pLastIndex));
51
52     for (std::vector<ModelPropertyVec>::iterator itorModelPropertyVec = modelDataSet.begin();
53          itorModelPropertyVec != modelDataSet.end(); ++itorModelPropertyVec)
54     {
55         ContextData contextData;
56
57         contextData.rootName = pContextModel->getModelName();
58         contextData.outputPropertyCount = (int)itorModelPropertyVec->size();
59
60         for (ModelPropertyVec::iterator itor = itorModelPropertyVec->begin();
61              itor != itorModelPropertyVec->end(); ++itor)
62         {
63             std::map<std::string, std::string> propertySet;
64
65             switch (itor->propertyType)
66             {
67                 case ModelProperty::TYPE_INTEGER:
68                 case ModelProperty::TYPE_NUMERIC:
69                     propertySet["type"] = "int";
70                     break;
71
72                 case ModelProperty::TYPE_REAL:
73                     propertySet["type"] = "double";
74                     break;
75
76                 case ModelProperty::TYPE_TEXT:
77                     propertySet["type"] = "string";
78                     break;
79
80                 default:
81                     propertySet["type"] = "string";
82             }
83
84             propertySet["name"] = itor->propertyName;
85             propertySet["value"] = itor->propertyValue;
86
87             contextData.outputProperty.push_back(propertySet);
88         }
89
90         data->push_back(contextData);
91     }
92
93 CLEANUP:
94     return res;
95 }