1 //******************************************************************
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
11 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
24 * This file contains the RCSActiveDiscoveryManagerImpl class which provide APIs to discover the Resource in the network
25 * and discovery requests management.
29 #ifndef RCSDISCOVERYMANAGER_IMPL_H
30 #define RCSDISCOVERYMANAGER_IMPL_H
36 #include <unordered_map>
41 #include "RCSDiscoveryManager.h"
42 #include "RCSAddress.h"
43 #include "ExpiryTimer.h"
44 #include "PrimitiveResource.h"
45 #include "RCSRemoteResourceObject.h"
51 class RCSDiscoveryManager;
52 class PrimitiveResource;
56 * The class contains discovery request information
58 * @see RCSDiscoveryManager
60 class DiscoverRequestInfo
64 std::string m_address;
65 std::string m_relativeUri;
66 std::string m_resourceType;
67 std::list<std::string> m_receivedIds;
68 bool m_isReceivedFindCallback;
69 DiscoverCallback m_findCB;
70 RCSDiscoveryManager::ResourceDiscoveredCallback m_discoverCB;
74 * The class contains the resource discovery and management requests methods.
76 class RCSDiscoveryManagerImpl
78 static unsigned int s_uniqueId;
83 * Typedef for callback of requesting presence API
85 * @see requestMulticastPresence
87 typedef std::function<void(OCStackResult, const unsigned int,
88 const std::string&)> PresenceCallback;
91 * Typedef for discovery request ID
93 * @note This is generated for each discovery request
95 typedef unsigned int ID;
98 * Typedef for callback of discoverResource API
100 typedef std::function<void(std::shared_ptr< PrimitiveResource >, ID)> FindCallback;
105 * @return Returns RCSDiscoveryManagerImpl instance.
107 static RCSDiscoveryManagerImpl* getInstance();
109 DiscoverRequestInfo m_discoveryItem;
110 std::unordered_map<ID,DiscoverRequestInfo> m_discoveryMap;
111 PresenceCallback m_presenceCB;
112 ExpiryTimer::Callback m_pollingCB;
117 static RCSDiscoveryManagerImpl * s_instance;
118 static std::mutex s_mutexForCreation;
124 * Starting discovery of resource
126 * @return DiscoverTask pointer
128 * @param address A RCSAddress object
129 * @param relativeURI The relative uri of resource to be searched
130 * @param resourceType Resource Type
131 * @param cb A callback to obtain discovered resource
133 * @throws InvalidParameterException If cb is empty
135 * @note If relativeURI is empty, will be discovered after be changed into "OC_RSRVD_WELL_KNOWN_URI"
136 * @note If resourceType is empty, will be discovered all resources in network
139 * @see RCSDiscoveryManager
141 std::unique_ptr<RCSDiscoveryManager::DiscoveryTask> startDiscovery(const RCSAddress& address,
142 const std::string& relativeURI,const std::string& resourceType,
143 RCSDiscoveryManager::ResourceDiscoveredCallback cb);
148 * Requesting presence by multicast
150 void requestMulticastPresence();
153 * Initializing callback of presence and polling
155 void initializedDiscoveryEnvironment();
158 * Checking duplicated callback and invoking callback when resource is discovered
160 * @param resource A pointer of discovered resource
161 * @param discoverID The ID of discovery request
163 * @see PrimitiveResource
165 void findCallback(std::shared_ptr< PrimitiveResource > resource, ID discoverID);
168 * Discovering resource on all requests and posting timer when timer is expired
170 void pollingCallback(unsigned int /*msg*/);
173 * Discovering resource on all requests when supporting presence function resource enter into network
175 * @param ret Not used in this class
176 * @param seq Not used in this class
177 * @param address A address of supporting presence function resource
179 void presenceCallback(OCStackResult, const unsigned int,const std::string&);
182 * Checking duplicated callback
184 * @return The callback is duplicated or not
186 * @param resource A pointer of discovered resource
187 * @param discoverID The ID of discovery request
189 * @see PrimitiveResource
191 bool isDuplicatedCallback(std::shared_ptr<PrimitiveResource> resource, ID discoverID);
196 * @return Returns the id
201 RCSDiscoveryManagerImpl();
202 ~RCSDiscoveryManagerImpl() = default;
206 #endif // RCSDISCOVERYMANAGER_IMPL_H