blob: 2be115fdf39672f560c3dbeeb89fa19ab03e25a1 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2013 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * 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:36 +00009 */
10
11// This file contains Macros for creating proxies for webrtc MediaStream and
12// PeerConnection classes.
13
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +010014// 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:36 +000021//
22// Example usage:
23//
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000024// class TestInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000025// public:
26// std::string FooA() = 0;
27// std::string FooB(bool arg1) const = 0;
nisse72c8d2b2016-04-15 03:49:07 -070028// std::string FooC(bool arg1) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000029// };
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 09:51:26 +010038// PROXY_PRIMARY_THREAD_DESTRUCTOR()
henrike@webrtc.org28e20752013-07-10 00:45:36 +000039// PROXY_METHOD0(std::string, FooA)
40// PROXY_CONSTMETHOD1(std::string, FooB, arg1)
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +010041// PROXY_SECONDARY_METHOD1(std::string, FooC, arg1)
deadbeefd99a2002017-01-18 08:55:23 -080042// END_PROXY_MAP()
henrike@webrtc.org28e20752013-07-10 00:45:36 +000043//
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +010044// 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 03:49:07 -070046//
47// The proxy can be created using
48//
49// TestProxy::Create(Thread* signaling_thread, Thread* worker_thread,
50// TestInterface*).
51//
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +010052// 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 08:55:23 -080054//
henrike@webrtc.org28e20752013-07-10 00:45:36 +000055
Markus Handella1b82012021-05-26 18:56:30 +020056#ifndef PC_PROXY_H_
57#define PC_PROXY_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000058
Harald Alvestrandc24a2182022-02-23 13:44:59 +000059#include <stddef.h>
60
kwibergd1fe2812016-04-27 06:47:29 -070061#include <memory>
Yves Gerey3e707812018-11-28 16:47:49 +010062#include <string>
Steve Antonc3639822019-11-26 15:27:50 -080063#include <tuple>
Tomas Gunnarsson0ca13d92020-06-10 12:17:50 +020064#include <type_traits>
oprypin803dc292017-02-01 01:55:59 -080065#include <utility>
kwibergd1fe2812016-04-27 06:47:29 -070066
Mirko Bonadeid9708072019-01-25 20:26:48 +010067#include "api/scoped_refptr.h"
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +020068#include "api/task_queue/task_queue_base.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020069#include "rtc_base/event.h"
Markus Handell3d46d0b2021-05-27 21:42:57 +020070#include "rtc_base/string_utils.h"
Mirko Bonadei35214fc2019-09-23 14:54:28 +020071#include "rtc_base/system/rtc_export.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020072#include "rtc_base/thread.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073
Markus Handell3d46d0b2021-05-27 21:42:57 +020074#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:36 +000078namespace webrtc {
Tommi1cb796f2021-05-21 08:50:09 +020079namespace proxy_internal {
Markus Handell3d46d0b2021-05-27 21:42:57 +020080
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 15:05:28 +020088 [[maybe_unused]] const char* const class_and_method_name_;
Markus Handell3d46d0b2021-05-27 21:42:57 +020089};
Tommi1cb796f2021-05-21 08:50:09 +020090} // namespace proxy_internal
henrike@webrtc.org28e20752013-07-10 00:45:36 +000091
Guido Urdanetaccab06f2020-01-15 11:30:29 +000092template <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:29 +0000117template <typename C, typename R, typename... Args>
Danil Chapovalova30439b2022-07-07 10:08:49 +0200118class MethodCall {
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000119 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 13:52:07 +0200126 R Marshal(rtc::Thread* t) {
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200127 if (t->IsCurrent()) {
128 Invoke(std::index_sequence_for<Args...>());
129 } else {
Danil Chapovalova30439b2022-07-07 10:08:49 +0200130 t->PostTask([this] {
131 Invoke(std::index_sequence_for<Args...>());
132 event_.Set();
133 });
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200134 event_.Wait(rtc::Event::kForever);
135 }
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000136 return r_.moved_result();
137 }
138
139 private:
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000140 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 18:43:36 +0200149 rtc::Event event_;
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000150};
151
152template <typename C, typename R, typename... Args>
Danil Chapovalova30439b2022-07-07 10:08:49 +0200153class ConstMethodCall {
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000154 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 13:52:07 +0200161 R Marshal(rtc::Thread* t) {
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200162 if (t->IsCurrent()) {
163 Invoke(std::index_sequence_for<Args...>());
164 } else {
Danil Chapovalova30439b2022-07-07 10:08:49 +0200165 t->PostTask([this] {
166 Invoke(std::index_sequence_for<Args...>());
167 event_.Set();
168 });
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200169 event_.Wait(rtc::Event::kForever);
170 }
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000171 return r_.moved_result();
172 }
173
174 private:
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000175 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 18:43:36 +0200184 rtc::Event event_;
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000185};
186
Tommi1cb796f2021-05-21 08:50:09 +0200187#define PROXY_STRINGIZE_IMPL(x) #x
188#define PROXY_STRINGIZE(x) PROXY_STRINGIZE_IMPL(x)
189
deadbeefd99a2002017-01-18 08:55:23 -0800190// Helper macros to reduce code duplication.
Niels Möller7f761572022-01-25 16:18:53 +0100191#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: \
203 const INTERNAL_CLASS* internal() const { return c(); } \
204 INTERNAL_CLASS* internal() { return c(); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000205
Yves Gerey665174f2018-06-19 15:03:05 +0200206// clang-format off
207// clang-format would put the semicolon alone,
208// leading to a presubmit error (cpplint.py)
Niels Möller7f761572022-01-25 16:18:53 +0100209#define END_PROXY_MAP(class_name) \
210 }; \
211 template <class INTERNAL_CLASS> \
212 constexpr char class_name##ProxyWithInternal<INTERNAL_CLASS>::proxy_name_[];
Yves Gerey665174f2018-06-19 15:03:05 +0200213// clang-format on
oprypin803dc292017-02-01 01:55:59 -0800214
Tomas Gunnarsson0d5ce622022-03-18 15:57:15 +0100215#define PRIMARY_PROXY_MAP_BOILERPLATE(class_name) \
216 protected: \
217 class_name##ProxyWithInternal(rtc::Thread* primary_thread, \
218 rtc::scoped_refptr<INTERNAL_CLASS> c) \
219 : primary_thread_(primary_thread), c_(std::move(c)) {} \
220 \
221 private: \
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100222 mutable rtc::Thread* primary_thread_;
223
Tomas Gunnarsson0d5ce622022-03-18 15:57:15 +0100224#define SECONDARY_PROXY_MAP_BOILERPLATE(class_name) \
225 protected: \
226 class_name##ProxyWithInternal(rtc::Thread* primary_thread, \
227 rtc::Thread* secondary_thread, \
228 rtc::scoped_refptr<INTERNAL_CLASS> c) \
229 : primary_thread_(primary_thread), \
230 secondary_thread_(secondary_thread), \
231 c_(std::move(c)) {} \
232 \
233 private: \
234 mutable rtc::Thread* primary_thread_; \
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100235 mutable rtc::Thread* secondary_thread_;
deadbeefd99a2002017-01-18 08:55:23 -0800236
237// Note that the destructor is protected so that the proxy can only be
238// destroyed via RefCountInterface.
Niels Möller7f761572022-01-25 16:18:53 +0100239#define REFCOUNTED_PROXY_MAP_BOILERPLATE(class_name) \
240 protected: \
241 ~class_name##ProxyWithInternal() { \
242 MethodCall<class_name##ProxyWithInternal, void> call( \
243 this, &class_name##ProxyWithInternal::DestroyInternal); \
Danil Chapovalovcc903d92022-08-12 13:52:07 +0200244 call.Marshal(destructor_thread()); \
Niels Möller7f761572022-01-25 16:18:53 +0100245 } \
246 \
247 private: \
248 const INTERNAL_CLASS* c() const { return c_.get(); } \
249 INTERNAL_CLASS* c() { return c_.get(); } \
250 void DestroyInternal() { c_ = nullptr; } \
deadbeefd99a2002017-01-18 08:55:23 -0800251 rtc::scoped_refptr<INTERNAL_CLASS> c_;
252
deadbeefe814a0d2017-02-25 18:15:09 -0800253// Note: This doesn't use a unique_ptr, because it intends to handle a corner
254// case where an object's deletion triggers a callback that calls back into
255// this proxy object. If relying on a unique_ptr to delete the object, its
256// inner pointer would be set to null before this reentrant callback would have
257// a chance to run, resulting in a segfault.
Niels Möller7f761572022-01-25 16:18:53 +0100258#define OWNED_PROXY_MAP_BOILERPLATE(class_name) \
259 public: \
260 ~class_name##ProxyWithInternal() { \
261 MethodCall<class_name##ProxyWithInternal, void> call( \
262 this, &class_name##ProxyWithInternal::DestroyInternal); \
Danil Chapovalovcc903d92022-08-12 13:52:07 +0200263 call.Marshal(destructor_thread()); \
Niels Möller7f761572022-01-25 16:18:53 +0100264 } \
265 \
266 private: \
267 const INTERNAL_CLASS* c() const { return c_; } \
268 INTERNAL_CLASS* c() { return c_; } \
269 void DestroyInternal() { delete c_; } \
deadbeefe814a0d2017-02-25 18:15:09 -0800270 INTERNAL_CLASS* c_;
deadbeefd99a2002017-01-18 08:55:23 -0800271
Tomas Gunnarsson0d5ce622022-03-18 15:57:15 +0100272#define BEGIN_PRIMARY_PROXY_MAP(class_name) \
273 PROXY_MAP_BOILERPLATE(class_name) \
274 PRIMARY_PROXY_MAP_BOILERPLATE(class_name) \
275 REFCOUNTED_PROXY_MAP_BOILERPLATE(class_name) \
276 public: \
277 static rtc::scoped_refptr<class_name##ProxyWithInternal> Create( \
278 rtc::Thread* primary_thread, rtc::scoped_refptr<INTERNAL_CLASS> c) { \
279 return rtc::make_ref_counted<class_name##ProxyWithInternal>( \
280 primary_thread, std::move(c)); \
Niels Möller7f761572022-01-25 16:18:53 +0100281 }
282
283#define BEGIN_PROXY_MAP(class_name) \
284 PROXY_MAP_BOILERPLATE(class_name) \
285 SECONDARY_PROXY_MAP_BOILERPLATE(class_name) \
286 REFCOUNTED_PROXY_MAP_BOILERPLATE(class_name) \
287 public: \
288 static rtc::scoped_refptr<class_name##ProxyWithInternal> Create( \
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100289 rtc::Thread* primary_thread, rtc::Thread* secondary_thread, \
Tomas Gunnarsson0d5ce622022-03-18 15:57:15 +0100290 rtc::scoped_refptr<INTERNAL_CLASS> c) { \
Niels Möller7f761572022-01-25 16:18:53 +0100291 return rtc::make_ref_counted<class_name##ProxyWithInternal>( \
Tomas Gunnarsson0d5ce622022-03-18 15:57:15 +0100292 primary_thread, secondary_thread, std::move(c)); \
Niels Möller7f761572022-01-25 16:18:53 +0100293 }
294
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100295#define PROXY_PRIMARY_THREAD_DESTRUCTOR() \
296 private: \
297 rtc::Thread* destructor_thread() const { return primary_thread_; } \
298 \
299 public: // NOLINTNEXTLINE
300
301#define PROXY_SECONDARY_THREAD_DESTRUCTOR() \
deadbeefd99a2002017-01-18 08:55:23 -0800302 private: \
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100303 rtc::Thread* destructor_thread() const { return secondary_thread_; } \
deadbeefd99a2002017-01-18 08:55:23 -0800304 \
oprypin803dc292017-02-01 01:55:59 -0800305 public: // NOLINTNEXTLINE
deadbeefd99a2002017-01-18 08:55:23 -0800306
Markus Handell3d46d0b2021-05-27 21:42:57 +0200307#if defined(RTC_DISABLE_PROXY_TRACE_EVENTS)
308#define TRACE_BOILERPLATE(method) \
309 do { \
310 } while (0)
311#else // if defined(RTC_DISABLE_PROXY_TRACE_EVENTS)
312#define TRACE_BOILERPLATE(method) \
313 static constexpr auto class_and_method_name = \
314 rtc::MakeCompileTimeString(proxy_name_) \
315 .Concat(rtc::MakeCompileTimeString("::")) \
316 .Concat(rtc::MakeCompileTimeString(#method)); \
317 proxy_internal::ScopedTrace scoped_trace(class_and_method_name.string)
318
319#endif // if defined(RTC_DISABLE_PROXY_TRACE_EVENTS)
320
Danil Chapovalovcc903d92022-08-12 13:52:07 +0200321#define PROXY_METHOD0(r, method) \
322 r method() override { \
323 TRACE_BOILERPLATE(method); \
324 MethodCall<C, r> call(c(), &C::method); \
325 return call.Marshal(primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000326 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000327
Danil Chapovalovcc903d92022-08-12 13:52:07 +0200328#define PROXY_CONSTMETHOD0(r, method) \
329 r method() const override { \
330 TRACE_BOILERPLATE(method); \
331 ConstMethodCall<C, r> call(c(), &C::method); \
332 return call.Marshal(primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000333 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000334
Niels Möller7f761572022-01-25 16:18:53 +0100335#define PROXY_METHOD1(r, method, t1) \
336 r method(t1 a1) override { \
337 TRACE_BOILERPLATE(method); \
338 MethodCall<C, r, t1> call(c(), &C::method, std::move(a1)); \
Danil Chapovalovcc903d92022-08-12 13:52:07 +0200339 return call.Marshal(primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000340 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000341
Niels Möller7f761572022-01-25 16:18:53 +0100342#define PROXY_CONSTMETHOD1(r, method, t1) \
343 r method(t1 a1) const override { \
344 TRACE_BOILERPLATE(method); \
345 ConstMethodCall<C, r, t1> call(c(), &C::method, std::move(a1)); \
Danil Chapovalovcc903d92022-08-12 13:52:07 +0200346 return call.Marshal(primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000347 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000348
Niels Möller7f761572022-01-25 16:18:53 +0100349#define PROXY_METHOD2(r, method, t1, t2) \
350 r method(t1 a1, t2 a2) override { \
351 TRACE_BOILERPLATE(method); \
352 MethodCall<C, r, t1, t2> call(c(), &C::method, std::move(a1), \
353 std::move(a2)); \
Danil Chapovalovcc903d92022-08-12 13:52:07 +0200354 return call.Marshal(primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000355 }
perkj@webrtc.org81134d02015-01-12 08:30:16 +0000356
Niels Möller7f761572022-01-25 16:18:53 +0100357#define PROXY_METHOD3(r, method, t1, t2, t3) \
358 r method(t1 a1, t2 a2, t3 a3) override { \
359 TRACE_BOILERPLATE(method); \
360 MethodCall<C, r, t1, t2, t3> call(c(), &C::method, std::move(a1), \
361 std::move(a2), std::move(a3)); \
Danil Chapovalovcc903d92022-08-12 13:52:07 +0200362 return call.Marshal(primary_thread_); \
deadbeefd99a2002017-01-18 08:55:23 -0800363 }
364
Niels Möller7f761572022-01-25 16:18:53 +0100365#define PROXY_METHOD4(r, method, t1, t2, t3, t4) \
366 r method(t1 a1, t2 a2, t3 a3, t4 a4) override { \
367 TRACE_BOILERPLATE(method); \
368 MethodCall<C, r, t1, t2, t3, t4> call(c(), &C::method, std::move(a1), \
369 std::move(a2), std::move(a3), \
370 std::move(a4)); \
Danil Chapovalovcc903d92022-08-12 13:52:07 +0200371 return call.Marshal(primary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000372 }
deadbeefd99a2002017-01-18 08:55:23 -0800373
Niels Möller7f761572022-01-25 16:18:53 +0100374#define PROXY_METHOD5(r, method, t1, t2, t3, t4, t5) \
375 r method(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) override { \
376 TRACE_BOILERPLATE(method); \
377 MethodCall<C, r, t1, t2, t3, t4, t5> call(c(), &C::method, std::move(a1), \
378 std::move(a2), std::move(a3), \
379 std::move(a4), std::move(a5)); \
Danil Chapovalovcc903d92022-08-12 13:52:07 +0200380 return call.Marshal(primary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000381 }
nisse5b68ab52016-04-07 07:45:54 -0700382
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100383// Define methods which should be invoked on the secondary thread.
Danil Chapovalovcc903d92022-08-12 13:52:07 +0200384#define PROXY_SECONDARY_METHOD0(r, method) \
385 r method() override { \
386 TRACE_BOILERPLATE(method); \
387 MethodCall<C, r> call(c(), &C::method); \
388 return call.Marshal(secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000389 }
nisse5b68ab52016-04-07 07:45:54 -0700390
Danil Chapovalovcc903d92022-08-12 13:52:07 +0200391#define PROXY_SECONDARY_CONSTMETHOD0(r, method) \
392 r method() const override { \
393 TRACE_BOILERPLATE(method); \
394 ConstMethodCall<C, r> call(c(), &C::method); \
395 return call.Marshal(secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000396 }
perkj@webrtc.org81134d02015-01-12 08:30:16 +0000397
Niels Möller7f761572022-01-25 16:18:53 +0100398#define PROXY_SECONDARY_METHOD1(r, method, t1) \
399 r method(t1 a1) override { \
400 TRACE_BOILERPLATE(method); \
401 MethodCall<C, r, t1> call(c(), &C::method, std::move(a1)); \
Danil Chapovalovcc903d92022-08-12 13:52:07 +0200402 return call.Marshal(secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000403 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000404
Niels Möller7f761572022-01-25 16:18:53 +0100405#define PROXY_SECONDARY_CONSTMETHOD1(r, method, t1) \
406 r method(t1 a1) const override { \
407 TRACE_BOILERPLATE(method); \
408 ConstMethodCall<C, r, t1> call(c(), &C::method, std::move(a1)); \
Danil Chapovalovcc903d92022-08-12 13:52:07 +0200409 return call.Marshal(secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000410 }
deadbeefd99a2002017-01-18 08:55:23 -0800411
Niels Möller7f761572022-01-25 16:18:53 +0100412#define PROXY_SECONDARY_METHOD2(r, method, t1, t2) \
413 r method(t1 a1, t2 a2) override { \
414 TRACE_BOILERPLATE(method); \
415 MethodCall<C, r, t1, t2> call(c(), &C::method, std::move(a1), \
416 std::move(a2)); \
Danil Chapovalovcc903d92022-08-12 13:52:07 +0200417 return call.Marshal(secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000418 }
deadbeefd99a2002017-01-18 08:55:23 -0800419
Niels Möller7f761572022-01-25 16:18:53 +0100420#define PROXY_SECONDARY_CONSTMETHOD2(r, method, t1, t2) \
421 r method(t1 a1, t2 a2) const override { \
422 TRACE_BOILERPLATE(method); \
423 ConstMethodCall<C, r, t1, t2> call(c(), &C::method, std::move(a1), \
424 std::move(a2)); \
Danil Chapovalovcc903d92022-08-12 13:52:07 +0200425 return call.Marshal(secondary_thread_); \
Niels Möller7f761572022-01-25 16:18:53 +0100426 }
427
428#define PROXY_SECONDARY_METHOD3(r, method, t1, t2, t3) \
429 r method(t1 a1, t2 a2, t3 a3) override { \
Markus Handell3d46d0b2021-05-27 21:42:57 +0200430 TRACE_BOILERPLATE(method); \
Niels Möller7f761572022-01-25 16:18:53 +0100431 MethodCall<C, r, t1, t2, t3> call(c(), &C::method, std::move(a1), \
432 std::move(a2), std::move(a3)); \
Danil Chapovalovcc903d92022-08-12 13:52:07 +0200433 return call.Marshal(secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000434 }
deadbeefe814a0d2017-02-25 18:15:09 -0800435
Niels Möller7f761572022-01-25 16:18:53 +0100436#define PROXY_SECONDARY_CONSTMETHOD3(r, method, t1, t2) \
437 r method(t1 a1, t2 a2, t3 a3) const override { \
438 TRACE_BOILERPLATE(method); \
439 ConstMethodCall<C, r, t1, t2, t3> call(c(), &C::method, std::move(a1), \
440 std::move(a2), std::move(a3)); \
Danil Chapovalovcc903d92022-08-12 13:52:07 +0200441 return call.Marshal(secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000442 }
deadbeefd99a2002017-01-18 08:55:23 -0800443
Tomas Gunnarsson0ca13d92020-06-10 12:17:50 +0200444// For use when returning purely const state (set during construction).
445// Use with caution. This method should only be used when the return value will
446// always be the same.
Markus Handell3d46d0b2021-05-27 21:42:57 +0200447#define BYPASS_PROXY_CONSTMETHOD0(r, method) \
448 r method() const override { \
449 TRACE_BOILERPLATE(method); \
450 return c_->method(); \
Tomas Gunnarsson0ca13d92020-06-10 12:17:50 +0200451 }
452
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000453} // namespace webrtc
454
Markus Handella1b82012021-05-26 18:56:30 +0200455#endif // PC_PROXY_H_