785145836a0f0e6730482c86b5b0851658ee3a02
[platform/upstream/iotivity.git] / service / resource-hosting / src / RequestObject.cpp
1 //******************************************************************
2 //
3 // Copyright 2015 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 #include "RequestObject.h"
22
23 namespace OIC
24 {
25 namespace Service
26 {
27
28 RequestObject::RequestObject()
29 : pSetRequestCB(nullptr)
30 {
31 }
32
33 RequestObject::RequestObject(SetRequestCallback cb)
34 : pSetRequestCB(cb)
35 {
36 }
37
38 RequestObject::~RequestObject()
39 {
40     pSetRequestCB = {};
41 }
42
43 void RequestObject::invokeRequest(RemoteObjectPtr remoteObject, RequestMethod method,
44         const RCSResourceAttributes & resourceAttibutes)
45 {
46     switch (method)
47     {
48     case RequestMethod::Set:
49     {
50         if(pSetRequestCB == nullptr)
51         {
52             remoteObject->setRemoteAttributes(resourceAttibutes,
53                     std::bind(&RequestObject::setRequestCB, this,
54                             std::placeholders::_1, resourceAttibutes));
55         }
56         else
57         {
58             remoteObject->setRemoteAttributes(resourceAttibutes,
59                     std::bind(pSetRequestCB,
60                             std::placeholders::_1, resourceAttibutes));
61         }
62     }
63         break;
64     case RequestMethod::Get:
65     case RequestMethod::Delete:
66     default:
67         // unknown type of method.
68         break;
69     }
70 }
71
72 void RequestObject::setRequestCB(const RCSResourceAttributes & returnedAttributes,
73         const RCSResourceAttributes & putAttibutes)
74 {
75     if(putAttibutes != returnedAttributes)
76     {
77         // TODO fail set attributes
78     }
79 }
80
81 } /* namespace Service */
82 } /* namespace OIC */