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