Line data Source code
1 : /* 2 : * 3 : * Copyright (c) 2021 Project CHIP Authors 4 : * 5 : * Licensed under the Apache License, Version 2.0 (the "License"); 6 : * you may not use this file except in compliance with the License. 7 : * You may obtain a copy of the License at 8 : * 9 : * http://www.apache.org/licenses/LICENSE-2.0 10 : * 11 : * Unless required by applicable law or agreed to in writing, software 12 : * distributed under the License is distributed on an "AS IS" BASIS, 13 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 : * See the License for the specific language governing permissions and 15 : * limitations under the License. 16 : */ 17 : 18 : #pragma once 19 : 20 : #include <lib/dnssd/Resolver.h> 21 : 22 : namespace chip { 23 : namespace Dnssd { 24 : 25 : /** 26 : * Convenience class for discovering Matter commissioners and commissionable nodes. 27 : * 28 : * The class simplifies the usage of the global DNS-SD resolver to discover Matter nodes by managing 29 : * the lifetime of the discovery context object. 30 : * 31 : * The proxy provides a method to register an external commissioning delegate whose 32 : * `OnNodeDiscovered` method is called whenever a new node is discovered. The delegate is 33 : * automatically unregistered when the proxy is shut down or destroyed. 34 : * 35 : * The proxy can be safely shut down or destroyed even if the last discovery operation has not 36 : * finished yet. 37 : */ 38 : class ResolverProxy 39 : { 40 : public: 41 0 : explicit ResolverProxy(Resolver * resolver = nullptr) : mResolver(resolver != nullptr ? *resolver : Resolver::Instance()) {} 42 8 : ~ResolverProxy() { Shutdown(); } 43 : 44 : CHIP_ERROR Init(Inet::EndPointManager<Inet::UDPEndPoint> * udpEndPoint = nullptr); 45 : void Shutdown(); 46 : 47 11 : void SetCommissioningDelegate(CommissioningResolveDelegate * delegate) 48 : { 49 11 : if (mContext != nullptr) 50 : { 51 6 : mContext->SetCommissioningDelegate(delegate); 52 : } 53 11 : } 54 : 55 : CHIP_ERROR DiscoverCommissionableNodes(DiscoveryFilter filter = DiscoveryFilter()); 56 : CHIP_ERROR DiscoverCommissioners(DiscoveryFilter filter = DiscoveryFilter()); 57 : CHIP_ERROR StopDiscovery(); 58 : 59 : private: 60 : Resolver & mResolver; 61 : DiscoveryContext * mContext = nullptr; 62 : }; 63 : 64 : } // namespace Dnssd 65 : } // namespace chip