mdns_responder_interface.h 2.1 KB

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