Merge branch 'master' into resource-manipulation
[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 transportFlags,
98             FindCallback& callback, QualityOfService QoS);
99
100         virtual OCStackResult ListenForDevice(const std::string& serviceUrl,
101             const std::string& deviceURI, OCConnectivityType transportFlags,
102             FindDeviceCallback& callback, QualityOfService QoS);
103
104         virtual OCStackResult GetResourceRepresentation(
105             const OCDevAddr& devAddr,
106             const std::string& uri,
107             const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
108             GetCallback& callback, QualityOfService QoS);
109
110         virtual OCStackResult PutResourceRepresentation(
111             const OCDevAddr& devAddr,
112             const std::string& uri,
113             const OCRepresentation& attributes, const QueryParamsMap& queryParams,
114             const HeaderOptions& headerOptions, PutCallback& callback, QualityOfService QoS);
115
116         virtual OCStackResult PostResourceRepresentation(
117             const OCDevAddr& devAddr,
118             const std::string& uri,
119             const OCRepresentation& attributes, const QueryParamsMap& queryParams,
120             const HeaderOptions& headerOptions, PostCallback& callback, QualityOfService QoS);
121
122         virtual OCStackResult DeleteResource(
123             const OCDevAddr& devAddr,
124             const std::string& uri,
125             const HeaderOptions& headerOptions,
126             DeleteCallback& callback, QualityOfService QoS);
127
128         virtual OCStackResult ObserveResource(
129             ObserveType observeType, OCDoHandle* handle,
130             const OCDevAddr& devAddr,
131             const std::string& uri,
132             const QueryParamsMap& queryParams, const HeaderOptions& headerOptions,
133             ObserveCallback& callback, QualityOfService QoS);
134
135         virtual OCStackResult CancelObserveResource(
136             OCDoHandle handle,
137             const std::string& host,
138             const std::string& uri,
139             const HeaderOptions& headerOptions, QualityOfService QoS);
140
141         virtual OCStackResult SubscribePresence(
142             OCDoHandle *handle,
143             const std::string& host,
144             const std::string& resourceType,
145             OCConnectivityType transportFlags,
146             SubscribeCallback& presenceHandler);
147
148         virtual OCStackResult UnsubscribePresence(OCDoHandle handle);
149         OCStackResult GetDefaultQos(QualityOfService& QoS);
150     private:
151         void listeningFunc();
152         std::string assembleSetResourceUri(std::string uri, const QueryParamsMap& queryParams);
153         std::string assembleSetResourcePayload(const OCRepresentation& attributes);
154         OCHeaderOption* assembleHeaderOptions(OCHeaderOption options[],
155            const HeaderOptions& headerOptions);
156         std::thread m_listeningThread;
157         bool m_threadRun;
158         std::weak_ptr<std::recursive_mutex> m_csdkLock;
159
160     private:
161         PlatformConfig  m_cfg;
162     };
163 }
164
165 #endif
166