1 //******************************************************************
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include "DiscomfortIndexSensorResource.h"
27 DiscomfortIndexSensorResource::DiscomfortIndexSensorResource()
29 m_pDiscomfortIndexSensor = new DiscomfortIndexSensor();
32 DiscomfortIndexSensorResource::~DiscomfortIndexSensorResource()
34 delete m_pDiscomfortIndexSensor;
37 void DiscomfortIndexSensorResource::handleSetAttributesRequest(
38 const RCSResourceAttributes &value,
39 const std::map< std::string, std::string > &queryParams)
42 BundleResource::setAttributes(value);
45 RCSResourceAttributes DiscomfortIndexSensorResource::handleGetAttributesRequest(
46 const std::map< std::string, std::string > &queryParams)
49 return BundleResource::getAttributes();
52 void DiscomfortIndexSensorResource::executeLogic()
54 std::string strDiscomfortIndex;
56 m_pDiscomfortIndexSensor->executeDISensorLogic(&m_mapInputData, &strDiscomfortIndex);
58 setAttribute("discomfortIndex", RCSResourceAttributes::Value(strDiscomfortIndex.c_str()), true);
60 for (auto it : m_mapInputData)
62 setAttribute(it.first, RCSResourceAttributes::Value(it.second.c_str()));
66 void DiscomfortIndexSensorResource::onUpdatedInputResource(const std::string attributeName,
67 std::vector<RCSResourceAttributes::Value> values)
74 for (auto it : values)
76 itString = it.toString();
77 std::stringstream ss(itString); //turn the string into a stream
78 ss >> dConvert; //convert
83 double result = sum / inputCount;
84 std::string indexCount;//string which will contain the indexCount
85 std::stringstream convert; // stringstream used for the conversion
86 convert << result;//add the value of Number to the characters in the stream
87 indexCount = convert.str();//set indexCount to the content of the stream
89 m_mapInputData[attributeName] = indexCount;
91 // execute logic only if all the input data are ready
92 if (m_mapInputData.find("temperature") != m_mapInputData.end()
93 && m_mapInputData.find("humidity") != m_mapInputData.end())