Added constructors to trivial struct types used in C++
[platform/upstream/iotivity.git] / resource / include / InProcClientWrapper.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 _IN_PROC_CLIENT_WRAPPER_H_
22 #define _IN_PROC_CLIENT_WRAPPER_H_
23
24 #include <thread>
25 #include <mutex>
26 #include <sstream>
27 #include <iostream>
28
29 #include <OCApi.h>
30 #include <ocstack.h>
31 #include <IClientWrapper.h>
32 #include <InitializeException.h>
33 #include <ResourceInitException.h>
34
35 namespace OC
36 {
37     namespace ClientCallbackContext
38     {
39         struct GetContext
40         {
41             GetCallback callback;
42             GetContext(GetCallback cb) : callback(cb){}
43         };
44
45         struct SetContext
46         {
47             PutCallback callback;
48             SetContext(PutCallback cb) : callback(cb){}
49         };
50
51         struct ListenContext
52         {
53             FindCallback callback;
54             std::weak_ptr<IClientWrapper> clientWrapper;
55
56             ListenContext(FindCallback cb, std::weak_ptr<IClientWrapper> cw)
57                 : callback(cb), clientWrapper(cw){}
58         };
59
60         struct DeviceListenContext
61         {
62             FindDeviceCallback callback;
63             IClientWrapper::Ptr clientWrapper;
64             DeviceListenContext(FindDeviceCallback cb, IClientWrapper::Ptr cw)
65                     : callback(cb), clientWrapper(cw){}
66         };
67
68         struct SubscribePresenceContext
69         {
70             SubscribeCallback callback;
71             SubscribePresenceContext(SubscribeCallback cb) : callback(cb){}
72         };
73
74         struct DeleteContext
75         {
76             DeleteCallback callback;
77             DeleteContext(DeleteCallback cb) : callback(cb){}
78         };
79
80         struct ObserveContext
81         {
82             ObserveCallback callback;
83             ObserveContext(ObserveCallback cb) : callback(cb){}
84         };
85     }
86
87     class InProcClientWrapper : public IClientWrapper
88     {
89
90     public:
91
92         InProcClientWrapper(std::weak_ptr<std::recursive_mutex> csdkLock,
93                             PlatformConfig cfg);
94         virtual ~InProcClientWrapper();
95
96         virtual OCStackResult ListenForResource(const std::string& serviceUrl,
97             const std::string& resourceType, OCConnectivityType connectivityType,
98             FindCallback& callback, QualityOfService QoS);
99
100         virtual OCStackResult ListenForDevice(const std::string& serviceUrl,
101             const std::string& deviceURI, OCConnectivityType connectivityType,
102             FindDeviceCallback& callback, QualityOfService QoS);
103
104         virtual OCStackResult GetResourceRepresentation(const std::string& host,
105             const std::string& uri, OCConnectivityType connectivityType,
106             const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
107             GetCallback& callback, QualityOfService QoS);
108
109         virtual OCStackResult PutResourceRepresentation(const std::string& host,
110             const std::string& uri, OCConnectivityType connectivityType,
111             const OCRepresentation& attributes, const QueryParamsMap& queryParams,
112             const HeaderOptions& headerOptions, PutCallback& callback, QualityOfService QoS);
113
114         virtual OCStackResult PostResourceRepresentation(const std::string& host,
115             const std::string& uri, OCConnectivityType connectivityType,
116             const OCRepresentation& attributes, const QueryParamsMap& queryParams,
117             const HeaderOptions& headerOptions, PostCallback& callback, QualityOfService QoS);
118
119         virtual OCStackResult DeleteResource(const std::string& host, const std::string& uri,
120             OCConnectivityType connectivityType, const HeaderOptions& headerOptions,
121             DeleteCallback& callback, QualityOfService QoS);
122
123         virtual OCStackResult ObserveResource(ObserveType observeType, OCDoHandle* handle,
124             const std::string& host, const std::string& uri, OCConnectivityType connectivityType,
125             const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
126             ObserveCallback& callback, QualityOfService QoS);
127
128         virtual OCStackResult CancelObserveResource(OCDoHandle handle, const std::string& host,
129             const std::string& uri, const HeaderOptions& headerOptions, QualityOfService QoS);
130
131         virtual OCStackResult SubscribePresence(OCDoHandle* handle, const std::string& host,
132             const std::string& resourceType, OCConnectivityType connectivityType,
133             SubscribeCallback& presenceHandler);
134
135         virtual OCStackResult UnsubscribePresence(OCDoHandle handle);
136         OCStackResult GetDefaultQos(QualityOfService& QoS);
137     private:
138         void listeningFunc();
139         std::string assembleSetResourceUri(std::string uri, const QueryParamsMap& queryParams);
140         std::string assembleSetResourcePayload(const OCRepresentation& attributes);
141         OCHeaderOption* assembleHeaderOptions(OCHeaderOption options[],
142            const HeaderOptions& headerOptions);
143         std::thread m_listeningThread;
144         bool m_threadRun;
145         std::weak_ptr<std::recursive_mutex> m_csdkLock;
146
147     private:
148         PlatformConfig  m_cfg;
149     };
150 }
151
152 #endif
153