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 #include "OCHeaderOption.h"
33 #include <OCException.h>
34 #include "StringConstants.h"
35 #include "oc_logger.hpp"
37 #include <OCRepresentation.h>
42 class OCResourceRequest;
43 class OCResourceResponse;
44 class OCDirectPairing;
49 typedef boost::iostreams::stream<OC::oc_log_stream> log_target_t;
53 /* We'll want to provide some sort of explicit hook for custom logging at some
54 point; until then, this should do nicely (note that since these are lambdas,
55 later a special target could be captured, allowing much flexibility): */
56 auto oclog_target = []() -> log_target_t&
58 static OC::oc_log_stream ols(oc_make_ostream_logger);
59 static log_target_t os(ols);
63 } // namespace OC::detail
65 auto oclog = []() -> boost::iostreams::stream<OC::oc_log_stream>&
67 return detail::oclog_target();
75 enum class OCPlatformStatus
81 enum class OCAdvertisementStatus
86 typedef std::string URI;
88 enum class ServiceType
95 * Host Mode of Operation.
102 Gateway /**< Client server mode along with routing capabilities.*/
106 * Quality of Service attempts to abstract the guarantees provided by the underlying transport
107 * protocol. The precise definitions of each quality of service level depend on the
108 * implementation. In descriptions below are for the current implementation and may changed
111 enum class QualityOfService : uint8_t
113 /** Packet delivery is best effort. */
116 /** Packet delivery is best effort. */
117 MidQos = OC_MEDIUM_QOS,
119 /** Acknowledgments are used to confirm delivery. */
120 HighQos = OC_HIGH_QOS,
122 /** No Quality is defined, let the stack decide. */
127 * Data structure to provide the configuration.
129 struct PlatformConfig
131 /** indicate InProc or OutOfProc. */
132 ServiceType serviceType;
134 /** indicate whether we want to do server, client or both. */
137 /** default flags for server. */
138 OCConnectivityType serverConnectivity;
140 /** default flags for client. */
141 OCConnectivityType clientConnectivity;
144 std::string ipAddress;
149 /** indicate Quality of Service : LowQos, MidQos,HighQos and NaQos(No quality Defined). */
150 QualityOfService QoS;
152 /** persistant storage Handler structure (open/read/write/close/unlink). */
153 OCPersistentStorage *ps;
157 : serviceType(ServiceType::InProc),
158 mode(ModeType::Both),
159 serverConnectivity(CT_DEFAULT),
160 clientConnectivity(CT_DEFAULT),
161 ipAddress("0.0.0.0"),
163 QoS(QualityOfService::NaQos),
166 PlatformConfig(const ServiceType serviceType_,
167 const ModeType mode_,
168 OCConnectivityType serverConnectivity_,
169 OCConnectivityType clientConnectivity_,
170 const QualityOfService QoS_,
171 OCPersistentStorage *ps_ = nullptr)
172 : serviceType(serviceType_),
174 serverConnectivity(serverConnectivity_),
175 clientConnectivity(clientConnectivity_),
181 // for backward compatibility
182 PlatformConfig(const ServiceType serviceType_,
183 const ModeType mode_,
184 const std::string& ipAddress_,
185 const uint16_t port_,
186 const QualityOfService QoS_,
187 OCPersistentStorage *ps_ = nullptr)
188 : serviceType(serviceType_),
190 serverConnectivity(CT_DEFAULT),
191 clientConnectivity(CT_DEFAULT),
192 ipAddress(ipAddress_),
199 enum RequestHandlerFlag
201 RequestFlag = 1 << 1,
202 ObserverFlag = 1 << 2
205 enum class ObserveType
211 // Typedef for header option vector
212 // OCHeaderOption class is in HeaderOption namespace
213 typedef std::vector<HeaderOption::OCHeaderOption> HeaderOptions;
215 // Typedef for query parameter map
216 typedef std::map<std::string, std::string> QueryParamsMap;
218 // Typedef for list of observation IDs
219 typedef std::vector<OCObservationId> ObservationIds;
221 enum class ObserveAction
229 // Action associated with observation request
230 ObserveAction action;
231 // Identifier for observation being registered/unregistered
232 OCObservationId obsId;
234 OCConnectivityType connectivityType;
239 // const strings for different interfaces
242 const std::string DEFAULT_INTERFACE = "oic.if.baseline";
244 // Used in discovering (GET) links to other resources of a collection.
245 const std::string LINK_INTERFACE = "oic.if.ll";
247 // Used in GET, PUT, POST, DELETE methods on links to other resources of a collection.
248 const std::string BATCH_INTERFACE = "oic.if.b";
250 // Used in GET, PUT, POST methods on links to other remote resources of a group.
251 const std::string GROUP_INTERFACE = "oic.mi.grp";
253 //Typedef for list direct paired devices
254 typedef std::vector<std::shared_ptr<OCDirectPairing>> PairedDevices;
256 typedef std::function<void(std::shared_ptr<OCResource>)> FindCallback;
258 typedef std::function<void(const std::string&, const int)> FindErrorCallback;
260 typedef std::function<void(const OCRepresentation&)> FindDeviceCallback;
262 typedef std::function<void(const OCRepresentation&)> FindPlatformCallback;
264 typedef std::function<OCEntityHandlerResult(
265 const std::shared_ptr<OCResourceRequest>)> EntityHandler;
267 typedef std::function<void(OCStackResult, const unsigned int,
268 const std::string&)> SubscribeCallback;
270 typedef std::function<void(const HeaderOptions&,
271 const OCRepresentation&, const int)> GetCallback;
273 typedef std::function<void(const HeaderOptions&,
274 const OCRepresentation&, const int)> PostCallback;
276 typedef std::function<void(const HeaderOptions&,
277 const OCRepresentation&, const int)> PutCallback;
279 typedef std::function<void(const HeaderOptions&, const int)> DeleteCallback;
281 typedef std::function<void(const HeaderOptions&,
282 const OCRepresentation&, const int, const int)> ObserveCallback;
284 typedef std::function<void(std::shared_ptr<OCDirectPairing>, OCStackResult)> DirectPairingCallback;
286 typedef std::function<void(const PairedDevices&)> GetDirectPairedCallback;