1 //******************************************************************
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
11 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #ifndef SERVERBUILDER_REQUESTHANDLER_H
22 #define SERVERBUILDER_REQUESTHANDLER_H
24 #include <RCSResponse.h>
25 #include <RCSResourceAttributes.h>
29 class OCResourceResponse;
30 class OCRepresentation;
38 class RCSResourceObject;
43 typedef std::function< std::shared_ptr< OC::OCResourceResponse >(RCSResourceObject&) >
47 typedef std::shared_ptr< RequestHandler > Pre;
49 static constexpr int DEFAULT_ERROR_CODE = 200;
53 RequestHandler(const RequestHandler&) = delete;
54 RequestHandler(RequestHandler&&) = default;
56 RequestHandler(int errorCode);
58 RequestHandler(const RCSResourceAttributes&, int errorCode = DEFAULT_ERROR_CODE);
60 RequestHandler(RCSResourceAttributes&&, int errorCode = DEFAULT_ERROR_CODE);
62 virtual ~RequestHandler() { };
64 std::shared_ptr< OC::OCResourceResponse > buildResponse(RCSResourceObject&);
67 const BuildResponseHolder m_holder;
70 class SetRequestHandler: public RequestHandler
73 typedef std::pair< std::string, RCSResourceAttributes::Value > AttrKeyValuePair;
74 typedef std::vector< AttrKeyValuePair > AttrKeyValuePairs;
77 typedef std::shared_ptr< SetRequestHandler > Ptr;
79 SetRequestHandler(const SetRequestHandler&) = delete;
80 SetRequestHandler(SetRequestHandler&&) = default;
84 SetRequestHandler(int errorCode);
86 SetRequestHandler(const RCSResourceAttributes&, int errorCode = DEFAULT_ERROR_CODE);
88 SetRequestHandler(RCSResourceAttributes&&, int errorCode = DEFAULT_ERROR_CODE);
90 AttrKeyValuePairs applyAcceptanceMethod(RCSSetResponse::AcceptanceMethod,
91 RCSResourceObject&, const RCSResourceAttributes&) const;
97 #endif // SERVERBUILDER_REQUESTHANDLER_H