Imported Upstream version 1.1.0
[platform/upstream/iotivity.git] / service / resource-container / examples / BMISensorBundle / src / BMISensorResource.cpp
1 //******************************************************************
2 //
3 // Copyright 2015 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
21 #include "BMISensorResource.h"
22
23
24 BMISensorResource::BMISensorResource()
25 {
26     m_pBMISensor = new BMISensor();
27 }
28
29 BMISensorResource::~BMISensorResource()
30 {
31     delete m_pBMISensor;
32 }
33
34 void BMISensorResource::handleSetAttributesRequest(
35     const RCSResourceAttributes &value)
36 {
37     BundleResource::setAttributes(value);
38 }
39
40 RCSResourceAttributes BMISensorResource::handleGetAttributesRequest()
41 {
42     return BundleResource::getAttributes();
43 }
44
45 void BMISensorResource::executeLogic()
46 {
47     std::string strBMIResult;
48
49     if (m_pBMISensor->executeBMISensorLogic(&m_mapInputData, &strBMIResult) != -1)
50         setAttribute("BMIresult", RCSResourceAttributes::Value(strBMIResult.c_str()));
51 }
52
53 void BMISensorResource::onUpdatedInputResource(const std::string attributeName,
54         std::vector<RCSResourceAttributes::Value> values)
55 {
56     // remove all existing data
57     m_mapInputData.clear();
58
59     if (!attributeName.compare("weight"))
60         m_mapInputData.insert(std::make_pair("weight", values.back().get< std::string >()));
61
62     if (!attributeName.compare("height"))
63         m_mapInputData.insert(std::make_pair("height", values.back().get< std::string >()));
64
65     executeLogic();
66 }