bb9bd647360b1696aa31589590a0077db37e75a2
[platform/upstream/iotivity.git] / service / resource-encapsulation / include / RCSDiscoveryManager.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 /**
22  * @file
23  *
24  * This file contains the RCSDiscoveryManager class which provide APIs to discover the Resource in the network
25  *
26  */
27
28 #ifndef RCSDISCOVERYMANAGER_H
29 #define RCSDISCOVERYMANAGER_H
30
31 #include <memory>
32 #include <functional>
33
34 #include "octypes.h"
35
36 namespace OIC
37 {
38     namespace Service
39     {
40         class RCSRemoteResourceObject;
41         class RCSAddress;
42
43         class DiscoveryTask
44         {
45             public:
46
47                 DiscoveryTask(unsigned int id) : m_id{ id } {};
48                 void cancel();
49                 bool isCanceled();
50                 ~DiscoveryTask();
51             private:
52
53                 unsigned int m_id;
54                 friend class RCSDiscoveryManager;
55                 friend class RCSDiscoveryManagerImpl;
56         };
57
58         /**
59          * This class contains the resource discovery methods.
60          *
61          * @see RCSRemoteResourceObject
62          */
63         class RCSDiscoveryManager
64         {
65             public:
66
67                 /**
68                  * Typedef for callback of discoverResource APIs
69                  *
70                  * @see discoverResource
71                  */
72                 typedef std::function< void(std::shared_ptr< RCSRemoteResourceObject >) >
73                                        ResourceDiscoveredCallback;
74
75                 /**
76                  * @return Returns RCSDiscoveryManager instance.
77                  *
78                  */
79                 static RCSDiscoveryManager* getInstance();
80
81                 /**
82                  * API for discovering the resource of Interest, regardless of URI and resource type
83                  *
84                  * @param address A RCSAddress object
85                  * @param cb A callback to obtain discovered resource
86                  *
87                  * @throws InvalidParameterException If cb is empty.
88                  *
89                  * @note The callback will be invoked in an internal thread.
90                  *
91                  * @see RCSAddress
92                  *
93                  */
94                 std::unique_ptr<DiscoveryTask> discoverResource(const RCSAddress& address,
95                         ResourceDiscoveredCallback cb);
96
97                 /**
98                  * API for discovering the resource of Interest, regardless of resource type
99                  *
100                  * @param address A RCSAddress object
101                  * @param relativeURI The relative uri of resource to be searched
102                  * @param cb A callback to obtain discovered resource
103                  *
104                  * @throws InvalidParameterException If cb is empty.
105                  *
106                  * @note The callback will be invoked in an internal thread.
107                  *
108                  * @see RCSAddress
109                  *
110                  */
111                 std::unique_ptr<DiscoveryTask> discoverResource(const RCSAddress& address,
112                         const std::string& relativeURI, ResourceDiscoveredCallback cb);
113
114                 /**
115                  * API for discovering the resource of Interest by Resource type.
116                  *
117                  * @param address A RCSAddress object
118                  * @param resourceType Ressource Type
119                  * @param cb A callback to obtain discovered resource
120                  *
121                  * @throws InvalidParameterException If cb is empty.
122                  *
123                  * @note The callback will be invoked in an internal thread.
124                  *
125                  * @see RCSAddress
126                  *
127                  */
128                 std::unique_ptr<DiscoveryTask> discoverResourceByType(const RCSAddress& address,
129                         const std::string& resourceType, ResourceDiscoveredCallback cb);
130
131                 /**
132                  * API for discovering the resource of Interest by Resource type with provided relativeURI
133                  *
134                  * @param address A RCSAddress object
135                  * @param relativeURI The relative uri of resource to be searched
136                  * @param resourceType Ressource Type
137                  * @param cb A callback to obtain discovered resource
138                  *
139                  * @throws InvalidParameterException If cb is empty.
140                  *
141                  * @note The callback will be invoked in an internal thread.
142                  *
143                  * @see RCSAddress
144                  *
145                  */
146                 std::unique_ptr<DiscoveryTask>  discoverResourceByType(const RCSAddress& address,
147                         const std::string& relativeURI, const std::string& resourceType,
148                         ResourceDiscoveredCallback cb);
149
150             private:
151
152                 RCSDiscoveryManager() = default;
153                 ~RCSDiscoveryManager()= default;;
154
155                 friend class DiscoveryTask;
156         };
157     }
158 }
159 #endif // RCSDISCOVERYMANAGER_H