Merge branch 'master' into group-manager
[platform/upstream/iotivity.git] / service / scene-manager / src / SceneCollectionResource.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 SCENE_COLLECTION_RESOURCE_OBJECT_H
22 #define SCENE_COLLECTION_RESOURCE_OBJECT_H
23
24 #include <list>
25
26 #include "RCSResourceObject.h"
27 #include "SceneCommons.h"
28 #include "SceneMemberResource.h"
29
30 namespace OIC
31 {
32     namespace Service
33     {
34         class SceneCollectionResource
35                 : public std::enable_shared_from_this<SceneCollectionResource>
36         {
37         public:
38             typedef std::shared_ptr< SceneCollectionResource > Ptr;
39             typedef std::function< void(int) > SceneExecuteCallback;
40
41             ~SceneCollectionResource() = default;
42
43             static SceneCollectionResource::Ptr createSceneCollectionObject();
44
45             void addScene(std::string &&);
46             void addScene(const std::string &);
47
48             void addSceneMember(SceneMemberResource::Ptr);
49
50             void execute(std::string &&);
51             void execute(const std::string &);
52             void execute(std::string &&, SceneExecuteCallback);
53             void execute(const std::string &, SceneExecuteCallback);
54
55             void setName(std::string &&);
56             void setName(const std::string &);
57
58             std::string getName() const;
59
60             std::string getId() const;
61             std::string getUri() const;
62             std::string getAddress() const;
63
64             const std::vector<SceneMemberResource::Ptr> getSceneMembers();
65
66             RCSResourceObject::Ptr getRCSResourceObject() const;
67
68         private:
69             class SceneExecuteResponseHandler
70             {
71             public:
72                 typedef std::shared_ptr<SceneExecuteResponseHandler> Ptr;
73
74                 SceneExecuteResponseHandler() = default;
75                 ~SceneExecuteResponseHandler() = default;
76
77                 int m_numOfMembers;
78                 int m_responseMembers;
79                 int m_errorCode;
80                 std::weak_ptr<SceneCollectionResource> m_Owner;
81                 SceneExecuteCallback m_Cb;
82
83                 static SceneExecuteResponseHandler::Ptr createExecuteHandler(
84                         const SceneCollectionResource::Ptr, SceneExecuteCallback);
85                 void onResponse(const RCSResourceAttributes &, int);
86             };
87
88             class SceneCollectionRequestHandler
89             {
90             public:
91                 SceneCollectionRequestHandler() = default;
92                 ~SceneCollectionRequestHandler() = default;
93
94                 std::weak_ptr<SceneCollectionResource> m_Owner;
95
96                 RCSSetResponse onSetRequest(
97                         const RCSRequest &, RCSResourceAttributes &);
98                 void onExecute(int, /*const RCSRequest &,*/ RCSResourceAttributes &);
99
100             private:
101                 RCSSetResponse addSceneRequest(
102                         const RCSRequest &, RCSResourceAttributes &);
103                 RCSSetResponse executeSceneRequest(
104                         const RCSRequest &, RCSResourceAttributes &);
105                 RCSSetResponse createSceneMemberRequest(
106                         const RCSRequest &, RCSResourceAttributes &);
107             };
108
109             std::string m_Uri;
110             std::string m_Address;
111
112             RCSResourceObject::Ptr m_SceneCollectionResourceObj;
113             std::mutex m_SceneMemberLock;
114             std::vector<SceneMemberResource::Ptr> m_SceneMembers;
115
116             SceneCollectionRequestHandler m_RequestHandler;
117             std::mutex m_ExecuteHandlerLock;
118             std::list<SceneExecuteResponseHandler::Ptr> m_ExecuteHandlers;
119
120             SceneCollectionResource() = default;
121
122             SceneCollectionResource(const SceneCollectionResource &) = delete;
123             SceneCollectionResource & operator = (
124                     const SceneCollectionResource &) = delete;
125
126             SceneCollectionResource(SceneCollectionResource &&) = delete;
127             SceneCollectionResource && operator = (
128                     SceneCollectionResource &&) = delete;
129
130             void onExecute(int, SceneExecuteCallback, SceneExecuteResponseHandler::Ptr);
131         };
132     }
133 }
134
135
136 #endif // SCENE_COLLECTION_RESOURCE_OBJECT_H