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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
32 //Squelch "decorated name length exceeded, name was truncated"
33 // This compensates for templates full of templates
34 #pragma warning(disable : 4503)
38 #include "OCHeaderOption.h"
39 #include <OCException.h>
40 #include "StringConstants.h"
41 #include "oc_logger.hpp"
43 #include <OCRepresentation.h>
48 class OCResourceRequest;
49 class OCResourceResponse;
55 extern std::ostream& oclog();
57 typedef boost::iostreams::stream<OC::oc_log_stream> log_target_t;
61 /* We'll want to provide some sort of explicit hook for custom logging at some
62 point; until then, this should do nicely (note that since these are lambdas,
63 later a special target could be captured, allowing much flexibility): */
64 auto oclog_target = []() -> log_target_t&
66 static OC::oc_log_stream ols(oc_make_ostream_logger);
67 static log_target_t os(ols);
71 } // namespace OC::detail
73 auto oclog = []() -> boost::iostreams::stream<OC::oc_log_stream>&
75 return detail::oclog_target();
83 enum class OCPlatformStatus
89 enum class OCAdvertisementStatus
94 typedef std::string URI;
96 enum class ServiceType
103 * Host Mode of Operation.
110 Gateway /**< Client server mode along with routing capabilities.*/
114 * Quality of Service attempts to abstract the guarantees provided by the underlying transport
115 * protocol. The precise definitions of each quality of service level depend on the
116 * implementation. In descriptions below are for the current implementation and may changed
119 enum class QualityOfService : uint8_t
121 /** Packet delivery is best effort. */
124 /** Packet delivery is best effort. */
125 MidQos = OC_MEDIUM_QOS,
127 /** Acknowledgments are used to confirm delivery. */
128 HighQos = OC_HIGH_QOS,
130 /** No Quality is defined, let the stack decide. */
135 * Data structure to provide the configuration.
137 struct PlatformConfig
139 /** indicate InProc or OutOfProc. */
140 ServiceType serviceType;
142 /** indicate whether we want to do server, client or both. */
145 /** default flags for server. */
146 OCConnectivityType serverConnectivity;
148 /** default flags for client. */
149 OCConnectivityType clientConnectivity;
152 std::string ipAddress;
157 /** indicate Quality of Service : LowQos, MidQos,HighQos and NaQos(No quality Defined). */
158 QualityOfService QoS;
160 /** persistant storage Handler structure (open/read/write/close/unlink). */
161 OCPersistentStorage *ps;
165 : serviceType(ServiceType::InProc),
166 mode(ModeType::Both),
167 serverConnectivity(CT_DEFAULT),
168 clientConnectivity(CT_DEFAULT),
169 ipAddress("0.0.0.0"),
171 QoS(QualityOfService::NaQos),
174 PlatformConfig(const ServiceType serviceType_,
175 const ModeType mode_,
176 OCConnectivityType serverConnectivity_,
177 OCConnectivityType clientConnectivity_,
178 const QualityOfService QoS_,
179 OCPersistentStorage *ps_ = nullptr)
180 : serviceType(serviceType_),
182 serverConnectivity(serverConnectivity_),
183 clientConnectivity(clientConnectivity_),
189 // for backward compatibility
190 PlatformConfig(const ServiceType serviceType_,
191 const ModeType mode_,
192 const std::string& ipAddress_,
193 const uint16_t port_,
194 const QualityOfService QoS_,
195 OCPersistentStorage *ps_ = nullptr)
196 : serviceType(serviceType_),
198 serverConnectivity(CT_DEFAULT),
199 clientConnectivity(CT_DEFAULT),
200 ipAddress(ipAddress_),
207 enum RequestHandlerFlag
209 RequestFlag = 1 << 1,
210 ObserverFlag = 1 << 2
213 enum class ObserveType
219 // Typedef for header option vector
220 // OCHeaderOption class is in HeaderOption namespace
221 typedef std::vector<HeaderOption::OCHeaderOption> HeaderOptions;
223 // Typedef for query parameter map
224 typedef std::map<std::string, std::string> QueryParamsMap;
226 // Typedef for list of observation IDs
227 typedef std::vector<OCObservationId> ObservationIds;
229 enum class ObserveAction
237 // Action associated with observation request
238 ObserveAction action;
239 // Identifier for observation being registered/unregistered
240 OCObservationId obsId;
242 OCConnectivityType connectivityType;
247 // const strings for different interfaces
250 const std::string DEFAULT_INTERFACE = "oic.if.baseline";
252 // Used in discovering (GET) links to other resources of a collection.
253 const std::string LINK_INTERFACE = "oic.if.ll";
255 // Used in GET, PUT, POST, DELETE methods on links to other resources of a collection.
256 const std::string BATCH_INTERFACE = "oic.if.b";
258 // Used in GET, PUT, POST methods on links to other remote resources of a group.
259 const std::string GROUP_INTERFACE = "oic.mi.grp";
262 typedef std::function<void(std::shared_ptr<OCResource>)> FindCallback;
264 typedef std::function<void(const std::string&, const int)> FindErrorCallback;
266 typedef std::function<void(const OCRepresentation&)> FindDeviceCallback;
268 typedef std::function<void(const OCRepresentation&)> FindPlatformCallback;
270 typedef std::function<OCEntityHandlerResult(
271 const std::shared_ptr<OCResourceRequest>)> EntityHandler;
273 typedef std::function<void(OCStackResult, const unsigned int,
274 const std::string&)> SubscribeCallback;
276 typedef std::function<void(const HeaderOptions&,
277 const OCRepresentation&, const int)> GetCallback;
279 typedef std::function<void(const HeaderOptions&,
280 const OCRepresentation&, const int)> PostCallback;
282 typedef std::function<void(const HeaderOptions&,
283 const OCRepresentation&, const int)> PutCallback;
285 typedef std::function<void(const HeaderOptions&, const int)> DeleteCallback;
287 typedef std::function<void(const HeaderOptions&,
288 const OCRepresentation&, const int, const int)> ObserveCallback;