Qingsi Wang | 0961933 | 2018-09-12 22:51:55 -0700 | [diff] [blame] | 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> |
Qingsi Wang | 0961933 | 2018-09-12 22:51:55 -0700 | [diff] [blame] | 15 | #include <string> |
| 16 | |
| 17 | #include "rtc_base/ipaddress.h" |
Qingsi Wang | 0961933 | 2018-09-12 22:51:55 -0700 | [diff] [blame] | 18 | |
| 19 | namespace webrtc { |
| 20 | |
| 21 | // Defines an mDNS responder that can be used in ICE candidate gathering, where |
Qingsi Wang | 7852d29 | 2018-10-31 11:17:07 -0700 | [diff] [blame^] | 22 | // the local IP addresses of host candidates are replaced by mDNS hostnames. |
| 23 | class MdnsResponderInterface { |
Qingsi Wang | 0961933 | 2018-09-12 22:51:55 -0700 | [diff] [blame] | 24 | public: |
| 25 | using NameCreatedCallback = |
| 26 | std::function<void(const rtc::IPAddress&, const std::string&)>; |
| 27 | using NameRemovedCallback = std::function<void(bool)>; |
| 28 | |
Qingsi Wang | 7852d29 | 2018-10-31 11:17:07 -0700 | [diff] [blame^] | 29 | MdnsResponderInterface() = default; |
| 30 | virtual ~MdnsResponderInterface() = default; |
Qingsi Wang | 0961933 | 2018-09-12 22:51:55 -0700 | [diff] [blame] | 31 | |
Qingsi Wang | 7852d29 | 2018-10-31 11:17:07 -0700 | [diff] [blame^] | 32 | // Asynchronously creates and returns a new name via |callback| for |addr| if |
| 33 | // there is no name mapped to it by this responder, and initializes the |
| 34 | // reference count of this name to one. Otherwise the existing name mapped to |
| 35 | // |addr| is returned and its reference count is incremented by one. |
Qingsi Wang | 0961933 | 2018-09-12 22:51:55 -0700 | [diff] [blame] | 36 | virtual void CreateNameForAddress(const rtc::IPAddress& addr, |
| 37 | NameCreatedCallback callback) = 0; |
Qingsi Wang | 7852d29 | 2018-10-31 11:17:07 -0700 | [diff] [blame^] | 38 | // Decrements the reference count of the mapped name of |addr|, if |
| 39 | // there is a map created previously via CreateNameForAddress; asynchronously |
| 40 | // removes the association between |addr| and its mapped name, and returns |
| 41 | // true via |callback| if the decremented reference count reaches zero. |
| 42 | // Otherwise no operation is done and false is returned via |callback| |
| 43 | // asynchronously. |
Qingsi Wang | 0961933 | 2018-09-12 22:51:55 -0700 | [diff] [blame] | 44 | virtual void RemoveNameForAddress(const rtc::IPAddress& addr, |
| 45 | NameRemovedCallback callback) = 0; |
| 46 | }; |
| 47 | |
| 48 | } // namespace webrtc |
| 49 | |
| 50 | #endif // RTC_BASE_MDNS_RESPONDER_INTERFACE_H_ |