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
33 #include "OCHeaderOption.h"
34 #include <OCException.h>
35 #include "StringConstants.h"
36 #include "oc_logger.hpp"
38 #include <OCRepresentation.h>
43 class OCResourceRequest;
44 class OCResourceResponse;
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
101 enum class QualityOfService : uint8_t
104 MidQos = OC_MEDIUM_QOS,
105 HighQos = OC_HIGH_QOS,
106 NaQos = OC_NA_QOS // No Quality is defined, let the stack decide
110 * Data structure to provide the configuration.
111 * ServiceType: indicate InProc or OutOfProc
112 * ModeType : indicate whether we want to do server, client or both
113 * ServerConnectivity : default flags for server
114 * ClientConnectivity : default flags for client
115 * QoS : indicate Quality of Service : LowQos, MidQos,HighQos and NaQos(No quality Defined).
117 struct PlatformConfig
119 ServiceType serviceType;
121 OCConnectivityType serverConnectivity;
122 OCConnectivityType clientConnectivity;
123 std::string ipAddress; // not used
124 uint16_t port; // not used
125 QualityOfService QoS;
129 : serviceType(ServiceType::InProc),
130 mode(ModeType::Both),
131 serverConnectivity(CT_DEFAULT),
132 clientConnectivity(CT_DEFAULT),
133 ipAddress("0.0.0.0"),
135 QoS(QualityOfService::NaQos)
137 PlatformConfig(const ServiceType serviceType_,
138 const ModeType mode_,
139 OCConnectivityType serverConnectivity_,
140 OCConnectivityType clientConnectivity_,
141 const QualityOfService QoS_)
142 : serviceType(serviceType_),
144 serverConnectivity(serverConnectivity_),
145 clientConnectivity(clientConnectivity_),
150 // for backward compatibility
151 PlatformConfig(const ServiceType serviceType_,
152 const ModeType mode_,
153 const std::string& ipAddress_,
154 const uint16_t port_,
155 const QualityOfService QoS_)
156 : serviceType(serviceType_),
158 serverConnectivity(CT_DEFAULT),
159 clientConnectivity(CT_DEFAULT),
160 ipAddress(ipAddress_),
166 enum RequestHandlerFlag
168 RequestFlag = 1 << 1,
169 ObserverFlag = 1 << 2
172 enum class ObserveType
178 // Typedef for header option vector
179 // OCHeaderOption class is in HeaderOption namespace
180 typedef std::vector<HeaderOption::OCHeaderOption> HeaderOptions;
182 // Typedef for query parameter map
183 typedef std::map<std::string, std::string> QueryParamsMap;
185 // Typedef for list of observation IDs
186 typedef std::vector<OCObservationId> ObservationIds;
188 enum class ObserveAction
196 // Action associated with observation request
197 ObserveAction action;
198 // Identifier for observation being registered/unregistered
199 OCObservationId obsId;
202 // const strings for different interfaces
205 const std::string DEFAULT_INTERFACE = "oic.if.baseline";
207 // Used in discovering (GET) links to other resources of a collection.
208 const std::string LINK_INTERFACE = "oic.if.ll";
210 // Used in GET, PUT, POST, DELETE methods on links to other resources of a collection.
211 const std::string BATCH_INTERFACE = "oic.if.b";
213 // Used in GET, PUT, POST methods on links to other remote resources of a group.
214 const std::string GROUP_INTERFACE = "oic.mi.grp";
217 typedef std::function<void(std::shared_ptr<OCResource>)> FindCallback;
219 typedef std::function<void(const OCRepresentation&)> FindDeviceCallback;
221 typedef std::function<void(const OCRepresentation&)> FindPlatformCallback;
223 typedef std::function<OCEntityHandlerResult(
224 const std::shared_ptr<OCResourceRequest>)> EntityHandler;
226 typedef std::function<void(OCStackResult, const unsigned int,
227 const std::string&)> SubscribeCallback;
229 typedef std::function<void(const HeaderOptions&,
230 const OCRepresentation&, const int)> GetCallback;
232 typedef std::function<void(const HeaderOptions&,
233 const OCRepresentation&, const int)> PostCallback;
235 typedef std::function<void(const HeaderOptions&,
236 const OCRepresentation&, const int)> PutCallback;
238 typedef std::function<void(const HeaderOptions&, const int)> DeleteCallback;
240 typedef std::function<void(const HeaderOptions&,
241 const OCRepresentation&, const int, const int)> ObserveCallback;