add doxygen comments for exceptions in Scene-manager remote apis
[platform/upstream/iotivity.git] / service / scene-manager / include / RemoteSceneList.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_SCENELIST_H_
22 #define SM_REMOTE_SCENELIST_H_
23
24 #include <memory>
25 #include <vector>
26 #include <functional>
27 #include <mutex>
28
29 #include "RemoteSceneCollection.h"
30 #include "RCSRemoteResourceObject.h"
31
32 namespace OIC
33 {
34     namespace Service
35     {
36         class SceneListResourceRequestor;
37
38         /**
39         * @class RemoteSceneList
40         *
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.
47         */
48         class RemoteSceneList
49         {
50             public:
51                 typedef std::unique_ptr< RemoteSceneList > Ptr;
52
53                 /**
54                 * Callback definition to be invoked when a response of createInstance is
55                 * received.
56                 *
57                 * @param list Created RemoteSceneList instance pointer
58                 * @param eCode The error code received from the SceneList on remote side
59                 *
60                 * @note Error code '200' stands for success, '400' for bad request,
61                 * and '500' for internal error.
62                 *
63                 * @see createInstance
64                 */
65                 typedef std::function< void(RemoteSceneList::Ptr list, int eCode) >
66                     CreateInstanceCallback;
67
68                 /**
69                 * Callback definition to be invoked when a response of addNewSceneCollection is
70                 * received.
71                 *
72                 * @param collection Created RemoteSceneCollection instance pointer
73                 * @param eCode The error code received from the SceneList on remote
74                 *
75                 * @note Error code '200' stands for success, '400' for bad request,
76                 * and '500' for internal error.
77                 *
78                 * @see addNewSceneCollection
79                 */
80                 typedef std::function< void(RemoteSceneCollection::Ptr collection, int eCode) >
81                     AddNewSceneCollectionCallback;
82
83                 /**
84                 * Callback definition to be invoked when a response of setName is
85                 * received.
86                 *
87                 * @param eCode the error code received from the SceneList on remote
88                 *
89                 * @note Error code '200' stands for success, '400' for bad request,
90                 * and '500' for internal error.
91                 *
92                 * @see setName
93                 */
94                 typedef std::function< void(int eCode) > SetNameCallback;
95
96             public:
97                 ~RemoteSceneList() = default;
98
99                 /**
100                 * Creates RemoteSceneList instance with provided RCSRemoteResourceObject of
101                 * discovered SceneList resource on remote side.
102                 *
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.
109                 *
110                 * @param sceneListResource RCSRemoteResourceObject pointer of SceneList
111                 * @param cb A callback to receive the response
112                 *
113                 * @throws RCSInvalidParameterException If parameter is invalid.
114                 * @throws PlatformException If the platform operation failed
115                 *
116                 * @see RCSRemoteResourceObject
117                 */
118                 static void createInstance(
119                     RCSRemoteResourceObject::Ptr sceneListResource, CreateInstanceCallback cb);
120
121                 /**
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.
125                 *
126                 * @param cb A callback to receive created RemoteSceneCollection instance
127                 *
128                 * @throws RCSInvalidParameterException If callback is null.
129                 * @throws PlatformException If the platform operation failed
130                 *
131                 * @note RemoteSceneCollection instance is only produced by RemoteSceneList class.
132                 */
133                 void addNewSceneCollection(AddNewSceneCollectionCallback cb);
134
135                 /**
136                 * Gets all RemoteSceneCollection instances stored in the RemoteSceneList instance.
137                 *
138                 * @return A vector of shared pointers of RemoteSceneCollection instances
139                 */
140                 std::vector< RemoteSceneCollection::Ptr > getRemoteSceneCollections() const;
141
142                 /**
143                 * Request to set a name attribute of the SceneList resource on remote side.
144                 *
145                 * @param name A name of the SceneList
146                 * @param cb A callback to receive the response
147                 *
148                 * @throws RCSInvalidParameterException If callback is null.
149                 * @throws PlatformException If the platform operation failed
150                 */
151                 void setName(const std::string &name, SetNameCallback cb);
152
153                 /**
154                 * Gets a name attribute of the SceneList resource.
155                 *
156                 * @return A name of the SceneList resource
157                 */
158                 std::string getName() const;
159
160             private:
161                 RemoteSceneList(std::shared_ptr< SceneListResourceRequestor >);
162
163                 static void onInstanceCreated(const RCSRepresentation &, int, const std::string &,
164                     std::shared_ptr< SceneListResourceRequestor >, const CreateInstanceCallback &);
165
166                 static RemoteSceneList::Ptr buildSceneList(
167                     std::shared_ptr< SceneListResourceRequestor >, const RCSResourceAttributes &);
168
169                 RemoteSceneCollection::Ptr createRemoteSceneCollection(
170                     const std::string &link, const std::string &id, const std::string &name);
171
172                 std::shared_ptr< SceneListResourceRequestor > getListResourceRequestor() const;
173
174                 std::vector<std::pair<RCSResourceAttributes, std::vector<RCSResourceAttributes>>>
175                     parseSceneListFromAttributes(const RCSResourceAttributes &);
176
177                 std::vector<RCSResourceAttributes> getChildrenAttributes(
178                     const RCSResourceAttributes &) const;
179
180                 void onSceneCollectionCreated(
181                     const std::string &link, const std::string &id, const std::string &name,
182                     int, const AddNewSceneCollectionCallback &);
183
184                 void onNameSet(int, const std::string &, const SetNameCallback &);
185
186             private:
187                 std::string m_name;
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;
192         };
193
194     }
195 }
196
197 #endif /* SM_REMOTE_SCENELIST_H_ */