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_SCENELIST_H_
22 #define SM_REMOTE_SCENELIST_H_
29 #include "RemoteSceneCollection.h"
30 #include "RCSRemoteResourceObject.h"
36 class SceneListResourceRequestor;
39 * @class RemoteSceneList
41 * @brief RemoteSceneList class is an interface class to send a request to
42 * SceneList resource on remote side. This class provides APIs for adding
43 * new SceneCollection resource to the SceneList resource and
44 * creating a RemoteSceneCollection instance corresponding to the
45 * created SceneCollection resource. This class also supports retrieving the existing
46 * instances as well as setting/getting a name attribute of the SceneList resource.
51 typedef std::unique_ptr< RemoteSceneList > Ptr;
54 * Callback definition to be invoked when a response of createInstance is
57 * @param list Created RemoteSceneList instance pointer
58 * @param eCode The error code received from the SceneList on remote side
60 * @note Error code '200' stands for success, '400' for bad request,
61 * and '500' for internal error.
65 typedef std::function< void(RemoteSceneList::Ptr list, int eCode) >
66 CreateInstanceCallback;
69 * Callback definition to be invoked when a response of addNewSceneCollection is
72 * @param collection Created RemoteSceneCollection instance pointer
73 * @param eCode The error code received from the SceneList on remote
75 * @note Error code '200' stands for success, '400' for bad request,
76 * and '500' for internal error.
78 * @see addNewSceneCollection
80 typedef std::function< void(RemoteSceneCollection::Ptr collection, int eCode) >
81 AddNewSceneCollectionCallback;
84 * Callback definition to be invoked when a response of setName is
87 * @param eCode the error code received from the SceneList on remote
89 * @note Error code '200' stands for success, '400' for bad request,
90 * and '500' for internal error.
94 typedef std::function< void(int eCode) > SetNameCallback;
97 ~RemoteSceneList() = default;
100 * Creates RemoteSceneList instance with provided RCSRemoteResourceObject of
101 * discovered SceneList resource on remote side.
103 * To create RemoteSceneList instance, discovery of SceneList resource
104 * which has 'oic.wk.scenelist' as resource type is required,
105 * and the found resource should be provided as parameter.
106 * After that, one can acceess existing SceneCollections, Scenes, and SceneActions
107 * instances that are already produced at the SceneList resource.
108 * Created RemoteSceneList will be delivered to CreateInstanceCallback.
110 * @param sceneListResource RCSRemoteResourceObject pointer of SceneList
111 * @param cb A callback to receive the response
113 * @throws RCSInvalidParameterException If parameter is invalid.
114 * @throws PlatformException If the platform operation failed
116 * @see RCSRemoteResourceObject
118 static void createInstance(
119 RCSRemoteResourceObject::Ptr sceneListResource, CreateInstanceCallback cb);
122 * Requests to add new SceneCollection resource to the SceneList resource on remote
123 * side and creates RemoteSceneCollection instance corresponding to the created
124 * SceneCollection resource.
126 * @param cb A callback to receive created RemoteSceneCollection instance
128 * @throws RCSInvalidParameterException If callback is null.
129 * @throws PlatformException If the platform operation failed
131 * @note RemoteSceneCollection instance is only produced by RemoteSceneList class.
133 void addNewSceneCollection(AddNewSceneCollectionCallback cb);
136 * Gets all RemoteSceneCollection instances stored in the RemoteSceneList instance.
138 * @return A vector of shared pointers of RemoteSceneCollection instances
140 std::vector< RemoteSceneCollection::Ptr > getRemoteSceneCollections() const;
143 * Request to set a name attribute of the SceneList resource on remote side.
145 * @param name A name of the SceneList
146 * @param cb A callback to receive the response
148 * @throws RCSInvalidParameterException If callback is null.
149 * @throws PlatformException If the platform operation failed
151 void setName(const std::string &name, SetNameCallback cb);
154 * Gets a name attribute of the SceneList resource.
156 * @return A name of the SceneList resource
158 std::string getName() const;
161 RemoteSceneList(std::shared_ptr< SceneListResourceRequestor >);
163 static void onInstanceCreated(const RCSRepresentation &, int, const std::string &,
164 std::shared_ptr< SceneListResourceRequestor >, const CreateInstanceCallback &);
166 static RemoteSceneList::Ptr buildSceneList(
167 std::shared_ptr< SceneListResourceRequestor >, const RCSResourceAttributes &);
169 RemoteSceneCollection::Ptr createRemoteSceneCollection(
170 const std::string &link, const std::string &id, const std::string &name);
172 std::shared_ptr< SceneListResourceRequestor > getListResourceRequestor() const;
174 std::vector<std::pair<RCSResourceAttributes, std::vector<RCSResourceAttributes>>>
175 parseSceneListFromAttributes(const RCSResourceAttributes &);
177 std::vector<RCSResourceAttributes> getChildrenAttributes(
178 const RCSResourceAttributes &) const;
180 void onSceneCollectionCreated(
181 const std::string &link, const std::string &id, const std::string &name,
182 int, const AddNewSceneCollectionCallback &);
184 void onNameSet(int, const std::string &, const SetNameCallback &);
188 std::vector< RemoteSceneCollection::Ptr > m_remoteSceneCollections;
189 mutable std::mutex m_nameLock;
190 mutable std::mutex m_collectionLock;
191 std::shared_ptr< SceneListResourceRequestor > m_requestor;
197 #endif /* SM_REMOTE_SCENELIST_H_ */