replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / service / resource-container / examples / DiscomfortIndexSensorBundle / src / DiscomfortIndexSensorResource.cpp
index d51febb..e98ce5f 100644 (file)
@@ -35,13 +35,17 @@ DiscomfortIndexSensorResource::~DiscomfortIndexSensorResource()
 }
 
 void DiscomfortIndexSensorResource::handleSetAttributesRequest(
-    RCSResourceAttributes &value)
+    const RCSResourceAttributes &value,
+    const std::map< std::string, std::string > &queryParams)
 {
+    (void)queryParams;
     BundleResource::setAttributes(value);
 }
 
-RCSResourceAttributes &DiscomfortIndexSensorResource::handleGetAttributesRequest()
+RCSResourceAttributes DiscomfortIndexSensorResource::handleGetAttributesRequest(
+    const std::map< std::string, std::string > &queryParams)
 {
+    (void)queryParams;
     return BundleResource::getAttributes();
 }
 
@@ -51,7 +55,7 @@ void DiscomfortIndexSensorResource::executeLogic()
 
     m_pDiscomfortIndexSensor->executeDISensorLogic(&m_mapInputData, &strDiscomfortIndex);
 
-    setAttribute("discomfortIndex", RCSResourceAttributes::Value(strDiscomfortIndex.c_str()));
+    setAttribute("discomfortIndex", RCSResourceAttributes::Value(strDiscomfortIndex.c_str()), true);
 
     for (auto it : m_mapInputData)
     {
@@ -62,8 +66,8 @@ void DiscomfortIndexSensorResource::executeLogic()
 void DiscomfortIndexSensorResource::onUpdatedInputResource(const std::string attributeName,
         std::vector<RCSResourceAttributes::Value> values)
 {
-    double sum = 0;
-    double dConvert;
+    double sum = 0.0;
+    double dConvert = 0.0;
     int inputCount = 0;
     std::string itString;
 
@@ -76,7 +80,11 @@ void DiscomfortIndexSensorResource::onUpdatedInputResource(const std::string att
         ++inputCount;
     }
 
-    double result = sum / inputCount;
+    double result = 0.0;
+    if (inputCount)
+    {
+        result = sum / inputCount;
+    }
     std::string indexCount;//string which will contain the indexCount
     std::stringstream convert; // stringstream used for the conversion
     convert << result;//add the value of Number to the characters in the stream