[IOT-1065][IOT-1069] RC - Tizen: sample application fix
[platform/upstream/iotivity.git] / service / scene-manager / src / SceneCollectionResourceRequestor.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_SCENECOLLECTION_RESOURCE_REQUESTOR_H_
22 #define SM_SCENECOLLECTION_RESOURCE_REQUESTOR_H_
23
24 #include <map>
25 #include <mutex>
26
27 #include "SceneCommons.h"
28 #include "RCSRemoteResourceObject.h"
29 #include "RCSRepresentation.h"
30 #include "SceneMemberResourceRequestor.h"
31
32 namespace OIC
33 {
34     namespace Service
35     {
36
37         class SceneCollectionResourceRequestor
38             : public std::enable_shared_from_this< SceneCollectionResourceRequestor >
39         {
40             public:
41                 typedef std::shared_ptr< SceneCollectionResourceRequestor > Ptr;
42                 typedef std::weak_ptr< SceneCollectionResourceRequestor > wPtr;
43
44                 enum REQUEST_TYPE
45                 {
46                     ADD_SCENE, REMOVE_SCENE, EXECUTE_SCENE
47                 };
48
49                 typedef std::function< 
50                     void(REQUEST_TYPE, const std::string &name, int eCode) >
51                         InternalSceneRequestCallback;
52
53                 typedef std::function < void(int eCode) > InternalAddMemberCallback;
54
55                 typedef std::function < void(int eCode) > InternalSetNameCallback;
56
57             public:
58                 SceneCollectionResourceRequestor(RCSRemoteResourceObject::Ptr collectionResource);
59                 ~SceneCollectionResourceRequestor() = default;
60
61                 void requestSceneCreation(const std::string &name, InternalSceneRequestCallback);
62                 void requestSceneRemoval(const std::string &name, InternalSceneRequestCallback);
63
64                 void requestSceneExecution(const std::string &name, InternalSceneRequestCallback);
65
66                 void requestAddSceneMember(RCSRemoteResourceObject::Ptr targetResource,
67                                            const std::string &sceneName,
68                                            const RCSResourceAttributes &attr,
69                                            InternalAddMemberCallback);
70
71                 void requestSetName(const std::string &, InternalSetNameCallback);
72
73                 void requestGet(const std::string &, RCSRemoteResourceObject::GetCallback);
74
75                 RCSRemoteResourceObject::Ptr getRemoteResourceObject() const;
76
77                 SceneMemberResourceRequestor::Ptr createSceneMemberResourceRequestor(
78                     const std::string &memHref, const std::string &id,
79                     RCSRemoteResourceObject::Ptr target);
80
81                 SceneMemberResourceRequestor::Ptr getSceneMemberResourceRequestor(
82                     const std::string &targetHref) const;
83
84             private:
85                 static void onSetResponseForScene(
86                     const RCSResourceAttributes &attrs, int eCode,
87                     const std::string &name, const InternalSceneRequestCallback &,
88                     REQUEST_TYPE, SceneCollectionResourceRequestor::wPtr);
89
90                 void onSetResponseForScene_impl(
91                     const RCSResourceAttributes &attrs, int eCode,
92                     const std::string &name, const InternalSceneRequestCallback &,
93                     REQUEST_TYPE);
94
95                 static void onSceneMemberAdded(
96                     const RCSRepresentation &, int eCode,
97                     RCSRemoteResourceObject::Ptr, const InternalAddMemberCallback &,
98                     SceneCollectionResourceRequestor::wPtr);
99
100                 void onSceneMemberAdded_impl(
101                     const RCSRepresentation &, int eCode,
102                     RCSRemoteResourceObject::Ptr, const InternalAddMemberCallback &);
103
104                 static void onNameSet(const RCSRepresentation &, int eCode, const std::string &,
105                     const InternalSetNameCallback &, SceneCollectionResourceRequestor::wPtr);
106
107                 void onNameSet_impl(const RCSRepresentation &, int eCode, const std::string &,
108                     const InternalSetNameCallback &);
109
110             private:
111                 RCSRemoteResourceObject::Ptr m_sceneCollectionResource;
112                 mutable std::mutex m_memberRequestorLock;
113                 std::map< std::string, SceneMemberResourceRequestor::Ptr > m_memberRequestors;
114         };
115         
116     }
117 }
118
119 #endif /* SM_SCENECOLLECTION_RESOURCE_REQUESTOR_H_ */
120