3 * Copyright (c) 2020 Project CHIP Authors
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include "core/CHIPError.h"
21 #include "inet/InetInterface.h"
22 #include "lib/mdns/platform/Mdns.h"
23 #include "platform/CHIPDeviceConfig.h"
31 virtual void HandleNodeIdResolve(CHIP_ERROR error, uint64_t nodeId, const MdnsService & address) = 0;
32 virtual ~ResolveDelegate() {}
35 class DiscoveryManager
39 * This method initializes the publisher.
45 * This method publishes the device on mDNS.
47 * This function will fetch device name and other information and publish them
48 * via mDNS. If device meta data has changed, you can call this function again
49 * to update the information.
51 * @param[in] addressType The protocol version of the IP address.
52 * @param[in] interface The interface to send mDNS multicast.
55 CHIP_ERROR StartPublishDevice(chip::Inet::IPAddressType addressType = chip::Inet::kIPAddressType_Any,
56 chip::Inet::InterfaceId interface = INET_NULL_INTERFACEID);
59 * This function stops publishing the device on mDNS.
62 CHIP_ERROR StopPublishDevice();
65 * This function registers the delegate to handle node id resolve results.
68 CHIP_ERROR RegisterResolveDelegate(ResolveDelegate * delegate);
71 * This function resolves a node id to its address.
74 CHIP_ERROR ResolveNodeId(uint64_t nodeId, uint64_t fabricId, chip::Inet::IPAddressType type = chip::Inet::kIPAddressType_Any);
76 static DiscoveryManager & GetInstance() { return sManager; }
79 DiscoveryManager() = default;
81 DiscoveryManager(const DiscoveryManager &) = delete;
82 DiscoveryManager & operator=(const DiscoveryManager &) = delete;
84 CHIP_ERROR PublishUnprovisionedDevice(chip::Inet::IPAddressType addressType, chip::Inet::InterfaceId interface);
85 CHIP_ERROR PublishProvisionedDevice(chip::Inet::IPAddressType addressType, chip::Inet::InterfaceId interface);
86 CHIP_ERROR SetupHostname();
88 static void HandleNodeIdResolve(void * context, MdnsService * result, CHIP_ERROR error);
89 static void HandleMdnsInit(void * context, CHIP_ERROR initError);
90 static void HandleMdnsError(void * context, CHIP_ERROR initError);
93 uint64_t mUnprovisionedInstanceName;
94 bool mMdnsInitialized = false;
95 bool mIsPublishingProvisionedDevice = false;
96 bool mIsPublishing = false;
97 #endif // CHIP_ENABLE_MDNS
98 ResolveDelegate * mResolveDelegate = nullptr;
100 static DiscoveryManager sManager;