Replace one use of sigslot with RoboCaller
The eventual goal is to replace sigslot entirely, but we need to start small, tread carefully, and evaluate how it works out. Also add a few more RoboCaller unit tests to cover the types we now use with RoboCaller. Change-Id: I9a5814d1668a37546ea484ca88ec9c2be1913d25 Bug: webrtc:11943 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/184660 Commit-Queue: Lahiru Ginnaliya Gamathige <glahiru@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#32266}
This commit is contained in:

committed by
Commit Bot

parent
59f1d1e36d
commit
e99c68dd21
@ -112,6 +112,7 @@ rtc_library("rtc_pc_base") {
|
||||
"../rtc_base",
|
||||
"../rtc_base:checks",
|
||||
"../rtc_base:deprecation",
|
||||
"../rtc_base:robo_caller",
|
||||
"../rtc_base:rtc_task_queue",
|
||||
"../rtc_base:stringutils",
|
||||
"../rtc_base/synchronization:mutex",
|
||||
|
@ -1256,10 +1256,11 @@ void JsepTransportController::UpdateAggregateStates_n() {
|
||||
}
|
||||
if (ice_connection_state_ != new_connection_state) {
|
||||
ice_connection_state_ = new_connection_state;
|
||||
invoker_.AsyncInvoke<void>(RTC_FROM_HERE, signaling_thread_,
|
||||
[this, new_connection_state] {
|
||||
SignalIceConnectionState(new_connection_state);
|
||||
});
|
||||
|
||||
invoker_.AsyncInvoke<void>(
|
||||
RTC_FROM_HERE, signaling_thread_, [this, new_connection_state] {
|
||||
SignalIceConnectionState.Send(new_connection_state);
|
||||
});
|
||||
}
|
||||
|
||||
// Compute the current RTCIceConnectionState as described in
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include "rtc_base/async_invoker.h"
|
||||
#include "rtc_base/constructor_magic.h"
|
||||
#include "rtc_base/ref_counted_object.h"
|
||||
#include "rtc_base/robo_caller.h"
|
||||
#include "rtc_base/third_party/sigslot/sigslot.h"
|
||||
|
||||
namespace rtc {
|
||||
@ -197,10 +198,11 @@ class JsepTransportController : public sigslot::has_slots<> {
|
||||
// Else if all completed => completed,
|
||||
// Else if all connected => connected,
|
||||
// Else => connecting
|
||||
sigslot::signal1<cricket::IceConnectionState> SignalIceConnectionState;
|
||||
RoboCaller<cricket::IceConnectionState> SignalIceConnectionState;
|
||||
|
||||
sigslot::signal1<PeerConnectionInterface::PeerConnectionState>
|
||||
SignalConnectionState;
|
||||
|
||||
sigslot::signal1<PeerConnectionInterface::IceConnectionState>
|
||||
SignalStandardizedIceConnectionState;
|
||||
|
||||
|
@ -89,8 +89,10 @@ class JsepTransportControllerTest : public JsepTransportController::Observer,
|
||||
}
|
||||
|
||||
void ConnectTransportControllerSignals() {
|
||||
transport_controller_->SignalIceConnectionState.connect(
|
||||
this, &JsepTransportControllerTest::OnConnectionState);
|
||||
transport_controller_->SignalIceConnectionState.AddReceiver(
|
||||
[this](cricket::IceConnectionState s) {
|
||||
JsepTransportControllerTest::OnConnectionState(s);
|
||||
});
|
||||
transport_controller_->SignalStandardizedIceConnectionState.connect(
|
||||
this, &JsepTransportControllerTest::OnStandardizedIceConnectionState);
|
||||
transport_controller_->SignalConnectionState.connect(
|
||||
|
@ -685,8 +685,6 @@ bool PeerConnection::Initialize(
|
||||
transport_controller_.reset(new JsepTransportController(
|
||||
signaling_thread(), network_thread(), port_allocator_.get(),
|
||||
async_resolver_factory_.get(), config));
|
||||
transport_controller_->SignalIceConnectionState.connect(
|
||||
this, &PeerConnection::OnTransportControllerConnectionState);
|
||||
transport_controller_->SignalStandardizedIceConnectionState.connect(
|
||||
this, &PeerConnection::SetStandardizedIceConnectionState);
|
||||
transport_controller_->SignalConnectionState.connect(
|
||||
@ -704,6 +702,12 @@ bool PeerConnection::Initialize(
|
||||
transport_controller_->SignalIceCandidatePairChanged.connect(
|
||||
this, &PeerConnection::OnTransportControllerCandidateChanged);
|
||||
|
||||
transport_controller_->SignalIceConnectionState.AddReceiver(
|
||||
[this](cricket::IceConnectionState s) {
|
||||
RTC_DCHECK_RUN_ON(signaling_thread());
|
||||
OnTransportControllerConnectionState(s);
|
||||
});
|
||||
|
||||
stats_.reset(new StatsCollector(this));
|
||||
stats_collector_ = RTCStatsCollector::Create(this);
|
||||
|
||||
@ -3625,7 +3629,6 @@ PeerConnection::InitializePortAllocator_n(
|
||||
"Disabled")) {
|
||||
port_allocator_flags &= ~(cricket::PORTALLOCATOR_ENABLE_IPV6);
|
||||
}
|
||||
|
||||
if (configuration.disable_ipv6_on_wifi) {
|
||||
port_allocator_flags &= ~(cricket::PORTALLOCATOR_ENABLE_IPV6_ON_WIFI);
|
||||
RTC_LOG(LS_INFO) << "IPv6 candidates on Wi-Fi are disabled.";
|
||||
|
@ -50,6 +50,32 @@ TEST(RoboCaller, ReferenceTest) {
|
||||
EXPECT_EQ(index, 2);
|
||||
}
|
||||
|
||||
enum State {
|
||||
kNew,
|
||||
kChecking,
|
||||
};
|
||||
|
||||
TEST(RoboCaller, SingleEnumValueTest) {
|
||||
RoboCaller<State> c;
|
||||
State s1 = kNew;
|
||||
int index = 0;
|
||||
|
||||
c.AddReceiver([&index](State s) { index++; });
|
||||
c.Send(s1);
|
||||
|
||||
EXPECT_EQ(index, 1);
|
||||
}
|
||||
|
||||
TEST(RoboCaller, SingleEnumReferenceTest) {
|
||||
RoboCaller<State&> c;
|
||||
State s = kNew;
|
||||
|
||||
c.AddReceiver([](State& s) { s = kChecking; });
|
||||
c.Send(s);
|
||||
|
||||
EXPECT_EQ(s, kChecking);
|
||||
}
|
||||
|
||||
TEST(RoboCaller, ConstReferenceTest) {
|
||||
RoboCaller<int&> c;
|
||||
int i = 0;
|
||||
@ -166,6 +192,22 @@ TEST(RoboCaller, MultipleReceiverSendTest) {
|
||||
|
||||
EXPECT_EQ(index, 5);
|
||||
}
|
||||
|
||||
class A {
|
||||
public:
|
||||
void increment(int& i) const { i++; }
|
||||
};
|
||||
|
||||
TEST(RoboCaller, MemberFunctionTest) {
|
||||
RoboCaller<int&> c;
|
||||
A a;
|
||||
int index = 1;
|
||||
|
||||
c.AddReceiver([&a](int& i) { a.increment(i); });
|
||||
c.Send(index);
|
||||
|
||||
EXPECT_EQ(index, 2);
|
||||
}
|
||||
// todo(glahiru): Add a test case to catch some error for Karl's first fix
|
||||
// todo(glahiru): Add a test for rtc::Bind
|
||||
// which used the following code in the Send
|
||||
|
Reference in New Issue
Block a user