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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
35 #include "OCHeaderOption.h"
36 #include <OCException.h>
37 #include "StringConstants.h"
38 #include "oc_logger.hpp"
40 #include <OCRepresentation.h>
45 class OCResourceRequest;
46 class OCResourceResponse;
47 class OCDirectPairing;
53 extern std::ostream& oclog();
55 typedef boost::iostreams::stream<OC::oc_log_stream> log_target_t;
59 /* We'll want to provide some sort of explicit hook for custom logging at some
60 point; until then, this should do nicely (note that since these are lambdas,
61 later a special target could be captured, allowing much flexibility): */
62 inline auto oclog_target = []() -> log_target_t&
64 static OC::oc_log_stream ols(oc_make_ostream_logger);
65 static log_target_t os(ols);
69 } // namespace OC::detail
71 inline auto oclog = []() -> boost::iostreams::stream<OC::oc_log_stream>&
73 return detail::oclog_target();
81 enum class OCPlatformStatus
87 enum class OCAdvertisementStatus
92 typedef std::string URI;
94 enum class ServiceType
101 * Host Mode of Operation.
108 Gateway /**< Client server mode along with routing capabilities.*/
112 * Quality of Service attempts to abstract the guarantees provided by the underlying transport
113 * protocol. The precise definitions of each quality of service level depend on the
114 * implementation. In descriptions below are for the current implementation and may changed
117 enum class QualityOfService : uint8_t
119 /** Packet delivery is best effort. */
122 /** Packet delivery is best effort. */
123 MidQos = OC_MEDIUM_QOS,
125 /** Acknowledgments are used to confirm delivery. */
126 HighQos = OC_HIGH_QOS,
128 /** No Quality is defined, let the stack decide. */
131 LowQosWithTcp = OC_LOW_QOS_WITH_TCP
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;
151 /** transport type to initialize. */
152 OCTransportAdapter transportType;
155 std::string ipAddress;
160 /** indicate Quality of Service : LowQos, MidQos,HighQos and NaQos(No quality Defined). */
161 QualityOfService QoS;
163 /** persistant storage Handler structure (open/read/write/close/unlink). */
164 OCPersistentStorage *ps;
166 /** persistant storage Handler structure (open/read/write/close/unlink). */
167 OCPersistentStorage *psEnc;
169 /** persistant storage Handler structure (open/read/write/close/unlink). */
170 OCPersistentStorage *psRescue;
172 /** pointer to save key. */
177 : serviceType(ServiceType::InProc),
178 mode(ModeType::Both),
179 serverConnectivity(CT_DEFAULT),
180 clientConnectivity(CT_DEFAULT),
181 transportType(OC_DEFAULT_ADAPTER),
182 ipAddress("0.0.0.0"),
184 QoS(QualityOfService::NaQos),
190 PlatformConfig(const ServiceType serviceType_,
191 const ModeType mode_,
192 OCConnectivityType serverConnectivity_,
193 OCConnectivityType clientConnectivity_,
194 const QualityOfService QoS_,
195 OCPersistentStorage *ps_ = nullptr,
196 OCPersistentStorage *psEnc_ = nullptr,
197 OCPersistentStorage *psRescue_ = nullptr,
198 unsigned char *key_ = nullptr)
199 : serviceType(serviceType_),
201 serverConnectivity(serverConnectivity_),
202 clientConnectivity(clientConnectivity_),
203 transportType(OC_DEFAULT_ADAPTER),
213 // for backward compatibility
214 PlatformConfig(const ServiceType serviceType_,
215 const ModeType mode_,
216 const std::string& ipAddress_,
217 const uint16_t port_,
218 const QualityOfService QoS_,
219 OCPersistentStorage *ps_ = nullptr,
220 OCPersistentStorage *psEnc_ = nullptr,
221 OCPersistentStorage *psRescue_ = nullptr,
222 unsigned char *key_ = nullptr)
223 : serviceType(serviceType_),
225 serverConnectivity(CT_DEFAULT),
226 clientConnectivity(CT_DEFAULT),
227 transportType(OC_DEFAULT_ADAPTER),
228 ipAddress(ipAddress_),
238 PlatformConfig(const ServiceType serviceType_,
239 const ModeType mode_,
240 const std::string& ipAddress_,
241 const uint16_t port_,
242 const OCTransportAdapter transportType_,
243 const QualityOfService QoS_,
245 OCPersistentStorage *ps_ = nullptr,
246 OCPersistentStorage *psEnc_ = nullptr,
247 OCPersistentStorage *psRescue_ = nullptr)
248 : serviceType(serviceType_),
250 transportType(transportType_),
251 ipAddress(ipAddress_),
260 PlatformConfig(const ServiceType serviceType_,
261 const ModeType mode_,
262 OCTransportAdapter transportType_,
263 const QualityOfService QoS_,
264 OCPersistentStorage *ps_ = nullptr,
265 OCPersistentStorage *psEnc_ = nullptr,
266 OCPersistentStorage *psRescue_ = nullptr,
267 unsigned char *key_ = nullptr)
268 : serviceType(serviceType_),
270 serverConnectivity(CT_DEFAULT),
271 clientConnectivity(CT_DEFAULT),
272 transportType(transportType_),
281 PlatformConfig(const ServiceType serviceType_,
282 const ModeType mode_,
283 OCConnectivityType serverConnectivity_,
284 OCConnectivityType clientConnectivity_,
285 OCTransportAdapter transportType_,
286 const QualityOfService QoS_,
287 OCPersistentStorage *ps_ = nullptr,
288 OCPersistentStorage *psEnc_ = nullptr,
289 OCPersistentStorage *psRescue_ = nullptr,
290 unsigned char *key_ = nullptr)
291 : serviceType(serviceType_),
293 serverConnectivity(serverConnectivity_),
294 clientConnectivity(clientConnectivity_),
295 transportType(transportType_),
307 enum RequestHandlerFlag
309 RequestFlag = 1 << 1,
310 ObserverFlag = 1 << 2
313 enum class ObserveType
319 // Typedef for list of resource handles.
320 typedef std::vector<OCResourceHandle> ResourceHandles;
322 // Typedef for header option vector.
323 // OCHeaderOption class is in HeaderOption namespace.
324 typedef std::vector<HeaderOption::OCHeaderOption> HeaderOptions;
326 // Typedef for query parameter map.
327 typedef std::map<std::string, std::string> QueryParamsMap;
329 // Typedef for query parameter map with Vector
330 typedef std::map< std::string, std::vector<std::string> > QueryParamsList;
332 // Typedef for list of observation IDs.
333 typedef std::vector<OCObservationId> ObservationIds;
335 enum class ObserveAction
343 // Action associated with observation request
344 ObserveAction action;
345 // Identifier for observation being registered/unregistered
346 OCObservationId obsId;
348 OCConnectivityType connectivityType;
353 // const strings for different interfaces
356 const std::string DEFAULT_INTERFACE = "oic.if.baseline";
358 // Used in discovering (GET) links to other resources of a collection.
359 const std::string LINK_INTERFACE = "oic.if.ll";
361 // Used in GET, PUT, POST, DELETE methods on links to other resources of a collection.
362 const std::string BATCH_INTERFACE = "oic.if.b";
364 // Used in GET, PUT, POST methods on links to other remote resources of a group.
365 const std::string GROUP_INTERFACE = "oic.mi.grp";
367 //Typedef for list direct paired devices
368 typedef std::vector<std::shared_ptr<OCDirectPairing>> PairedDevices;
370 typedef std::function<void(std::shared_ptr<OCResource>)> FindCallback;
372 typedef std::function<void(const std::string&, const int)> FindErrorCallback;
374 typedef std::function<void(std::vector<std::shared_ptr<OCResource>>)> FindResListCallback;
376 typedef std::function<void(const OCRepresentation&)> FindDeviceCallback;
378 typedef std::function<void(const OCRepresentation&)> FindPlatformCallback;
380 typedef std::function<OCEntityHandlerResult(
381 const std::shared_ptr<OCResourceRequest>)> EntityHandler;
383 typedef std::function<void(OCStackResult, const unsigned int,
384 const std::string&)> SubscribeCallback;
386 typedef std::function<void(const HeaderOptions&,
387 const OCRepresentation&, const int)> GetCallback;
389 typedef std::function<void(const HeaderOptions&,
390 const OCRepresentation&, const int)> PostCallback;
392 typedef std::function<void(const HeaderOptions&,
393 const OCRepresentation&, const int)> PutCallback;
395 typedef std::function<void(const HeaderOptions&, const int)> DeleteCallback;
397 typedef std::function<void(const HeaderOptions&,
398 const OCRepresentation&, const int, const int)> ObserveCallback;
400 typedef std::function<void(std::shared_ptr<OCDirectPairing>, OCStackResult)> DirectPairingCallback;
402 typedef std::function<void(const PairedDevices&)> GetDirectPairedCallback;
404 typedef std::function<void(const int, const std::string&,
405 std::shared_ptr<OCResource>)> MQTopicCallback;
407 typedef std::function<void(const int, const OCRepresentation&)> KeepAliveCallback;