Imported Upstream version 1.1.0
[platform/upstream/iotivity.git] / service / scene-manager / include / RemoteSceneAction.h
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 #ifndef SM_REMOTE_SCENEACTION_H_
22 #define SM_REMOTE_SCENEACTION_H_
23
24 #include <memory>
25 #include <string>
26 #include <mutex>
27
28 #include "RCSRemoteResourceObject.h"
29
30 namespace OIC
31 {
32     namespace Service
33     {
34
35         class SceneMemberResourceRequestor;
36
37         /*
38         * @class RemoteSceneAction
39         *
40         * @brief RemoteSceneAction class indicates a unit of actions when a scene is executed.
41         * RemoteSceneAction instance is initialized with 3 essential parameters:
42         * a target resource, target attribute key, and its target value.
43         * And this class also provides APIs to update a target attribute information if one wants.
44         * Note that, adding a new RemoteSceneAction is done by sending a CoAP request to update a
45         * SceneMember resource's attribute.
46         */
47         class RemoteSceneAction
48         {
49             public:
50                 typedef std::shared_ptr< RemoteSceneAction > Ptr;
51
52                 /**
53                 * Callback definition to be invoked when a response of resetExecutionParameter is
54                 * received.
55                 *
56                 * @param eCode the error code received on a remote-side scene resource server
57                 *
58                 * @note Error code '200' stands for success, '400' for bad request,
59                 * and '500' for internal error.
60                 *
61                 * @see resetExecutionParameter
62                 */
63                 typedef std::function< void(int eCode) > ResetExecutionParameterCallback;
64
65             public:
66                 ~RemoteSceneAction() = default;
67
68                 /**
69                 * Requests to reset the RemoteSceneAction parameters like
70                 * a target attribute key and its value.
71                 *
72                 * @param key key of attribute
73                 * @param value value to be mapped against the key
74                 * @param cb A callback to receive the response
75                 *
76                 * @throws RCSInvalidParameterException If parameter is invalid.
77                 * @throws PlatformException If the platform operation failed
78                 *
79                 * @see RCSResourceAttributes::Value
80                 */
81                 void resetExecutionParameter(const std::string &key,
82                     const RCSResourceAttributes::Value &value, ResetExecutionParameterCallback cb);
83
84                 /**
85                 * Requests to reset the RemoteSceneAction parameters like
86                 * a target attribute key and its value.
87                 *
88                 * @param attr Attributes to set
89                 * @param cb A callback to receive the response
90                 *
91                 * @throws RCSInvalidParameterException If parameter is invalid.
92                 * @throws PlatformException If the platform operation failed
93                 *
94                 * @see RCSResourceAttributes
95                 */
96                 void resetExecutionParameter(
97                     const RCSResourceAttributes &attr, ResetExecutionParameterCallback cb);
98
99                 /**
100                 * Returns an execution parameter of the SceneAction.
101                 *
102                 * @return RCSResourceAttributes
103                 */
104                 RCSResourceAttributes getExecutionParameter() const;
105
106                 /**
107                 * Returns a target remote resource object of the RemoteSceneAction instance
108                 *
109                 * @return pointer of RCSRemoteResourceObject
110                 */
111                 RCSRemoteResourceObject::Ptr getRemoteResourceObject() const;
112
113             private:
114                 RemoteSceneAction(std::shared_ptr< SceneMemberResourceRequestor >,
115                                   const std::string &sceneName, const RCSResourceAttributes &);
116                 RemoteSceneAction(std::shared_ptr< SceneMemberResourceRequestor >,
117                                   const std::string &sceneName,
118                                   const std::string &key, const RCSResourceAttributes::Value &);
119
120                 void onExecutionParameterSet(int, const RCSResourceAttributes &,
121                     const ResetExecutionParameterCallback &);
122
123             private:
124                 std::string m_sceneName;
125                 mutable std::mutex m_attributeLock;
126                 RCSResourceAttributes m_attributes;
127                 std::shared_ptr< SceneMemberResourceRequestor > m_requestor;
128
129                 friend class RemoteScene;
130         };
131
132     }
133 }
134
135 #endif /* SM_REMOTE_SCENEACTION_H_ */