From edc347c4e5367280cae2fe58f3b2d8b45620bbbb Mon Sep 17 00:00:00 2001 From: Mirko Bonadei Date: Thu, 13 May 2021 16:50:45 +0200 Subject: [PATCH] Introduce (Un)SubscribeDtlsTransportState methods. WebRTC is going to remove cricket::DtlsTransportState and switch to webrtc::DtlsTransportState. This CL introduces a set of new methods to allow to subscribe to DTLS transport state updates while WebRTC internally migrates away from cricket::DtlsTransportState. No-Try: True Bug: webrtc:12762 Change-Id: I79cf48e2f7122cc76fde6e4fd1541382fd096d53 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/218607 Commit-Queue: Mirko Bonadei Reviewed-by: Harald Alvestrand Cr-Commit-Position: refs/heads/master@{#34075} --- p2p/base/dtls_transport_internal.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/p2p/base/dtls_transport_internal.h b/p2p/base/dtls_transport_internal.h index ff71196f34..d0af5e8409 100644 --- a/p2p/base/dtls_transport_internal.h +++ b/p2p/base/dtls_transport_internal.h @@ -132,9 +132,27 @@ class DtlsTransportInternal : public rtc::PacketTransportInternal { dtls_state_callback_list_.RemoveReceivers(id); } + // F: void(DtlsTransportInternal*, const webrtc::DtlsTransportState) + template + void SubscribeDtlsTransportState(F&& callback) { + dtls_transport_state_callback_list_.AddReceiver(std::forward(callback)); + } + + template + void SubscribeDtlsTransportState(const void* id, F&& callback) { + dtls_transport_state_callback_list_.AddReceiver(id, + std::forward(callback)); + } + // Unsubscribe the subscription with given id. + void UnsubscribeDtlsTransportState(const void* id) { + dtls_transport_state_callback_list_.RemoveReceivers(id); + } + void SendDtlsState(DtlsTransportInternal* transport, DtlsTransportState state) { dtls_state_callback_list_.Send(transport, state); + dtls_transport_state_callback_list_.Send(transport, + ConvertDtlsTransportState(state)); } // Emitted whenever the Dtls handshake failed on some transport channel. @@ -155,8 +173,12 @@ class DtlsTransportInternal : public rtc::PacketTransportInternal { RTC_DISALLOW_COPY_AND_ASSIGN(DtlsTransportInternal); webrtc::CallbackList dtls_handshake_error_callback_list_; + // TODO(bugs.webrtc.org/12762): Remove in favor of + // dtls_transport_state_callback_list_. webrtc::CallbackList dtls_state_callback_list_; + webrtc::CallbackList + dtls_transport_state_callback_list_; }; } // namespace cricket