diff --git a/BUILD.gn b/BUILD.gn index cec97c5be1..dec3d6f902 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -539,7 +539,7 @@ if (rtc_include_tests) { "call:fake_network_pipe_unittests", "p2p:libstunprober_unittests", "p2p:rtc_p2p_unittests", - "rtc_base:robo_caller_unittests", + "rtc_base:callback_list_unittests", "rtc_base:rtc_base_approved_unittests", "rtc_base:rtc_base_unittests", "rtc_base:rtc_json_unittests", diff --git a/pc/BUILD.gn b/pc/BUILD.gn index fbd0295176..7c677d2740 100644 --- a/pc/BUILD.gn +++ b/pc/BUILD.gn @@ -110,9 +110,9 @@ rtc_library("rtc_pc_base") { "../modules/rtp_rtcp:rtp_rtcp_format", "../p2p:rtc_p2p", "../rtc_base", + "../rtc_base:callback_list", "../rtc_base:checks", "../rtc_base:deprecation", - "../rtc_base:robo_caller", "../rtc_base:rtc_task_queue", "../rtc_base:stringutils", "../rtc_base/synchronization:mutex", @@ -273,9 +273,9 @@ rtc_library("peerconnection") { "../modules/rtp_rtcp:rtp_rtcp_format", "../p2p:rtc_p2p", "../rtc_base", + "../rtc_base:callback_list", "../rtc_base:checks", "../rtc_base:deprecation", - "../rtc_base:robo_caller", "../rtc_base:rtc_base_approved", "../rtc_base:rtc_operations_chain", "../rtc_base:safe_minmax", diff --git a/pc/jsep_transport_controller.h b/pc/jsep_transport_controller.h index f3a92947a5..f0adeedf26 100644 --- a/pc/jsep_transport_controller.h +++ b/pc/jsep_transport_controller.h @@ -35,7 +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/callback_list.h" #include "rtc_base/third_party/sigslot/sigslot.h" namespace rtc { @@ -198,7 +198,7 @@ class JsepTransportController : public sigslot::has_slots<> { // Else if all completed => completed, // Else if all connected => connected, // Else => connecting - RoboCaller SignalIceConnectionState; + CallbackList SignalIceConnectionState; sigslot::signal1 SignalConnectionState; diff --git a/pc/peer_connection.cc b/pc/peer_connection.cc index e6e8c7f1f5..b2437fa5ac 100644 --- a/pc/peer_connection.cc +++ b/pc/peer_connection.cc @@ -52,7 +52,7 @@ #include "rtc_base/logging.h" #include "rtc_base/net_helper.h" #include "rtc_base/network_constants.h" -#include "rtc_base/robo_caller.h" +#include "rtc_base/callback_list.h" #include "rtc_base/socket_address.h" #include "rtc_base/string_encode.h" #include "rtc_base/task_utils/to_queued_task.h" diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn index d11c8a3193..66da6e03aa 100644 --- a/rtc_base/BUILD.gn +++ b/rtc_base/BUILD.gn @@ -48,10 +48,10 @@ rtc_source_set("untyped_function") { deps = [ "system:assume" ] } -rtc_source_set("robo_caller") { +rtc_source_set("callback_list") { sources = [ - "robo_caller.cc", - "robo_caller.h", + "callback_list.cc", + "callback_list.h", ] deps = [ ":untyped_function", @@ -1072,13 +1072,13 @@ rtc_library("testclient") { ] } -rtc_library("robo_caller_unittests") { +rtc_library("callback_list_unittests") { testonly = true - sources = [ "robo_caller_unittest.cc" ] + sources = [ "callback_list_unittest.cc" ] deps = [ + ":callback_list", ":gunit_helpers", - ":robo_caller", ":rtc_base", "../api:function_view", "../test:test_support", diff --git a/rtc_base/robo_caller.cc b/rtc_base/callback_list.cc similarity index 61% rename from rtc_base/robo_caller.cc rename to rtc_base/callback_list.cc index a7c35cbfdb..0b1de8e7ba 100644 --- a/rtc_base/robo_caller.cc +++ b/rtc_base/callback_list.cc @@ -8,33 +8,33 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "rtc_base/robo_caller.h" +#include "rtc_base/callback_list.h" namespace webrtc { -namespace robo_caller_impl { +namespace callback_list_impl { -RoboCallerReceivers::RoboCallerReceivers() = default; -RoboCallerReceivers::~RoboCallerReceivers() = default; +CallbackListReceivers::CallbackListReceivers() = default; +CallbackListReceivers::~CallbackListReceivers() = default; -void RoboCallerReceivers::Foreach( +void CallbackListReceivers::Foreach( rtc::FunctionView fv) { for (auto& r : receivers_) { fv(r); } } -template void RoboCallerReceivers::AddReceiver( +template void CallbackListReceivers::AddReceiver( UntypedFunction::TrivialUntypedFunctionArgs<1>); -template void RoboCallerReceivers::AddReceiver( +template void CallbackListReceivers::AddReceiver( UntypedFunction::TrivialUntypedFunctionArgs<2>); -template void RoboCallerReceivers::AddReceiver( +template void CallbackListReceivers::AddReceiver( UntypedFunction::TrivialUntypedFunctionArgs<3>); -template void RoboCallerReceivers::AddReceiver( +template void CallbackListReceivers::AddReceiver( UntypedFunction::TrivialUntypedFunctionArgs<4>); -template void RoboCallerReceivers::AddReceiver( +template void CallbackListReceivers::AddReceiver( UntypedFunction::NontrivialUntypedFunctionArgs); -template void RoboCallerReceivers::AddReceiver( +template void CallbackListReceivers::AddReceiver( UntypedFunction::FunctionPointerUntypedFunctionArgs); -} // namespace robo_caller_impl +} // namespace callback_list_impl } // namespace webrtc diff --git a/rtc_base/robo_caller.h b/rtc_base/callback_list.h similarity index 67% rename from rtc_base/robo_caller.h rename to rtc_base/callback_list.h index 9df6a48a5e..218693aff4 100644 --- a/rtc_base/robo_caller.h +++ b/rtc_base/callback_list.h @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#ifndef RTC_BASE_ROBO_CALLER_H_ -#define RTC_BASE_ROBO_CALLER_H_ +#ifndef RTC_BASE_CALLBACK_LIST_H_ +#define RTC_BASE_CALLBACK_LIST_H_ #include #include @@ -20,16 +20,16 @@ #include "rtc_base/untyped_function.h" namespace webrtc { -namespace robo_caller_impl { +namespace callback_list_impl { -class RoboCallerReceivers { +class CallbackListReceivers { public: - RoboCallerReceivers(); - RoboCallerReceivers(const RoboCallerReceivers&) = delete; - RoboCallerReceivers& operator=(const RoboCallerReceivers&) = delete; - RoboCallerReceivers(RoboCallerReceivers&&) = delete; - RoboCallerReceivers& operator=(RoboCallerReceivers&&) = delete; - ~RoboCallerReceivers(); + CallbackListReceivers(); + CallbackListReceivers(const CallbackListReceivers&) = delete; + CallbackListReceivers& operator=(const CallbackListReceivers&) = delete; + CallbackListReceivers(CallbackListReceivers&&) = delete; + CallbackListReceivers& operator=(CallbackListReceivers&&) = delete; + ~CallbackListReceivers(); template RTC_NO_INLINE void AddReceiver(UntypedFunctionArgsT args) { @@ -42,20 +42,20 @@ class RoboCallerReceivers { std::vector receivers_; }; -extern template void RoboCallerReceivers::AddReceiver( +extern template void CallbackListReceivers::AddReceiver( UntypedFunction::TrivialUntypedFunctionArgs<1>); -extern template void RoboCallerReceivers::AddReceiver( +extern template void CallbackListReceivers::AddReceiver( UntypedFunction::TrivialUntypedFunctionArgs<2>); -extern template void RoboCallerReceivers::AddReceiver( +extern template void CallbackListReceivers::AddReceiver( UntypedFunction::TrivialUntypedFunctionArgs<3>); -extern template void RoboCallerReceivers::AddReceiver( +extern template void CallbackListReceivers::AddReceiver( UntypedFunction::TrivialUntypedFunctionArgs<4>); -extern template void RoboCallerReceivers::AddReceiver( +extern template void CallbackListReceivers::AddReceiver( UntypedFunction::NontrivialUntypedFunctionArgs); -extern template void RoboCallerReceivers::AddReceiver( +extern template void CallbackListReceivers::AddReceiver( UntypedFunction::FunctionPointerUntypedFunctionArgs); -} // namespace robo_caller_impl +} // namespace callback_list_impl // A collection of receivers (callable objects) that can be called all at once. // Optimized for minimal binary size. @@ -68,13 +68,13 @@ extern template void RoboCallerReceivers::AddReceiver( // if they wish to stay in the CSC and another value if they wish to be removed. // It depends on what's convenient for the callers... template -class RoboCaller { +class CallbackList { public: - RoboCaller() = default; - RoboCaller(const RoboCaller&) = delete; - RoboCaller& operator=(const RoboCaller&) = delete; - RoboCaller(RoboCaller&&) = delete; - RoboCaller& operator=(RoboCaller&&) = delete; + CallbackList() = default; + CallbackList(const CallbackList&) = delete; + CallbackList& operator=(const CallbackList&) = delete; + CallbackList(CallbackList&&) = delete; + CallbackList& operator=(CallbackList&&) = delete; // Adds a new receiver. The receiver (a callable object or a function pointer) // must be movable, but need not be copyable. Its call signature should be @@ -94,9 +94,9 @@ class RoboCaller { } private: - robo_caller_impl::RoboCallerReceivers receivers_; + callback_list_impl::CallbackListReceivers receivers_; }; } // namespace webrtc -#endif // RTC_BASE_ROBO_CALLER_H_ +#endif // RTC_BASE_CALLBACK_LIST_H_ diff --git a/rtc_base/robo_caller_unittest.cc b/rtc_base/callback_list_unittest.cc similarity index 74% rename from rtc_base/robo_caller_unittest.cc rename to rtc_base/callback_list_unittest.cc index 3ca9051a9e..811f85ead3 100644 --- a/rtc_base/robo_caller_unittest.cc +++ b/rtc_base/callback_list_unittest.cc @@ -12,20 +12,20 @@ #include "api/function_view.h" #include "rtc_base/bind.h" -#include "rtc_base/robo_caller.h" +#include "rtc_base/callback_list.h" #include "test/gtest.h" namespace webrtc { namespace { -TEST(RoboCaller, NoRecieverSingleMessageTest) { - RoboCaller c; +TEST(CallbackList, NoRecieverSingleMessageTest) { + CallbackList c; c.Send("message"); } -TEST(RoboCaller, MultipleParameterMessageTest) { - RoboCaller c; std::string str = "messege"; @@ -34,14 +34,14 @@ TEST(RoboCaller, MultipleParameterMessageTest) { c.Send(str, "message1", "message0", 123, &i, str); } -TEST(RoboCaller, NoParameterMessageTest) { - RoboCaller<> c; +TEST(CallbackList, NoParameterMessageTest) { + CallbackList<> c; c.Send(); } -TEST(RoboCaller, ReferenceTest) { - RoboCaller c; +TEST(CallbackList, ReferenceTest) { + CallbackList c; int index = 1; c.AddReceiver([](int& index) { index++; }); @@ -55,8 +55,8 @@ enum State { kChecking, }; -TEST(RoboCaller, SingleEnumValueTest) { - RoboCaller c; +TEST(CallbackList, SingleEnumValueTest) { + CallbackList c; State s1 = kNew; int index = 0; @@ -66,8 +66,8 @@ TEST(RoboCaller, SingleEnumValueTest) { EXPECT_EQ(index, 1); } -TEST(RoboCaller, SingleEnumReferenceTest) { - RoboCaller c; +TEST(CallbackList, SingleEnumReferenceTest) { + CallbackList c; State s = kNew; c.AddReceiver([](State& s) { s = kChecking; }); @@ -76,8 +76,8 @@ TEST(RoboCaller, SingleEnumReferenceTest) { EXPECT_EQ(s, kChecking); } -TEST(RoboCaller, ConstReferenceTest) { - RoboCaller c; +TEST(CallbackList, ConstReferenceTest) { + CallbackList c; int i = 0; int index = 1; @@ -87,8 +87,8 @@ TEST(RoboCaller, ConstReferenceTest) { EXPECT_EQ(i, 1); } -TEST(RoboCaller, PointerTest) { - RoboCaller c; +TEST(CallbackList, PointerTest) { + CallbackList c; int index = 1; c.AddReceiver([](int* index) { (*index)++; }); @@ -97,8 +97,8 @@ TEST(RoboCaller, PointerTest) { EXPECT_EQ(index, 2); } -TEST(RoboCaller, CallByValue) { - RoboCaller c; +TEST(CallbackList, CallByValue) { + CallbackList c; int x = 17; c.AddReceiver([&x](int n) { x += n; }); @@ -112,8 +112,8 @@ void PlusOne(int& a) { a++; } -TEST(RoboCaller, FunctionPtrTest) { - RoboCaller c; +TEST(CallbackList, FunctionPtrTest) { + CallbackList c; int index = 1; c.AddReceiver(PlusOne); @@ -132,8 +132,8 @@ struct LargeNonTrivial { void operator()(int& a) { a = 1; } }; -TEST(RoboCaller, LargeNonTrivialTest) { - RoboCaller c; +TEST(CallbackList, LargeNonTrivialTest) { + CallbackList c; int i = 0; static_assert(sizeof(LargeNonTrivial) > UntypedFunction::kInlineStorageSize, ""); @@ -148,8 +148,8 @@ struct LargeTrivial { void operator()(int& x) { x = 1; } }; -TEST(RoboCaller, LargeTrivial) { - RoboCaller c; +TEST(CallbackList, LargeTrivial) { + CallbackList c; LargeTrivial lt; int i = 0; @@ -167,8 +167,8 @@ struct OnlyNonTriviallyConstructible { void operator()(int& a) { a = 1; } }; -TEST(RoboCaller, OnlyNonTriviallyMoveConstructible) { - RoboCaller c; +TEST(CallbackList, OnlyNonTriviallyMoveConstructible) { + CallbackList c; int i = 0; c.AddReceiver(OnlyNonTriviallyConstructible()); @@ -177,8 +177,8 @@ TEST(RoboCaller, OnlyNonTriviallyMoveConstructible) { EXPECT_EQ(i, 1); } -TEST(RoboCaller, MultipleReceiverSendTest) { - RoboCaller c; +TEST(CallbackList, MultipleReceiverSendTest) { + CallbackList c; std::function plus = PlusOne; int index = 1; @@ -197,8 +197,8 @@ class A { void increment(int& i) const { i++; } }; -TEST(RoboCaller, MemberFunctionTest) { - RoboCaller c; +TEST(CallbackList, MemberFunctionTest) { + CallbackList c; A a; int index = 1;