Add Doxygen comments for OCApi
[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 __INTEL_OCAPI_H_2014_07_10
22 #define __INTEL_OCAPI_H_2014_07_10
23
24 #include <string>
25 #include <sstream>
26 #include <vector>
27 #include <map>
28 #include <memory>
29 #include <iterator>
30
31 #include "octypes.h"
32 #include "OCHeaderOption.h"
33 #include <OCException.h>
34 #include "StringConstants.h"
35 #include "oc_logger.hpp"
36
37 #include <OCRepresentation.h>
38
39 namespace OC
40 {
41     class OCResource;
42     class OCResourceRequest;
43     class OCResourceResponse;
44 } // namespace OC
45
46 namespace OC
47 {
48     typedef boost::iostreams::stream<OC::oc_log_stream>     log_target_t;
49
50     namespace detail
51     {
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&
56         {
57             static OC::oc_log_stream    ols(oc_make_ostream_logger);
58             static log_target_t         os(ols);
59
60             return os;
61         };
62     } // namespace OC::detail
63
64     auto oclog = []() -> boost::iostreams::stream<OC::oc_log_stream>&
65     {
66         return detail::oclog_target();
67     };
68
69 } // namespace OC
70
71 namespace OC
72 {
73
74     enum class OCPlatformStatus
75     {
76         PlatformUp,
77         PlatformDown
78     };
79
80     enum class OCAdvertisementStatus
81     {
82         None
83     };
84
85     typedef std::string URI;
86
87     enum class ServiceType
88     {
89         InProc,
90         OutOfProc
91     };
92
93     /**
94      * Host Mode of Operation.
95      */
96     enum class ModeType
97     {
98         Server,
99         Client,
100         Both
101     };
102
103     /**
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
107      * over time.
108      */
109     enum class QualityOfService : uint8_t
110     {
111         /** Packet delivery is best effort. */
112         LowQos      = OC_LOW_QOS,
113
114         /** Packet delivery is best effort. */
115         MidQos      = OC_MEDIUM_QOS,
116
117         /** Acknowledgments are used to confirm delivery. */
118         HighQos     = OC_HIGH_QOS,
119
120         /** No Quality is defined, let the stack decide. */
121         NaQos       = OC_NA_QOS
122     };
123
124     /**
125      *  Data structure to provide the configuration.
126      */
127     struct PlatformConfig
128     {
129         /** indicate InProc or OutOfProc. */
130         ServiceType                serviceType;
131
132         /** indicate whether we want to do server, client or both. */
133         ModeType                   mode;
134
135         /** default flags for server. */
136         OCConnectivityType         serverConnectivity;
137
138         /** default flags for client. */
139         OCConnectivityType         clientConnectivity;
140
141         /** not used. */
142         std::string                ipAddress;
143
144         /** not used. */
145         uint16_t                   port;
146
147         /** indicate Quality of Service : LowQos, MidQos,HighQos and NaQos(No quality Defined). */
148         QualityOfService           QoS;
149
150         /** persistant storage Handler structure (open/read/write/close/unlink). */
151         OCPersistentStorage        *ps;
152
153         public:
154             PlatformConfig()
155                 : serviceType(ServiceType::InProc),
156                 mode(ModeType::Both),
157                 serverConnectivity(CT_DEFAULT),
158                 clientConnectivity(CT_DEFAULT),
159                 ipAddress("0.0.0.0"),
160                 port(0),
161                 QoS(QualityOfService::NaQos),
162                 ps(nullptr)
163         {}
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_),
171                 mode(mode_),
172                 serverConnectivity(serverConnectivity_),
173                 clientConnectivity(clientConnectivity_),
174                 ipAddress(""),
175                 port(0),
176                 QoS(QoS_),
177                 ps(ps_)
178         {}
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_),
187                 mode(mode_),
188                 serverConnectivity(CT_DEFAULT),
189                 clientConnectivity(CT_DEFAULT),
190                 ipAddress(ipAddress_),
191                 port(port_),
192                 QoS(QoS_),
193                 ps(ps_)
194         {}
195     };
196
197     enum RequestHandlerFlag
198     {
199         RequestFlag = 1 << 1,
200         ObserverFlag = 1 << 2
201     };
202
203     enum class ObserveType
204     {
205         Observe,
206         ObserveAll
207     };
208     //
209     // Typedef for header option vector
210     // OCHeaderOption class is in HeaderOption namespace
211     typedef std::vector<HeaderOption::OCHeaderOption> HeaderOptions;
212
213     // Typedef for query parameter map
214     typedef std::map<std::string, std::string> QueryParamsMap;
215
216     // Typedef for list of observation IDs
217     typedef std::vector<OCObservationId> ObservationIds;
218
219     enum class ObserveAction
220     {
221         ObserveRegister,
222         ObserveUnregister
223     };
224
225     typedef struct
226     {
227         // Action associated with observation request
228         ObserveAction action;
229         // Identifier for observation being registered/unregistered
230         OCObservationId obsId;
231     } ObservationInfo;
232
233     // const strings for different interfaces
234
235     // Default interface
236     const std::string DEFAULT_INTERFACE = "oic.if.baseline";
237
238     // Used in discovering (GET) links to other resources of a collection.
239     const std::string LINK_INTERFACE = "oic.if.ll";
240
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";
243
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";
246
247
248     typedef std::function<void(std::shared_ptr<OCResource>)> FindCallback;
249
250     typedef std::function<void(const OCRepresentation&)> FindDeviceCallback;
251
252     typedef std::function<void(const OCRepresentation&)> FindPlatformCallback;
253
254     typedef std::function<OCEntityHandlerResult(
255                             const std::shared_ptr<OCResourceRequest>)> EntityHandler;
256
257     typedef std::function<void(OCStackResult, const unsigned int,
258                                 const std::string&)> SubscribeCallback;
259
260     typedef std::function<void(const HeaderOptions&,
261                                 const OCRepresentation&, const int)> GetCallback;
262
263     typedef std::function<void(const HeaderOptions&,
264                                 const OCRepresentation&, const int)> PostCallback;
265
266     typedef std::function<void(const HeaderOptions&,
267                                 const OCRepresentation&, const int)> PutCallback;
268
269     typedef std::function<void(const HeaderOptions&, const int)> DeleteCallback;
270
271     typedef std::function<void(const HeaderOptions&,
272                                 const OCRepresentation&, const int, const int)> ObserveCallback;
273 } // namespace OC
274
275 #endif