blob: f39b4a59e206b2c78b932179bfd7a61901f1fa80 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:361/*
kjellanderb24317b2016-02-10 15:54:432 * Copyright 2013 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:363 *
kjellanderb24317b2016-02-10 15:54:434 * 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.
henrike@webrtc.org28e20752013-07-10 00:45:369 */
10
11// This file contains Macros for creating proxies for webrtc MediaStream and
12// PeerConnection classes.
13
Mirko Bonadei9d9b8de2021-02-26 08:51:2614// The proxied objects are initialized with either one or two thread
15// objects that operations can be proxied to: The primary and secondary
16// threads.
17// In common usage, the primary thread will be the PeerConnection's
18// signaling thread, and the secondary thread will be either the
19// PeerConnection's worker thread or the PeerConnection's network thread.
20
henrike@webrtc.org28e20752013-07-10 00:45:3621//
22// Example usage:
23//
buildbot@webrtc.orgd4e598d2014-07-29 17:36:5224// class TestInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:3625// public:
26// std::string FooA() = 0;
27// std::string FooB(bool arg1) const = 0;
nisse72c8d2b2016-04-15 10:49:0728// std::string FooC(bool arg1) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:3629// };
30//
31// Note that return types can not be a const reference.
32//
33// class Test : public TestInterface {
34// ... implementation of the interface.
35// };
36//
37// BEGIN_PROXY_MAP(Test)
Mirko Bonadei9d9b8de2021-02-26 08:51:2638// PROXY_PRIMARY_THREAD_DESTRUCTOR()
henrike@webrtc.org28e20752013-07-10 00:45:3639// PROXY_METHOD0(std::string, FooA)
40// PROXY_CONSTMETHOD1(std::string, FooB, arg1)
Mirko Bonadei9d9b8de2021-02-26 08:51:2641// PROXY_SECONDARY_METHOD1(std::string, FooC, arg1)
deadbeefd99a2002017-01-18 16:55:2342// END_PROXY_MAP()
henrike@webrtc.org28e20752013-07-10 00:45:3643//
Mirko Bonadei9d9b8de2021-02-26 08:51:2644// Where the destructor and first two methods are invoked on the primary
45// thread, and the third is invoked on the secondary thread.
nisse72c8d2b2016-04-15 10:49:0746//
47// The proxy can be created using
48//
49// TestProxy::Create(Thread* signaling_thread, Thread* worker_thread,
50// TestInterface*).
51//
Mirko Bonadei9d9b8de2021-02-26 08:51:2652// The variant defined with BEGIN_PRIMARY_PROXY_MAP is unaware of
53// the secondary thread, and invokes all methods on the primary thread.
deadbeefd99a2002017-01-18 16:55:2354//
henrike@webrtc.org28e20752013-07-10 00:45:3655
Markus Handella1b82012021-05-26 16:56:3056#ifndef PC_PROXY_H_
57#define PC_PROXY_H_
henrike@webrtc.org28e20752013-07-10 00:45:3658
Harald Alvestrandc24a2182022-02-23 13:44:5959#include <stddef.h>
60
kwibergd1fe2812016-04-27 13:47:2961#include <memory>
Yves Gerey3e707812018-11-28 15:47:4962#include <string>
Steve Antonc3639822019-11-26 23:27:5063#include <tuple>
Tomas Gunnarsson0ca13d92020-06-10 10:17:5064#include <type_traits>
oprypin803dc292017-02-01 09:55:5965#include <utility>
kwibergd1fe2812016-04-27 13:47:2966
Mirko Bonadeid9708072019-01-25 19:26:4867#include "api/scoped_refptr.h"
Tomas Gunnarssonabdb4702020-09-05 16:43:3668#include "api/task_queue/task_queue_base.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3169#include "rtc_base/event.h"
Markus Handell3d46d0b2021-05-27 19:42:5770#include "rtc_base/string_utils.h"
Mirko Bonadei35214fc2019-09-23 12:54:2871#include "rtc_base/system/rtc_export.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3172#include "rtc_base/thread.h"
henrike@webrtc.org28e20752013-07-10 00:45:3673
Markus Handell3d46d0b2021-05-27 19:42:5774#if !defined(RTC_DISABLE_PROXY_TRACE_EVENTS) && !defined(WEBRTC_CHROMIUM_BUILD)
75#define RTC_DISABLE_PROXY_TRACE_EVENTS
76#endif
77
henrike@webrtc.org28e20752013-07-10 00:45:3678namespace webrtc {
Tommi1cb796f2021-05-21 06:50:0979namespace proxy_internal {
Markus Handell3d46d0b2021-05-27 19:42:5780
81// Class for tracing the lifetime of MethodCall::Marshal.
82class ScopedTrace {
83 public:
84 explicit ScopedTrace(const char* class_and_method_name);
85 ~ScopedTrace();
86
87 private:
Johannes Kron8d1e4fb2022-05-10 13:05:2888 [[maybe_unused]] const char* const class_and_method_name_;
Markus Handell3d46d0b2021-05-27 19:42:5789};
Tommi1cb796f2021-05-21 06:50:0990} // namespace proxy_internal
henrike@webrtc.org28e20752013-07-10 00:45:3691
Guido Urdanetaccab06f2020-01-15 11:30:2992template <typename R>
93class ReturnType {
94 public:
95 template <typename C, typename M, typename... Args>
96 void Invoke(C* c, M m, Args&&... args) {
97 r_ = (c->*m)(std::forward<Args>(args)...);
98 }
99
100 R moved_result() { return std::move(r_); }
101
102 private:
103 R r_;
104};
105
106template <>
107class ReturnType<void> {
108 public:
109 template <typename C, typename M, typename... Args>
110 void Invoke(C* c, M m, Args&&... args) {
111 (c->*m)(std::forward<Args>(args)...);
112 }
113
114 void moved_result() {}
115};
116
Guido Urdanetaccab06f2020-01-15 11:30:29117template <typename C, typename R, typename... Args>
Danil Chapovalova30439b2022-07-07 08:08:49118class MethodCall {
Guido Urdanetaccab06f2020-01-15 11:30:29119 public:
120 typedef R (C::*Method)(Args...);
121 MethodCall(C* c, Method m, Args&&... args)
122 : c_(c),
123 m_(m),
124 args_(std::forward_as_tuple(std::forward<Args>(args)...)) {}
125
Danil Chapovalovcc903d92022-08-12 11:52:07126 R Marshal(rtc::Thread* t) {
Tomas Gunnarssonabdb4702020-09-05 16:43:36127 if (t->IsCurrent()) {
128 Invoke(std::index_sequence_for<Args...>());
129 } else {
Danil Chapovalova30439b2022-07-07 08:08:49130 t->PostTask([this] {
131 Invoke(std::index_sequence_for<Args...>());
132 event_.Set();
133 });
Tomas Gunnarssonabdb4702020-09-05 16:43:36134 event_.Wait(rtc::Event::kForever);
135 }
Guido Urdanetaccab06f2020-01-15 11:30:29136 return r_.moved_result();
137 }
138
139 private:
Guido Urdanetaccab06f2020-01-15 11:30:29140 template <size_t... Is>
141 void Invoke(std::index_sequence<Is...>) {
142 r_.Invoke(c_, m_, std::move(std::get<Is>(args_))...);
143 }
144
145 C* c_;
146 Method m_;
147 ReturnType<R> r_;
148 std::tuple<Args&&...> args_;
Tomas Gunnarssonabdb4702020-09-05 16:43:36149 rtc::Event event_;
Guido Urdanetaccab06f2020-01-15 11:30:29150};
151
152template <typename C, typename R, typename... Args>
Danil Chapovalova30439b2022-07-07 08:08:49153class ConstMethodCall {
Guido Urdanetaccab06f2020-01-15 11:30:29154 public:
155 typedef R (C::*Method)(Args...) const;
156 ConstMethodCall(const C* c, Method m, Args&&... args)
157 : c_(c),
158 m_(m),
159 args_(std::forward_as_tuple(std::forward<Args>(args)...)) {}
160
Danil Chapovalovcc903d92022-08-12 11:52:07161 R Marshal(rtc::Thread* t) {
Tomas Gunnarssonabdb4702020-09-05 16:43:36162 if (t->IsCurrent()) {
163 Invoke(std::index_sequence_for<Args...>());
164 } else {
Danil Chapovalova30439b2022-07-07 08:08:49165 t->PostTask([this] {
166 Invoke(std::index_sequence_for<Args...>());
167 event_.Set();
168 });
Tomas Gunnarssonabdb4702020-09-05 16:43:36169 event_.Wait(rtc::Event::kForever);
170 }
Guido Urdanetaccab06f2020-01-15 11:30:29171 return r_.moved_result();
172 }
173
174 private:
Guido Urdanetaccab06f2020-01-15 11:30:29175 template <size_t... Is>
176 void Invoke(std::index_sequence<Is...>) {
177 r_.Invoke(c_, m_, std::move(std::get<Is>(args_))...);
178 }
179
180 const C* c_;
181 Method m_;
182 ReturnType<R> r_;
183 std::tuple<Args&&...> args_;
Tomas Gunnarssonabdb4702020-09-05 16:43:36184 rtc::Event event_;
Guido Urdanetaccab06f2020-01-15 11:30:29185};
186
Tommi1cb796f2021-05-21 06:50:09187#define PROXY_STRINGIZE_IMPL(x) #x
188#define PROXY_STRINGIZE(x) PROXY_STRINGIZE_IMPL(x)
189
deadbeefd99a2002017-01-18 16:55:23190// Helper macros to reduce code duplication.
Niels Möller7f761572022-01-25 15:18:53191#define PROXY_MAP_BOILERPLATE(class_name) \
192 template <class INTERNAL_CLASS> \
193 class class_name##ProxyWithInternal; \
194 typedef class_name##ProxyWithInternal<class_name##Interface> \
195 class_name##Proxy; \
196 template <class INTERNAL_CLASS> \
197 class class_name##ProxyWithInternal : public class_name##Interface { \
198 protected: \
199 static constexpr char proxy_name_[] = #class_name "Proxy"; \
200 typedef class_name##Interface C; \
201 \
202 public: \
Jared Siskinbceec842023-04-20 21:10:51203 const INTERNAL_CLASS* internal() const { \
204 return c(); \
205 } \
206 INTERNAL_CLASS* internal() { \
207 return c(); \
208 }
henrike@webrtc.org28e20752013-07-10 00:45:36209
Yves Gerey665174f2018-06-19 13:03:05210// clang-format off
211// clang-format would put the semicolon alone,
212// leading to a presubmit error (cpplint.py)
Niels Möller7f761572022-01-25 15:18:53213#define END_PROXY_MAP(class_name) \
214 }; \
215 template <class INTERNAL_CLASS> \
216 constexpr char class_name##ProxyWithInternal<INTERNAL_CLASS>::proxy_name_[];
Yves Gerey665174f2018-06-19 13:03:05217// clang-format on
oprypin803dc292017-02-01 09:55:59218
Tomas Gunnarsson0d5ce622022-03-18 14:57:15219#define PRIMARY_PROXY_MAP_BOILERPLATE(class_name) \
220 protected: \
221 class_name##ProxyWithInternal(rtc::Thread* primary_thread, \
222 rtc::scoped_refptr<INTERNAL_CLASS> c) \
223 : primary_thread_(primary_thread), c_(std::move(c)) {} \
224 \
225 private: \
Mirko Bonadei9d9b8de2021-02-26 08:51:26226 mutable rtc::Thread* primary_thread_;
227
Tomas Gunnarsson0d5ce622022-03-18 14:57:15228#define SECONDARY_PROXY_MAP_BOILERPLATE(class_name) \
229 protected: \
230 class_name##ProxyWithInternal(rtc::Thread* primary_thread, \
231 rtc::Thread* secondary_thread, \
232 rtc::scoped_refptr<INTERNAL_CLASS> c) \
233 : primary_thread_(primary_thread), \
234 secondary_thread_(secondary_thread), \
235 c_(std::move(c)) {} \
236 \
237 private: \
238 mutable rtc::Thread* primary_thread_; \
Mirko Bonadei9d9b8de2021-02-26 08:51:26239 mutable rtc::Thread* secondary_thread_;
deadbeefd99a2002017-01-18 16:55:23240
241// Note that the destructor is protected so that the proxy can only be
242// destroyed via RefCountInterface.
Niels Möller7f761572022-01-25 15:18:53243#define REFCOUNTED_PROXY_MAP_BOILERPLATE(class_name) \
244 protected: \
245 ~class_name##ProxyWithInternal() { \
246 MethodCall<class_name##ProxyWithInternal, void> call( \
247 this, &class_name##ProxyWithInternal::DestroyInternal); \
Danil Chapovalovcc903d92022-08-12 11:52:07248 call.Marshal(destructor_thread()); \
Niels Möller7f761572022-01-25 15:18:53249 } \
250 \
251 private: \
Jared Siskinbceec842023-04-20 21:10:51252 const INTERNAL_CLASS* c() const { \
253 return c_.get(); \
254 } \
255 INTERNAL_CLASS* c() { \
256 return c_.get(); \
257 } \
258 void DestroyInternal() { \
259 c_ = nullptr; \
260 } \
deadbeefd99a2002017-01-18 16:55:23261 rtc::scoped_refptr<INTERNAL_CLASS> c_;
262
deadbeefe814a0d2017-02-26 02:15:09263// Note: This doesn't use a unique_ptr, because it intends to handle a corner
264// case where an object's deletion triggers a callback that calls back into
265// this proxy object. If relying on a unique_ptr to delete the object, its
266// inner pointer would be set to null before this reentrant callback would have
267// a chance to run, resulting in a segfault.
Niels Möller7f761572022-01-25 15:18:53268#define OWNED_PROXY_MAP_BOILERPLATE(class_name) \
269 public: \
270 ~class_name##ProxyWithInternal() { \
271 MethodCall<class_name##ProxyWithInternal, void> call( \
272 this, &class_name##ProxyWithInternal::DestroyInternal); \
Danil Chapovalovcc903d92022-08-12 11:52:07273 call.Marshal(destructor_thread()); \
Niels Möller7f761572022-01-25 15:18:53274 } \
275 \
276 private: \
Jared Siskinbceec842023-04-20 21:10:51277 const INTERNAL_CLASS* c() const { \
278 return c_; \
279 } \
280 INTERNAL_CLASS* c() { \
281 return c_; \
282 } \
283 void DestroyInternal() { \
284 delete c_; \
285 } \
deadbeefe814a0d2017-02-26 02:15:09286 INTERNAL_CLASS* c_;
deadbeefd99a2002017-01-18 16:55:23287
Tomas Gunnarsson0d5ce622022-03-18 14:57:15288#define BEGIN_PRIMARY_PROXY_MAP(class_name) \
289 PROXY_MAP_BOILERPLATE(class_name) \
290 PRIMARY_PROXY_MAP_BOILERPLATE(class_name) \
291 REFCOUNTED_PROXY_MAP_BOILERPLATE(class_name) \
292 public: \
293 static rtc::scoped_refptr<class_name##ProxyWithInternal> Create( \
294 rtc::Thread* primary_thread, rtc::scoped_refptr<INTERNAL_CLASS> c) { \
295 return rtc::make_ref_counted<class_name##ProxyWithInternal>( \
296 primary_thread, std::move(c)); \
Niels Möller7f761572022-01-25 15:18:53297 }
298
299#define BEGIN_PROXY_MAP(class_name) \
300 PROXY_MAP_BOILERPLATE(class_name) \
301 SECONDARY_PROXY_MAP_BOILERPLATE(class_name) \
302 REFCOUNTED_PROXY_MAP_BOILERPLATE(class_name) \
303 public: \
304 static rtc::scoped_refptr<class_name##ProxyWithInternal> Create( \
Mirko Bonadei9d9b8de2021-02-26 08:51:26305 rtc::Thread* primary_thread, rtc::Thread* secondary_thread, \
Tomas Gunnarsson0d5ce622022-03-18 14:57:15306 rtc::scoped_refptr<INTERNAL_CLASS> c) { \
Niels Möller7f761572022-01-25 15:18:53307 return rtc::make_ref_counted<class_name##ProxyWithInternal>( \
Tomas Gunnarsson0d5ce622022-03-18 14:57:15308 primary_thread, secondary_thread, std::move(c)); \
Niels Möller7f761572022-01-25 15:18:53309 }
310
Jared Siskinbceec842023-04-20 21:10:51311#define PROXY_PRIMARY_THREAD_DESTRUCTOR() \
312 private: \
313 rtc::Thread* destructor_thread() const { \
314 return primary_thread_; \
315 } \
316 \
Mirko Bonadei9d9b8de2021-02-26 08:51:26317 public: // NOLINTNEXTLINE
318
Jared Siskinbceec842023-04-20 21:10:51319#define PROXY_SECONDARY_THREAD_DESTRUCTOR() \
320 private: \
321 rtc::Thread* destructor_thread() const { \
322 return secondary_thread_; \
323 } \
324 \
oprypin803dc292017-02-01 09:55:59325 public: // NOLINTNEXTLINE
deadbeefd99a2002017-01-18 16:55:23326
Markus Handell3d46d0b2021-05-27 19:42:57327#if defined(RTC_DISABLE_PROXY_TRACE_EVENTS)
328#define TRACE_BOILERPLATE(method) \
329 do { \
330 } while (0)
331#else // if defined(RTC_DISABLE_PROXY_TRACE_EVENTS)
332#define TRACE_BOILERPLATE(method) \
333 static constexpr auto class_and_method_name = \
334 rtc::MakeCompileTimeString(proxy_name_) \
335 .Concat(rtc::MakeCompileTimeString("::")) \
336 .Concat(rtc::MakeCompileTimeString(#method)); \
337 proxy_internal::ScopedTrace scoped_trace(class_and_method_name.string)
338
339#endif // if defined(RTC_DISABLE_PROXY_TRACE_EVENTS)
340
Danil Chapovalovcc903d92022-08-12 11:52:07341#define PROXY_METHOD0(r, method) \
342 r method() override { \
343 TRACE_BOILERPLATE(method); \
344 MethodCall<C, r> call(c(), &C::method); \
345 return call.Marshal(primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35346 }
henrike@webrtc.org28e20752013-07-10 00:45:36347
Danil Chapovalovcc903d92022-08-12 11:52:07348#define PROXY_CONSTMETHOD0(r, method) \
349 r method() const override { \
350 TRACE_BOILERPLATE(method); \
351 ConstMethodCall<C, r> call(c(), &C::method); \
352 return call.Marshal(primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35353 }
henrike@webrtc.org28e20752013-07-10 00:45:36354
Niels Möller7f761572022-01-25 15:18:53355#define PROXY_METHOD1(r, method, t1) \
356 r method(t1 a1) override { \
357 TRACE_BOILERPLATE(method); \
358 MethodCall<C, r, t1> call(c(), &C::method, std::move(a1)); \
Danil Chapovalovcc903d92022-08-12 11:52:07359 return call.Marshal(primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35360 }
henrike@webrtc.org28e20752013-07-10 00:45:36361
Niels Möller7f761572022-01-25 15:18:53362#define PROXY_CONSTMETHOD1(r, method, t1) \
363 r method(t1 a1) const override { \
364 TRACE_BOILERPLATE(method); \
365 ConstMethodCall<C, r, t1> call(c(), &C::method, std::move(a1)); \
Danil Chapovalovcc903d92022-08-12 11:52:07366 return call.Marshal(primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35367 }
henrike@webrtc.org28e20752013-07-10 00:45:36368
Niels Möller7f761572022-01-25 15:18:53369#define PROXY_METHOD2(r, method, t1, t2) \
370 r method(t1 a1, t2 a2) override { \
371 TRACE_BOILERPLATE(method); \
372 MethodCall<C, r, t1, t2> call(c(), &C::method, std::move(a1), \
373 std::move(a2)); \
Danil Chapovalovcc903d92022-08-12 11:52:07374 return call.Marshal(primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35375 }
perkj@webrtc.org81134d02015-01-12 08:30:16376
Niels Möller7f761572022-01-25 15:18:53377#define PROXY_METHOD3(r, method, t1, t2, t3) \
378 r method(t1 a1, t2 a2, t3 a3) override { \
379 TRACE_BOILERPLATE(method); \
380 MethodCall<C, r, t1, t2, t3> call(c(), &C::method, std::move(a1), \
381 std::move(a2), std::move(a3)); \
Danil Chapovalovcc903d92022-08-12 11:52:07382 return call.Marshal(primary_thread_); \
deadbeefd99a2002017-01-18 16:55:23383 }
384
Niels Möller7f761572022-01-25 15:18:53385#define PROXY_METHOD4(r, method, t1, t2, t3, t4) \
386 r method(t1 a1, t2 a2, t3 a3, t4 a4) override { \
387 TRACE_BOILERPLATE(method); \
388 MethodCall<C, r, t1, t2, t3, t4> call(c(), &C::method, std::move(a1), \
389 std::move(a2), std::move(a3), \
390 std::move(a4)); \
Danil Chapovalovcc903d92022-08-12 11:52:07391 return call.Marshal(primary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29392 }
deadbeefd99a2002017-01-18 16:55:23393
Niels Möller7f761572022-01-25 15:18:53394#define PROXY_METHOD5(r, method, t1, t2, t3, t4, t5) \
395 r method(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) override { \
396 TRACE_BOILERPLATE(method); \
397 MethodCall<C, r, t1, t2, t3, t4, t5> call(c(), &C::method, std::move(a1), \
398 std::move(a2), std::move(a3), \
399 std::move(a4), std::move(a5)); \
Danil Chapovalovcc903d92022-08-12 11:52:07400 return call.Marshal(primary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29401 }
nisse5b68ab52016-04-07 14:45:54402
Mirko Bonadei9d9b8de2021-02-26 08:51:26403// Define methods which should be invoked on the secondary thread.
Danil Chapovalovcc903d92022-08-12 11:52:07404#define PROXY_SECONDARY_METHOD0(r, method) \
405 r method() override { \
406 TRACE_BOILERPLATE(method); \
407 MethodCall<C, r> call(c(), &C::method); \
408 return call.Marshal(secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29409 }
nisse5b68ab52016-04-07 14:45:54410
Danil Chapovalovcc903d92022-08-12 11:52:07411#define PROXY_SECONDARY_CONSTMETHOD0(r, method) \
412 r method() const override { \
413 TRACE_BOILERPLATE(method); \
414 ConstMethodCall<C, r> call(c(), &C::method); \
415 return call.Marshal(secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29416 }
perkj@webrtc.org81134d02015-01-12 08:30:16417
Niels Möller7f761572022-01-25 15:18:53418#define PROXY_SECONDARY_METHOD1(r, method, t1) \
419 r method(t1 a1) override { \
420 TRACE_BOILERPLATE(method); \
421 MethodCall<C, r, t1> call(c(), &C::method, std::move(a1)); \
Danil Chapovalovcc903d92022-08-12 11:52:07422 return call.Marshal(secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29423 }
henrike@webrtc.org28e20752013-07-10 00:45:36424
Niels Möller7f761572022-01-25 15:18:53425#define PROXY_SECONDARY_CONSTMETHOD1(r, method, t1) \
426 r method(t1 a1) const override { \
427 TRACE_BOILERPLATE(method); \
428 ConstMethodCall<C, r, t1> call(c(), &C::method, std::move(a1)); \
Danil Chapovalovcc903d92022-08-12 11:52:07429 return call.Marshal(secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29430 }
deadbeefd99a2002017-01-18 16:55:23431
Niels Möller7f761572022-01-25 15:18:53432#define PROXY_SECONDARY_METHOD2(r, method, t1, t2) \
433 r method(t1 a1, t2 a2) override { \
434 TRACE_BOILERPLATE(method); \
435 MethodCall<C, r, t1, t2> call(c(), &C::method, std::move(a1), \
436 std::move(a2)); \
Danil Chapovalovcc903d92022-08-12 11:52:07437 return call.Marshal(secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29438 }
deadbeefd99a2002017-01-18 16:55:23439
Niels Möller7f761572022-01-25 15:18:53440#define PROXY_SECONDARY_CONSTMETHOD2(r, method, t1, t2) \
441 r method(t1 a1, t2 a2) const override { \
442 TRACE_BOILERPLATE(method); \
443 ConstMethodCall<C, r, t1, t2> call(c(), &C::method, std::move(a1), \
444 std::move(a2)); \
Danil Chapovalovcc903d92022-08-12 11:52:07445 return call.Marshal(secondary_thread_); \
Niels Möller7f761572022-01-25 15:18:53446 }
447
448#define PROXY_SECONDARY_METHOD3(r, method, t1, t2, t3) \
449 r method(t1 a1, t2 a2, t3 a3) override { \
Markus Handell3d46d0b2021-05-27 19:42:57450 TRACE_BOILERPLATE(method); \
Niels Möller7f761572022-01-25 15:18:53451 MethodCall<C, r, t1, t2, t3> call(c(), &C::method, std::move(a1), \
452 std::move(a2), std::move(a3)); \
Danil Chapovalovcc903d92022-08-12 11:52:07453 return call.Marshal(secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29454 }
deadbeefe814a0d2017-02-26 02:15:09455
Niels Möller7f761572022-01-25 15:18:53456#define PROXY_SECONDARY_CONSTMETHOD3(r, method, t1, t2) \
457 r method(t1 a1, t2 a2, t3 a3) const override { \
458 TRACE_BOILERPLATE(method); \
459 ConstMethodCall<C, r, t1, t2, t3> call(c(), &C::method, std::move(a1), \
460 std::move(a2), std::move(a3)); \
Danil Chapovalovcc903d92022-08-12 11:52:07461 return call.Marshal(secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29462 }
deadbeefd99a2002017-01-18 16:55:23463
Tomas Gunnarsson0ca13d92020-06-10 10:17:50464// For use when returning purely const state (set during construction).
465// Use with caution. This method should only be used when the return value will
466// always be the same.
Markus Handell3d46d0b2021-05-27 19:42:57467#define BYPASS_PROXY_CONSTMETHOD0(r, method) \
468 r method() const override { \
469 TRACE_BOILERPLATE(method); \
470 return c_->method(); \
Tomas Gunnarsson0ca13d92020-06-10 10:17:50471 }
Tommia13b4d12023-04-05 15:17:17472// Allows a custom implementation of a method where the otherwise proxied
473// implementation can do a more efficient, yet thread-safe, job than the proxy
474// can do by default or when more flexibility is needed than can be provided
475// by a proxy.
476// Note that calls to these methods should be expected to be made from unknown
477// threads.
478#define BYPASS_PROXY_METHOD0(r, method) \
479 r method() override { \
480 TRACE_BOILERPLATE(method); \
481 return c_->method(); \
482 }
483
484// The 1 argument version of `BYPASS_PROXY_METHOD0`.
485#define BYPASS_PROXY_METHOD1(r, method, t1) \
486 r method(t1 a1) override { \
487 TRACE_BOILERPLATE(method); \
488 return c_->method(std::move(a1)); \
489 }
490
491// The 2 argument version of `BYPASS_PROXY_METHOD0`.
492#define BYPASS_PROXY_METHOD2(r, method, t1, t2) \
493 r method(t1 a1, t2 a2) override { \
494 TRACE_BOILERPLATE(method); \
495 return c_->method(std::move(a1), std::move(a2)); \
496 }
henrike@webrtc.org28e20752013-07-10 00:45:36497} // namespace webrtc
498
Markus Handella1b82012021-05-26 16:56:30499#endif // PC_PROXY_H_