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;
150 std::string ipAddress;
155 /** indicate Quality of Service : LowQos, MidQos,HighQos and NaQos(No quality Defined). */
156 QualityOfService QoS;
158 /** persistant storage Handler structure (open/read/write/close/unlink). */
159 OCPersistentStorage *ps;
163 : serviceType(ServiceType::InProc),
164 mode(ModeType::Both),
165 serverConnectivity(CT_DEFAULT),
166 clientConnectivity(CT_DEFAULT),
167 ipAddress("0.0.0.0"),
169 QoS(QualityOfService::NaQos),
172 PlatformConfig(const ServiceType serviceType_,
173 const ModeType mode_,
174 OCConnectivityType serverConnectivity_,
175 OCConnectivityType clientConnectivity_,
176 const QualityOfService QoS_,
177 OCPersistentStorage *ps_ = nullptr)
178 : serviceType(serviceType_),
180 serverConnectivity(serverConnectivity_),
181 clientConnectivity(clientConnectivity_),
187 // for backward compatibility
188 PlatformConfig(const ServiceType serviceType_,
189 const ModeType mode_,
190 const std::string& ipAddress_,
191 const uint16_t port_,
192 const QualityOfService QoS_,
193 OCPersistentStorage *ps_ = nullptr)
194 : serviceType(serviceType_),
196 serverConnectivity(CT_DEFAULT),
197 clientConnectivity(CT_DEFAULT),
198 ipAddress(ipAddress_),
205 enum RequestHandlerFlag
207 RequestFlag = 1 << 1,
208 ObserverFlag = 1 << 2
211 enum class ObserveType
217 enum class AclGroupType
223 // Typedef for list of resource handles.
224 typedef std::vector<OCResourceHandle> ResourceHandles;
226 // Typedef for header option vector.
227 // OCHeaderOption class is in HeaderOption namespace.
228 typedef std::vector<HeaderOption::OCHeaderOption> HeaderOptions;
230 // Typedef for query parameter map.
231 typedef std::map<std::string, std::string> QueryParamsMap;
233 // Typedef for query parameter map with Vector
234 typedef std::map< std::string, std::vector<std::string> > QueryParamsList;
236 // Typedef for list of observation IDs.
237 typedef std::vector<OCObservationId> ObservationIds;
239 enum class ObserveAction
247 // Action associated with observation request
248 ObserveAction action;
249 // Identifier for observation being registered/unregistered
250 OCObservationId obsId;
252 OCConnectivityType connectivityType;
257 // const strings for different interfaces
260 const std::string DEFAULT_INTERFACE = "oic.if.baseline";
262 // Used in discovering (GET) links to other resources of a collection.
263 const std::string LINK_INTERFACE = "oic.if.ll";
265 // Used in GET, PUT, POST, DELETE methods on links to other resources of a collection.
266 const std::string BATCH_INTERFACE = "oic.if.b";
268 // Used in GET, PUT, POST methods on links to other remote resources of a group.
269 const std::string GROUP_INTERFACE = "oic.mi.grp";
271 //Typedef for list direct paired devices
272 typedef std::vector<std::shared_ptr<OCDirectPairing>> PairedDevices;
274 typedef std::function<void(std::shared_ptr<OCResource>)> FindCallback;
276 typedef std::function<void(const std::string&, const int)> FindErrorCallback;
278 typedef std::function<void(const OCRepresentation&)> FindDeviceCallback;
280 typedef std::function<void(const OCRepresentation&)> FindPlatformCallback;
282 typedef std::function<OCEntityHandlerResult(
283 const std::shared_ptr<OCResourceRequest>)> EntityHandler;
285 typedef std::function<void(OCStackResult, const unsigned int,
286 const std::string&)> SubscribeCallback;
288 typedef std::function<void(const HeaderOptions&,
289 const OCRepresentation&, const int)> GetCallback;
291 typedef std::function<void(const HeaderOptions&,
292 const OCRepresentation&, const int)> PostCallback;
294 typedef std::function<void(const HeaderOptions&,
295 const OCRepresentation&, const int)> PutCallback;
297 typedef std::function<void(const HeaderOptions&, const int)> DeleteCallback;
299 typedef std::function<void(const HeaderOptions&,
300 const OCRepresentation&, const int, const int)> ObserveCallback;
302 typedef std::function<void(std::shared_ptr<OCDirectPairing>, OCStackResult)> DirectPairingCallback;
304 typedef std::function<void(const PairedDevices&)> GetDirectPairedCallback;
306 typedef std::function<void(const int, const std::string&,
307 std::shared_ptr<OCResource>)> MQTopicCallback;
309 typedef std::function<void(const OCRepresentation&, const int)> PublishResourceCallback;
311 typedef std::function<void(const int)> DeleteResourceCallback;