blob: 89a7f511509b54f13074eaa7c5da929ba21974d6 [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//
henrike@webrtc.org28e20752013-07-10 00:45:36 +000056
Markus Handella1b82012021-05-26 18:56:30 +020057#ifndef PC_PROXY_H_
58#define PC_PROXY_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000059
Harald Alvestrandc24a2182022-02-23 13:44:59 +000060#include <stddef.h>
61
kwibergd1fe2812016-04-27 06:47:29 -070062#include <memory>
Yves Gerey3e707812018-11-28 16:47:49 +010063#include <string>
Steve Antonc3639822019-11-26 15:27:50 -080064#include <tuple>
Tomas Gunnarsson0ca13d92020-06-10 12:17:50 +020065#include <type_traits>
oprypin803dc292017-02-01 01:55:59 -080066#include <utility>
kwibergd1fe2812016-04-27 06:47:29 -070067
Mirko Bonadeid9708072019-01-25 20:26:48 +010068#include "api/scoped_refptr.h"
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +020069#include "api/task_queue/queued_task.h"
70#include "api/task_queue/task_queue_base.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020071#include "rtc_base/event.h"
Harald Alvestrandc24a2182022-02-23 13:44:59 +000072#include "rtc_base/location.h"
Steve Anton10542f22019-01-11 09:11:00 -080073#include "rtc_base/message_handler.h"
Markus Handell3d46d0b2021-05-27 21:42:57 +020074#include "rtc_base/string_utils.h"
Mirko Bonadei35214fc2019-09-23 14:54:28 +020075#include "rtc_base/system/rtc_export.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020076#include "rtc_base/thread.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077
Markus Handell3d46d0b2021-05-27 21:42:57 +020078#if !defined(RTC_DISABLE_PROXY_TRACE_EVENTS) && !defined(WEBRTC_CHROMIUM_BUILD)
79#define RTC_DISABLE_PROXY_TRACE_EVENTS
80#endif
81
Yves Gerey3e707812018-11-28 16:47:49 +010082namespace rtc {
83class Location;
84}
85
henrike@webrtc.org28e20752013-07-10 00:45:36 +000086namespace webrtc {
Tommi1cb796f2021-05-21 08:50:09 +020087namespace proxy_internal {
Markus Handell3d46d0b2021-05-27 21:42:57 +020088
89// Class for tracing the lifetime of MethodCall::Marshal.
90class ScopedTrace {
91 public:
92 explicit ScopedTrace(const char* class_and_method_name);
93 ~ScopedTrace();
94
95 private:
Johannes Kron8d1e4fb2022-05-10 15:05:28 +020096 [[maybe_unused]] const char* const class_and_method_name_;
Markus Handell3d46d0b2021-05-27 21:42:57 +020097};
Tommi1cb796f2021-05-21 08:50:09 +020098} // namespace proxy_internal
henrike@webrtc.org28e20752013-07-10 00:45:36 +000099
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000100template <typename R>
101class ReturnType {
102 public:
103 template <typename C, typename M, typename... Args>
104 void Invoke(C* c, M m, Args&&... args) {
105 r_ = (c->*m)(std::forward<Args>(args)...);
106 }
107
108 R moved_result() { return std::move(r_); }
109
110 private:
111 R r_;
112};
113
114template <>
115class ReturnType<void> {
116 public:
117 template <typename C, typename M, typename... Args>
118 void Invoke(C* c, M m, Args&&... args) {
119 (c->*m)(std::forward<Args>(args)...);
120 }
121
122 void moved_result() {}
123};
124
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000125template <typename C, typename R, typename... Args>
Danil Chapovalova30439b2022-07-07 10:08:49 +0200126class MethodCall {
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000127 public:
128 typedef R (C::*Method)(Args...);
129 MethodCall(C* c, Method m, Args&&... args)
130 : c_(c),
131 m_(m),
132 args_(std::forward_as_tuple(std::forward<Args>(args)...)) {}
133
134 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200135 if (t->IsCurrent()) {
136 Invoke(std::index_sequence_for<Args...>());
137 } else {
Danil Chapovalova30439b2022-07-07 10:08:49 +0200138 t->PostTask([this] {
139 Invoke(std::index_sequence_for<Args...>());
140 event_.Set();
141 });
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200142 event_.Wait(rtc::Event::kForever);
143 }
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000144 return r_.moved_result();
145 }
146
147 private:
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000148 template <size_t... Is>
149 void Invoke(std::index_sequence<Is...>) {
150 r_.Invoke(c_, m_, std::move(std::get<Is>(args_))...);
151 }
152
153 C* c_;
154 Method m_;
155 ReturnType<R> r_;
156 std::tuple<Args&&...> args_;
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200157 rtc::Event event_;
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000158};
159
160template <typename C, typename R, typename... Args>
Danil Chapovalova30439b2022-07-07 10:08:49 +0200161class ConstMethodCall {
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000162 public:
163 typedef R (C::*Method)(Args...) const;
164 ConstMethodCall(const C* c, Method m, Args&&... args)
165 : c_(c),
166 m_(m),
167 args_(std::forward_as_tuple(std::forward<Args>(args)...)) {}
168
169 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200170 if (t->IsCurrent()) {
171 Invoke(std::index_sequence_for<Args...>());
172 } else {
Danil Chapovalova30439b2022-07-07 10:08:49 +0200173 t->PostTask([this] {
174 Invoke(std::index_sequence_for<Args...>());
175 event_.Set();
176 });
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200177 event_.Wait(rtc::Event::kForever);
178 }
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000179 return r_.moved_result();
180 }
181
182 private:
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000183 template <size_t... Is>
184 void Invoke(std::index_sequence<Is...>) {
185 r_.Invoke(c_, m_, std::move(std::get<Is>(args_))...);
186 }
187
188 const C* c_;
189 Method m_;
190 ReturnType<R> r_;
191 std::tuple<Args&&...> args_;
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200192 rtc::Event event_;
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000193};
194
Tommi1cb796f2021-05-21 08:50:09 +0200195#define PROXY_STRINGIZE_IMPL(x) #x
196#define PROXY_STRINGIZE(x) PROXY_STRINGIZE_IMPL(x)
197
deadbeefd99a2002017-01-18 08:55:23 -0800198// Helper macros to reduce code duplication.
Niels Möller7f761572022-01-25 16:18:53 +0100199#define PROXY_MAP_BOILERPLATE(class_name) \
200 template <class INTERNAL_CLASS> \
201 class class_name##ProxyWithInternal; \
202 typedef class_name##ProxyWithInternal<class_name##Interface> \
203 class_name##Proxy; \
204 template <class INTERNAL_CLASS> \
205 class class_name##ProxyWithInternal : public class_name##Interface { \
206 protected: \
207 static constexpr char proxy_name_[] = #class_name "Proxy"; \
208 typedef class_name##Interface C; \
209 \
210 public: \
211 const INTERNAL_CLASS* internal() const { return c(); } \
212 INTERNAL_CLASS* internal() { return c(); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000213
Yves Gerey665174f2018-06-19 15:03:05 +0200214// clang-format off
215// clang-format would put the semicolon alone,
216// leading to a presubmit error (cpplint.py)
Niels Möller7f761572022-01-25 16:18:53 +0100217#define END_PROXY_MAP(class_name) \
218 }; \
219 template <class INTERNAL_CLASS> \
220 constexpr char class_name##ProxyWithInternal<INTERNAL_CLASS>::proxy_name_[];
Yves Gerey665174f2018-06-19 15:03:05 +0200221// clang-format on
oprypin803dc292017-02-01 01:55:59 -0800222
Tomas Gunnarsson0d5ce622022-03-18 15:57:15 +0100223#define PRIMARY_PROXY_MAP_BOILERPLATE(class_name) \
224 protected: \
225 class_name##ProxyWithInternal(rtc::Thread* primary_thread, \
226 rtc::scoped_refptr<INTERNAL_CLASS> c) \
227 : primary_thread_(primary_thread), c_(std::move(c)) {} \
228 \
229 private: \
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100230 mutable rtc::Thread* primary_thread_;
231
Tomas Gunnarsson0d5ce622022-03-18 15:57:15 +0100232#define SECONDARY_PROXY_MAP_BOILERPLATE(class_name) \
233 protected: \
234 class_name##ProxyWithInternal(rtc::Thread* primary_thread, \
235 rtc::Thread* secondary_thread, \
236 rtc::scoped_refptr<INTERNAL_CLASS> c) \
237 : primary_thread_(primary_thread), \
238 secondary_thread_(secondary_thread), \
239 c_(std::move(c)) {} \
240 \
241 private: \
242 mutable rtc::Thread* primary_thread_; \
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100243 mutable rtc::Thread* secondary_thread_;
deadbeefd99a2002017-01-18 08:55:23 -0800244
245// Note that the destructor is protected so that the proxy can only be
246// destroyed via RefCountInterface.
Niels Möller7f761572022-01-25 16:18:53 +0100247#define REFCOUNTED_PROXY_MAP_BOILERPLATE(class_name) \
248 protected: \
249 ~class_name##ProxyWithInternal() { \
250 MethodCall<class_name##ProxyWithInternal, void> call( \
251 this, &class_name##ProxyWithInternal::DestroyInternal); \
252 call.Marshal(RTC_FROM_HERE, destructor_thread()); \
253 } \
254 \
255 private: \
256 const INTERNAL_CLASS* c() const { return c_.get(); } \
257 INTERNAL_CLASS* c() { return c_.get(); } \
258 void DestroyInternal() { c_ = nullptr; } \
deadbeefd99a2002017-01-18 08:55:23 -0800259 rtc::scoped_refptr<INTERNAL_CLASS> c_;
260
deadbeefe814a0d2017-02-25 18:15:09 -0800261// Note: This doesn't use a unique_ptr, because it intends to handle a corner
262// case where an object's deletion triggers a callback that calls back into
263// this proxy object. If relying on a unique_ptr to delete the object, its
264// inner pointer would be set to null before this reentrant callback would have
265// a chance to run, resulting in a segfault.
Niels Möller7f761572022-01-25 16:18:53 +0100266#define OWNED_PROXY_MAP_BOILERPLATE(class_name) \
267 public: \
268 ~class_name##ProxyWithInternal() { \
269 MethodCall<class_name##ProxyWithInternal, void> call( \
270 this, &class_name##ProxyWithInternal::DestroyInternal); \
271 call.Marshal(RTC_FROM_HERE, destructor_thread()); \
272 } \
273 \
274 private: \
275 const INTERNAL_CLASS* c() const { return c_; } \
276 INTERNAL_CLASS* c() { return c_; } \
277 void DestroyInternal() { delete c_; } \
deadbeefe814a0d2017-02-25 18:15:09 -0800278 INTERNAL_CLASS* c_;
deadbeefd99a2002017-01-18 08:55:23 -0800279
Tomas Gunnarsson0d5ce622022-03-18 15:57:15 +0100280#define BEGIN_PRIMARY_PROXY_MAP(class_name) \
281 PROXY_MAP_BOILERPLATE(class_name) \
282 PRIMARY_PROXY_MAP_BOILERPLATE(class_name) \
283 REFCOUNTED_PROXY_MAP_BOILERPLATE(class_name) \
284 public: \
285 static rtc::scoped_refptr<class_name##ProxyWithInternal> Create( \
286 rtc::Thread* primary_thread, rtc::scoped_refptr<INTERNAL_CLASS> c) { \
287 return rtc::make_ref_counted<class_name##ProxyWithInternal>( \
288 primary_thread, std::move(c)); \
Niels Möller7f761572022-01-25 16:18:53 +0100289 }
290
291#define BEGIN_PROXY_MAP(class_name) \
292 PROXY_MAP_BOILERPLATE(class_name) \
293 SECONDARY_PROXY_MAP_BOILERPLATE(class_name) \
294 REFCOUNTED_PROXY_MAP_BOILERPLATE(class_name) \
295 public: \
296 static rtc::scoped_refptr<class_name##ProxyWithInternal> Create( \
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100297 rtc::Thread* primary_thread, rtc::Thread* secondary_thread, \
Tomas Gunnarsson0d5ce622022-03-18 15:57:15 +0100298 rtc::scoped_refptr<INTERNAL_CLASS> c) { \
Niels Möller7f761572022-01-25 16:18:53 +0100299 return rtc::make_ref_counted<class_name##ProxyWithInternal>( \
Tomas Gunnarsson0d5ce622022-03-18 15:57:15 +0100300 primary_thread, secondary_thread, std::move(c)); \
Niels Möller7f761572022-01-25 16:18:53 +0100301 }
302
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100303#define PROXY_PRIMARY_THREAD_DESTRUCTOR() \
304 private: \
305 rtc::Thread* destructor_thread() const { return primary_thread_; } \
306 \
307 public: // NOLINTNEXTLINE
308
309#define PROXY_SECONDARY_THREAD_DESTRUCTOR() \
deadbeefd99a2002017-01-18 08:55:23 -0800310 private: \
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100311 rtc::Thread* destructor_thread() const { return secondary_thread_; } \
deadbeefd99a2002017-01-18 08:55:23 -0800312 \
oprypin803dc292017-02-01 01:55:59 -0800313 public: // NOLINTNEXTLINE
deadbeefd99a2002017-01-18 08:55:23 -0800314
Markus Handell3d46d0b2021-05-27 21:42:57 +0200315#if defined(RTC_DISABLE_PROXY_TRACE_EVENTS)
316#define TRACE_BOILERPLATE(method) \
317 do { \
318 } while (0)
319#else // if defined(RTC_DISABLE_PROXY_TRACE_EVENTS)
320#define TRACE_BOILERPLATE(method) \
321 static constexpr auto class_and_method_name = \
322 rtc::MakeCompileTimeString(proxy_name_) \
323 .Concat(rtc::MakeCompileTimeString("::")) \
324 .Concat(rtc::MakeCompileTimeString(#method)); \
325 proxy_internal::ScopedTrace scoped_trace(class_and_method_name.string)
326
327#endif // if defined(RTC_DISABLE_PROXY_TRACE_EVENTS)
328
329#define PROXY_METHOD0(r, method) \
330 r method() override { \
331 TRACE_BOILERPLATE(method); \
Niels Möller7f761572022-01-25 16:18:53 +0100332 MethodCall<C, r> call(c(), &C::method); \
Markus Handell3d46d0b2021-05-27 21:42:57 +0200333 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000334 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000335
Markus Handell3d46d0b2021-05-27 21:42:57 +0200336#define PROXY_CONSTMETHOD0(r, method) \
337 r method() const override { \
338 TRACE_BOILERPLATE(method); \
Niels Möller7f761572022-01-25 16:18:53 +0100339 ConstMethodCall<C, r> call(c(), &C::method); \
Markus Handell3d46d0b2021-05-27 21:42:57 +0200340 return call.Marshal(RTC_FROM_HERE, 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_METHOD1(r, method, t1) \
344 r method(t1 a1) override { \
345 TRACE_BOILERPLATE(method); \
346 MethodCall<C, r, t1> call(c(), &C::method, std::move(a1)); \
347 return call.Marshal(RTC_FROM_HERE, 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_CONSTMETHOD1(r, method, t1) \
351 r method(t1 a1) const override { \
352 TRACE_BOILERPLATE(method); \
353 ConstMethodCall<C, r, t1> call(c(), &C::method, std::move(a1)); \
354 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000355 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000356
Niels Möller7f761572022-01-25 16:18:53 +0100357#define PROXY_METHOD2(r, method, t1, t2) \
358 r method(t1 a1, t2 a2) override { \
359 TRACE_BOILERPLATE(method); \
360 MethodCall<C, r, t1, t2> call(c(), &C::method, std::move(a1), \
361 std::move(a2)); \
362 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000363 }
perkj@webrtc.org81134d02015-01-12 08:30:16 +0000364
Niels Möller7f761572022-01-25 16:18:53 +0100365#define PROXY_METHOD3(r, method, t1, t2, t3) \
366 r method(t1 a1, t2 a2, t3 a3) override { \
367 TRACE_BOILERPLATE(method); \
368 MethodCall<C, r, t1, t2, t3> call(c(), &C::method, std::move(a1), \
369 std::move(a2), std::move(a3)); \
370 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
deadbeefd99a2002017-01-18 08:55:23 -0800371 }
372
Niels Möller7f761572022-01-25 16:18:53 +0100373#define PROXY_METHOD4(r, method, t1, t2, t3, t4) \
374 r method(t1 a1, t2 a2, t3 a3, t4 a4) override { \
375 TRACE_BOILERPLATE(method); \
376 MethodCall<C, r, t1, t2, t3, t4> call(c(), &C::method, std::move(a1), \
377 std::move(a2), std::move(a3), \
378 std::move(a4)); \
379 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000380 }
deadbeefd99a2002017-01-18 08:55:23 -0800381
Niels Möller7f761572022-01-25 16:18:53 +0100382#define PROXY_METHOD5(r, method, t1, t2, t3, t4, t5) \
383 r method(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) override { \
384 TRACE_BOILERPLATE(method); \
385 MethodCall<C, r, t1, t2, t3, t4, t5> call(c(), &C::method, std::move(a1), \
386 std::move(a2), std::move(a3), \
387 std::move(a4), std::move(a5)); \
388 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000389 }
nisse5b68ab52016-04-07 07:45:54 -0700390
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100391// Define methods which should be invoked on the secondary thread.
Markus Handell3d46d0b2021-05-27 21:42:57 +0200392#define PROXY_SECONDARY_METHOD0(r, method) \
393 r method() override { \
394 TRACE_BOILERPLATE(method); \
Niels Möller7f761572022-01-25 16:18:53 +0100395 MethodCall<C, r> call(c(), &C::method); \
Markus Handell3d46d0b2021-05-27 21:42:57 +0200396 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000397 }
nisse5b68ab52016-04-07 07:45:54 -0700398
Markus Handell3d46d0b2021-05-27 21:42:57 +0200399#define PROXY_SECONDARY_CONSTMETHOD0(r, method) \
400 r method() const override { \
401 TRACE_BOILERPLATE(method); \
Niels Möller7f761572022-01-25 16:18:53 +0100402 ConstMethodCall<C, r> call(c(), &C::method); \
Markus Handell3d46d0b2021-05-27 21:42:57 +0200403 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000404 }
perkj@webrtc.org81134d02015-01-12 08:30:16 +0000405
Niels Möller7f761572022-01-25 16:18:53 +0100406#define PROXY_SECONDARY_METHOD1(r, method, t1) \
407 r method(t1 a1) override { \
408 TRACE_BOILERPLATE(method); \
409 MethodCall<C, r, t1> call(c(), &C::method, std::move(a1)); \
410 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000411 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000412
Niels Möller7f761572022-01-25 16:18:53 +0100413#define PROXY_SECONDARY_CONSTMETHOD1(r, method, t1) \
414 r method(t1 a1) const override { \
415 TRACE_BOILERPLATE(method); \
416 ConstMethodCall<C, r, t1> call(c(), &C::method, std::move(a1)); \
417 return call.Marshal(RTC_FROM_HERE, 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_METHOD2(r, method, t1, t2) \
421 r method(t1 a1, t2 a2) override { \
422 TRACE_BOILERPLATE(method); \
423 MethodCall<C, r, t1, t2> call(c(), &C::method, std::move(a1), \
424 std::move(a2)); \
425 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000426 }
deadbeefd99a2002017-01-18 08:55:23 -0800427
Niels Möller7f761572022-01-25 16:18:53 +0100428#define PROXY_SECONDARY_CONSTMETHOD2(r, method, t1, t2) \
429 r method(t1 a1, t2 a2) const override { \
430 TRACE_BOILERPLATE(method); \
431 ConstMethodCall<C, r, t1, t2> call(c(), &C::method, std::move(a1), \
432 std::move(a2)); \
433 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
434 }
435
436#define PROXY_SECONDARY_METHOD3(r, method, t1, t2, t3) \
437 r method(t1 a1, t2 a2, t3 a3) override { \
Markus Handell3d46d0b2021-05-27 21:42:57 +0200438 TRACE_BOILERPLATE(method); \
Niels Möller7f761572022-01-25 16:18:53 +0100439 MethodCall<C, r, t1, t2, t3> call(c(), &C::method, std::move(a1), \
440 std::move(a2), std::move(a3)); \
Markus Handell3d46d0b2021-05-27 21:42:57 +0200441 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000442 }
deadbeefe814a0d2017-02-25 18:15:09 -0800443
Niels Möller7f761572022-01-25 16:18:53 +0100444#define PROXY_SECONDARY_CONSTMETHOD3(r, method, t1, t2) \
445 r method(t1 a1, t2 a2, t3 a3) const override { \
446 TRACE_BOILERPLATE(method); \
447 ConstMethodCall<C, r, t1, t2, t3> call(c(), &C::method, std::move(a1), \
448 std::move(a2), std::move(a3)); \
449 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000450 }
deadbeefd99a2002017-01-18 08:55:23 -0800451
Tomas Gunnarsson0ca13d92020-06-10 12:17:50 +0200452// For use when returning purely const state (set during construction).
453// Use with caution. This method should only be used when the return value will
454// always be the same.
Markus Handell3d46d0b2021-05-27 21:42:57 +0200455#define BYPASS_PROXY_CONSTMETHOD0(r, method) \
456 r method() const override { \
457 TRACE_BOILERPLATE(method); \
458 return c_->method(); \
Tomas Gunnarsson0ca13d92020-06-10 12:17:50 +0200459 }
460
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000461} // namespace webrtc
462
Markus Handella1b82012021-05-26 18:56:30 +0200463#endif // PC_PROXY_H_