add scene manager remote interface class implementation
[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
28 #include "RemoteSceneCollection.h"
29 #include "RCSRemoteResourceObject.h"
30
31 namespace OIC
32 {
33     namespace Service
34     {
35
36         class SceneListResourceRequestor;
37
38         class RemoteSceneList
39             : public std::enable_shared_from_this< RemoteSceneList >
40         {
41             public:
42                 typedef std::unique_ptr< RemoteSceneList > Ptr;
43
44                 typedef std::function< void(RemoteSceneList::Ptr, int) >
45                 CreateInstanceCallback;
46
47                 typedef std::function< void(RemoteSceneCollection::Ptr, int) >
48                 AddNewSceneCollectionCallback;
49
50                 typedef std::function< void(int eCode) >
51                 SetNameCallback;
52
53
54             public:
55                 ~RemoteSceneList() = default;
56
57                 static void createInstance
58                 (RCSRemoteResourceObject::Ptr pSceneListResource, CreateInstanceCallback);
59
60                 void addNewSceneCollection(AddNewSceneCollectionCallback);
61                 void removeSceneCollection(RemoteSceneCollection::Ptr);
62
63                 std::vector< RemoteSceneCollection::Ptr > getRemoteSceneCollections() const;
64
65                 void setName(const std::string &name, SetNameCallback);
66                 std::string getName() const;
67
68
69             private:
70                 class GetResponseHandler
71                 {
72                     public:
73                         typedef std::shared_ptr< GetResponseHandler > Ptr;
74
75                         typedef std::function< void(int eCode) >
76                         GetCallback;
77
78                         GetResponseHandler(std::shared_ptr< RemoteSceneList > ptr);
79                         ~GetResponseHandler() = default;
80
81                         int m_numOfCollections;
82                         int m_respondedCollections;
83                         int m_errorCode;
84                         std::weak_ptr< RemoteSceneList > m_owner;
85                         GetCallback m_cb;
86
87                         void startGetResponseHandler(const std::string &host, GetCallback cb);
88
89                         void onGetCollectionAttrs(const HeaderOpts &, const RCSRepresentation &,
90                                                   int eCode, RemoteSceneCollection::Ptr,
91                                                   const std::string &);
92
93                         void onGetListAttrs(const HeaderOpts &, const RCSRepresentation &, int,
94                                             const std::string &);
95                 };
96
97
98             private:
99                 RemoteSceneList(std::shared_ptr< SceneListResourceRequestor > pRequestor);
100
101                 static void onInstanceCreated(int, std::shared_ptr< RemoteSceneList >,
102                                               CreateInstanceCallback);
103
104                 RemoteSceneCollection::Ptr createRemoteSceneCollectionInstance
105                 (const std::string &link, const std::string &id, const std::string &name);
106
107                 void setGetResponseHandler(const std::string &, GetResponseHandler::GetCallback);
108
109                 void onSceneCollectionCreated
110                 (const std::string &link, const std::string &id, const std::string &name,
111                  int eCode, AddNewSceneCollectionCallback);
112
113                 void onNameSet(int, const std::string &, const SetNameCallback &);
114
115
116             private:
117                 std::string m_name;
118                 std::vector< RemoteSceneCollection::Ptr > m_remoteSceneCollections;
119                 std::shared_ptr< SceneListResourceRequestor > m_requestorPtr;
120
121                 GetResponseHandler::Ptr m_getResponseHandler;
122
123                 friend class GetResponseHandler;
124         };
125
126     }
127 }
128
129 #endif /* SM_REMOTE_SCENELIST_H_ */
130