xref: /aosp_15_r20/external/webrtc/rtc_base/mdns_responder_interface.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright 2018 The WebRTC Project Authors. All rights reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef RTC_BASE_MDNS_RESPONDER_INTERFACE_H_
12 #define RTC_BASE_MDNS_RESPONDER_INTERFACE_H_
13 
14 #include <functional>
15 #include <string>
16 
17 #include "absl/strings/string_view.h"
18 #include "rtc_base/ip_address.h"
19 
20 namespace webrtc {
21 
22 // Defines an mDNS responder that can be used in ICE candidate gathering, where
23 // the local IP addresses of host candidates are replaced by mDNS hostnames.
24 class MdnsResponderInterface {
25  public:
26   using NameCreatedCallback =
27       std::function<void(const rtc::IPAddress&, absl::string_view)>;
28   using NameRemovedCallback = std::function<void(bool)>;
29 
30   MdnsResponderInterface() = default;
31   virtual ~MdnsResponderInterface() = default;
32 
33   // Asynchronously creates and returns a new name via `callback` for `addr` if
34   // there is no name mapped to it by this responder, and initializes the
35   // reference count of this name to one. Otherwise the existing name mapped to
36   // `addr` is returned and its reference count is incremented by one.
37   virtual void CreateNameForAddress(const rtc::IPAddress& addr,
38                                     NameCreatedCallback callback) = 0;
39   // Decrements the reference count of the mapped name of `addr`, if
40   // there is a map created previously via CreateNameForAddress; asynchronously
41   // removes the association between `addr` and its mapped name, and returns
42   // true via `callback` if the decremented reference count reaches zero.
43   // Otherwise no operation is done and false is returned via `callback`
44   // asynchronously.
45   virtual void RemoveNameForAddress(const rtc::IPAddress& addr,
46                                     NameRemovedCallback callback) = 0;
47 };
48 
49 }  // namespace webrtc
50 
51 #endif  // RTC_BASE_MDNS_RESPONDER_INTERFACE_H_
52