add scene manager remote interface class implementation
[platform/upstream/iotivity.git] / service / scene-manager / src / RemoteSceneAction.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 "RemoteSceneAction.h"
22
23 #include "SceneCommons.h"
24 #include "RemoteSceneUtils.h"
25 #include "SceneMemberResourceRequestor.h"
26
27 namespace OIC
28 {
29     namespace Service
30     {
31
32         RemoteSceneAction::RemoteSceneAction
33         (std::shared_ptr< SceneMemberResourceRequestor > pRequestor,
34          const std::string &sceneName, const RCSResourceAttributes &attrs)
35             : m_sceneName{ sceneName }, m_attributes{ attrs }, m_requestorPtr{ pRequestor }
36         {
37             // TODO: check pRequestor not null
38         }
39
40         RemoteSceneAction::RemoteSceneAction
41         (std::shared_ptr< SceneMemberResourceRequestor > pRequestor,
42          const std::string &sceneName,
43          const std::string &key, const RCSResourceAttributes::Value &value)
44             : m_sceneName{ sceneName }, m_requestorPtr{ pRequestor }
45         {
46             // TODO: check pRequestor not null
47             m_attributes[key] = value;
48         }
49
50         void RemoteSceneAction::update(const RCSResourceAttributes &attr,
51                                        UpdateCallback clientCB)
52         {
53             SceneMemberResourceRequestor::InternalAddSceneActionCallback internalCB
54                 = std::bind(&RemoteSceneAction::onUpdated, this,
55                             std::placeholders::_1, attr, std::move(clientCB));
56
57             m_requestorPtr->requestSceneActionCreation(m_sceneName,
58                     attr, internalCB);
59         }
60
61         void RemoteSceneAction::update(const std::string &key,
62                                        const RCSResourceAttributes::Value &value,
63                                        UpdateCallback clientCB)
64         {
65             RCSResourceAttributes attr;
66             attr[key] = RCSResourceAttributes::Value(value);
67
68             update(attr, std::move(clientCB));
69         }
70
71         RCSResourceAttributes RemoteSceneAction::getAction() const
72         {
73             return m_attributes;
74         }
75
76         RCSRemoteResourceObject::Ptr RemoteSceneAction::getRemoteResourceObject() const
77         {
78             return m_requestorPtr->getRemoteResourceObject();
79         }
80
81         void RemoteSceneAction::onUpdated(int eCode, const RCSResourceAttributes &attr,
82                                           const UpdateCallback &clientCB)
83         {
84             if (eCode == SCENE_RESPONSE_SUCCESS)
85             {
86                 m_attributes = attr;
87             }
88
89             clientCB(eCode);
90         }
91
92     }
93 }