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.
104 * Quality of Service attempts to abstract the guarantees provided by the underlying transport
105 * protocol. The precise definitions of each quality of service level depend on the
106 * implementation. In descriptions below are for the current implementation and may changed
109 enum class QualityOfService : uint8_t
111 /** Packet delivery is best effort. */
114 /** Packet delivery is best effort. */
115 MidQos = OC_MEDIUM_QOS,
117 /** Acknowledgments are used to confirm delivery. */
118 HighQos = OC_HIGH_QOS,
120 /** No Quality is defined, let the stack decide. */
125 * Data structure to provide the configuration.
127 struct PlatformConfig
129 /** indicate InProc or OutOfProc. */
130 ServiceType serviceType;
132 /** indicate whether we want to do server, client or both. */
135 /** default flags for server. */
136 OCConnectivityType serverConnectivity;
138 /** default flags for client. */
139 OCConnectivityType clientConnectivity;
142 std::string ipAddress;
147 /** indicate Quality of Service : LowQos, MidQos,HighQos and NaQos(No quality Defined). */
148 QualityOfService QoS;
150 /** persistant storage Handler structure (open/read/write/close/unlink). */
151 OCPersistentStorage *ps;
155 : serviceType(ServiceType::InProc),
156 mode(ModeType::Both),
157 serverConnectivity(CT_DEFAULT),
158 clientConnectivity(CT_DEFAULT),
159 ipAddress("0.0.0.0"),
161 QoS(QualityOfService::NaQos),
164 PlatformConfig(const ServiceType serviceType_,
165 const ModeType mode_,
166 OCConnectivityType serverConnectivity_,
167 OCConnectivityType clientConnectivity_,
168 const QualityOfService QoS_,
169 OCPersistentStorage *ps_ = nullptr)
170 : serviceType(serviceType_),
172 serverConnectivity(serverConnectivity_),
173 clientConnectivity(clientConnectivity_),
179 // for backward compatibility
180 PlatformConfig(const ServiceType serviceType_,
181 const ModeType mode_,
182 const std::string& ipAddress_,
183 const uint16_t port_,
184 const QualityOfService QoS_,
185 OCPersistentStorage *ps_ = nullptr)
186 : serviceType(serviceType_),
188 serverConnectivity(CT_DEFAULT),
189 clientConnectivity(CT_DEFAULT),
190 ipAddress(ipAddress_),
197 enum RequestHandlerFlag
199 RequestFlag = 1 << 1,
200 ObserverFlag = 1 << 2
203 enum class ObserveType
209 // Typedef for header option vector
210 // OCHeaderOption class is in HeaderOption namespace
211 typedef std::vector<HeaderOption::OCHeaderOption> HeaderOptions;
213 // Typedef for query parameter map
214 typedef std::map<std::string, std::string> QueryParamsMap;
216 // Typedef for list of observation IDs
217 typedef std::vector<OCObservationId> ObservationIds;
219 enum class ObserveAction
227 // Action associated with observation request
228 ObserveAction action;
229 // Identifier for observation being registered/unregistered
230 OCObservationId obsId;
233 // const strings for different interfaces
236 const std::string DEFAULT_INTERFACE = "oic.if.baseline";
238 // Used in discovering (GET) links to other resources of a collection.
239 const std::string LINK_INTERFACE = "oic.if.ll";
241 // Used in GET, PUT, POST, DELETE methods on links to other resources of a collection.
242 const std::string BATCH_INTERFACE = "oic.if.b";
244 // Used in GET, PUT, POST methods on links to other remote resources of a group.
245 const std::string GROUP_INTERFACE = "oic.mi.grp";
248 typedef std::function<void(std::shared_ptr<OCResource>)> FindCallback;
250 typedef std::function<void(const OCRepresentation&)> FindDeviceCallback;
252 typedef std::function<void(const OCRepresentation&)> FindPlatformCallback;
254 typedef std::function<OCEntityHandlerResult(
255 const std::shared_ptr<OCResourceRequest>)> EntityHandler;
257 typedef std::function<void(OCStackResult, const unsigned int,
258 const std::string&)> SubscribeCallback;
260 typedef std::function<void(const HeaderOptions&,
261 const OCRepresentation&, const int)> GetCallback;
263 typedef std::function<void(const HeaderOptions&,
264 const OCRepresentation&, const int)> PostCallback;
266 typedef std::function<void(const HeaderOptions&,
267 const OCRepresentation&, const int)> PutCallback;
269 typedef std::function<void(const HeaderOptions&, const int)> DeleteCallback;
271 typedef std::function<void(const HeaderOptions&,
272 const OCRepresentation&, const int, const int)> ObserveCallback;