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
100 enum class QualityOfService : uint8_t
103 MidQos = OC_MEDIUM_QOS,
104 HighQos = OC_HIGH_QOS,
105 NaQos = OC_NA_QOS // No Quality is defined, let the stack decide
109 * Data structure to provide the configuration.
110 * ServiceType: indicate InProc or OutOfProc
111 * ModeType : indicate whether we want to do server, client or both
112 * ipAddress : ip address of server.
113 * if you speecifiy 0.0.0.0 : it listens on any interface.
114 * port : port of server.
115 * : if you specifiy 0 : next available random port is used.
116 * : if you specify 5683 : client discovery can work even if they don't specify port.
117 * QoS : Quality of Service : CONFIRMABLE or NON CONFIRMABLE.
119 struct PlatformConfig
121 ServiceType serviceType;
123 std::string ipAddress;
126 QualityOfService QoS;
130 : serviceType(ServiceType::InProc),
131 mode(ModeType::Both),
132 ipAddress("0.0.0.0"),
134 QoS(QualityOfService::NaQos)
136 PlatformConfig(const ServiceType serviceType_,
137 const ModeType mode_,
138 const std::string& ipAddress_,
139 const uint16_t port_,
140 const QualityOfService QoS_)
141 : serviceType(serviceType_),
143 ipAddress(ipAddress_),
149 enum RequestHandlerFlag
152 RequestFlag = 1 << 1,
153 ObserverFlag = 1 << 2
156 enum class ObserveType
162 // Typedef for header option vector
163 // OCHeaderOption class is in HeaderOption namespace
164 typedef std::vector<HeaderOption::OCHeaderOption> HeaderOptions;
166 // Typedef for query parameter map
167 typedef std::map<std::string, std::string> QueryParamsMap;
169 // Typedef for list of observation IDs
170 typedef std::vector<OCObservationId> ObservationIds;
172 enum class ObserveAction
180 // Action associated with observation request
181 ObserveAction action;
182 // Identifier for observation being registered/unregistered
183 OCObservationId obsId;
186 // const strings for different interfaces
189 const std::string DEFAULT_INTERFACE = "oc.mi.def";
191 // Used in discovering (GET) links to other resources of a collection.
192 const std::string LINK_INTERFACE = "oc.mi.ll";
194 // Used in GET, PUT, POST, DELETE methods on links to other resources of a collection.
195 const std::string BATCH_INTERFACE = "oc.mi.b";
197 // Used in GET, PUT, POST methods on links to other remote resources of a group.
198 const std::string GROUP_INTERFACE = "oc.mi.c";
201 typedef std::function<void(std::shared_ptr<OCResource>)> FindCallback;
203 typedef std::function<void(const OCRepresentation&)> FindDeviceCallback;
205 typedef std::function<OCEntityHandlerResult(
206 const std::shared_ptr<OCResourceRequest>)> EntityHandler;
208 typedef std::function<void(OCStackResult, const unsigned int,
209 const std::string&)> SubscribeCallback;
211 typedef std::function<void(const HeaderOptions&,
212 const OCRepresentation&, const int)> GetCallback;
214 typedef std::function<void(const HeaderOptions&,
215 const OCRepresentation&, const int)> PostCallback;
217 typedef std::function<void(const HeaderOptions&,
218 const OCRepresentation&, const int)> PutCallback;
220 typedef std::function<void(const HeaderOptions&, const int)> DeleteCallback;
222 typedef std::function<void(const HeaderOptions&,
223 const OCRepresentation&, const int, const int)> ObserveCallback;