1 //******************************************************************
3 // Copyright 2016 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
11 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #ifndef SCENE_COLLECTION_RESOURCE_OBJECT_H
22 #define SCENE_COLLECTION_RESOURCE_OBJECT_H
26 #include "RCSResourceObject.h"
27 #include "SceneCommons.h"
28 #include "SceneMemberResource.h"
34 class SceneCollectionResource
35 : public std::enable_shared_from_this<SceneCollectionResource>
38 typedef std::shared_ptr< SceneCollectionResource > Ptr;
39 typedef std::function< void(int) > SceneExecuteCallback;
41 ~SceneCollectionResource() = default;
43 static SceneCollectionResource::Ptr createSceneCollectionObject();
45 void addScene(std::string &&);
46 void addScene(const std::string &);
48 void addSceneMember(SceneMemberResource::Ptr);
50 void execute(std::string &&);
51 void execute(const std::string &);
52 void execute(std::string &&, SceneExecuteCallback);
53 void execute(const std::string &, SceneExecuteCallback);
55 void setName(std::string &&);
56 void setName(const std::string &);
58 std::string getName() const;
60 std::string getId() const;
61 std::string getUri() const;
62 std::string getAddress() const;
64 const std::vector<SceneMemberResource::Ptr> getSceneMembers();
66 RCSResourceObject::Ptr getRCSResourceObject() const;
69 class SceneExecuteResponseHandler
72 typedef std::shared_ptr<SceneExecuteResponseHandler> Ptr;
74 SceneExecuteResponseHandler() = default;
75 ~SceneExecuteResponseHandler() = default;
78 int m_responseMembers;
80 std::weak_ptr<SceneCollectionResource> m_Owner;
81 SceneExecuteCallback m_Cb;
83 static SceneExecuteResponseHandler::Ptr createExecuteHandler(
84 const SceneCollectionResource::Ptr, SceneExecuteCallback);
85 void onResponse(const RCSResourceAttributes &, int);
88 class SceneCollectionRequestHandler
91 SceneCollectionRequestHandler() = default;
92 ~SceneCollectionRequestHandler() = default;
94 std::weak_ptr<SceneCollectionResource> m_Owner;
96 RCSSetResponse onSetRequest(
97 const RCSRequest &, RCSResourceAttributes &);
98 void onExecute(int, /*const RCSRequest &,*/ RCSResourceAttributes &);
101 RCSSetResponse addSceneRequest(
102 const RCSRequest &, RCSResourceAttributes &);
103 RCSSetResponse executeSceneRequest(
104 const RCSRequest &, RCSResourceAttributes &);
105 RCSSetResponse createSceneMemberRequest(
106 const RCSRequest &, RCSResourceAttributes &);
110 std::string m_Address;
112 RCSResourceObject::Ptr m_SceneCollectionResourceObj;
113 std::mutex m_SceneMemberLock;
114 std::vector<SceneMemberResource::Ptr> m_SceneMembers;
116 SceneCollectionRequestHandler m_RequestHandler;
117 std::mutex m_ExecuteHandlerLock;
118 std::list<SceneExecuteResponseHandler::Ptr> m_ExecuteHandlers;
120 SceneCollectionResource() = default;
122 SceneCollectionResource(const SceneCollectionResource &) = delete;
123 SceneCollectionResource & operator = (
124 const SceneCollectionResource &) = delete;
126 SceneCollectionResource(SceneCollectionResource &&) = delete;
127 SceneCollectionResource && operator = (
128 SceneCollectionResource &&) = delete;
130 void onExecute(int, SceneExecuteCallback, SceneExecuteResponseHandler::Ptr);
136 #endif // SCENE_COLLECTION_RESOURCE_OBJECT_H