Remove resource directory dependency in lib OC
[platform/upstream/iotivity.git] / resource / csdk / resource-directory / include / 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 public:
50     RDClient(OCQualityOfService qos = OC_NA_QOS) : m_qos(qos)
51     {
52     }
53
54     static RDClient& Instance()
55     {
56         static RDClient client;
57         return client;
58     }
59
60     /**
61      * API for Virtual Resource("/oic/d" and "/oic/p") Publish to Resource Directory.
62      * @note This API applies to resource server side only.
63      *
64      * @param host Host IP Address of a service to direct resource publish query.
65      * @param connectivityType ::OCConnectivityType type of connectivity.
66      * @param callback Handles callbacks, success states and failure states.
67      *
68      * @return Returns ::OC_STACK_OK if success.
69      */
70     OCStackResult publishResourceToRD(const std::string& host,
71                                       OCConnectivityType connectivityType,
72                                       OC::ResourceHandles& resourceHandles,
73                                       PublishResourceCallback callback);
74
75     OCStackResult publishResourceToRD(const std::string& host,
76                                      OCConnectivityType connectivityType,
77                                      PublishResourceCallback callback,
78                                      QualityOfService qos);
79
80     OCStackResult publishResourceToRD(const std::string& host,
81                                       OCConnectivityType connectivityType,
82                                       OC::ResourceHandles& resourceHandles,
83                                       PublishResourceCallback callback,
84                                       QualityOfService qos);
85
86     /**
87      * API for published resource delete from Resource Directory.
88      * @note This API applies to resource server side only.
89      *
90      * @param host Host IP Address of a service to direct resource delete query.
91      * @param connectivityType ::OCConnectivityType type of connectivity.
92      * @param callback Handles callbacks, success states and failure states.
93      *
94      * @return Returns ::OC_STACK_OK if success.
95      */
96     OCStackResult deleteResourceFromRD(const std::string& host,
97                                         OCConnectivityType connectivityType,
98                                         OC::ResourceHandles& resourceHandles,
99                                         DeleteResourceCallback callback);
100
101     OCStackResult deleteResourceFromRD(const std::string& host,
102                                        OCConnectivityType connectivityType,
103                                        DeleteResourceCallback callback,
104                                        QualityOfService qos);
105
106     OCStackResult deleteResourceFromRD(const std::string& host,
107                                       OCConnectivityType connectivityType,
108                                       OC::ResourceHandles &resourceHandles,
109                                       DeleteResourceCallback callback,
110                                       QualityOfService qos);
111
112 };