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_SCENECOLLECTION_H_
22 #define SM_REMOTE_SCENECOLLECTION_H_
27 #include <unordered_map>
30 #include "RemoteScene.h"
31 #include "RCSRemoteResourceObject.h"
38 class SceneCollectionResourceRequestor;
41 * @class RemoteSceneCollection
43 * @brief RemoteSceneCollection class is an interface class to send a request to
44 * SceneCollection resource on remote side. This class provides APIs for adding new Scene
45 * to the SceneCollection resource and creating a new RemoteSceneCollection instance
46 * corresponding to the created SceneCollection resource. This class also supports
47 * retrieving all Scene instances created before. Besides, it provides APIs for retrieving
48 * and updating attribute values of the SceneCollection resource like name attribute.
50 class RemoteSceneCollection
53 typedef std::shared_ptr< RemoteSceneCollection > Ptr;
56 * Callback definition to be invoked when a response of addNewScene is
59 * @param scene created RemoteScene instance pointer
60 * @param eCode the error code received from the SceneCollection on remote
62 * @note Error code '200' stands for success, '400' for bad request,
63 * and '500' for internal error.
67 typedef std::function< void(RemoteScene::Ptr scene, int eCode) >
71 * Callback definition to be invoked when a response of setName is
74 * @param eCode the error code received from the SceneCollection on remote
76 * @note Error code '200' stands for success, '400' for bad request,
77 * and '500' for internal error.
81 typedef std::function< void(int eCode) > SetNameCallback;
84 ~RemoteSceneCollection() = default;
87 * Requests to add new Scene to the SceneCollection resource on remote side
88 * and creates RemoteScene instance corresponding to the created Scene.
90 * @param name A name of Scene to add
91 * @param cb A callback to receive created RemoteScene instance
93 * @throws RCSInvalidParameterException If parameter is invalid
94 * @throws PlatformException If the platform operation failed
96 * @note RemoteScene instance is only produced by RemoteSceneCollection class.
97 * @note Name of Scene must be unique in one SceneCollection
99 void addNewScene(const std::string &name, AddNewSceneCallback cb);
102 * Gets all RemoteScene instances from RemoteSceneCollection instance.
104 * @return A unordered_map of shared pointers of RemoteScene instances
106 std::unordered_map< std::string, RemoteScene::Ptr > getRemoteScenes() const;
109 * Gets RemoteScene instance with a specific Scene name.
111 * @param sceneName name of the Scene to get
113 * @return A shared pointer of RemoteScene instance
115 * @throws RCSInvalidParameterException If sceneName is invalid
117 RemoteScene::Ptr getRemoteScene(const std::string &sceneName) const;
120 * Request to set a name attribute of the SceneCollection resource on remote side.
122 * @param name A name of the SceneCollection
123 * @param cb A callback to receive the response
125 * @throws RCSInvalidParameterException If callback is null
126 * @throws PlatformException If the platform operation failed
128 void setName(const std::string &name, SetNameCallback cb);
131 * Gets a name attribute of the SceneCollection resource
133 * @return A name of the SceneCollection
135 std::string getName() const;
138 * Gets an id attribute of the SceneCollection resource.
140 * @return an id of the SceneCollection resource
142 std::string getId() const;
145 RemoteSceneCollection(
146 std::shared_ptr< SceneCollectionResourceRequestor >,
147 const std::string &id, const std::string &name);
149 void addExistingRemoteScenes(const std::vector< std::string > &);
151 void initializeRemoteScenes(const std::vector< RCSResourceAttributes > &,
152 const std::string &);
154 RemoteScene::Ptr createRemoteScene(const std::string &);
156 void onSceneAddedRemoved(int, const std::string &name, int,
157 const AddNewSceneCallback &);
159 void onNameSet(int, const std::string &, const SetNameCallback &);
164 mutable std::mutex m_nameLock;
165 mutable std::mutex m_sceneLock;
166 std::unordered_map< std::string, RemoteScene::Ptr > m_remoteScenes;
167 std::shared_ptr< SceneCollectionResourceRequestor > m_requestor;
169 friend class RemoteSceneList;
175 #endif /* SM_REMOTE_SCENECOLLECTION_H_ */