blob: a8eb6b21d414427261a722ebae4221319c46a38e [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"
Steve Anton10542f22019-01-11 09:11:00 -080070#include "rtc_base/message_handler.h"
Markus Handell3d46d0b2021-05-27 21:42:57 +020071#include "rtc_base/string_utils.h"
Mirko Bonadei35214fc2019-09-23 14:54:28 +020072#include "rtc_base/system/rtc_export.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020073#include "rtc_base/thread.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000074
Markus Handell3d46d0b2021-05-27 21:42:57 +020075#if !defined(RTC_DISABLE_PROXY_TRACE_EVENTS) && !defined(WEBRTC_CHROMIUM_BUILD)
76#define RTC_DISABLE_PROXY_TRACE_EVENTS
77#endif
78
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079namespace webrtc {
Tommi1cb796f2021-05-21 08:50:09 +020080namespace proxy_internal {
Markus Handell3d46d0b2021-05-27 21:42:57 +020081
82// Class for tracing the lifetime of MethodCall::Marshal.
83class ScopedTrace {
84 public:
85 explicit ScopedTrace(const char* class_and_method_name);
86 ~ScopedTrace();
87
88 private:
Johannes Kron8d1e4fb2022-05-10 15:05:28 +020089 [[maybe_unused]] const char* const class_and_method_name_;
Markus Handell3d46d0b2021-05-27 21:42:57 +020090};
Tommi1cb796f2021-05-21 08:50:09 +020091} // namespace proxy_internal
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092
Guido Urdanetaccab06f2020-01-15 11:30:29 +000093template <typename R>
94class ReturnType {
95 public:
96 template <typename C, typename M, typename... Args>
97 void Invoke(C* c, M m, Args&&... args) {
98 r_ = (c->*m)(std::forward<Args>(args)...);
99 }
100
101 R moved_result() { return std::move(r_); }
102
103 private:
104 R r_;
105};
106
107template <>
108class ReturnType<void> {
109 public:
110 template <typename C, typename M, typename... Args>
111 void Invoke(C* c, M m, Args&&... args) {
112 (c->*m)(std::forward<Args>(args)...);
113 }
114
115 void moved_result() {}
116};
117
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000118template <typename C, typename R, typename... Args>
Danil Chapovalova30439b2022-07-07 10:08:49 +0200119class MethodCall {
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000120 public:
121 typedef R (C::*Method)(Args...);
122 MethodCall(C* c, Method m, Args&&... args)
123 : c_(c),
124 m_(m),
125 args_(std::forward_as_tuple(std::forward<Args>(args)...)) {}
126
Danil Chapovalovcc903d92022-08-12 13:52:07 +0200127 R Marshal(rtc::Thread* t) {
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200128 if (t->IsCurrent()) {
129 Invoke(std::index_sequence_for<Args...>());
130 } else {
Danil Chapovalova30439b2022-07-07 10:08:49 +0200131 t->PostTask([this] {
132 Invoke(std::index_sequence_for<Args...>());
133 event_.Set();
134 });
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200135 event_.Wait(rtc::Event::kForever);
136 }
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000137 return r_.moved_result();
138 }
139
140 private:
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000141 template <size_t... Is>
142 void Invoke(std::index_sequence<Is...>) {
143 r_.Invoke(c_, m_, std::move(std::get<Is>(args_))...);
144 }
145
146 C* c_;
147 Method m_;
148 ReturnType<R> r_;
149 std::tuple<Args&&...> args_;
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200150 rtc::Event event_;
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000151};
152
153template <typename C, typename R, typename... Args>
Danil Chapovalova30439b2022-07-07 10:08:49 +0200154class ConstMethodCall {
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000155 public:
156 typedef R (C::*Method)(Args...) const;
157 ConstMethodCall(const C* c, Method m, Args&&... args)
158 : c_(c),
159 m_(m),
160 args_(std::forward_as_tuple(std::forward<Args>(args)...)) {}
161
Danil Chapovalovcc903d92022-08-12 13:52:07 +0200162 R Marshal(rtc::Thread* t) {
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200163 if (t->IsCurrent()) {
164 Invoke(std::index_sequence_for<Args...>());
165 } else {
Danil Chapovalova30439b2022-07-07 10:08:49 +0200166 t->PostTask([this] {
167 Invoke(std::index_sequence_for<Args...>());
168 event_.Set();
169 });
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200170 event_.Wait(rtc::Event::kForever);
171 }
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000172 return r_.moved_result();
173 }
174
175 private:
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000176 template <size_t... Is>
177 void Invoke(std::index_sequence<Is...>) {
178 r_.Invoke(c_, m_, std::move(std::get<Is>(args_))...);
179 }
180
181 const C* c_;
182 Method m_;
183 ReturnType<R> r_;
184 std::tuple<Args&&...> args_;
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200185 rtc::Event event_;
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000186};
187
Tommi1cb796f2021-05-21 08:50:09 +0200188#define PROXY_STRINGIZE_IMPL(x) #x
189#define PROXY_STRINGIZE(x) PROXY_STRINGIZE_IMPL(x)
190
deadbeefd99a2002017-01-18 08:55:23 -0800191// Helper macros to reduce code duplication.
Niels Möller7f761572022-01-25 16:18:53 +0100192#define PROXY_MAP_BOILERPLATE(class_name) \
193 template <class INTERNAL_CLASS> \
194 class class_name##ProxyWithInternal; \
195 typedef class_name##ProxyWithInternal<class_name##Interface> \
196 class_name##Proxy; \
197 template <class INTERNAL_CLASS> \
198 class class_name##ProxyWithInternal : public class_name##Interface { \
199 protected: \
200 static constexpr char proxy_name_[] = #class_name "Proxy"; \
201 typedef class_name##Interface C; \
202 \
203 public: \
204 const INTERNAL_CLASS* internal() const { return c(); } \
205 INTERNAL_CLASS* internal() { return c(); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000206
Yves Gerey665174f2018-06-19 15:03:05 +0200207// clang-format off
208// clang-format would put the semicolon alone,
209// leading to a presubmit error (cpplint.py)
Niels Möller7f761572022-01-25 16:18:53 +0100210#define END_PROXY_MAP(class_name) \
211 }; \
212 template <class INTERNAL_CLASS> \
213 constexpr char class_name##ProxyWithInternal<INTERNAL_CLASS>::proxy_name_[];
Yves Gerey665174f2018-06-19 15:03:05 +0200214// clang-format on
oprypin803dc292017-02-01 01:55:59 -0800215
Tomas Gunnarsson0d5ce622022-03-18 15:57:15 +0100216#define PRIMARY_PROXY_MAP_BOILERPLATE(class_name) \
217 protected: \
218 class_name##ProxyWithInternal(rtc::Thread* primary_thread, \
219 rtc::scoped_refptr<INTERNAL_CLASS> c) \
220 : primary_thread_(primary_thread), c_(std::move(c)) {} \
221 \
222 private: \
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100223 mutable rtc::Thread* primary_thread_;
224
Tomas Gunnarsson0d5ce622022-03-18 15:57:15 +0100225#define SECONDARY_PROXY_MAP_BOILERPLATE(class_name) \
226 protected: \
227 class_name##ProxyWithInternal(rtc::Thread* primary_thread, \
228 rtc::Thread* secondary_thread, \
229 rtc::scoped_refptr<INTERNAL_CLASS> c) \
230 : primary_thread_(primary_thread), \
231 secondary_thread_(secondary_thread), \
232 c_(std::move(c)) {} \
233 \
234 private: \
235 mutable rtc::Thread* primary_thread_; \
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100236 mutable rtc::Thread* secondary_thread_;
deadbeefd99a2002017-01-18 08:55:23 -0800237
238// Note that the destructor is protected so that the proxy can only be
239// destroyed via RefCountInterface.
Niels Möller7f761572022-01-25 16:18:53 +0100240#define REFCOUNTED_PROXY_MAP_BOILERPLATE(class_name) \
241 protected: \
242 ~class_name##ProxyWithInternal() { \
243 MethodCall<class_name##ProxyWithInternal, void> call( \
244 this, &class_name##ProxyWithInternal::DestroyInternal); \
Danil Chapovalovcc903d92022-08-12 13:52:07 +0200245 call.Marshal(destructor_thread()); \
Niels Möller7f761572022-01-25 16:18:53 +0100246 } \
247 \
248 private: \
249 const INTERNAL_CLASS* c() const { return c_.get(); } \
250 INTERNAL_CLASS* c() { return c_.get(); } \
251 void DestroyInternal() { c_ = nullptr; } \
deadbeefd99a2002017-01-18 08:55:23 -0800252 rtc::scoped_refptr<INTERNAL_CLASS> c_;
253
deadbeefe814a0d2017-02-25 18:15:09 -0800254// Note: This doesn't use a unique_ptr, because it intends to handle a corner
255// case where an object's deletion triggers a callback that calls back into
256// this proxy object. If relying on a unique_ptr to delete the object, its
257// inner pointer would be set to null before this reentrant callback would have
258// a chance to run, resulting in a segfault.
Niels Möller7f761572022-01-25 16:18:53 +0100259#define OWNED_PROXY_MAP_BOILERPLATE(class_name) \
260 public: \
261 ~class_name##ProxyWithInternal() { \
262 MethodCall<class_name##ProxyWithInternal, void> call( \
263 this, &class_name##ProxyWithInternal::DestroyInternal); \
Danil Chapovalovcc903d92022-08-12 13:52:07 +0200264 call.Marshal(destructor_thread()); \
Niels Möller7f761572022-01-25 16:18:53 +0100265 } \
266 \
267 private: \
268 const INTERNAL_CLASS* c() const { return c_; } \
269 INTERNAL_CLASS* c() { return c_; } \
270 void DestroyInternal() { delete c_; } \
deadbeefe814a0d2017-02-25 18:15:09 -0800271 INTERNAL_CLASS* c_;
deadbeefd99a2002017-01-18 08:55:23 -0800272
Tomas Gunnarsson0d5ce622022-03-18 15:57:15 +0100273#define BEGIN_PRIMARY_PROXY_MAP(class_name) \
274 PROXY_MAP_BOILERPLATE(class_name) \
275 PRIMARY_PROXY_MAP_BOILERPLATE(class_name) \
276 REFCOUNTED_PROXY_MAP_BOILERPLATE(class_name) \
277 public: \
278 static rtc::scoped_refptr<class_name##ProxyWithInternal> Create( \
279 rtc::Thread* primary_thread, rtc::scoped_refptr<INTERNAL_CLASS> c) { \
280 return rtc::make_ref_counted<class_name##ProxyWithInternal>( \
281 primary_thread, std::move(c)); \
Niels Möller7f761572022-01-25 16:18:53 +0100282 }
283
284#define BEGIN_PROXY_MAP(class_name) \
285 PROXY_MAP_BOILERPLATE(class_name) \
286 SECONDARY_PROXY_MAP_BOILERPLATE(class_name) \
287 REFCOUNTED_PROXY_MAP_BOILERPLATE(class_name) \
288 public: \
289 static rtc::scoped_refptr<class_name##ProxyWithInternal> Create( \
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100290 rtc::Thread* primary_thread, rtc::Thread* secondary_thread, \
Tomas Gunnarsson0d5ce622022-03-18 15:57:15 +0100291 rtc::scoped_refptr<INTERNAL_CLASS> c) { \
Niels Möller7f761572022-01-25 16:18:53 +0100292 return rtc::make_ref_counted<class_name##ProxyWithInternal>( \
Tomas Gunnarsson0d5ce622022-03-18 15:57:15 +0100293 primary_thread, secondary_thread, std::move(c)); \
Niels Möller7f761572022-01-25 16:18:53 +0100294 }
295
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100296#define PROXY_PRIMARY_THREAD_DESTRUCTOR() \
297 private: \
298 rtc::Thread* destructor_thread() const { return primary_thread_; } \
299 \
300 public: // NOLINTNEXTLINE
301
302#define PROXY_SECONDARY_THREAD_DESTRUCTOR() \
deadbeefd99a2002017-01-18 08:55:23 -0800303 private: \
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100304 rtc::Thread* destructor_thread() const { return secondary_thread_; } \
deadbeefd99a2002017-01-18 08:55:23 -0800305 \
oprypin803dc292017-02-01 01:55:59 -0800306 public: // NOLINTNEXTLINE
deadbeefd99a2002017-01-18 08:55:23 -0800307
Markus Handell3d46d0b2021-05-27 21:42:57 +0200308#if defined(RTC_DISABLE_PROXY_TRACE_EVENTS)
309#define TRACE_BOILERPLATE(method) \
310 do { \
311 } while (0)
312#else // if defined(RTC_DISABLE_PROXY_TRACE_EVENTS)
313#define TRACE_BOILERPLATE(method) \
314 static constexpr auto class_and_method_name = \
315 rtc::MakeCompileTimeString(proxy_name_) \
316 .Concat(rtc::MakeCompileTimeString("::")) \
317 .Concat(rtc::MakeCompileTimeString(#method)); \
318 proxy_internal::ScopedTrace scoped_trace(class_and_method_name.string)
319
320#endif // if defined(RTC_DISABLE_PROXY_TRACE_EVENTS)
321
Danil Chapovalovcc903d92022-08-12 13:52:07 +0200322#define PROXY_METHOD0(r, method) \
323 r method() override { \
324 TRACE_BOILERPLATE(method); \
325 MethodCall<C, r> call(c(), &C::method); \
326 return call.Marshal(primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000327 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000328
Danil Chapovalovcc903d92022-08-12 13:52:07 +0200329#define PROXY_CONSTMETHOD0(r, method) \
330 r method() const override { \
331 TRACE_BOILERPLATE(method); \
332 ConstMethodCall<C, r> call(c(), &C::method); \
333 return call.Marshal(primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000334 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000335
Niels Möller7f761572022-01-25 16:18:53 +0100336#define PROXY_METHOD1(r, method, t1) \
337 r method(t1 a1) override { \
338 TRACE_BOILERPLATE(method); \
339 MethodCall<C, r, t1> call(c(), &C::method, std::move(a1)); \
Danil Chapovalovcc903d92022-08-12 13:52:07 +0200340 return call.Marshal(primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000341 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000342
Niels Möller7f761572022-01-25 16:18:53 +0100343#define PROXY_CONSTMETHOD1(r, method, t1) \
344 r method(t1 a1) const override { \
345 TRACE_BOILERPLATE(method); \
346 ConstMethodCall<C, r, t1> call(c(), &C::method, std::move(a1)); \
Danil Chapovalovcc903d92022-08-12 13:52:07 +0200347 return call.Marshal(primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000348 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000349
Niels Möller7f761572022-01-25 16:18:53 +0100350#define PROXY_METHOD2(r, method, t1, t2) \
351 r method(t1 a1, t2 a2) override { \
352 TRACE_BOILERPLATE(method); \
353 MethodCall<C, r, t1, t2> call(c(), &C::method, std::move(a1), \
354 std::move(a2)); \
Danil Chapovalovcc903d92022-08-12 13:52:07 +0200355 return call.Marshal(primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000356 }
perkj@webrtc.org81134d02015-01-12 08:30:16 +0000357
Niels Möller7f761572022-01-25 16:18:53 +0100358#define PROXY_METHOD3(r, method, t1, t2, t3) \
359 r method(t1 a1, t2 a2, t3 a3) override { \
360 TRACE_BOILERPLATE(method); \
361 MethodCall<C, r, t1, t2, t3> call(c(), &C::method, std::move(a1), \
362 std::move(a2), std::move(a3)); \
Danil Chapovalovcc903d92022-08-12 13:52:07 +0200363 return call.Marshal(primary_thread_); \
deadbeefd99a2002017-01-18 08:55:23 -0800364 }
365
Niels Möller7f761572022-01-25 16:18:53 +0100366#define PROXY_METHOD4(r, method, t1, t2, t3, t4) \
367 r method(t1 a1, t2 a2, t3 a3, t4 a4) override { \
368 TRACE_BOILERPLATE(method); \
369 MethodCall<C, r, t1, t2, t3, t4> call(c(), &C::method, std::move(a1), \
370 std::move(a2), std::move(a3), \
371 std::move(a4)); \
Danil Chapovalovcc903d92022-08-12 13:52:07 +0200372 return call.Marshal(primary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000373 }
deadbeefd99a2002017-01-18 08:55:23 -0800374
Niels Möller7f761572022-01-25 16:18:53 +0100375#define PROXY_METHOD5(r, method, t1, t2, t3, t4, t5) \
376 r method(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) override { \
377 TRACE_BOILERPLATE(method); \
378 MethodCall<C, r, t1, t2, t3, t4, t5> call(c(), &C::method, std::move(a1), \
379 std::move(a2), std::move(a3), \
380 std::move(a4), std::move(a5)); \
Danil Chapovalovcc903d92022-08-12 13:52:07 +0200381 return call.Marshal(primary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000382 }
nisse5b68ab52016-04-07 07:45:54 -0700383
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100384// Define methods which should be invoked on the secondary thread.
Danil Chapovalovcc903d92022-08-12 13:52:07 +0200385#define PROXY_SECONDARY_METHOD0(r, method) \
386 r method() override { \
387 TRACE_BOILERPLATE(method); \
388 MethodCall<C, r> call(c(), &C::method); \
389 return call.Marshal(secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000390 }
nisse5b68ab52016-04-07 07:45:54 -0700391
Danil Chapovalovcc903d92022-08-12 13:52:07 +0200392#define PROXY_SECONDARY_CONSTMETHOD0(r, method) \
393 r method() const override { \
394 TRACE_BOILERPLATE(method); \
395 ConstMethodCall<C, r> call(c(), &C::method); \
396 return call.Marshal(secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000397 }
perkj@webrtc.org81134d02015-01-12 08:30:16 +0000398
Niels Möller7f761572022-01-25 16:18:53 +0100399#define PROXY_SECONDARY_METHOD1(r, method, t1) \
400 r method(t1 a1) override { \
401 TRACE_BOILERPLATE(method); \
402 MethodCall<C, r, t1> call(c(), &C::method, std::move(a1)); \
Danil Chapovalovcc903d92022-08-12 13:52:07 +0200403 return call.Marshal(secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000404 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000405
Niels Möller7f761572022-01-25 16:18:53 +0100406#define PROXY_SECONDARY_CONSTMETHOD1(r, method, t1) \
407 r method(t1 a1) const override { \
408 TRACE_BOILERPLATE(method); \
409 ConstMethodCall<C, r, t1> call(c(), &C::method, std::move(a1)); \
Danil Chapovalovcc903d92022-08-12 13:52:07 +0200410 return call.Marshal(secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000411 }
deadbeefd99a2002017-01-18 08:55:23 -0800412
Niels Möller7f761572022-01-25 16:18:53 +0100413#define PROXY_SECONDARY_METHOD2(r, method, t1, t2) \
414 r method(t1 a1, t2 a2) override { \
415 TRACE_BOILERPLATE(method); \
416 MethodCall<C, r, t1, t2> call(c(), &C::method, std::move(a1), \
417 std::move(a2)); \
Danil Chapovalovcc903d92022-08-12 13:52:07 +0200418 return call.Marshal(secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000419 }
deadbeefd99a2002017-01-18 08:55:23 -0800420
Niels Möller7f761572022-01-25 16:18:53 +0100421#define PROXY_SECONDARY_CONSTMETHOD2(r, method, t1, t2) \
422 r method(t1 a1, t2 a2) const override { \
423 TRACE_BOILERPLATE(method); \
424 ConstMethodCall<C, r, t1, t2> call(c(), &C::method, std::move(a1), \
425 std::move(a2)); \
Danil Chapovalovcc903d92022-08-12 13:52:07 +0200426 return call.Marshal(secondary_thread_); \
Niels Möller7f761572022-01-25 16:18:53 +0100427 }
428
429#define PROXY_SECONDARY_METHOD3(r, method, t1, t2, t3) \
430 r method(t1 a1, t2 a2, t3 a3) override { \
Markus Handell3d46d0b2021-05-27 21:42:57 +0200431 TRACE_BOILERPLATE(method); \
Niels Möller7f761572022-01-25 16:18:53 +0100432 MethodCall<C, r, t1, t2, t3> call(c(), &C::method, std::move(a1), \
433 std::move(a2), std::move(a3)); \
Danil Chapovalovcc903d92022-08-12 13:52:07 +0200434 return call.Marshal(secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000435 }
deadbeefe814a0d2017-02-25 18:15:09 -0800436
Niels Möller7f761572022-01-25 16:18:53 +0100437#define PROXY_SECONDARY_CONSTMETHOD3(r, method, t1, t2) \
438 r method(t1 a1, t2 a2, t3 a3) const override { \
439 TRACE_BOILERPLATE(method); \
440 ConstMethodCall<C, r, t1, t2, t3> call(c(), &C::method, std::move(a1), \
441 std::move(a2), std::move(a3)); \
Danil Chapovalovcc903d92022-08-12 13:52:07 +0200442 return call.Marshal(secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000443 }
deadbeefd99a2002017-01-18 08:55:23 -0800444
Tomas Gunnarsson0ca13d92020-06-10 12:17:50 +0200445// For use when returning purely const state (set during construction).
446// Use with caution. This method should only be used when the return value will
447// always be the same.
Markus Handell3d46d0b2021-05-27 21:42:57 +0200448#define BYPASS_PROXY_CONSTMETHOD0(r, method) \
449 r method() const override { \
450 TRACE_BOILERPLATE(method); \
451 return c_->method(); \
Tomas Gunnarsson0ca13d92020-06-10 12:17:50 +0200452 }
453
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000454} // namespace webrtc
455
Markus Handella1b82012021-05-26 18:56:30 +0200456#endif // PC_PROXY_H_