Merge branch 'simulator'
[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         /**
44          * This class contains the resource discovery methods.
45          *
46          * @see RCSRemoteResourceObject
47          */
48         class RCSDiscoveryManager
49         {
50             public:
51                 class DiscoveryTask
52                 {
53                     public:
54
55                         void cancel();
56                         bool isCanceled();
57                         ~DiscoveryTask();
58
59                         DiscoveryTask(const DiscoveryTask&) = delete;
60                         DiscoveryTask(DiscoveryTask&&) = delete;
61                         DiscoveryTask& operator = (const DiscoveryTask&) const = delete;
62                         DiscoveryTask& operator = (DiscoveryTask&&) const = delete;
63
64                     private:
65
66                         explicit DiscoveryTask(unsigned int id) : m_id{ id } {};
67                     private:
68
69                         unsigned int m_id;
70                         friend class RCSDiscoveryManagerImpl;
71                 };
72             public:
73
74                 /**
75                  * Typedef for callback of discoverResource APIs
76                  *
77                  * @see discoverResource
78                  */
79                 typedef std::function< void(std::shared_ptr< RCSRemoteResourceObject >) >
80                                        ResourceDiscoveredCallback;
81
82                 /**
83                  * Returns RCSDiscoveryManager instance.
84                  *
85                  */
86                 static RCSDiscoveryManager* getInstance();
87
88                 /**
89                  * API for discovering the resource of Interest, regardless of URI and resource type
90                  *
91                  * @param address A RCSAddress object
92                  * @param cb A callback to obtain discovered resource
93                  *
94                  * @throws InvalidParameterException If cb is empty.
95                  * @throws PlatformException If the operation failed.
96                  *
97                  * @note The callback will be invoked in an internal thread.
98                  *
99                  * @see RCSAddress
100                  *
101                  */
102                 std::unique_ptr<DiscoveryTask> discoverResource(const RCSAddress& address,
103                         ResourceDiscoveredCallback cb);
104
105                 /**
106                  * API for discovering the resource of Interest, regardless of resource type
107                  *
108                  * @param address A RCSAddress object
109                  * @param relativeURI The relative uri of resource to be searched
110                  * @param cb A callback to obtain discovered resource
111                  *
112                  * @throws InvalidParameterException If cb is empty.
113                  * @throws PlatformException If the operation failed.
114                  *
115                  * @note The callback will be invoked in an internal thread.
116                  *
117                  * @see RCSAddress
118                  *
119                  */
120                 std::unique_ptr<DiscoveryTask> discoverResource(const RCSAddress& address,
121                         const std::string& relativeURI, ResourceDiscoveredCallback cb);
122
123                 /**
124                  * API for discovering the resource of Interest by Resource type.
125                  *
126                  * @param address A RCSAddress object
127                  * @param resourceType Ressource Type
128                  * @param cb A callback to obtain discovered resource
129                  *
130                  * @throws InvalidParameterException If cb is empty.
131                  * @throws PlatformException If the operation failed.
132                  *
133                  * @note The callback will be invoked in an internal thread.
134                  *
135                  * @see RCSAddress
136                  *
137                  */
138                 std::unique_ptr<DiscoveryTask> discoverResourceByType(const RCSAddress& address,
139                         const std::string& resourceType, ResourceDiscoveredCallback cb);
140
141                 /**
142                  * API for discovering the resource of Interest by Resource type with provided relativeURI
143                  *
144                  * @param address A RCSAddress object
145                  * @param relativeURI The relative uri of resource to be searched
146                  * @param resourceType Ressource Type
147                  * @param cb A callback to obtain discovered resource
148                  *
149                  * @throws InvalidParameterException If cb is empty.
150                  * @throws PlatformException If the operation failed.
151                  *
152                  * @note The callback will be invoked in an internal thread.
153                  *
154                  * @see RCSAddress
155                  *
156                  */
157                 std::unique_ptr<DiscoveryTask>  discoverResourceByType(const RCSAddress& address,
158                         const std::string& relativeURI, const std::string& resourceType,
159                         ResourceDiscoveredCallback cb);
160
161             private:
162
163                 RCSDiscoveryManager() = default;
164                 ~RCSDiscoveryManager()= default;;
165
166                 friend class DiscoveryTask;
167         };
168     }
169 }
170 #endif // RCSDISCOVERYMANAGER_H