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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #ifndef __INTEL_OCAPI_H_2014_07_10
22 #define __INTEL_OCAPI_H_2014_07_10
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;
48 typedef boost::iostreams::stream<OC::oc_log_stream> log_target_t;
52 /* We'll want to provide some sort of explicit hook for custom logging at some
53 point; until then, this should do nicely (note that since these are lambdas,
54 later a special target could be captured, allowing much flexibility): */
55 auto oclog_target = []() -> log_target_t&
57 static OC::oc_log_stream ols(oc_make_ostream_logger);
58 static log_target_t os(ols);
62 } // namespace OC::detail
64 auto oclog = []() -> boost::iostreams::stream<OC::oc_log_stream>&
66 return detail::oclog_target();
74 enum class OCPlatformStatus
80 enum class OCAdvertisementStatus
85 typedef std::string URI;
87 enum class ServiceType
94 * Host Mode of Operation.
101 Gateway /**< Client server mode along with routing capabilities.*/
105 * Quality of Service attempts to abstract the guarantees provided by the underlying transport
106 * protocol. The precise definitions of each quality of service level depend on the
107 * implementation. In descriptions below are for the current implementation and may changed
110 enum class QualityOfService : uint8_t
112 /** Packet delivery is best effort. */
115 /** Packet delivery is best effort. */
116 MidQos = OC_MEDIUM_QOS,
118 /** Acknowledgments are used to confirm delivery. */
119 HighQos = OC_HIGH_QOS,
121 /** No Quality is defined, let the stack decide. */
126 * Data structure to provide the configuration.
128 struct PlatformConfig
130 /** indicate InProc or OutOfProc. */
131 ServiceType serviceType;
133 /** indicate whether we want to do server, client or both. */
136 /** default flags for server. */
137 OCConnectivityType serverConnectivity;
139 /** default flags for client. */
140 OCConnectivityType clientConnectivity;
143 std::string ipAddress;
148 /** indicate Quality of Service : LowQos, MidQos,HighQos and NaQos(No quality Defined). */
149 QualityOfService QoS;
151 /** persistant storage Handler structure (open/read/write/close/unlink). */
152 OCPersistentStorage *ps;
156 : serviceType(ServiceType::InProc),
157 mode(ModeType::Both),
158 serverConnectivity(CT_DEFAULT),
159 clientConnectivity(CT_DEFAULT),
160 ipAddress("0.0.0.0"),
162 QoS(QualityOfService::NaQos),
165 PlatformConfig(const ServiceType serviceType_,
166 const ModeType mode_,
167 OCConnectivityType serverConnectivity_,
168 OCConnectivityType clientConnectivity_,
169 const QualityOfService QoS_,
170 OCPersistentStorage *ps_ = nullptr)
171 : serviceType(serviceType_),
173 serverConnectivity(serverConnectivity_),
174 clientConnectivity(clientConnectivity_),
180 // for backward compatibility
181 PlatformConfig(const ServiceType serviceType_,
182 const ModeType mode_,
183 const std::string& ipAddress_,
184 const uint16_t port_,
185 const QualityOfService QoS_,
186 OCPersistentStorage *ps_ = nullptr)
187 : serviceType(serviceType_),
189 serverConnectivity(CT_DEFAULT),
190 clientConnectivity(CT_DEFAULT),
191 ipAddress(ipAddress_),
198 enum RequestHandlerFlag
200 RequestFlag = 1 << 1,
201 ObserverFlag = 1 << 2
204 enum class ObserveType
210 // Typedef for header option vector
211 // OCHeaderOption class is in HeaderOption namespace
212 typedef std::vector<HeaderOption::OCHeaderOption> HeaderOptions;
214 // Typedef for query parameter map
215 typedef std::map<std::string, std::string> QueryParamsMap;
217 // Typedef for list of observation IDs
218 typedef std::vector<OCObservationId> ObservationIds;
220 enum class ObserveAction
228 // Action associated with observation request
229 ObserveAction action;
230 // Identifier for observation being registered/unregistered
231 OCObservationId obsId;
234 // const strings for different interfaces
237 const std::string DEFAULT_INTERFACE = "oic.if.baseline";
239 // Used in discovering (GET) links to other resources of a collection.
240 const std::string LINK_INTERFACE = "oic.if.ll";
242 // Used in GET, PUT, POST, DELETE methods on links to other resources of a collection.
243 const std::string BATCH_INTERFACE = "oic.if.b";
245 // Used in GET, PUT, POST methods on links to other remote resources of a group.
246 const std::string GROUP_INTERFACE = "oic.mi.grp";
249 typedef std::function<void(std::shared_ptr<OCResource>)> FindCallback;
251 typedef std::function<void(const OCRepresentation&)> FindDeviceCallback;
253 typedef std::function<void(const OCRepresentation&)> FindPlatformCallback;
255 typedef std::function<OCEntityHandlerResult(
256 const std::shared_ptr<OCResourceRequest>)> EntityHandler;
258 typedef std::function<void(OCStackResult, const unsigned int,
259 const std::string&)> SubscribeCallback;
261 typedef std::function<void(const HeaderOptions&,
262 const OCRepresentation&, const int)> GetCallback;
264 typedef std::function<void(const HeaderOptions&,
265 const OCRepresentation&, const int)> PostCallback;
267 typedef std::function<void(const HeaderOptions&,
268 const OCRepresentation&, const int)> PutCallback;
270 typedef std::function<void(const HeaderOptions&, const int)> DeleteCallback;
272 typedef std::function<void(const HeaderOptions&,
273 const OCRepresentation&, const int, const int)> ObserveCallback;