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}
63 virtual ~OCResourceRequest(void)
68 * Retrieves the type of request string for the entity handler function to operate
69 * @return std::string request type. This could be 'GET'/'PUT'/'POST'/'DELETE'
71 std::string getRequestType() const {return m_requestType;}
74 * Retrieves the query parameters from the request
75 * @return std::string query parameters in the request
77 const QueryParamsMap& getQueryParameters() const {return m_queryParameters;}
80 * Retrieves the request handler flag type. This can be either INIT flag or
81 * REQUEST flag or OBSERVE flag.
83 * INIT indicates that the vendor's entity handler should go and perform
84 * initialization operations
85 * REQUEST indicates that it is a request of certain type (GET/PUT/POST/DELETE)
86 * and entity handler needs to perform corresponding operations
87 * OBSERVE indicates that the request is of type Observe and entity handler
88 * needs to perform corresponding operations
89 * @return int type of request flag
91 int getRequestHandlerFlag() const {return m_requestHandlerFlag;}
94 * Provides the entire resource attribute representation
95 * @return OCRepresentation reference containing the name value pairs
96 * representing the resource's attributes
98 const OCRepresentation& getResourceRepresentation() const {return m_representation;}
101 * @return ObservationInfo reference provides observation information
103 const ObservationInfo& getObservationInfo() const {return m_observationInfo;}
107 * @param resourceUri specifies the resource uri
109 void setResourceUri(const std::string resourceUri)
111 m_resourceUri = resourceUri;
116 * @return std::string resource uri
118 std::string getResourceUri(void)
120 return m_resourceUri;
124 * This API retrieves headerOptions which was sent from a client
126 * @return std::map HeaderOptions with the header options
128 const HeaderOptions& getHeaderOptions() const
130 return m_headerOptions;
134 * This API retrieves the request handle
136 * @return OCRequestHandle
138 const OCRequestHandle& getRequestHandle() const
140 return m_requestHandle;
144 * This API retrieves the resource handle
146 * return OCResourceHandle
148 const OCResourceHandle& getResourceHandle() const
150 return m_resourceHandle;
154 std::string m_requestType;
155 std::string m_resourceUri;
156 QueryParamsMap m_queryParameters;
157 int m_requestHandlerFlag;
158 OCRepresentation m_representation;
159 ObservationInfo m_observationInfo;
160 HeaderOptions m_headerOptions;
161 OCRequestHandle m_requestHandle;
162 OCResourceHandle m_resourceHandle;
166 friend void (::formResourceRequest)(OCEntityHandlerFlag, OCEntityHandlerRequest*,
167 std::shared_ptr<OC::OCResourceRequest>);
168 void setRequestType(const std::string& requestType)
170 m_requestType = requestType;
173 void setPayload(const std::string& requestPayload)
175 if(requestPayload.empty())
180 MessageContainer info;
181 info.setJSONRepresentation(requestPayload);
183 const std::vector<OCRepresentation>& reps = info.representations();
186 std::vector<OCRepresentation>::const_iterator itr = reps.begin();
187 std::vector<OCRepresentation>::const_iterator back = reps.end();
188 m_representation = *itr;
191 for(;itr != back; ++itr)
193 m_representation.addChild(*itr);
198 throw OCException(OC::Exception::INVALID_REPRESENTATION);
202 void setQueryParams(QueryParamsMap& queryParams)
204 m_queryParameters = queryParams;
207 void setRequestHandlerFlag(int requestHandlerFlag)
209 m_requestHandlerFlag = requestHandlerFlag;
212 void setObservationInfo(const ObservationInfo& observationInfo)
214 m_observationInfo = observationInfo;
217 void setHeaderOptions(const HeaderOptions& headerOptions)
219 m_headerOptions = headerOptions;
223 * This API allows to set request handle
224 * @param requestHandle - OCRequestHandle type used to set the
227 void setRequestHandle(const OCRequestHandle& requestHandle)
229 m_requestHandle = requestHandle;
233 * This API allows to set the resource handle
234 * @param resourceHandle - OCResourceHandle type used to set the
237 void setResourceHandle(const OCResourceHandle& resourceHandle)
239 m_resourceHandle = resourceHandle;
245 #endif //__OCRESOURCEREQUEST_H