blob: e48f479183d54c37f441542de226da8a1feae727 [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.
deadbeefb10f32f2017-02-08 01:38:21 -080013// TODO(deadbeef): Move this to pc/; this is part of the implementation.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000014
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +010015// The proxied objects are initialized with either one or two thread
16// objects that operations can be proxied to: The primary and secondary
17// threads.
18// In common usage, the primary thread will be the PeerConnection's
19// signaling thread, and the secondary thread will be either the
20// PeerConnection's worker thread or the PeerConnection's network thread.
21
henrike@webrtc.org28e20752013-07-10 00:45:36 +000022//
23// Example usage:
24//
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000025// class TestInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000026// public:
27// std::string FooA() = 0;
28// std::string FooB(bool arg1) const = 0;
nisse72c8d2b2016-04-15 03:49:07 -070029// std::string FooC(bool arg1) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000030// };
31//
32// Note that return types can not be a const reference.
33//
34// class Test : public TestInterface {
35// ... implementation of the interface.
36// };
37//
38// BEGIN_PROXY_MAP(Test)
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +010039// PROXY_PRIMARY_THREAD_DESTRUCTOR()
henrike@webrtc.org28e20752013-07-10 00:45:36 +000040// PROXY_METHOD0(std::string, FooA)
41// PROXY_CONSTMETHOD1(std::string, FooB, arg1)
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +010042// PROXY_SECONDARY_METHOD1(std::string, FooC, arg1)
deadbeefd99a2002017-01-18 08:55:23 -080043// END_PROXY_MAP()
henrike@webrtc.org28e20752013-07-10 00:45:36 +000044//
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +010045// Where the destructor and first two methods are invoked on the primary
46// thread, and the third is invoked on the secondary thread.
nisse72c8d2b2016-04-15 03:49:07 -070047//
48// The proxy can be created using
49//
50// TestProxy::Create(Thread* signaling_thread, Thread* worker_thread,
51// TestInterface*).
52//
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +010053// The variant defined with BEGIN_PRIMARY_PROXY_MAP is unaware of
54// the secondary thread, and invokes all methods on the primary thread.
deadbeefd99a2002017-01-18 08:55:23 -080055//
56// The variant defined with BEGIN_OWNED_PROXY_MAP does not use
57// refcounting, and instead just takes ownership of the object being proxied.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000058
Markus Handella1b82012021-05-26 18:56:30 +020059#ifndef PC_PROXY_H_
60#define PC_PROXY_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061
Harald Alvestrandc24a2182022-02-23 13:44:59 +000062#include <stddef.h>
63
kwibergd1fe2812016-04-27 06:47:29 -070064#include <memory>
Yves Gerey3e707812018-11-28 16:47:49 +010065#include <string>
Steve Antonc3639822019-11-26 15:27:50 -080066#include <tuple>
Tomas Gunnarsson0ca13d92020-06-10 12:17:50 +020067#include <type_traits>
oprypin803dc292017-02-01 01:55:59 -080068#include <utility>
kwibergd1fe2812016-04-27 06:47:29 -070069
Mirko Bonadeid9708072019-01-25 20:26:48 +010070#include "api/scoped_refptr.h"
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +020071#include "api/task_queue/queued_task.h"
72#include "api/task_queue/task_queue_base.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020073#include "rtc_base/event.h"
Harald Alvestrandc24a2182022-02-23 13:44:59 +000074#include "rtc_base/location.h"
Steve Anton10542f22019-01-11 09:11:00 -080075#include "rtc_base/message_handler.h"
Steve Anton10542f22019-01-11 09:11:00 -080076#include "rtc_base/ref_counted_object.h"
Markus Handell3d46d0b2021-05-27 21:42:57 +020077#include "rtc_base/string_utils.h"
Mirko Bonadei35214fc2019-09-23 14:54:28 +020078#include "rtc_base/system/rtc_export.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020079#include "rtc_base/thread.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000080
Markus Handell3d46d0b2021-05-27 21:42:57 +020081#if !defined(RTC_DISABLE_PROXY_TRACE_EVENTS) && !defined(WEBRTC_CHROMIUM_BUILD)
82#define RTC_DISABLE_PROXY_TRACE_EVENTS
83#endif
84
Yves Gerey3e707812018-11-28 16:47:49 +010085namespace rtc {
86class Location;
87}
88
henrike@webrtc.org28e20752013-07-10 00:45:36 +000089namespace webrtc {
Tommi1cb796f2021-05-21 08:50:09 +020090namespace proxy_internal {
Markus Handell3d46d0b2021-05-27 21:42:57 +020091
92// Class for tracing the lifetime of MethodCall::Marshal.
93class ScopedTrace {
94 public:
95 explicit ScopedTrace(const char* class_and_method_name);
96 ~ScopedTrace();
97
98 private:
99 const char* const class_and_method_name_;
100};
Tommi1cb796f2021-05-21 08:50:09 +0200101} // namespace proxy_internal
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000102
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000103template <typename R>
104class ReturnType {
105 public:
106 template <typename C, typename M, typename... Args>
107 void Invoke(C* c, M m, Args&&... args) {
108 r_ = (c->*m)(std::forward<Args>(args)...);
109 }
110
111 R moved_result() { return std::move(r_); }
112
113 private:
114 R r_;
115};
116
117template <>
118class ReturnType<void> {
119 public:
120 template <typename C, typename M, typename... Args>
121 void Invoke(C* c, M m, Args&&... args) {
122 (c->*m)(std::forward<Args>(args)...);
123 }
124
125 void moved_result() {}
126};
127
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000128template <typename C, typename R, typename... Args>
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200129class MethodCall : public QueuedTask {
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000130 public:
131 typedef R (C::*Method)(Args...);
132 MethodCall(C* c, Method m, Args&&... args)
133 : c_(c),
134 m_(m),
135 args_(std::forward_as_tuple(std::forward<Args>(args)...)) {}
136
137 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200138 if (t->IsCurrent()) {
139 Invoke(std::index_sequence_for<Args...>());
140 } else {
141 t->PostTask(std::unique_ptr<QueuedTask>(this));
142 event_.Wait(rtc::Event::kForever);
143 }
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000144 return r_.moved_result();
145 }
146
147 private:
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200148 bool Run() override {
149 Invoke(std::index_sequence_for<Args...>());
150 event_.Set();
151 return false;
152 }
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000153
154 template <size_t... Is>
155 void Invoke(std::index_sequence<Is...>) {
156 r_.Invoke(c_, m_, std::move(std::get<Is>(args_))...);
157 }
158
159 C* c_;
160 Method m_;
161 ReturnType<R> r_;
162 std::tuple<Args&&...> args_;
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200163 rtc::Event event_;
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000164};
165
166template <typename C, typename R, typename... Args>
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200167class ConstMethodCall : public QueuedTask {
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000168 public:
169 typedef R (C::*Method)(Args...) const;
170 ConstMethodCall(const C* c, Method m, Args&&... args)
171 : c_(c),
172 m_(m),
173 args_(std::forward_as_tuple(std::forward<Args>(args)...)) {}
174
175 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200176 if (t->IsCurrent()) {
177 Invoke(std::index_sequence_for<Args...>());
178 } else {
179 t->PostTask(std::unique_ptr<QueuedTask>(this));
180 event_.Wait(rtc::Event::kForever);
181 }
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000182 return r_.moved_result();
183 }
184
185 private:
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200186 bool Run() override {
187 Invoke(std::index_sequence_for<Args...>());
188 event_.Set();
189 return false;
190 }
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000191
192 template <size_t... Is>
193 void Invoke(std::index_sequence<Is...>) {
194 r_.Invoke(c_, m_, std::move(std::get<Is>(args_))...);
195 }
196
197 const C* c_;
198 Method m_;
199 ReturnType<R> r_;
200 std::tuple<Args&&...> args_;
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200201 rtc::Event event_;
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000202};
203
Tommi1cb796f2021-05-21 08:50:09 +0200204#define PROXY_STRINGIZE_IMPL(x) #x
205#define PROXY_STRINGIZE(x) PROXY_STRINGIZE_IMPL(x)
206
deadbeefd99a2002017-01-18 08:55:23 -0800207// Helper macros to reduce code duplication.
Niels Möller7f761572022-01-25 16:18:53 +0100208#define PROXY_MAP_BOILERPLATE(class_name) \
209 template <class INTERNAL_CLASS> \
210 class class_name##ProxyWithInternal; \
211 typedef class_name##ProxyWithInternal<class_name##Interface> \
212 class_name##Proxy; \
213 template <class INTERNAL_CLASS> \
214 class class_name##ProxyWithInternal : public class_name##Interface { \
215 protected: \
216 static constexpr char proxy_name_[] = #class_name "Proxy"; \
217 typedef class_name##Interface C; \
218 \
219 public: \
220 const INTERNAL_CLASS* internal() const { return c(); } \
221 INTERNAL_CLASS* internal() { return c(); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000222
Yves Gerey665174f2018-06-19 15:03:05 +0200223// clang-format off
224// clang-format would put the semicolon alone,
225// leading to a presubmit error (cpplint.py)
Niels Möller7f761572022-01-25 16:18:53 +0100226#define END_PROXY_MAP(class_name) \
227 }; \
228 template <class INTERNAL_CLASS> \
229 constexpr char class_name##ProxyWithInternal<INTERNAL_CLASS>::proxy_name_[];
Yves Gerey665174f2018-06-19 15:03:05 +0200230// clang-format on
oprypin803dc292017-02-01 01:55:59 -0800231
Niels Möller7f761572022-01-25 16:18:53 +0100232#define PRIMARY_PROXY_MAP_BOILERPLATE(class_name) \
233 protected: \
234 class_name##ProxyWithInternal(rtc::Thread* primary_thread, \
235 INTERNAL_CLASS* c) \
236 : primary_thread_(primary_thread), c_(c) {} \
237 \
238 private: \
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100239 mutable rtc::Thread* primary_thread_;
240
Niels Möller7f761572022-01-25 16:18:53 +0100241#define SECONDARY_PROXY_MAP_BOILERPLATE(class_name) \
242 protected: \
243 class_name##ProxyWithInternal(rtc::Thread* primary_thread, \
244 rtc::Thread* secondary_thread, \
245 INTERNAL_CLASS* c) \
246 : primary_thread_(primary_thread), \
247 secondary_thread_(secondary_thread), \
248 c_(c) {} \
249 \
250 private: \
251 mutable rtc::Thread* primary_thread_; \
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100252 mutable rtc::Thread* secondary_thread_;
deadbeefd99a2002017-01-18 08:55:23 -0800253
254// Note that the destructor is protected so that the proxy can only be
255// destroyed via RefCountInterface.
Niels Möller7f761572022-01-25 16:18:53 +0100256#define REFCOUNTED_PROXY_MAP_BOILERPLATE(class_name) \
257 protected: \
258 ~class_name##ProxyWithInternal() { \
259 MethodCall<class_name##ProxyWithInternal, void> call( \
260 this, &class_name##ProxyWithInternal::DestroyInternal); \
261 call.Marshal(RTC_FROM_HERE, destructor_thread()); \
262 } \
263 \
264 private: \
265 const INTERNAL_CLASS* c() const { return c_.get(); } \
266 INTERNAL_CLASS* c() { return c_.get(); } \
267 void DestroyInternal() { c_ = nullptr; } \
deadbeefd99a2002017-01-18 08:55:23 -0800268 rtc::scoped_refptr<INTERNAL_CLASS> c_;
269
deadbeefe814a0d2017-02-25 18:15:09 -0800270// Note: This doesn't use a unique_ptr, because it intends to handle a corner
271// case where an object's deletion triggers a callback that calls back into
272// this proxy object. If relying on a unique_ptr to delete the object, its
273// inner pointer would be set to null before this reentrant callback would have
274// a chance to run, resulting in a segfault.
Niels Möller7f761572022-01-25 16:18:53 +0100275#define OWNED_PROXY_MAP_BOILERPLATE(class_name) \
276 public: \
277 ~class_name##ProxyWithInternal() { \
278 MethodCall<class_name##ProxyWithInternal, void> call( \
279 this, &class_name##ProxyWithInternal::DestroyInternal); \
280 call.Marshal(RTC_FROM_HERE, destructor_thread()); \
281 } \
282 \
283 private: \
284 const INTERNAL_CLASS* c() const { return c_; } \
285 INTERNAL_CLASS* c() { return c_; } \
286 void DestroyInternal() { delete c_; } \
deadbeefe814a0d2017-02-25 18:15:09 -0800287 INTERNAL_CLASS* c_;
deadbeefd99a2002017-01-18 08:55:23 -0800288
Niels Möller7f761572022-01-25 16:18:53 +0100289#define BEGIN_PRIMARY_PROXY_MAP(class_name) \
290 PROXY_MAP_BOILERPLATE(class_name) \
291 PRIMARY_PROXY_MAP_BOILERPLATE(class_name) \
292 REFCOUNTED_PROXY_MAP_BOILERPLATE(class_name) \
deadbeefe814a0d2017-02-25 18:15:09 -0800293 public: \
Niels Möller7f761572022-01-25 16:18:53 +0100294 static rtc::scoped_refptr<class_name##ProxyWithInternal> Create( \
295 rtc::Thread* primary_thread, INTERNAL_CLASS* c) { \
296 return rtc::make_ref_counted<class_name##ProxyWithInternal>( \
297 primary_thread, c); \
298 }
299
300#define BEGIN_PROXY_MAP(class_name) \
301 PROXY_MAP_BOILERPLATE(class_name) \
302 SECONDARY_PROXY_MAP_BOILERPLATE(class_name) \
303 REFCOUNTED_PROXY_MAP_BOILERPLATE(class_name) \
304 public: \
305 static rtc::scoped_refptr<class_name##ProxyWithInternal> Create( \
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100306 rtc::Thread* primary_thread, rtc::Thread* secondary_thread, \
Niels Möller7f761572022-01-25 16:18:53 +0100307 INTERNAL_CLASS* c) { \
308 return rtc::make_ref_counted<class_name##ProxyWithInternal>( \
309 primary_thread, secondary_thread, c); \
310 }
311
312#define BEGIN_OWNED_PROXY_MAP(class_name) \
313 PROXY_MAP_BOILERPLATE(class_name) \
314 SECONDARY_PROXY_MAP_BOILERPLATE(class_name) \
315 OWNED_PROXY_MAP_BOILERPLATE(class_name) \
316 public: \
317 static std::unique_ptr<class_name##Interface> Create( \
318 rtc::Thread* primary_thread, rtc::Thread* secondary_thread, \
319 std::unique_ptr<INTERNAL_CLASS> c) { \
320 return std::unique_ptr<class_name##Interface>( \
321 new class_name##ProxyWithInternal(primary_thread, secondary_thread, \
322 c.release())); \
deadbeefd99a2002017-01-18 08:55:23 -0800323 }
324
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100325#define PROXY_PRIMARY_THREAD_DESTRUCTOR() \
326 private: \
327 rtc::Thread* destructor_thread() const { return primary_thread_; } \
328 \
329 public: // NOLINTNEXTLINE
330
331#define PROXY_SECONDARY_THREAD_DESTRUCTOR() \
deadbeefd99a2002017-01-18 08:55:23 -0800332 private: \
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100333 rtc::Thread* destructor_thread() const { return secondary_thread_; } \
deadbeefd99a2002017-01-18 08:55:23 -0800334 \
oprypin803dc292017-02-01 01:55:59 -0800335 public: // NOLINTNEXTLINE
deadbeefd99a2002017-01-18 08:55:23 -0800336
Markus Handell3d46d0b2021-05-27 21:42:57 +0200337#if defined(RTC_DISABLE_PROXY_TRACE_EVENTS)
338#define TRACE_BOILERPLATE(method) \
339 do { \
340 } while (0)
341#else // if defined(RTC_DISABLE_PROXY_TRACE_EVENTS)
342#define TRACE_BOILERPLATE(method) \
343 static constexpr auto class_and_method_name = \
344 rtc::MakeCompileTimeString(proxy_name_) \
345 .Concat(rtc::MakeCompileTimeString("::")) \
346 .Concat(rtc::MakeCompileTimeString(#method)); \
347 proxy_internal::ScopedTrace scoped_trace(class_and_method_name.string)
348
349#endif // if defined(RTC_DISABLE_PROXY_TRACE_EVENTS)
350
351#define PROXY_METHOD0(r, method) \
352 r method() override { \
353 TRACE_BOILERPLATE(method); \
Niels Möller7f761572022-01-25 16:18:53 +0100354 MethodCall<C, r> call(c(), &C::method); \
Markus Handell3d46d0b2021-05-27 21:42:57 +0200355 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000356 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000357
Markus Handell3d46d0b2021-05-27 21:42:57 +0200358#define PROXY_CONSTMETHOD0(r, method) \
359 r method() const override { \
360 TRACE_BOILERPLATE(method); \
Niels Möller7f761572022-01-25 16:18:53 +0100361 ConstMethodCall<C, r> call(c(), &C::method); \
Markus Handell3d46d0b2021-05-27 21:42:57 +0200362 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000363 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000364
Niels Möller7f761572022-01-25 16:18:53 +0100365#define PROXY_METHOD1(r, method, t1) \
366 r method(t1 a1) override { \
367 TRACE_BOILERPLATE(method); \
368 MethodCall<C, r, t1> call(c(), &C::method, std::move(a1)); \
369 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000370 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000371
Niels Möller7f761572022-01-25 16:18:53 +0100372#define PROXY_CONSTMETHOD1(r, method, t1) \
373 r method(t1 a1) const override { \
374 TRACE_BOILERPLATE(method); \
375 ConstMethodCall<C, r, t1> call(c(), &C::method, std::move(a1)); \
376 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000377 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000378
Niels Möller7f761572022-01-25 16:18:53 +0100379#define PROXY_METHOD2(r, method, t1, t2) \
380 r method(t1 a1, t2 a2) override { \
381 TRACE_BOILERPLATE(method); \
382 MethodCall<C, r, t1, t2> call(c(), &C::method, std::move(a1), \
383 std::move(a2)); \
384 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000385 }
perkj@webrtc.org81134d02015-01-12 08:30:16 +0000386
Niels Möller7f761572022-01-25 16:18:53 +0100387#define PROXY_METHOD3(r, method, t1, t2, t3) \
388 r method(t1 a1, t2 a2, t3 a3) override { \
389 TRACE_BOILERPLATE(method); \
390 MethodCall<C, r, t1, t2, t3> call(c(), &C::method, std::move(a1), \
391 std::move(a2), std::move(a3)); \
392 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
deadbeefd99a2002017-01-18 08:55:23 -0800393 }
394
Niels Möller7f761572022-01-25 16:18:53 +0100395#define PROXY_METHOD4(r, method, t1, t2, t3, t4) \
396 r method(t1 a1, t2 a2, t3 a3, t4 a4) override { \
397 TRACE_BOILERPLATE(method); \
398 MethodCall<C, r, t1, t2, t3, t4> call(c(), &C::method, std::move(a1), \
399 std::move(a2), std::move(a3), \
400 std::move(a4)); \
401 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000402 }
deadbeefd99a2002017-01-18 08:55:23 -0800403
Niels Möller7f761572022-01-25 16:18:53 +0100404#define PROXY_METHOD5(r, method, t1, t2, t3, t4, t5) \
405 r method(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) override { \
406 TRACE_BOILERPLATE(method); \
407 MethodCall<C, r, t1, t2, t3, t4, t5> call(c(), &C::method, std::move(a1), \
408 std::move(a2), std::move(a3), \
409 std::move(a4), std::move(a5)); \
410 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000411 }
nisse5b68ab52016-04-07 07:45:54 -0700412
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100413// Define methods which should be invoked on the secondary thread.
Markus Handell3d46d0b2021-05-27 21:42:57 +0200414#define PROXY_SECONDARY_METHOD0(r, method) \
415 r method() override { \
416 TRACE_BOILERPLATE(method); \
Niels Möller7f761572022-01-25 16:18:53 +0100417 MethodCall<C, r> call(c(), &C::method); \
Markus Handell3d46d0b2021-05-27 21:42:57 +0200418 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000419 }
nisse5b68ab52016-04-07 07:45:54 -0700420
Markus Handell3d46d0b2021-05-27 21:42:57 +0200421#define PROXY_SECONDARY_CONSTMETHOD0(r, method) \
422 r method() const override { \
423 TRACE_BOILERPLATE(method); \
Niels Möller7f761572022-01-25 16:18:53 +0100424 ConstMethodCall<C, r> call(c(), &C::method); \
Markus Handell3d46d0b2021-05-27 21:42:57 +0200425 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000426 }
perkj@webrtc.org81134d02015-01-12 08:30:16 +0000427
Niels Möller7f761572022-01-25 16:18:53 +0100428#define PROXY_SECONDARY_METHOD1(r, method, t1) \
429 r method(t1 a1) override { \
430 TRACE_BOILERPLATE(method); \
431 MethodCall<C, r, t1> call(c(), &C::method, std::move(a1)); \
432 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000433 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000434
Niels Möller7f761572022-01-25 16:18:53 +0100435#define PROXY_SECONDARY_CONSTMETHOD1(r, method, t1) \
436 r method(t1 a1) const override { \
437 TRACE_BOILERPLATE(method); \
438 ConstMethodCall<C, r, t1> call(c(), &C::method, std::move(a1)); \
439 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000440 }
deadbeefd99a2002017-01-18 08:55:23 -0800441
Niels Möller7f761572022-01-25 16:18:53 +0100442#define PROXY_SECONDARY_METHOD2(r, method, t1, t2) \
443 r method(t1 a1, t2 a2) override { \
444 TRACE_BOILERPLATE(method); \
445 MethodCall<C, r, t1, t2> call(c(), &C::method, std::move(a1), \
446 std::move(a2)); \
447 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000448 }
deadbeefd99a2002017-01-18 08:55:23 -0800449
Niels Möller7f761572022-01-25 16:18:53 +0100450#define PROXY_SECONDARY_CONSTMETHOD2(r, method, t1, t2) \
451 r method(t1 a1, t2 a2) const override { \
452 TRACE_BOILERPLATE(method); \
453 ConstMethodCall<C, r, t1, t2> call(c(), &C::method, std::move(a1), \
454 std::move(a2)); \
455 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
456 }
457
458#define PROXY_SECONDARY_METHOD3(r, method, t1, t2, t3) \
459 r method(t1 a1, t2 a2, t3 a3) override { \
Markus Handell3d46d0b2021-05-27 21:42:57 +0200460 TRACE_BOILERPLATE(method); \
Niels Möller7f761572022-01-25 16:18:53 +0100461 MethodCall<C, r, t1, t2, t3> call(c(), &C::method, std::move(a1), \
462 std::move(a2), std::move(a3)); \
Markus Handell3d46d0b2021-05-27 21:42:57 +0200463 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000464 }
deadbeefe814a0d2017-02-25 18:15:09 -0800465
Niels Möller7f761572022-01-25 16:18:53 +0100466#define PROXY_SECONDARY_CONSTMETHOD3(r, method, t1, t2) \
467 r method(t1 a1, t2 a2, t3 a3) const override { \
468 TRACE_BOILERPLATE(method); \
469 ConstMethodCall<C, r, t1, t2, t3> call(c(), &C::method, std::move(a1), \
470 std::move(a2), std::move(a3)); \
471 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000472 }
deadbeefd99a2002017-01-18 08:55:23 -0800473
Tomas Gunnarsson0ca13d92020-06-10 12:17:50 +0200474// For use when returning purely const state (set during construction).
475// Use with caution. This method should only be used when the return value will
476// always be the same.
Markus Handell3d46d0b2021-05-27 21:42:57 +0200477#define BYPASS_PROXY_CONSTMETHOD0(r, method) \
478 r method() const override { \
479 TRACE_BOILERPLATE(method); \
480 return c_->method(); \
Tomas Gunnarsson0ca13d92020-06-10 12:17:50 +0200481 }
482
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000483} // namespace webrtc
484
Markus Handella1b82012021-05-26 18:56:30 +0200485#endif // PC_PROXY_H_