Merge "Merge branch 'master' into resource-manipulation" into resource-manipulation
[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        : Quality of Service : CONFIRMABLE or NON CONFIRMABLE.
115     */
116     struct PlatformConfig
117     {
118         ServiceType                serviceType;
119         ModeType                   mode;
120         OCConnectivityType         serverConnectivity;
121         OCConnectivityType         clientConnectivity;
122         std::string                ipAddress;   // not used
123         uint16_t                   port;        // not used
124         QualityOfService           QoS;
125
126         public:
127             PlatformConfig()
128                 : serviceType(ServiceType::InProc),
129                 mode(ModeType::Both),
130                 serverConnectivity(CT_DEFAULT),
131                 clientConnectivity(CT_DEFAULT),
132                 ipAddress("0.0.0.0"),
133                 port(0),
134                 QoS(QualityOfService::NaQos)
135         {}
136             PlatformConfig(const ServiceType serviceType_,
137             const ModeType mode_,
138             OCConnectivityType serverConnectivity_,
139             OCConnectivityType clientConnectivity_,
140             const QualityOfService QoS_)
141                 : serviceType(serviceType_),
142                 mode(mode_),
143                 serverConnectivity(serverConnectivity_),
144                 clientConnectivity(clientConnectivity_),
145                 ipAddress(""),
146                 port(0),
147                 QoS(QoS_)
148         {}
149             // for backward compatibility
150             PlatformConfig(const ServiceType serviceType_,
151             const ModeType mode_,
152             const std::string& ipAddress_,
153             const uint16_t port_,
154             const QualityOfService QoS_)
155                 : serviceType(serviceType_),
156                 mode(mode_),
157                 serverConnectivity(CT_DEFAULT),
158                 clientConnectivity(CT_DEFAULT),
159                 ipAddress(ipAddress_),
160                 port(port_),
161                 QoS(QoS_)
162         {}
163     };
164
165     enum RequestHandlerFlag
166     {
167         RequestFlag = 1 << 1,
168         ObserverFlag = 1 << 2
169     };
170
171     enum class ObserveType
172     {
173         Observe,
174         ObserveAll
175     };
176     //
177     // Typedef for header option vector
178     // OCHeaderOption class is in HeaderOption namespace
179     typedef std::vector<HeaderOption::OCHeaderOption> HeaderOptions;
180
181     // Typedef for query parameter map
182     typedef std::map<std::string, std::string> QueryParamsMap;
183
184     // Typedef for list of observation IDs
185     typedef std::vector<OCObservationId> ObservationIds;
186
187     enum class ObserveAction
188     {
189         ObserveRegister,
190         ObserveUnregister
191     };
192
193     typedef struct
194     {
195         // Action associated with observation request
196         ObserveAction action;
197         // Identifier for observation being registered/unregistered
198         OCObservationId obsId;
199     } ObservationInfo;
200
201     // const strings for different interfaces
202
203     // Default interface
204     const std::string DEFAULT_INTERFACE = "oic.if.baseline";
205
206     // Used in discovering (GET) links to other resources of a collection.
207     const std::string LINK_INTERFACE = "oic.if.ll";
208
209     // Used in GET, PUT, POST, DELETE methods on links to other resources of a collection.
210     const std::string BATCH_INTERFACE = "oic.if.b";
211
212     // Used in GET, PUT, POST methods on links to other remote resources of a group.
213     const std::string GROUP_INTERFACE = "oc.mi.grp";
214
215
216     typedef std::function<void(std::shared_ptr<OCResource>)> FindCallback;
217
218     typedef std::function<void(const OCRepresentation&)> FindDeviceCallback;
219
220     typedef std::function<void(const OCRepresentation&)> FindPlatformCallback;
221
222     typedef std::function<OCEntityHandlerResult(
223                             const std::shared_ptr<OCResourceRequest>)> EntityHandler;
224
225     typedef std::function<void(OCStackResult, const unsigned int,
226                                 const std::string&)> SubscribeCallback;
227
228     typedef std::function<void(const HeaderOptions&,
229                                 const OCRepresentation&, const int)> GetCallback;
230
231     typedef std::function<void(const HeaderOptions&,
232                                 const OCRepresentation&, const int)> PostCallback;
233
234     typedef std::function<void(const HeaderOptions&,
235                                 const OCRepresentation&, const int)> PutCallback;
236
237     typedef std::function<void(const HeaderOptions&, const int)> DeleteCallback;
238
239     typedef std::function<void(const HeaderOptions&,
240                                 const OCRepresentation&, const int, const int)> ObserveCallback;
241 } // namespace OC
242
243 #endif