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;
50 class OCDirectPairing;
56 extern std::ostream& oclog();
58 typedef boost::iostreams::stream<OC::oc_log_stream> log_target_t;
62 /* We'll want to provide some sort of explicit hook for custom logging at some
63 point; until then, this should do nicely (note that since these are lambdas,
64 later a special target could be captured, allowing much flexibility): */
65 auto oclog_target = []() -> log_target_t&
67 static OC::oc_log_stream ols(oc_make_ostream_logger);
68 static log_target_t os(ols);
72 } // namespace OC::detail
74 auto oclog = []() -> boost::iostreams::stream<OC::oc_log_stream>&
76 return detail::oclog_target();
84 enum class OCPlatformStatus
90 enum class OCAdvertisementStatus
95 typedef std::string URI;
97 enum class ServiceType
104 * Host Mode of Operation.
111 Gateway /**< Client server mode along with routing capabilities.*/
115 * Quality of Service attempts to abstract the guarantees provided by the underlying transport
116 * protocol. The precise definitions of each quality of service level depend on the
117 * implementation. In descriptions below are for the current implementation and may changed
120 enum class QualityOfService : uint8_t
122 /** Packet delivery is best effort. */
125 /** Packet delivery is best effort. */
126 MidQos = OC_MEDIUM_QOS,
128 /** Acknowledgments are used to confirm delivery. */
129 HighQos = OC_HIGH_QOS,
131 /** No Quality is defined, let the stack decide. */
136 * Data structure to provide the configuration.
138 struct PlatformConfig
140 /** indicate InProc or OutOfProc. */
141 ServiceType serviceType;
143 /** indicate whether we want to do server, client or both. */
146 /** default flags for server. */
147 OCConnectivityType serverConnectivity;
149 /** default flags for client. */
150 OCConnectivityType clientConnectivity;
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;
166 : serviceType(ServiceType::InProc),
167 mode(ModeType::Both),
168 serverConnectivity(CT_DEFAULT),
169 clientConnectivity(CT_DEFAULT),
170 ipAddress("0.0.0.0"),
172 QoS(QualityOfService::NaQos),
175 PlatformConfig(const ServiceType serviceType_,
176 const ModeType mode_,
177 OCConnectivityType serverConnectivity_,
178 OCConnectivityType clientConnectivity_,
179 const QualityOfService QoS_,
180 OCPersistentStorage *ps_ = nullptr)
181 : serviceType(serviceType_),
183 serverConnectivity(serverConnectivity_),
184 clientConnectivity(clientConnectivity_),
190 // for backward compatibility
191 PlatformConfig(const ServiceType serviceType_,
192 const ModeType mode_,
193 const std::string& ipAddress_,
194 const uint16_t port_,
195 const QualityOfService QoS_,
196 OCPersistentStorage *ps_ = nullptr)
197 : serviceType(serviceType_),
199 serverConnectivity(CT_DEFAULT),
200 clientConnectivity(CT_DEFAULT),
201 ipAddress(ipAddress_),
208 enum RequestHandlerFlag
210 RequestFlag = 1 << 1,
211 ObserverFlag = 1 << 2
214 enum class ObserveType
220 // Typedef for header option vector
221 // OCHeaderOption class is in HeaderOption namespace
222 typedef std::vector<HeaderOption::OCHeaderOption> HeaderOptions;
224 // Typedef for query parameter map
225 typedef std::map<std::string, std::string> QueryParamsMap;
227 // Typedef for list of observation IDs
228 typedef std::vector<OCObservationId> ObservationIds;
230 enum class ObserveAction
238 // Action associated with observation request
239 ObserveAction action;
240 // Identifier for observation being registered/unregistered
241 OCObservationId obsId;
243 OCConnectivityType connectivityType;
248 // const strings for different interfaces
251 const std::string DEFAULT_INTERFACE = "oic.if.baseline";
253 // Used in discovering (GET) links to other resources of a collection.
254 const std::string LINK_INTERFACE = "oic.if.ll";
256 // Used in GET, PUT, POST, DELETE methods on links to other resources of a collection.
257 const std::string BATCH_INTERFACE = "oic.if.b";
259 // Used in GET, PUT, POST methods on links to other remote resources of a group.
260 const std::string GROUP_INTERFACE = "oic.mi.grp";
262 //Typedef for list direct paired devices
263 typedef std::vector<std::shared_ptr<OCDirectPairing>> PairedDevices;
265 typedef std::function<void(std::shared_ptr<OCResource>)> FindCallback;
267 typedef std::function<void(const std::string&, const int)> FindErrorCallback;
269 typedef std::function<void(const OCRepresentation&)> FindDeviceCallback;
271 typedef std::function<void(const OCRepresentation&)> FindPlatformCallback;
273 typedef std::function<OCEntityHandlerResult(
274 const std::shared_ptr<OCResourceRequest>)> EntityHandler;
276 typedef std::function<void(OCStackResult, const unsigned int,
277 const std::string&)> SubscribeCallback;
279 typedef std::function<void(const HeaderOptions&,
280 const OCRepresentation&, const int)> GetCallback;
282 typedef std::function<void(const HeaderOptions&,
283 const OCRepresentation&, const int)> PostCallback;
285 typedef std::function<void(const HeaderOptions&,
286 const OCRepresentation&, const int)> PutCallback;
288 typedef std::function<void(const HeaderOptions&, const int)> DeleteCallback;
290 typedef std::function<void(const HeaderOptions&,
291 const OCRepresentation&, const int, const int)> ObserveCallback;
293 typedef std::function<void(std::shared_ptr<OCDirectPairing>, OCStackResult)> DirectPairingCallback;
295 typedef std::function<void(const PairedDevices&)> GetDirectPairedCallback;