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;
50 virtual ~OCResourceRequest(void)
55 * Retrieves the type of request string for the entity handler function to operate
56 * @return std::string request type. This could be 'GET'/'PUT'/'POST'/'DELETE'
58 std::string getRequestType() const {return m_requestType;}
61 * Retrieves the query parameters from the request
62 * @return std::string query parameters in the request
64 const QueryParamsMap& getQueryParameters() const {return m_queryParameters;}
67 * Retrieves the request handler flag type. This can be either INIT flag or
68 * REQUEST flag or OBSERVE flag.
70 * INIT indicates that the vendor's entity handler should go and perform
71 * initialization operations
72 * REQUEST indicates that it is a request of certain type (GET/PUT/POST/DELETE)
73 * and entity handler needs to perform corresponding operations
74 * OBSERVE indicates that the request is of type Observe and entity handler
75 * needs to perform corresponding operations
76 * @return int type of request flag
78 int getRequestHandlerFlag() const {return m_requestHandlerFlag;}
81 * Provides the entire resource attribute representation
82 * @return OCRepresentation reference containing the name value pairs
83 * representing the resource's attributes
85 const OCRepresentation& getResourceRepresentation() const {return m_representation;}
88 * @return ObservationInfo reference provides observation information
90 const ObservationInfo& getObservationInfo() const {return m_observationInfo;}
94 * @param resourceUri specifies the resource uri
96 void setResourceUri(const std::string resourceUri)
98 m_resourceUri = resourceUri;
103 * @return std::string resource uri
105 std::string getResourceUri(void)
107 return m_resourceUri;
111 * This API retrieves headerOptions which was sent from a client
113 * @return std::map HeaderOptions with the header options
115 const HeaderOptions& getHeaderOptions() const
117 return m_headerOptions;
121 * This API retrieves the request handle
123 * @return OCRequestHandle
125 const OCRequestHandle& getRequestHandle() const
127 return m_requestHandle;
131 * This API retrieves the resource handle
133 * return OCResourceHandle
135 const OCResourceHandle& getResourceHandle() const
137 return m_resourceHandle;
141 std::string m_requestType;
142 std::string m_resourceUri;
143 QueryParamsMap m_queryParameters;
144 int m_requestHandlerFlag;
145 OCRepresentation m_representation;
146 ObservationInfo m_observationInfo;
147 HeaderOptions m_headerOptions;
148 OCRequestHandle m_requestHandle;
149 OCResourceHandle m_resourceHandle;
153 friend void (::formResourceRequest)(OCEntityHandlerFlag, OCEntityHandlerRequest*,
154 std::shared_ptr<OC::OCResourceRequest>);
155 void setRequestType(const std::string& requestType)
157 m_requestType = requestType;
160 void setPayload(const std::string& requestPayload)
162 if(requestPayload.empty())
167 MessageContainer info;
168 info.setJSONRepresentation(requestPayload);
170 const std::vector<OCRepresentation>& reps = info.representations();
173 std::vector<OCRepresentation>::const_iterator itr = reps.begin();
174 std::vector<OCRepresentation>::const_iterator back = reps.end();
175 m_representation = *itr;
178 for(;itr != back; ++itr)
180 m_representation.addChild(*itr);
185 throw OCException(OC::Exception::INVALID_REPRESENTATION);
189 void setQueryParams(QueryParamsMap& queryParams)
191 m_queryParameters = queryParams;
194 void setRequestHandlerFlag(int requestHandlerFlag)
196 m_requestHandlerFlag = requestHandlerFlag;
199 void setObservationInfo(const ObservationInfo& observationInfo)
201 m_observationInfo = observationInfo;
204 void setHeaderOptions(const HeaderOptions& headerOptions)
206 m_headerOptions = headerOptions;
210 * This API allows to set request handle
211 * @param requestHandle - OCRequestHandle type used to set the
214 void setRequestHandle(const OCRequestHandle& requestHandle)
216 m_requestHandle = requestHandle;
220 * This API allows to set the resource handle
221 * @param resourceHandle - OCResourceHandle type used to set the
224 void setResourceHandle(const OCResourceHandle& resourceHandle)
226 m_resourceHandle = resourceHandle;
232 #endif //__OCRESOURCEREQUEST_H