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>
38 #include "RCSDiscoveryManager.h"
39 #include "ExpiryTimer.h"
40 #include "PrimitiveResource.h"
41 #include "RCSRemoteResourceObject.h"
47 class RCSDiscoveryManager;
48 class PrimitiveResource;
52 * The class contains discovery request information
54 * @see RCSDiscoveryManager
56 class DiscoveryRequestInfo
59 DiscoveryRequestInfo(const std::string &, const std::string &,
60 const std::string &, DiscoverCallback);
63 std::string m_address;
64 std::string m_relativeUri;
65 std::string m_resourceType;
66 std::list<std::string> m_receivedIds;
67 DiscoverCallback m_discoverCB;
69 void discoverRequest() const;
70 bool isKnownResource(const std::shared_ptr<PrimitiveResource>&);
71 bool isMatchingAddress(const std::string&) const;
76 * The class contains the resource discovery and management requests methods.
78 class RCSDiscoveryManagerImpl
80 static unsigned int s_uniqueId;
85 * Typedef for callback of requesting presence API
87 * @see requestMulticastPresence
89 typedef std::function<void(OCStackResult, const unsigned int,
90 const std::string&)> PresenceCallback;
93 * Typedef for discovery request ID
95 * @note This is generated for each discovery request
97 typedef unsigned int ID;
102 * @return Returns RCSDiscoveryManagerImpl instance.
104 static RCSDiscoveryManagerImpl* getInstance();
107 * Starting discovery of resource
109 * @return DiscoverTask pointer
111 * @param address A RCSAddress object
112 * @param relativeURI The relative uri of resource to be searched
113 * @param resourceType Resource Type
114 * @param cb A callback to obtain discovered resource
116 * @throws InvalidParameterException If cb is empty
118 * @note If relativeURI is empty, will be discovered after be changed into "OC_RSRVD_WELL_KNOWN_URI"
119 * @note If resourceType is empty, will be discovered all resources in network
122 * @see RCSDiscoveryManager
124 std::unique_ptr<RCSDiscoveryManager::DiscoveryTask> startDiscovery(const RCSAddress& address,
125 const std::string& relativeURI,const std::string& resourceType,
126 RCSDiscoveryManager::ResourceDiscoveredCallback cb);
132 RCSDiscoveryManagerImpl();
133 ~RCSDiscoveryManagerImpl() = default;
136 * Requesting presence by multicast
138 void requestMulticastPresence();
141 * Checking duplicated callback and invoking callback when resource is discovered
143 * @param resource A pointer of discovered resource
144 * @param discoverID The ID of discovery request
147 * @see PrimitiveResource
149 void onResourceFound(std::shared_ptr<PrimitiveResource> resource, ID discoveryId,
150 const RCSDiscoveryManager::ResourceDiscoveredCallback& cb);
153 * Discovering resource on all requests and posting timer when timer is expired
158 * Discovering resource on all requests when supporting presence function resource enter into network
160 * @param ret Not used in this class
161 * @param seq Not used in this class
162 * @param address A address of supporting presence function resource
164 void onPresence(OCStackResult ret, const unsigned int seq, const std::string& address);
169 * @return Returns the id
177 std::unordered_map<ID,DiscoveryRequestInfo> m_discoveryMap;
182 #endif // RCSDISCOVERYMANAGER_IMPL_H