Imported Upstream version 1.0.1
[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() : pSetRequestCB(nullptr){ }
29 RequestObject::RequestObject(SetRequestCallback cb) : pSetRequestCB(cb){ };
30
31 RequestObject::~RequestObject()
32 {
33     pSetRequestCB = {};
34 }
35
36 void RequestObject::invokeRequest(RemoteObjectPtr remoteObject, RequestMethod method,
37         RCSResourceAttributes & resourceAttibutes)
38 {
39     try
40     {
41         switch (method)
42         {
43         case RequestMethod::Setter:
44         {
45             if(pSetRequestCB == nullptr)
46             {
47                 remoteObject->setRemoteAttributes(resourceAttibutes,
48                         std::bind(&RequestObject::setRequestCB, this,
49                                 std::placeholders::_1, resourceAttibutes));
50             }
51             else
52             {
53                 remoteObject->setRemoteAttributes(resourceAttibutes,
54                         std::bind(pSetRequestCB,
55                                 std::placeholders::_1, resourceAttibutes));
56             }
57         }
58             break;
59         case RequestMethod::Getter:
60         case RequestMethod::Delete:
61         default:
62             // unknown type of method.
63             break;
64         }
65     }catch(...)
66     {
67         throw;
68     }
69 }
70
71 void RequestObject::setRequestCB(const RCSResourceAttributes & returnedAttributes,
72         RCSResourceAttributes & putAttibutes)
73 {
74     if(putAttibutes != returnedAttributes)
75     {
76         // TODO fail set attributes
77     }
78 }
79
80 } /* namespace Service */
81 } /* namespace OIC */