fix RPMLINT warning and add debug option for debuginfo package
[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     enum class ModeType
94     {
95         Server,
96         Client,
97         Both
98     };
99
100     enum class QualityOfService : uint8_t
101     {
102         LowQos      = OC_LOW_QOS,
103         MidQos      = OC_MEDIUM_QOS,
104         HighQos     = OC_HIGH_QOS,
105         NaQos       = OC_NA_QOS // No Quality is defined, let the stack decide
106     };
107
108     /**
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     *  ServerConnectivity : default flags for server
113     *  ClientConnectivity : default flags for client
114     *  QoS        : indicate Quality of Service : LowQos, MidQos,HighQos and NaQos(No quality Defined).
115     *  ps         : persistant storage Handler structure (open/read/write/close/unlink)
116     */
117     struct PlatformConfig
118     {
119         ServiceType                serviceType;
120         ModeType                   mode;
121         OCConnectivityType         serverConnectivity;
122         OCConnectivityType         clientConnectivity;
123         std::string                ipAddress;   // not used
124         uint16_t                   port;        // not used
125         QualityOfService           QoS;
126         OCPersistentStorage        *ps;
127
128         public:
129             PlatformConfig()
130                 : serviceType(ServiceType::InProc),
131                 mode(ModeType::Both),
132                 serverConnectivity(CT_DEFAULT),
133                 clientConnectivity(CT_DEFAULT),
134                 ipAddress("0.0.0.0"),
135                 port(0),
136                 QoS(QualityOfService::NaQos),
137                 ps(nullptr)
138         {}
139             PlatformConfig(const ServiceType serviceType_,
140             const ModeType mode_,
141             OCConnectivityType serverConnectivity_,
142             OCConnectivityType clientConnectivity_,
143             const QualityOfService QoS_,
144             OCPersistentStorage *ps_ = nullptr)
145                 : serviceType(serviceType_),
146                 mode(mode_),
147                 serverConnectivity(serverConnectivity_),
148                 clientConnectivity(clientConnectivity_),
149                 ipAddress(""),
150                 port(0),
151                 QoS(QoS_),
152                 ps(ps_)
153         {}
154             // for backward compatibility
155             PlatformConfig(const ServiceType serviceType_,
156             const ModeType mode_,
157             const std::string& ipAddress_,
158             const uint16_t port_,
159             const QualityOfService QoS_,
160             OCPersistentStorage *ps_ = nullptr)
161                 : serviceType(serviceType_),
162                 mode(mode_),
163                 serverConnectivity(CT_DEFAULT),
164                 clientConnectivity(CT_DEFAULT),
165                 ipAddress(ipAddress_),
166                 port(port_),
167                 QoS(QoS_),
168                 ps(ps_)
169         {}
170     };
171
172     enum RequestHandlerFlag
173     {
174         RequestFlag = 1 << 1,
175         ObserverFlag = 1 << 2
176     };
177
178     enum class ObserveType
179     {
180         Observe,
181         ObserveAll
182     };
183     //
184     // Typedef for header option vector
185     // OCHeaderOption class is in HeaderOption namespace
186     typedef std::vector<HeaderOption::OCHeaderOption> HeaderOptions;
187
188     // Typedef for query parameter map
189     typedef std::map<std::string, std::string> QueryParamsMap;
190
191     // Typedef for list of observation IDs
192     typedef std::vector<OCObservationId> ObservationIds;
193
194     enum class ObserveAction
195     {
196         ObserveRegister,
197         ObserveUnregister
198     };
199
200     typedef struct
201     {
202         // Action associated with observation request
203         ObserveAction action;
204         // Identifier for observation being registered/unregistered
205         OCObservationId obsId;
206     } ObservationInfo;
207
208     // const strings for different interfaces
209
210     // Default interface
211     const std::string DEFAULT_INTERFACE = "oic.if.baseline";
212
213     // Used in discovering (GET) links to other resources of a collection.
214     const std::string LINK_INTERFACE = "oic.if.ll";
215
216     // Used in GET, PUT, POST, DELETE methods on links to other resources of a collection.
217     const std::string BATCH_INTERFACE = "oic.if.b";
218
219     // Used in GET, PUT, POST methods on links to other remote resources of a group.
220     const std::string GROUP_INTERFACE = "oic.mi.grp";
221
222
223     typedef std::function<void(std::shared_ptr<OCResource>)> FindCallback;
224
225     typedef std::function<void(const OCRepresentation&)> FindDeviceCallback;
226
227     typedef std::function<void(const OCRepresentation&)> FindPlatformCallback;
228
229     typedef std::function<OCEntityHandlerResult(
230                             const std::shared_ptr<OCResourceRequest>)> EntityHandler;
231
232     typedef std::function<void(OCStackResult, const unsigned int,
233                                 const std::string&)> SubscribeCallback;
234
235     typedef std::function<void(const HeaderOptions&,
236                                 const OCRepresentation&, const int)> GetCallback;
237
238     typedef std::function<void(const HeaderOptions&,
239                                 const OCRepresentation&, const int)> PostCallback;
240
241     typedef std::function<void(const HeaderOptions&,
242                                 const OCRepresentation&, const int)> PutCallback;
243
244     typedef std::function<void(const HeaderOptions&, const int)> DeleteCallback;
245
246     typedef std::function<void(const HeaderOptions&,
247                                 const OCRepresentation&, const int, const int)> ObserveCallback;
248 } // namespace OC
249
250 #endif