CBOR rebase onto master for merge/review
[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
25 #include <string>
26 #include <sstream>
27 #include <vector>
28 #include <map>
29 #include <memory>
30 #include <iterator>
31
32 #include "octypes.h"
33 #include "OCHeaderOption.h"
34 #include <OCException.h>
35 #include "StringConstants.h"
36 #include "oc_logger.hpp"
37
38 #include <OCRepresentation.h>
39
40 namespace OC
41 {
42     class OCResource;
43     class OCResourceRequest;
44     class OCResourceResponse;
45 } // namespace OC
46
47 namespace OC
48 {
49     typedef boost::iostreams::stream<OC::oc_log_stream>     log_target_t;
50
51     namespace detail
52     {
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&
57         {
58             static OC::oc_log_stream    ols(oc_make_ostream_logger);
59             static log_target_t         os(ols);
60
61             return os;
62         };
63     } // namespace OC::detail
64
65     auto oclog = []() -> boost::iostreams::stream<OC::oc_log_stream>&
66     {
67         return detail::oclog_target();
68     };
69
70 } // namespace OC
71
72 namespace OC
73 {
74
75     enum class OCPlatformStatus
76     {
77         PlatformUp,
78         PlatformDown
79     };
80
81     enum class OCAdvertisementStatus
82     {
83         None
84     };
85
86     typedef std::string URI;
87
88     enum class ServiceType
89     {
90         InProc,
91         OutOfProc
92     };
93
94     enum class ModeType
95     {
96         Server,
97         Client,
98         Both
99     };
100
101     enum class QualityOfService : uint8_t
102     {
103         LowQos      = OC_LOW_QOS,
104         MidQos      = OC_MEDIUM_QOS,
105         HighQos     = OC_HIGH_QOS,
106         NaQos       = OC_NA_QOS // No Quality is defined, let the stack decide
107     };
108
109     /**
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).
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
127         public:
128             PlatformConfig()
129                 : serviceType(ServiceType::InProc),
130                 mode(ModeType::Both),
131                 serverConnectivity(CT_DEFAULT),
132                 clientConnectivity(CT_DEFAULT),
133                 ipAddress("0.0.0.0"),
134                 port(0),
135                 QoS(QualityOfService::NaQos)
136         {}
137             PlatformConfig(const ServiceType serviceType_,
138             const ModeType mode_,
139             OCConnectivityType serverConnectivity_,
140             OCConnectivityType clientConnectivity_,
141             const QualityOfService QoS_)
142                 : serviceType(serviceType_),
143                 mode(mode_),
144                 serverConnectivity(serverConnectivity_),
145                 clientConnectivity(clientConnectivity_),
146                 ipAddress(""),
147                 port(0),
148                 QoS(QoS_)
149         {}
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_),
157                 mode(mode_),
158                 serverConnectivity(CT_DEFAULT),
159                 clientConnectivity(CT_DEFAULT),
160                 ipAddress(ipAddress_),
161                 port(port_),
162                 QoS(QoS_)
163         {}
164     };
165
166     enum RequestHandlerFlag
167     {
168         RequestFlag = 1 << 1,
169         ObserverFlag = 1 << 2
170     };
171
172     enum class ObserveType
173     {
174         Observe,
175         ObserveAll
176     };
177     //
178     // Typedef for header option vector
179     // OCHeaderOption class is in HeaderOption namespace
180     typedef std::vector<HeaderOption::OCHeaderOption> HeaderOptions;
181
182     // Typedef for query parameter map
183     typedef std::map<std::string, std::string> QueryParamsMap;
184
185     // Typedef for list of observation IDs
186     typedef std::vector<OCObservationId> ObservationIds;
187
188     enum class ObserveAction
189     {
190         ObserveRegister,
191         ObserveUnregister
192     };
193
194     typedef struct
195     {
196         // Action associated with observation request
197         ObserveAction action;
198         // Identifier for observation being registered/unregistered
199         OCObservationId obsId;
200     } ObservationInfo;
201
202     // const strings for different interfaces
203
204     // Default interface
205     const std::string DEFAULT_INTERFACE = "oic.if.baseline";
206
207     // Used in discovering (GET) links to other resources of a collection.
208     const std::string LINK_INTERFACE = "oic.if.ll";
209
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";
212
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";
215
216
217     typedef std::function<void(std::shared_ptr<OCResource>)> FindCallback;
218
219     typedef std::function<void(const OCRepresentation&)> FindDeviceCallback;
220
221     typedef std::function<void(const OCRepresentation&)> FindPlatformCallback;
222
223     typedef std::function<OCEntityHandlerResult(
224                             const std::shared_ptr<OCResourceRequest>)> EntityHandler;
225
226     typedef std::function<void(OCStackResult, const unsigned int,
227                                 const std::string&)> SubscribeCallback;
228
229     typedef std::function<void(const HeaderOptions&,
230                                 const OCRepresentation&, const int)> GetCallback;
231
232     typedef std::function<void(const HeaderOptions&,
233                                 const OCRepresentation&, const int)> PostCallback;
234
235     typedef std::function<void(const HeaderOptions&,
236                                 const OCRepresentation&, const int)> PutCallback;
237
238     typedef std::function<void(const HeaderOptions&, const int)> DeleteCallback;
239
240     typedef std::function<void(const HeaderOptions&,
241                                 const OCRepresentation&, const int, const int)> ObserveCallback;
242 } // namespace OC
243
244 #endif