Initial version
[platform/core/service/cloud/ua-client.git] / inc / iotivity / RDClient.h
1 //******************************************************************
2 //
3 // Copyright 2015 Samsung Electronics 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 #include "OCRepresentation.h"
22 #include "OCApi.h"
23 #include "octypes.h"
24
25 typedef std::function<void(const OC::OCRepresentation&, const int)> PublishResourceCallback;
26 typedef std::function<void(const int)> DeleteResourceCallback;
27
28 using namespace OC;
29
30 namespace ServerCallbackContext
31 {
32     struct PublishContext
33     {
34         PublishResourceCallback callback;
35         PublishContext(PublishResourceCallback cb) : callback(cb){}
36     };
37
38     struct DeleteContext
39     {
40         DeleteResourceCallback callback;
41         DeleteContext(DeleteResourceCallback cb) : callback(cb){}
42     };
43 }
44
45 class RDClient
46 {
47 private:
48     OCQualityOfService m_qos;
49     std::shared_ptr<std::recursive_mutex> _csdkLock;
50     std::weak_ptr<std::recursive_mutex> m_csdkLock;
51
52 public:
53     RDClient(OCQualityOfService qos = OC_NA_QOS)
54         : m_qos(qos),
55         _csdkLock{ std::make_shared<std::recursive_mutex>() }
56     {
57         m_csdkLock = _csdkLock;
58     }
59
60     static RDClient& Instance()
61     {
62         static RDClient client;
63         return client;
64     }
65
66     /**
67      * API for Virtual Resource("/oic/d" and "/oic/p") Publish to Resource Directory.
68      * @note This API applies to resource server side only.
69      *
70      * @param host Host IP Address of a service to direct resource publish query.
71      * @param connectivityType ::OCConnectivityType type of connectivity.
72      * @param callback Handles callbacks, success states and failure states.
73      *
74      * @return Returns ::OC_STACK_OK if success.
75      */
76     OCStackResult publishResourceToRD(const std::string& host,
77                                       OCConnectivityType connectivityType,
78                                       OC::ResourceHandles& resourceHandles,
79                                       PublishResourceCallback callback);
80
81     OCStackResult publishResourceToRD(const std::string& host,
82                                      OCConnectivityType connectivityType,
83                                      PublishResourceCallback callback,
84                                      QualityOfService qos);
85
86     OCStackResult publishResourceToRD(const std::string& host,
87                                       OCConnectivityType connectivityType,
88                                       OC::ResourceHandles& resourceHandles,
89                                       PublishResourceCallback callback,
90                                       QualityOfService qos);
91
92     /**
93      * API for published resource delete from Resource Directory.
94      * @note This API applies to resource server side only.
95      *
96      * @param host Host IP Address of a service to direct resource delete query.
97      * @param connectivityType ::OCConnectivityType type of connectivity.
98      * @param callback Handles callbacks, success states and failure states.
99      *
100      * @return Returns ::OC_STACK_OK if success.
101      */
102     OCStackResult deleteResourceFromRD(const std::string& host,
103                                         OCConnectivityType connectivityType,
104                                         OC::ResourceHandles& resourceHandles,
105                                         DeleteResourceCallback callback);
106
107     OCStackResult deleteResourceFromRD(const std::string& host,
108                                        OCConnectivityType connectivityType,
109                                        DeleteResourceCallback callback,
110                                        QualityOfService qos);
111
112     OCStackResult deleteResourceFromRD(const std::string& host,
113                                       OCConnectivityType connectivityType,
114                                       OC::ResourceHandles &resourceHandles,
115                                       DeleteResourceCallback callback,
116                                       QualityOfService qos);
117
118 };