1 //******************************************************************
3 // Copyright 2016 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
11 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #ifndef SM_REMOTE_SCENE_H_
22 #define SM_REMOTE_SCENE_H_
26 #include <unordered_map>
29 #include "RemoteSceneAction.h"
30 #include "RCSRemoteResourceObject.h"
36 class SceneCollectionResourceRequestor;
37 class SceneMemberResourceRequestor;
42 * @brief RemoteScene class is an interface class to send a request to a Scene provided by
43 * SceneCollection resource on remote side. This class provides APIs for adding new
44 * SceneAction to the Scene and creating a new SceneAction instance, retrieving all
45 * SceneAction instances created before. And it also provides an API to execute a Scene
51 typedef std::shared_ptr< RemoteScene > Ptr;
54 * Callback definition to be invoked a the response of addNewSceneAction is
57 * @param action created RemoteSceneAction instance pointer
58 * @param eCode the error code received
60 * @note Error code '200' stands for success, '400' for bad request,
61 * and '500' for internal error.
63 * @see addNewSceneAction
65 typedef std::function< void(RemoteSceneAction::Ptr action, int eCode) >
66 AddNewSceneActionCallback;
69 * Callback definition to be invoked when a response of execute is
72 * @param sceneName name of the scene which is executed
73 * @param eCode the error code received
75 * @note Error code '200' stands for success, '400' for bad request,
76 * and '500' for internal error.
80 typedef std::function< void(const std::string &sceneName, int eCode) >
81 RemoteSceneExecuteCallback;
84 ~RemoteScene() = default;
87 * Requests to add new SceneAction to the Scene on remote side and
88 * creates RemoteSceneAction instance corresponding to the created SceneAction.
90 * @param targetResource A pointer of discovered resource
91 * @param attrs AttributeS to set when the Scene executed
92 * @param cb A callback to receive created RemoteSceneAction instance
94 * @throws RCSInvalidParameterException If parameter is invalid.
95 * @throws PlatformException If the platform operation failed
97 * @note RemoteSceneAction instance is only produced by RemoteScene class
99 * @see RCSResourceAttributes
101 void addNewSceneAction(RCSRemoteResourceObject::Ptr targetResource,
102 const RCSResourceAttributes &attrs, AddNewSceneActionCallback cb);
105 * Requests to add new SceneAction to the Scene on remote side and
106 * creates RemoteSceneAction instance corresponding to the created SceneAction.
108 * @param targetResource A pointer of discovered resource
109 * @param key A key of an attribute
110 * @param value A value to be mapped against the key
111 * @param cb A callback to receive created RemoteSceneAction instance
113 * @throws RCSInvalidParameterException If parameter is invalid.
114 * @throws PlatformException If the platform operation failed
116 * @note RemoteSceneAction instance is only produced by RemoteScene class
118 * @see RCSResourceAttributes::Value
120 void addNewSceneAction(RCSRemoteResourceObject::Ptr targetResource,
121 const std::string &key,
122 const RCSResourceAttributes::Value &value,
123 AddNewSceneActionCallback cb);
126 * Gets all RemoteSceneAction instances included in the Scene.
128 * @return A vector of shared pointer of RemoteSceneAction instances
130 std::vector< RemoteSceneAction::Ptr > getRemoteSceneActions() const;
133 * Gets RemoteSceneAction instance by using a certain discovered resource.
135 * @param targetResource A pointer of discovered resource
137 * @return A shared pointer of RemoteSceneAction instance
139 * @throws RCSInvalidParameterException If targetResource is invalid
141 RemoteSceneAction::Ptr getRemoteSceneAction(
142 const RCSRemoteResourceObject::Ptr targetResource) const;
145 * Gets a name attribute of the Scene.
147 * @return A name of the Scene
149 std::string getName() const;
152 * Requests to execute the Scene on remote side.
154 * @param cb A callback to receive result of Scene execution
156 * @throws RCSInvalidParameterException If callback is null
157 * @throws PlatformException If the platform operation failed
159 void execute(RemoteSceneExecuteCallback cb);
163 const std::string &name, std::shared_ptr< SceneCollectionResourceRequestor >);
165 RemoteSceneAction::Ptr createRemoteSceneAction(
166 const std::string &, const RCSResourceAttributes &);
168 void addExistingRemoteSceneAction(const std::string &, const std::string &,
169 RCSRemoteResourceObject::Ptr, const std::string &key,
170 const RCSResourceAttributes::Value &);
172 void onSceneActionAdded(
173 int, RCSRemoteResourceObject::Ptr,
174 const RCSResourceAttributes &, const AddNewSceneActionCallback &);
176 void onSceneExecuted(const std::string &name, int,
177 const RemoteSceneExecuteCallback &);
181 mutable std::mutex m_sceneActionLock;
182 std::unordered_map < std::string, RemoteSceneAction::Ptr >
183 m_remoteSceneActions;
185 std::shared_ptr< SceneCollectionResourceRequestor > m_requestor;
187 friend class RemoteSceneCollection;
193 #endif /* SM_REMOTE_SCENE_H_ */