Imported Upstream version 0.9.2
[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 <ResourceAttributesUtils.h>
26
27 namespace OC
28 {
29     class OCResourceResponse;
30     class OCRepresentation;
31 }
32
33 namespace OIC
34 {
35     namespace Service
36     {
37
38         class RCSResourceObject;
39
40         class RequestHandler
41         {
42         private:
43             typedef std::function< std::shared_ptr< OC::OCResourceResponse >(RCSResourceObject&) >
44                         BuildResponseHolder;
45
46         public:
47             typedef std::shared_ptr< RequestHandler > Pre;
48
49             static constexpr int DEFAULT_ERROR_CODE = 200;
50             static constexpr OCEntityHandlerResult DEFAULT_RESULT = OC_EH_OK;
51
52             RequestHandler();
53
54             RequestHandler(const RequestHandler&) = delete;
55             RequestHandler(RequestHandler&&) = default;
56
57             RequestHandler(const OCEntityHandlerResult& result, int errorCode);
58
59             RequestHandler(const RCSResourceAttributes&,
60                     const OCEntityHandlerResult& result = DEFAULT_RESULT,
61                     int errorCode = DEFAULT_ERROR_CODE);
62
63             RequestHandler(RCSResourceAttributes&&,
64                     const OCEntityHandlerResult& result = DEFAULT_RESULT,
65                     int errorCode = DEFAULT_ERROR_CODE);
66
67
68             virtual ~RequestHandler() { };
69
70             std::shared_ptr< OC::OCResourceResponse > buildResponse(RCSResourceObject&);
71
72         private:
73             const BuildResponseHolder m_holder;
74         };
75
76         class SetRequestHandler: public RequestHandler
77         {
78         public:
79             typedef std::shared_ptr< SetRequestHandler > Ptr;
80
81             SetRequestHandler(const SetRequestHandler&) = delete;
82             SetRequestHandler(SetRequestHandler&&) = default;
83
84             SetRequestHandler();
85
86             SetRequestHandler(const OCEntityHandlerResult& result, int errorCode);
87
88             SetRequestHandler(const RCSResourceAttributes&,
89                     const OCEntityHandlerResult& result = DEFAULT_RESULT,
90                     int errorCode = DEFAULT_ERROR_CODE);
91
92             SetRequestHandler(RCSResourceAttributes&&,
93                     const OCEntityHandlerResult& result = DEFAULT_RESULT,
94                     int errorCode = DEFAULT_ERROR_CODE);
95
96             AttrKeyValuePairs applyAcceptanceMethod(RCSSetResponse::AcceptanceMethod,
97                     RCSResourceObject&, const RCSResourceAttributes&) const;
98         };
99
100     }
101 }
102
103 #endif // SERVERBUILDER_REQUESTHANDLER_H