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 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 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. */
133 * Data structure to provide the configuration.
135 struct PlatformConfig
137 /** indicate InProc or OutOfProc. */
138 ServiceType serviceType;
140 /** indicate whether we want to do server, client or both. */
143 /** default flags for server. */
144 OCConnectivityType serverConnectivity;
146 /** default flags for client. */
147 OCConnectivityType clientConnectivity;
149 /** transport type to initialize. */
150 OCTransportAdapter transportType;
153 std::string ipAddress;
158 /** indicate Quality of Service : LowQos, MidQos,HighQos and NaQos(No quality Defined). */
159 QualityOfService QoS;
161 /** persistant storage Handler structure (open/read/write/close/unlink). */
162 OCPersistentStorage *ps;
164 /** persistant storage Handler structure (open/read/write/close/unlink). */
165 OCPersistentStorage *psEnc;
167 /** persistant storage Handler structure (open/read/write/close/unlink). */
168 OCPersistentStorage *psRescue;
170 /** pointer to save key. */
175 : serviceType(ServiceType::InProc),
176 mode(ModeType::Both),
177 serverConnectivity(CT_DEFAULT),
178 clientConnectivity(CT_DEFAULT),
179 transportType(OC_DEFAULT_ADAPTER),
180 ipAddress("0.0.0.0"),
182 QoS(QualityOfService::NaQos),
188 PlatformConfig(const ServiceType serviceType_,
189 const ModeType mode_,
190 OCConnectivityType serverConnectivity_,
191 OCConnectivityType clientConnectivity_,
192 const QualityOfService QoS_,
193 OCPersistentStorage *ps_ = nullptr,
194 OCPersistentStorage *psEnc_ = nullptr,
195 OCPersistentStorage *psRescue_ = nullptr,
196 unsigned char *key_ = nullptr)
197 : serviceType(serviceType_),
199 serverConnectivity(serverConnectivity_),
200 clientConnectivity(clientConnectivity_),
201 transportType(OC_DEFAULT_ADAPTER),
211 // for backward compatibility
212 PlatformConfig(const ServiceType serviceType_,
213 const ModeType mode_,
214 const std::string& ipAddress_,
215 const uint16_t port_,
216 const QualityOfService QoS_,
217 OCPersistentStorage *ps_ = nullptr,
218 OCPersistentStorage *psEnc_ = nullptr,
219 OCPersistentStorage *psRescue_ = nullptr,
220 unsigned char *key_ = nullptr)
221 : serviceType(serviceType_),
223 serverConnectivity(CT_DEFAULT),
224 clientConnectivity(CT_DEFAULT),
225 transportType(OC_DEFAULT_ADAPTER),
226 ipAddress(ipAddress_),
236 PlatformConfig(const ServiceType serviceType_,
237 const ModeType mode_,
238 const std::string& ipAddress_,
239 const uint16_t port_,
240 const OCTransportAdapter transportType_,
241 const QualityOfService QoS_,
243 OCPersistentStorage *ps_ = nullptr,
244 OCPersistentStorage *psEnc_ = nullptr,
245 OCPersistentStorage *psRescue_ = nullptr)
246 : serviceType(serviceType_),
248 transportType(transportType_),
249 ipAddress(ipAddress_),
258 PlatformConfig(const ServiceType serviceType_,
259 const ModeType mode_,
260 OCTransportAdapter transportType_,
261 const QualityOfService QoS_,
262 OCPersistentStorage *ps_ = nullptr,
263 OCPersistentStorage *psEnc_ = nullptr,
264 OCPersistentStorage *psRescue_ = nullptr,
265 unsigned char *key_ = nullptr)
266 : serviceType(serviceType_),
268 serverConnectivity(CT_DEFAULT),
269 clientConnectivity(CT_DEFAULT),
270 transportType(transportType_),
279 PlatformConfig(const ServiceType serviceType_,
280 const ModeType mode_,
281 OCConnectivityType serverConnectivity_,
282 OCConnectivityType clientConnectivity_,
283 OCTransportAdapter transportType_,
284 const QualityOfService QoS_,
285 OCPersistentStorage *ps_ = nullptr,
286 OCPersistentStorage *psEnc_ = nullptr,
287 OCPersistentStorage *psRescue_ = nullptr,
288 unsigned char *key_ = nullptr)
289 : serviceType(serviceType_),
291 serverConnectivity(serverConnectivity_),
292 clientConnectivity(clientConnectivity_),
293 transportType(transportType_),
305 enum RequestHandlerFlag
307 RequestFlag = 1 << 1,
308 ObserverFlag = 1 << 2
311 enum class ObserveType
317 // Typedef for list of resource handles.
318 typedef std::vector<OCResourceHandle> ResourceHandles;
320 // Typedef for header option vector.
321 // OCHeaderOption class is in HeaderOption namespace.
322 typedef std::vector<HeaderOption::OCHeaderOption> HeaderOptions;
324 // Typedef for query parameter map.
325 typedef std::map<std::string, std::string> QueryParamsMap;
327 // Typedef for query parameter map with Vector
328 typedef std::map< std::string, std::vector<std::string> > QueryParamsList;
330 // Typedef for list of observation IDs.
331 typedef std::vector<OCObservationId> ObservationIds;
333 enum class ObserveAction
341 // Action associated with observation request
342 ObserveAction action;
343 // Identifier for observation being registered/unregistered
344 OCObservationId obsId;
346 OCConnectivityType connectivityType;
351 // const strings for different interfaces
354 const std::string DEFAULT_INTERFACE = "oic.if.baseline";
356 // Used in discovering (GET) links to other resources of a collection.
357 const std::string LINK_INTERFACE = "oic.if.ll";
359 // Used in GET, PUT, POST, DELETE methods on links to other resources of a collection.
360 const std::string BATCH_INTERFACE = "oic.if.b";
362 // Used in GET, PUT, POST methods on links to other remote resources of a group.
363 const std::string GROUP_INTERFACE = "oic.mi.grp";
365 //Typedef for list direct paired devices
366 typedef std::vector<std::shared_ptr<OCDirectPairing>> PairedDevices;
368 typedef std::function<void(std::shared_ptr<OCResource>)> FindCallback;
370 typedef std::function<void(const std::string&, const int)> FindErrorCallback;
372 typedef std::function<void(std::vector<std::shared_ptr<OCResource>>)> FindResListCallback;
374 typedef std::function<void(const OCRepresentation&)> FindDeviceCallback;
376 typedef std::function<void(const OCRepresentation&)> FindPlatformCallback;
378 typedef std::function<OCEntityHandlerResult(
379 const std::shared_ptr<OCResourceRequest>)> EntityHandler;
381 typedef std::function<void(OCStackResult, const unsigned int,
382 const std::string&)> SubscribeCallback;
384 typedef std::function<void(const HeaderOptions&,
385 const OCRepresentation&, const int)> GetCallback;
387 typedef std::function<void(const HeaderOptions&,
388 const OCRepresentation&, const int)> PostCallback;
390 typedef std::function<void(const HeaderOptions&,
391 const OCRepresentation&, const int)> PutCallback;
393 typedef std::function<void(const HeaderOptions&, const int)> DeleteCallback;
395 typedef std::function<void(const HeaderOptions&,
396 const OCRepresentation&, const int, const int)> ObserveCallback;
398 typedef std::function<void(std::shared_ptr<OCDirectPairing>, OCStackResult)> DirectPairingCallback;
400 typedef std::function<void(const PairedDevices&)> GetDirectPairedCallback;
402 typedef std::function<void(const int, const std::string&,
403 std::shared_ptr<OCResource>)> MQTopicCallback;
405 typedef std::function<void(const int, const OCRepresentation&)> KeepAliveCallback;