1 //******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH 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 /// @file OCResourceRequest.h
23 /// @brief This file contains the declaration of classes and its members related to
26 #ifndef __OCRESOURCEREQUEST_H
27 #define __OCRESOURCEREQUEST_H
30 #include "OCRepresentation.h"
32 void formResourceRequest(OCEntityHandlerFlag,
33 OCEntityHandlerRequest*,
34 std::shared_ptr<OC::OCResourceRequest>);
40 * @brief OCResourceRequest provides APIs to extract details from a request URI
42 class OCResourceRequest
45 typedef std::shared_ptr<OCResourceRequest> Ptr;
51 m_requestHandlerFlag{},
55 m_requestHandle{nullptr},
56 m_resourceHandle{nullptr}
60 OCResourceRequest(OCResourceRequest&&) = default;
61 OCResourceRequest& operator=(OCResourceRequest&&) = default;
65 virtual ~OCResourceRequest(void)
70 * Retrieves the type of request string for the entity handler function to operate
71 * @return std::string request type. This could be 'GET'/'PUT'/'POST'/'DELETE'
73 std::string getRequestType() const {return m_requestType;}
76 * Retrieves the query parameters from the request
77 * @return std::string query parameters in the request
79 const QueryParamsMap& getQueryParameters() const {return m_queryParameters;}
82 * Retrieves the request handler flag type. This can be either INIT flag or
83 * REQUEST flag or OBSERVE flag.
85 * INIT indicates that the vendor's entity handler should go and perform
86 * initialization operations
87 * REQUEST indicates that it is a request of certain type (GET/PUT/POST/DELETE)
88 * and entity handler needs to perform corresponding operations
89 * OBSERVE indicates that the request is of type Observe and entity handler
90 * needs to perform corresponding operations
91 * @return int type of request flag
93 int getRequestHandlerFlag() const {return m_requestHandlerFlag;}
96 * Provides the entire resource attribute representation
97 * @return OCRepresentation reference containing the name value pairs
98 * representing the resource's attributes
100 const OCRepresentation& getResourceRepresentation() const {return m_representation;}
103 * @return ObservationInfo reference provides observation information
105 const ObservationInfo& getObservationInfo() const {return m_observationInfo;}
109 * @param resourceUri specifies the resource uri
111 void setResourceUri(const std::string resourceUri)
113 m_resourceUri = resourceUri;
118 * @return std::string resource uri
120 std::string getResourceUri(void)
122 return m_resourceUri;
126 * This API retrieves headerOptions which was sent from a client
128 * @return std::map HeaderOptions with the header options
130 const HeaderOptions& getHeaderOptions() const
132 return m_headerOptions;
136 * This API retrieves the request handle
138 * @return OCRequestHandle
140 const OCRequestHandle& getRequestHandle() const
142 return m_requestHandle;
146 * This API retrieves the resource handle
148 * return OCResourceHandle
150 const OCResourceHandle& getResourceHandle() const
152 return m_resourceHandle;
156 std::string m_requestType;
157 std::string m_resourceUri;
158 QueryParamsMap m_queryParameters;
159 int m_requestHandlerFlag;
160 OCRepresentation m_representation;
161 ObservationInfo m_observationInfo;
162 HeaderOptions m_headerOptions;
163 OCRequestHandle m_requestHandle;
164 OCResourceHandle m_resourceHandle;
168 friend void (::formResourceRequest)(OCEntityHandlerFlag, OCEntityHandlerRequest*,
169 std::shared_ptr<OC::OCResourceRequest>);
170 void setRequestType(const std::string& requestType)
172 m_requestType = requestType;
175 void setPayload(const std::string& requestPayload);
177 void setQueryParams(QueryParamsMap& queryParams)
179 m_queryParameters = queryParams;
182 void setRequestHandlerFlag(int requestHandlerFlag)
184 m_requestHandlerFlag = requestHandlerFlag;
187 void setObservationInfo(const ObservationInfo& observationInfo)
189 m_observationInfo = observationInfo;
192 void setHeaderOptions(const HeaderOptions& headerOptions)
194 m_headerOptions = headerOptions;
198 * This API allows to set request handle
199 * @param requestHandle - OCRequestHandle type used to set the
202 void setRequestHandle(const OCRequestHandle& requestHandle)
204 m_requestHandle = requestHandle;
208 * This API allows to set the resource handle
209 * @param resourceHandle - OCResourceHandle type used to set the
212 void setResourceHandle(const OCResourceHandle& resourceHandle)
214 m_resourceHandle = resourceHandle;
220 #endif //__OCRESOURCEREQUEST_H