[CONPRO-1430] BlockWiseTransfer Error
[platform/upstream/iotivity.git] / service / scene-manager / include / RemoteSceneCollection.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_SCENECOLLECTION_H_
22 #define SM_REMOTE_SCENECOLLECTION_H_
23
24 #include <memory>
25 #include <functional>
26 #include <string>
27 #include <unordered_map>
28 #include <mutex>
29
30 #include "RemoteScene.h"
31 #include "RCSRemoteResourceObject.h"
32
33 namespace OIC
34 {
35     namespace Service
36     {
37
38         class SceneCollectionResourceRequestor;
39
40         /**
41         * @class RemoteSceneCollection
42         *
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.
49         */
50         class RemoteSceneCollection
51         {
52             public:
53                 typedef std::shared_ptr< RemoteSceneCollection > Ptr;
54
55                 /**
56                 * Callback definition to be invoked when a response of addNewScene is
57                 * received.
58                 *
59                 * @param scene created RemoteScene instance pointer
60                 * @param eCode the error code received from the SceneCollection on remote
61                 *
62                 * @note Error code '200' stands for success, '400' for bad request,
63                 * and '500' for internal error.
64                 *
65                 * @see addNewScene
66                 */
67                 typedef std::function< void(RemoteScene::Ptr scene, int eCode) >
68                     AddNewSceneCallback;
69
70                 /**
71                 * Callback definition to be invoked when a response of setName is
72                 * received.
73                 *
74                 * @param eCode the error code received from the SceneCollection on remote
75                 *
76                 * @note Error code '200' stands for success, '400' for bad request,
77                 * and '500' for internal error.
78                 *
79                 * @see setName
80                 */
81                 typedef std::function< void(int eCode) > SetNameCallback;
82
83             public:
84                 ~RemoteSceneCollection() = default;
85
86                 /**
87                 * Requests to add new Scene to the SceneCollection resource on remote side
88                 * and creates RemoteScene instance corresponding to the created Scene.
89                 *
90                 * @param name A name of Scene to add
91                 * @param cb A callback to receive created RemoteScene instance
92                 *
93                 * @throws RCSInvalidParameterException If parameter is invalid
94                 * @throws PlatformException If the platform operation failed
95                 *
96                 * @note RemoteScene instance is only produced by RemoteSceneCollection class.
97                 * @note Name of Scene must be unique in one SceneCollection
98                 */
99                 void addNewScene(const std::string &name, AddNewSceneCallback cb);
100
101                 /**
102                 * Gets all RemoteScene instances from RemoteSceneCollection instance.
103                 *
104                 * @return A unordered_map of shared pointers of RemoteScene instances
105                 */
106                 std::unordered_map< std::string, RemoteScene::Ptr > getRemoteScenes() const;
107
108                 /**
109                 * Gets RemoteScene instance with a specific Scene name.
110                 *
111                 * @param sceneName name of the Scene to get
112                 *
113                 * @return A shared pointer of RemoteScene instance
114                 *
115                 * @throws RCSInvalidParameterException If sceneName is invalid
116                 */
117                 RemoteScene::Ptr getRemoteScene(const std::string &sceneName) const;
118
119                 /**
120                 * Request to set a name attribute of the SceneCollection resource on remote side.
121                 *
122                 * @param name A name of the SceneCollection
123                 * @param cb A callback to receive the response
124                 *
125                 * @throws RCSInvalidParameterException If callback is null
126                 * @throws PlatformException If the platform operation failed
127                 */
128                 void setName(const std::string &name, SetNameCallback cb);
129
130                 /**
131                 * Gets a name attribute of the SceneCollection resource
132                 *
133                 * @return A name of the SceneCollection
134                 */
135                 std::string getName() const;
136
137                 /**
138                 * Gets an id attribute of the SceneCollection resource.
139                 *
140                 * @return an id of the SceneCollection resource
141                 */
142                 std::string getId() const;
143
144             private:
145                 RemoteSceneCollection(
146                     std::shared_ptr< SceneCollectionResourceRequestor >,
147                     const std::string &id, const std::string &name);
148
149                 void addExistingRemoteScenes(const std::vector< std::string > &);
150
151                 void initializeRemoteScenes(const std::vector< RCSResourceAttributes > &,
152                                                      const std::string &);
153
154                 RemoteScene::Ptr createRemoteScene(const std::string &);
155
156                 void onSceneAddedRemoved(int, const std::string &name, int,
157                                          const AddNewSceneCallback &);
158
159                 void onNameSet(int, const std::string &, const SetNameCallback &);
160
161             private:
162                 std::string m_id;
163                 std::string m_name;
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;
168
169                 friend class RemoteSceneList;
170         };
171
172     }
173 }
174
175 #endif /* SM_REMOTE_SCENECOLLECTION_H_ */