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 OCResourceRequest(OCResourceRequest&&) = default;
64 OCResourceRequest& operator=(OCResourceRequest&&) = default;
68 virtual ~OCResourceRequest(void)
73 * Retrieves the type of request string for the entity handler function to operate
74 * @return std::string request type. This could be 'GET'/'PUT'/'POST'/'DELETE'
76 std::string getRequestType() const {return m_requestType;}
79 * Retrieves the query parameters from the request
80 * @return std::string query parameters in the request
82 const QueryParamsMap& getQueryParameters() const {return m_queryParameters;}
85 * Retrieves the request handler flag type. This can be either INIT flag or
86 * REQUEST flag or OBSERVE flag.
88 * INIT indicates that the vendor's entity handler should go and perform
89 * initialization operations
90 * REQUEST indicates that it is a request of certain type (GET/PUT/POST/DELETE)
91 * and entity handler needs to perform corresponding operations
92 * OBSERVE indicates that the request is of type Observe and entity handler
93 * needs to perform corresponding operations
94 * @return int type of request flag
96 int getRequestHandlerFlag() const {return m_requestHandlerFlag;}
99 * Provides the entire resource attribute representation
100 * @return OCRepresentation reference containing the name value pairs
101 * representing the resource's attributes
103 const OCRepresentation& getResourceRepresentation() const {return m_representation;}
106 * @return ObservationInfo reference provides observation information
108 const ObservationInfo& getObservationInfo() const {return m_observationInfo;}
112 * @param resourceUri specifies the resource uri
114 void setResourceUri(const std::string resourceUri)
116 m_resourceUri = resourceUri;
121 * @return std::string resource uri
123 std::string getResourceUri(void)
125 return m_resourceUri;
129 * This API retrieves headerOptions which was sent from a client
131 * @return std::map HeaderOptions with the header options
133 const HeaderOptions& getHeaderOptions() const
135 return m_headerOptions;
139 * This API retrieves the request handle
141 * @return OCRequestHandle
143 const OCRequestHandle& getRequestHandle() const
145 return m_requestHandle;
149 * This API retrieves the resource handle
151 * return OCResourceHandle
153 const OCResourceHandle& getResourceHandle() const
155 return m_resourceHandle;
159 * This API retrieves the request message ID
161 * @return int16_t value of message ID
163 int16_t getMessageID() const {return m_messageID;}
166 std::string m_requestType;
167 std::string m_resourceUri;
168 QueryParamsMap m_queryParameters;
169 int m_requestHandlerFlag;
171 OCRepresentation m_representation;
172 ObservationInfo m_observationInfo;
173 HeaderOptions m_headerOptions;
174 OCRequestHandle m_requestHandle;
175 OCResourceHandle m_resourceHandle;
179 friend void (::formResourceRequest)(OCEntityHandlerFlag, OCEntityHandlerRequest*,
180 std::shared_ptr<OC::OCResourceRequest>);
181 void setRequestType(const std::string& requestType)
183 m_requestType = requestType;
186 void setPayload(OCPayload* requestPayload);
188 void setQueryParams(QueryParamsMap& queryParams)
190 m_queryParameters = queryParams;
193 void setRequestHandlerFlag(int requestHandlerFlag)
195 m_requestHandlerFlag = requestHandlerFlag;
198 void setMessageID(int16_t messageID)
200 m_messageID = messageID;
203 void setObservationInfo(const ObservationInfo& observationInfo)
205 m_observationInfo = observationInfo;
208 void setHeaderOptions(const HeaderOptions& headerOptions)
210 m_headerOptions = headerOptions;
214 * This API allows to set request handle
215 * @param requestHandle - OCRequestHandle type used to set the
218 void setRequestHandle(const OCRequestHandle& requestHandle)
220 m_requestHandle = requestHandle;
224 * This API allows to set the resource handle
225 * @param resourceHandle - OCResourceHandle type used to set the
228 void setResourceHandle(const OCResourceHandle& resourceHandle)
230 m_resourceHandle = resourceHandle;
236 #endif // OC_RESOURCEREQUEST_H_