Imported Upstream version 1.1.0
[platform/upstream/iotivity.git] / service / resource-encapsulation / src / serverBuilder / include / RequestHandler.h
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 #ifndef SERVERBUILDER_REQUESTHANDLER_H
22 #define SERVERBUILDER_REQUESTHANDLER_H
23
24 #include "RCSResponse.h"
25 #include "RCSResourceAttributes.h"
26
27 #include "OCRepresentation.h"
28
29 namespace OIC
30 {
31     namespace Service
32     {
33
34         class RCSResourceObject;
35
36         class RequestHandler
37         {
38         public:
39             RequestHandler();
40
41             RequestHandler(const RequestHandler&) = delete;
42             RequestHandler(RequestHandler&&) = default;
43
44             RequestHandler(int errorCode);
45
46             RequestHandler(const RCSResourceAttributes&, int errorCode = DEFAULT_ERROR_CODE);
47
48             RequestHandler(RCSResourceAttributes&&, int errorCode = DEFAULT_ERROR_CODE);
49
50             virtual ~RequestHandler() { };
51
52             int getErrorCode() const;
53
54             bool hasCustomRepresentation() const;
55
56             OC::OCRepresentation getRepresentation() const;
57
58         public:
59             static constexpr int DEFAULT_ERROR_CODE = 200;
60
61         private:
62             const int m_errorCode;
63             const bool m_customRep;
64             const OC::OCRepresentation m_ocRep;
65         };
66
67         class SetRequestHandler: public RequestHandler
68         {
69         private:
70             typedef std::pair< std::string, RCSResourceAttributes::Value > AttrKeyValuePair;
71             typedef std::vector< AttrKeyValuePair > AttrKeyValuePairs;
72
73         public:
74             SetRequestHandler(const SetRequestHandler&) = delete;
75             SetRequestHandler(SetRequestHandler&&) = default;
76
77             SetRequestHandler();
78
79             SetRequestHandler(int errorCode);
80
81             SetRequestHandler(const RCSResourceAttributes&, int errorCode = DEFAULT_ERROR_CODE);
82
83             SetRequestHandler(RCSResourceAttributes&&, int errorCode = DEFAULT_ERROR_CODE);
84
85             AttrKeyValuePairs applyAcceptanceMethod(RCSSetResponse::AcceptanceMethod,
86                     RCSResourceObject&, const RCSResourceAttributes&) const;
87         };
88
89     }
90 }
91
92 #endif // SERVERBUILDER_REQUESTHANDLER_H