[IOT-1065][IOT-1069] RC - Tizen: sample application fix
[platform/upstream/iotivity.git] / service / scene-manager / src / SceneMemberResource.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 /**
22  * @file
23  *
24  * This file contains the declaration of classes and its members related to SceneMemberResrouceObject
25  */
26
27 #ifndef SCENE_MEMBER_RESOURCE_OBJECT_H
28 #define SCENE_MEMBER_RESOURCE_OBJECT_H
29
30 #include "RCSResourceObject.h"
31 #include "RCSRemoteResourceObject.h"
32 #include "SceneCommons.h"
33
34 namespace OIC
35 {
36     namespace Service
37     {
38         class SceneMemberResource
39                 : public std::enable_shared_from_this<SceneMemberResource>
40         {
41         public:
42             typedef std::shared_ptr< SceneMemberResource > Ptr;
43
44             /**
45              * Callback definition to be invoked when the response of setRemoteAttribitues is received.
46              *
47              * @param attrs the result attributes
48              * @param eCode the error code received from the resource
49              *
50              * @see RCSRemoteResourceObject::setRemoteAttributes
51              */
52             typedef std::function< void(const RCSResourceAttributes & attrs, int eCode) >
53                 MemberexecuteCallback;
54
55             /**
56              * A Mapping information about each scene values.
57              */
58             struct MappingInfo
59             {
60                 MappingInfo(
61                         const std::string & scene,
62                         const std::string & keyName,
63                         const RCSResourceAttributes::Value & val)
64                 :sceneName(scene), key(keyName), value(val) { }
65
66                 MappingInfo(MappingInfo &&) = default;
67                 MappingInfo(const MappingInfo &) = default;
68
69                 static MappingInfo create(const RCSResourceAttributes &);
70
71                 std::string sceneName;              ///< name of scene value
72                 std::string key;                    ///< key to set at attributes of remote resource
73                 RCSResourceAttributes::Value value; ///< val to set at attributes of remote resource
74             };
75
76             ~SceneMemberResource() = default;
77
78             /**
79              * Register a Scene member resource and return a SceneMemberResourceObject
80              * using link information of remote resource.
81              *
82              * @param attrs information to make scene member resource
83              */
84             static SceneMemberResource::Ptr
85             createSceneMemberResource(RCSResourceAttributes && attrs);
86
87             /**
88              * @overload
89              */
90             static SceneMemberResource::Ptr
91             createSceneMemberResource(const RCSResourceAttributes &);
92
93             /**
94              * Register a Scene member resource and returns a SceneMemberResourceObject
95              * using information of RCSRemoteResourceObject.
96              *
97              * @param remoteObj information to make scene member resource
98              */
99             static SceneMemberResource::Ptr
100             createSceneMemberResource(RCSRemoteResourceObject::Ptr remoteObj);
101
102             /**
103              * Add Scene mapping information at scene member resource.
104              *
105              * @param mappingInfo
106              */
107             void addMappingInfo(MappingInfo && mappingInfo);
108
109             /**
110              * @overload
111              */
112             void addMappingInfo(const MappingInfo &);
113
114             /**
115              * Returns all Mapping information of a scene member resource.
116              */
117             std::vector<MappingInfo> getMappingInfos() const;
118
119             std::vector<MappingInfo> findMappingInfos(const std::string & sceneValue) const;
120
121             bool hasSceneValue(const std::string &) const;
122
123             /**
124              * Returns ID of a Scene member resource.
125              */
126             std::string getId() const;
127
128             /**
129              * Returns Uri of a Scene member resource. (e.g. coap://192.168.0.2.1:12345/SceneMember)
130              */
131             std::string getFullUri() const;
132
133             /**
134              * Returns Uri of a Target resource of scene member. (e.g. coap://192.168.0.2.1:12345/light)
135              */
136             std::string getTargetUri() const;
137
138             /**
139              * Returns RCSRemoteResourceObject about Scene member resource
140              */
141             RCSRemoteResourceObject::Ptr getRemoteResourceObject() const;
142
143             /**
144              * Returns RCSResourceObject of Scene member resource
145              */
146             RCSResourceObject::Ptr getRCSResourceObject() const;
147
148             /**
149              * Execute of Scene Action (with callback for response).
150              *
151              * @param sceneValue scene value to execute
152              * @param cb callback to response
153              */
154             void execute(std::string && sceneValue, MemberexecuteCallback cb);
155
156             /**
157              * @overload
158              */
159             void execute(const std::string &, MemberexecuteCallback);
160
161             /**
162              * Execute of Scene Action (without callback for response).
163              *
164              * @param sceneValue scene value to execute
165              */
166             void execute(std::string && sceneValue);
167
168             /**
169              * @overload
170              */
171             void execute(const std::string &);
172
173             void setName(const std::string &);
174             void setName(std::string &&);
175
176             std::string getName() const;
177
178         private:
179             class SceneMemberRequestHandler
180             {
181             public:
182                 SceneMemberRequestHandler() = default;
183                 ~SceneMemberRequestHandler() = default;
184
185                 std::weak_ptr<SceneMemberResource> m_owner;
186
187                 RCSSetResponse onSetRequest(const RCSRequest & , RCSResourceAttributes &);
188
189                 RCSSetResponse addMappingInfos(const RCSRequest & , RCSResourceAttributes &);
190                 RCSSetResponse setSceneMemberName(const RCSRequest & , RCSResourceAttributes &);
191             };
192
193             std::string m_uri;
194             RCSResourceObject::Ptr m_sceneMemberResourceObj;
195             RCSRemoteResourceObject::Ptr m_remoteMemberObj;
196             SceneMemberRequestHandler m_requestHandler;
197
198             SceneMemberResource() = default;
199
200             SceneMemberResource(const SceneMemberResource &) = delete;
201             SceneMemberResource & operator = (const SceneMemberResource &) = delete;
202
203             SceneMemberResource(SceneMemberResource &&) = delete;
204             SceneMemberResource & operator = (SceneMemberResource &&) = delete;
205
206             void createResourceObject();
207             void setDefaultAttributes();
208             void initSetRequestHandler();
209         };
210     }
211 }
212
213 #endif // SCENE_MEMBER_RESOURCE_OBJECT_H