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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
24 * This file contains the declaration of classes and its members related to
28 #ifndef OC_RESOURCEREQUEST_H_
29 #define OC_RESOURCEREQUEST_H_
32 #include "OCRepresentation.h"
34 void formResourceRequest(OCEntityHandlerFlag,
35 OCEntityHandlerRequest*,
36 std::shared_ptr<OC::OCResourceRequest>);
42 * @brief OCResourceRequest provides APIs to extract details from a request URI
44 class OCResourceRequest
47 typedef std::shared_ptr<OCResourceRequest> Ptr;
53 m_requestHandlerFlag{},
58 m_requestHandle{nullptr},
59 m_resourceHandle{nullptr}
63 #if defined(_MSC_VER) && (_MSC_VER < 1900)
64 OCResourceRequest(OCResourceRequest&& o):
65 m_requestType(std::move(o.m_requestType)),
66 m_resourceUri(std::move(o.m_resourceUri)),
67 m_queryParameters(std::move(o.m_queryParameters)),
68 m_requestHandlerFlag(o.m_requestHandlerFlag),
69 m_representation(std::move(o.m_representation)),
70 m_observationInfo(std::move(o.m_observationInfo)),
71 m_headerOptions(std::move(o.m_headerOptions)),
72 m_requestHandle(std::move(o.m_requestHandle)),
73 m_resourceHandle(std::move(o.m_resourceHandle))
76 OCResourceRequest& operator=(OCResourceRequest&& o)
78 m_requestType = std::move(o.m_requestType);
79 m_resourceUri = std::move(o.m_resourceUri);
80 m_queryParameters = std::move(o.m_queryParameters);
81 m_requestHandlerFlag = o.m_requestHandlerFlag;
82 m_representation = std::move(o.m_representation);
83 m_observationInfo = std::move(o.m_observationInfo);
84 m_headerOptions = std::move(o.m_headerOptions);
85 m_requestHandle = std::move(o.m_requestHandle);
86 m_resourceHandle = std::move(o.m_resourceHandle);
89 OCResourceRequest(OCResourceRequest&&) = default;
90 OCResourceRequest& operator=(OCResourceRequest&&) = default;
96 virtual ~OCResourceRequest(void)
101 * Retrieves the type of request string for the entity handler function to operate
102 * @return std::string request type. This could be 'GET'/'PUT'/'POST'/'DELETE'
104 std::string getRequestType() const {return m_requestType;}
107 * Retrieves the query parameters from the request
108 * @return std::string query parameters in the request
110 const QueryParamsMap& getQueryParameters() const {return m_queryParameters;}
113 * Retrieves the request handler flag type. This can be either INIT flag or
114 * REQUEST flag or OBSERVE flag.
116 * INIT indicates that the vendor's entity handler should go and perform
117 * initialization operations
118 * REQUEST indicates that it is a request of certain type (GET/PUT/POST/DELETE)
119 * and entity handler needs to perform corresponding operations
120 * OBSERVE indicates that the request is of type Observe and entity handler
121 * needs to perform corresponding operations
122 * @return int type of request flag
124 int getRequestHandlerFlag() const {return m_requestHandlerFlag;}
127 * Provides the entire resource attribute representation
128 * @return OCRepresentation reference containing the name value pairs
129 * representing the resource's attributes
131 const OCRepresentation& getResourceRepresentation() const {return m_representation;}
134 * @return ObservationInfo reference provides observation information
136 const ObservationInfo& getObservationInfo() const {return m_observationInfo;}
140 * @param resourceUri specifies the resource uri
142 void setResourceUri(const std::string resourceUri)
144 m_resourceUri = resourceUri;
149 * @return std::string resource uri
151 std::string getResourceUri(void)
153 return m_resourceUri;
157 * This API retrieves headerOptions which was sent from a client
159 * @return std::map HeaderOptions with the header options
161 const HeaderOptions& getHeaderOptions() const
163 return m_headerOptions;
167 * This API retrieves the request handle
169 * @return OCRequestHandle
171 const OCRequestHandle& getRequestHandle() const
173 return m_requestHandle;
177 * This API retrieves the resource handle
179 * return OCResourceHandle
181 const OCResourceHandle& getResourceHandle() const
183 return m_resourceHandle;
187 * This API retrieves the request message ID
189 * @return int16_t value of message ID
191 int16_t getMessageID() const {return m_messageID;}
194 std::string m_requestType;
195 std::string m_resourceUri;
196 QueryParamsMap m_queryParameters;
197 int m_requestHandlerFlag;
199 OCRepresentation m_representation;
200 ObservationInfo m_observationInfo;
201 HeaderOptions m_headerOptions;
202 OCRequestHandle m_requestHandle;
203 OCResourceHandle m_resourceHandle;
207 friend void (::formResourceRequest)(OCEntityHandlerFlag, OCEntityHandlerRequest*,
208 std::shared_ptr<OC::OCResourceRequest>);
209 void setRequestType(const std::string& requestType)
211 m_requestType = requestType;
214 void setPayload(OCPayload* requestPayload);
216 void setQueryParams(QueryParamsMap& queryParams)
218 m_queryParameters = queryParams;
221 void setRequestHandlerFlag(int requestHandlerFlag)
223 m_requestHandlerFlag = requestHandlerFlag;
226 void setMessageID(int16_t messageID)
228 m_messageID = messageID;
231 void setObservationInfo(const ObservationInfo& observationInfo)
233 m_observationInfo = observationInfo;
236 void setHeaderOptions(const HeaderOptions& headerOptions)
238 m_headerOptions = headerOptions;
242 * This API allows to set request handle
243 * @param requestHandle - OCRequestHandle type used to set the
246 void setRequestHandle(const OCRequestHandle& requestHandle)
248 m_requestHandle = requestHandle;
252 * This API allows to set the resource handle
253 * @param resourceHandle - OCResourceHandle type used to set the
256 void setResourceHandle(const OCResourceHandle& resourceHandle)
258 m_resourceHandle = resourceHandle;
264 #endif // OC_RESOURCEREQUEST_H_