Fix initializing logic of remote scene list
[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         class RemoteSceneCollection
41         {
42             public:
43                 typedef std::shared_ptr< RemoteSceneCollection > Ptr;
44
45                 typedef std::function< void(RemoteScene::Ptr, int eCode) >
46                     AddNewSceneCallback;
47
48                 typedef std::function< void(int eCode) > RemoveSceneCallback;
49
50                 typedef std::function< void(int eCode) > SetNameCallback;
51
52             public:
53                 ~RemoteSceneCollection() = default;
54
55                 void addNewScene(const std::string &name, AddNewSceneCallback);
56                 void removeScene(RemoteScene::Ptr, RemoveSceneCallback);
57
58                 std::unordered_map< std::string, RemoteScene::Ptr > getRemoteScenes() const;
59                 RemoteScene::Ptr getRemoteScene(const std::string &sceneName) const;
60
61                 void setName(const std::string &name, SetNameCallback);
62                 std::string getName() const;
63
64                 std::string getId() const;
65
66             private:
67                 RemoteSceneCollection(
68                     std::shared_ptr< SceneCollectionResourceRequestor >,
69                     const std::string &id, const std::string &name);
70
71                 void addExistingRemoteScenes(const std::vector< std::string > &);
72
73                 void initializeRemoteScenes(const std::vector< RCSResourceAttributes > &,
74                                                      const std::string &);
75
76                 RemoteScene::Ptr createRemoteSceneInstance(const std::string &);
77
78                 void onSceneAddedRemoved(int, const std::string &name, int,
79                                          const AddNewSceneCallback &, const RemoveSceneCallback &);
80
81                 void onNameSet(int, const std::string &, const SetNameCallback &);
82
83             private:
84                 std::string m_id;
85                 std::string m_name;
86                 mutable std::mutex m_sceneLock;
87                 std::unordered_map< std::string, RemoteScene::Ptr > m_remoteScenes;
88                 std::shared_ptr< SceneCollectionResourceRequestor > m_requestor;
89
90                 friend class RemoteSceneList;
91         };
92
93     }
94 }
95
96 #endif /* SM_REMOTE_SCENECOLLECTION_H_ */
97