[IOT-1065][IOT-1069] RC - Tizen: sample application fix
[platform/upstream/iotivity.git] / service / scene-manager / src / SceneAction.cpp
1 //******************************************************************
2 //
3 // Copyright 2016 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 "SceneAction.h"
22
23 #include "SceneMemberResource.h"
24
25 namespace OIC
26 {
27     namespace Service
28     {
29         SceneAction::SceneAction(const SceneMemberResource::Ptr SceneMemberResource,
30                 const std::string& sceneName, const RCSResourceAttributes& attr) :
31                 m_pRemoteResourceObject(SceneMemberResource->getRemoteResourceObject()),
32                 m_sceneName(sceneName),
33                 m_sceneMemberResource(SceneMemberResource)
34         {
35             for (const auto& it : attr)
36             {
37                 m_sceneMemberResource->addMappingInfo(
38                         SceneMemberResource::MappingInfo(m_sceneName, it.key(), it.value()));
39             }
40         }
41
42         SceneAction::SceneAction(const SceneMemberResource::Ptr SceneMemberResource,
43                 const std::string& sceneName, const std::string& key,
44                 const RCSResourceAttributes::Value& value) :
45                 m_pRemoteResourceObject(SceneMemberResource->getRemoteResourceObject()),
46                 m_sceneName(sceneName), m_sceneMemberResource(SceneMemberResource)
47         {
48             m_sceneMemberResource->addMappingInfo(
49                                 SceneMemberResource::MappingInfo(m_sceneName, key, value));
50         }
51
52         void SceneAction::resetExecutionParameter(const std::string& key,
53                 RCSResourceAttributes::Value value)
54         {
55             RCSResourceAttributes attr;
56             attr[key] = value;
57             resetExecutionParameter(attr);
58         }
59
60         void SceneAction::resetExecutionParameter(const RCSResourceAttributes& attr)
61         {
62             for(const auto& it : attr)
63             {
64                 m_sceneMemberResource->addMappingInfo(
65                         SceneMemberResource::MappingInfo(m_sceneName, it.key(), it.value()));
66             }
67         }
68
69         RCSResourceAttributes SceneAction::getExecutionParameter() const
70         {
71             RCSResourceAttributes attr;
72             for(const auto& it : m_sceneMemberResource->getMappingInfos())
73             {
74                 if(it.sceneName == m_sceneName)
75                 {
76                     attr[it.key] = RCSResourceAttributes::Value(it.value);
77                 }
78             }
79             return attr;
80         }
81
82         RCSRemoteResourceObject::Ptr SceneAction::getRemoteResourceObject() const
83         {
84             return m_pRemoteResourceObject;
85         }
86
87     } /* namespace Service */
88 } /* namespace OIC */
89