Adding more samsung specific properties
[platform/upstream/iotivity.git] / resource / include / OCApi.h
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
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
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
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.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 #ifndef OC_OCAPI_H_
22 #define OC_OCAPI_H_
23
24 #include <string>
25 #include <sstream>
26 #include <vector>
27 #include <map>
28 #include <memory>
29 #include <iterator>
30 #if defined(_MSC_VER)
31 #include <functional>
32 #endif
33
34 #include "octypes.h"
35 #include "OCHeaderOption.h"
36 #include <OCException.h>
37 #include "StringConstants.h"
38 #include "oc_logger.hpp"
39
40 #include <OCRepresentation.h>
41
42 namespace OC
43 {
44     class OCResource;
45     class OCResourceRequest;
46     class OCResourceResponse;
47     class OCDirectPairing;
48 } // namespace OC
49
50 namespace OC
51 {
52 #if defined(_MSC_VER)
53     extern std::ostream& oclog();
54 #else
55     typedef boost::iostreams::stream<OC::oc_log_stream>     log_target_t;
56
57     namespace detail
58     {
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&
63         {
64             static OC::oc_log_stream    ols(oc_make_ostream_logger);
65             static log_target_t         os(ols);
66
67             return os;
68         };
69     } // namespace OC::detail
70
71     auto oclog = []() -> boost::iostreams::stream<OC::oc_log_stream>&
72     {
73         return detail::oclog_target();
74     };
75 #endif
76 } // namespace OC
77
78 namespace OC
79 {
80
81     enum class OCPlatformStatus
82     {
83         PlatformUp,
84         PlatformDown
85     };
86
87     enum class OCAdvertisementStatus
88     {
89         None
90     };
91
92     typedef std::string URI;
93
94     enum class ServiceType
95     {
96         InProc,
97         OutOfProc
98     };
99
100     /**
101      * Host Mode of Operation.
102      */
103     enum class ModeType
104     {
105         Server,
106         Client,
107         Both,
108         Gateway  /**< Client server mode along with routing capabilities.*/
109     };
110
111     /**
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
115      * over time.
116      */
117     enum class QualityOfService : uint8_t
118     {
119         /** Packet delivery is best effort. */
120         LowQos      = OC_LOW_QOS,
121
122         /** Packet delivery is best effort. */
123         MidQos      = OC_MEDIUM_QOS,
124
125         /** Acknowledgments are used to confirm delivery. */
126         HighQos     = OC_HIGH_QOS,
127
128         /** No Quality is defined, let the stack decide. */
129         NaQos       = OC_NA_QOS,
130
131         LowQosWithTcp = OC_LOW_QOS_WITH_TCP
132     };
133
134     /**
135      *  Data structure to provide the configuration.
136      */
137     struct PlatformConfig
138     {
139         /** indicate InProc or OutOfProc. */
140         ServiceType                serviceType;
141
142         /** indicate whether we want to do server, client or both. */
143         ModeType                   mode;
144
145         /** default flags for server. */
146         OCConnectivityType         serverConnectivity;
147
148         /** default flags for client. */
149         OCConnectivityType         clientConnectivity;
150
151         /** transport type to initialize. */
152         OCTransportAdapter         transportType;
153
154         /** not used. */
155         std::string                ipAddress;
156
157         /** not used. */
158         uint16_t                   port;
159
160         /** indicate Quality of Service : LowQos, MidQos,HighQos and NaQos(No quality Defined). */
161         QualityOfService           QoS;
162
163         /** persistant storage Handler structure (open/read/write/close/unlink). */
164         OCPersistentStorage        *ps;
165
166         /** persistant storage Handler structure (open/read/write/close/unlink). */
167         OCPersistentStorage        *psEnc;
168
169         /** persistant storage Handler structure (open/read/write/close/unlink). */
170         OCPersistentStorage        *psRescue;
171
172         /** pointer to save key. */
173         unsigned char*              key;
174
175         public:
176             PlatformConfig()
177                 : serviceType(ServiceType::InProc),
178                 mode(ModeType::Both),
179                 serverConnectivity(CT_DEFAULT),
180                 clientConnectivity(CT_DEFAULT),
181                 transportType(OC_DEFAULT_ADAPTER),
182                 ipAddress("0.0.0.0"),
183                 port(0),
184                 QoS(QualityOfService::NaQos),                
185                 ps(nullptr),
186                 psEnc(nullptr),
187                 psRescue(nullptr),
188                 key(nullptr)
189         {}
190             PlatformConfig(const ServiceType serviceType_,
191             const ModeType mode_,
192             OCConnectivityType serverConnectivity_,
193             OCConnectivityType clientConnectivity_,
194             const QualityOfService QoS_,
195             OCPersistentStorage *ps_ = nullptr,
196             OCPersistentStorage *psEnc_ = nullptr,
197             OCPersistentStorage *psRescue_ = nullptr,
198             unsigned char *key_ = nullptr)
199                 : serviceType(serviceType_),
200                 mode(mode_),
201                 serverConnectivity(serverConnectivity_),
202                 clientConnectivity(clientConnectivity_),
203                 transportType(OC_DEFAULT_ADAPTER),
204                 ipAddress(""),
205                 port(0),
206                 QoS(QoS_),                
207                 ps(ps_),
208                 psEnc(psEnc_),
209                 psRescue(psRescue_),
210                 key(key_)
211
212         {}
213             // for backward compatibility
214             PlatformConfig(const ServiceType serviceType_,
215             const ModeType mode_,
216             const std::string& ipAddress_,
217             const uint16_t port_,
218             const QualityOfService QoS_,
219             OCPersistentStorage *ps_ = nullptr,
220             OCPersistentStorage *psEnc_ = nullptr,
221             OCPersistentStorage *psRescue_ = nullptr,
222             unsigned char *key_ = nullptr)
223                 : serviceType(serviceType_),
224                 mode(mode_),
225                 serverConnectivity(CT_DEFAULT),
226                 clientConnectivity(CT_DEFAULT),
227                 transportType(OC_DEFAULT_ADAPTER),
228                 ipAddress(ipAddress_),
229                 port(port_),
230                 QoS(QoS_),                
231                 ps(ps_),
232                 psEnc(psEnc_),
233                 psRescue(psRescue_),
234                 key(key_)
235  
236         {}
237
238             PlatformConfig(const ServiceType serviceType_,
239             const ModeType mode_,
240             const std::string& ipAddress_,
241             const uint16_t port_,
242             const OCTransportAdapter transportType_,
243             const QualityOfService QoS_,
244             unsigned char *key_,
245             OCPersistentStorage *ps_ = nullptr,
246             OCPersistentStorage *psEnc_ = nullptr,
247             OCPersistentStorage *psRescue_ = nullptr)
248                 : serviceType(serviceType_),
249                 mode(mode_),
250                 transportType(transportType_),
251                 ipAddress(ipAddress_),
252                 port(port_),
253                 QoS(QoS_),                
254                 ps(ps_),
255                 psEnc(psEnc_),
256                 psRescue(psRescue_),
257                 key(key_)
258         {}
259
260            PlatformConfig(const ServiceType serviceType_,
261             const ModeType mode_,
262             OCTransportAdapter transportType_,
263             const QualityOfService QoS_,
264             OCPersistentStorage *ps_ = nullptr,
265             OCPersistentStorage *psEnc_ = nullptr,
266             OCPersistentStorage *psRescue_ = nullptr,
267             unsigned char *key_ = nullptr)
268                 : serviceType(serviceType_),
269                 mode(mode_),
270                 serverConnectivity(CT_DEFAULT),
271                 clientConnectivity(CT_DEFAULT),
272                 transportType(transportType_),
273                 ipAddress(""),
274                 port(0),
275                 QoS(QoS_),
276                 ps(ps_),
277                 psEnc(psEnc_),
278                 psRescue(psRescue_),
279                 key(key_)
280         {}
281             PlatformConfig(const ServiceType serviceType_,
282             const ModeType mode_,
283             OCConnectivityType serverConnectivity_,
284             OCConnectivityType clientConnectivity_,
285             OCTransportAdapter transportType_,
286             const QualityOfService QoS_,
287             OCPersistentStorage *ps_ = nullptr,
288             OCPersistentStorage *psEnc_ = nullptr,
289             OCPersistentStorage *psRescue_ = nullptr,
290             unsigned char *key_ = nullptr)
291                 : serviceType(serviceType_),
292                 mode(mode_),
293                 serverConnectivity(serverConnectivity_),
294                 clientConnectivity(clientConnectivity_),
295                 transportType(transportType_),
296                 ipAddress(""),
297                 port(0),
298                 QoS(QoS_),
299                 ps(ps_),
300                 psEnc(psEnc_),
301                 psRescue(psRescue_),
302                 key(key_)
303         {}
304
305     };
306
307     enum RequestHandlerFlag
308     {
309         RequestFlag = 1 << 1,
310         ObserverFlag = 1 << 2
311     };
312
313     enum class ObserveType
314     {
315         Observe,
316         ObserveAll
317     };
318
319     // Typedef for list of resource handles.
320     typedef std::vector<OCResourceHandle> ResourceHandles;
321
322     // Typedef for header option vector.
323     // OCHeaderOption class is in HeaderOption namespace.
324     typedef std::vector<HeaderOption::OCHeaderOption> HeaderOptions;
325
326     // Typedef for query parameter map.
327     typedef std::map<std::string, std::string> QueryParamsMap;
328
329     // Typedef for query parameter map with Vector
330     typedef std::map< std::string, std::vector<std::string> > QueryParamsList;
331
332     // Typedef for list of observation IDs.
333     typedef std::vector<OCObservationId> ObservationIds;
334
335     enum class ObserveAction
336     {
337         ObserveRegister,
338         ObserveUnregister
339     };
340
341     typedef struct
342     {
343         // Action associated with observation request
344         ObserveAction action;
345         // Identifier for observation being registered/unregistered
346         OCObservationId obsId;
347
348         OCConnectivityType connectivityType;
349         std::string address;
350         uint16_t port;
351     } ObservationInfo;
352
353     // const strings for different interfaces
354
355     // Default interface
356     const std::string DEFAULT_INTERFACE = "oic.if.baseline";
357
358     // Used in discovering (GET) links to other resources of a collection.
359     const std::string LINK_INTERFACE = "oic.if.ll";
360
361     // Used in GET, PUT, POST, DELETE methods on links to other resources of a collection.
362     const std::string BATCH_INTERFACE = "oic.if.b";
363
364     // Used in GET, PUT, POST methods on links to other remote resources of a group.
365     const std::string GROUP_INTERFACE = "oic.mi.grp";
366
367     //Typedef for list direct paired devices
368     typedef std::vector<std::shared_ptr<OCDirectPairing>> PairedDevices;
369
370     typedef std::function<void(std::shared_ptr<OCResource>)> FindCallback;
371
372     typedef std::function<void(const std::string&, const int)> FindErrorCallback;
373
374     typedef std::function<void(std::vector<std::shared_ptr<OCResource>>)> FindResListCallback;
375
376     typedef std::function<void(const OCRepresentation&)> FindDeviceCallback;
377
378     typedef std::function<void(const OCRepresentation&)> FindPlatformCallback;
379
380     typedef std::function<OCEntityHandlerResult(
381                             const std::shared_ptr<OCResourceRequest>)> EntityHandler;
382
383     typedef std::function<void(OCStackResult, const unsigned int,
384                                 const std::string&)> SubscribeCallback;
385
386     typedef std::function<void(const HeaderOptions&,
387                                 const OCRepresentation&, const int)> GetCallback;
388
389     typedef std::function<void(const HeaderOptions&,
390                                 const OCRepresentation&, const int)> PostCallback;
391
392     typedef std::function<void(const HeaderOptions&,
393                                 const OCRepresentation&, const int)> PutCallback;
394
395     typedef std::function<void(const HeaderOptions&, const int)> DeleteCallback;
396
397     typedef std::function<void(const HeaderOptions&,
398                                 const OCRepresentation&, const int, const int)> ObserveCallback;
399
400     typedef std::function<void(std::shared_ptr<OCDirectPairing>, OCStackResult)> DirectPairingCallback;
401
402     typedef std::function<void(const PairedDevices&)> GetDirectPairedCallback;
403
404     typedef std::function<void(const int, const std::string&,
405                                std::shared_ptr<OCResource>)> MQTopicCallback;
406 #ifdef TCP_ADAPTER
407     typedef std::function<void(const int, const OCRepresentation&)> KeepAliveCallback;
408 #endif
409 } // namespace OC
410
411 #endif