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 RCSResourceAttributes &value)
40 BundleResource::setAttributes(value);
43 RCSResourceAttributes &DiscomfortIndexSensorResource::handleGetAttributesRequest()
45 return BundleResource::getAttributes();
48 void DiscomfortIndexSensorResource::executeLogic()
50 std::string strDiscomfortIndex;
52 m_pDiscomfortIndexSensor->executeDISensorLogic(&m_mapInputData, &strDiscomfortIndex);
54 setAttribute("discomfortIndex", RCSResourceAttributes::Value(strDiscomfortIndex.c_str()));
56 for (auto it : m_mapInputData)
58 setAttribute(it.first, RCSResourceAttributes::Value(it.second.c_str()));
62 void DiscomfortIndexSensorResource::onUpdatedInputResource(const std::string attributeName,
63 std::vector<RCSResourceAttributes::Value> values)
70 for (auto it : values)
72 itString = it.toString();
73 std::stringstream ss(itString); //turn the string into a stream
74 ss >> dConvert; //convert
79 double result = sum / inputCount;
80 std::string indexCount;//string which will contain the indexCount
81 std::stringstream convert; // stringstream used for the conversion
82 convert << result;//add the value of Number to the characters in the stream
83 indexCount = convert.str();//set indexCount to the content of the stream
85 m_mapInputData[attributeName] = indexCount;
87 // execute logic only if all the input data are ready
88 if (m_mapInputData.find("temperature") != m_mapInputData.end()
89 && m_mapInputData.find("humidity") != m_mapInputData.end())