blob: 3877a6fcc82711dd35c2e73756bf7dda73212ae7 [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/task_queue_base.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020070#include "rtc_base/event.h"
Harald Alvestrandc24a2182022-02-23 13:44:59 +000071#include "rtc_base/location.h"
Steve Anton10542f22019-01-11 09:11:00 -080072#include "rtc_base/message_handler.h"
Markus Handell3d46d0b2021-05-27 21:42:57 +020073#include "rtc_base/string_utils.h"
Mirko Bonadei35214fc2019-09-23 14:54:28 +020074#include "rtc_base/system/rtc_export.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020075#include "rtc_base/thread.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076
Markus Handell3d46d0b2021-05-27 21:42:57 +020077#if !defined(RTC_DISABLE_PROXY_TRACE_EVENTS) && !defined(WEBRTC_CHROMIUM_BUILD)
78#define RTC_DISABLE_PROXY_TRACE_EVENTS
79#endif
80
Yves Gerey3e707812018-11-28 16:47:49 +010081namespace rtc {
82class Location;
83}
84
henrike@webrtc.org28e20752013-07-10 00:45:36 +000085namespace webrtc {
Tommi1cb796f2021-05-21 08:50:09 +020086namespace proxy_internal {
Markus Handell3d46d0b2021-05-27 21:42:57 +020087
88// Class for tracing the lifetime of MethodCall::Marshal.
89class ScopedTrace {
90 public:
91 explicit ScopedTrace(const char* class_and_method_name);
92 ~ScopedTrace();
93
94 private:
Johannes Kron8d1e4fb2022-05-10 15:05:28 +020095 [[maybe_unused]] const char* const class_and_method_name_;
Markus Handell3d46d0b2021-05-27 21:42:57 +020096};
Tommi1cb796f2021-05-21 08:50:09 +020097} // namespace proxy_internal
henrike@webrtc.org28e20752013-07-10 00:45:36 +000098
Guido Urdanetaccab06f2020-01-15 11:30:29 +000099template <typename R>
100class ReturnType {
101 public:
102 template <typename C, typename M, typename... Args>
103 void Invoke(C* c, M m, Args&&... args) {
104 r_ = (c->*m)(std::forward<Args>(args)...);
105 }
106
107 R moved_result() { return std::move(r_); }
108
109 private:
110 R r_;
111};
112
113template <>
114class ReturnType<void> {
115 public:
116 template <typename C, typename M, typename... Args>
117 void Invoke(C* c, M m, Args&&... args) {
118 (c->*m)(std::forward<Args>(args)...);
119 }
120
121 void moved_result() {}
122};
123
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000124template <typename C, typename R, typename... Args>
Danil Chapovalova30439b2022-07-07 10:08:49 +0200125class MethodCall {
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000126 public:
127 typedef R (C::*Method)(Args...);
128 MethodCall(C* c, Method m, Args&&... args)
129 : c_(c),
130 m_(m),
131 args_(std::forward_as_tuple(std::forward<Args>(args)...)) {}
132
133 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200134 if (t->IsCurrent()) {
135 Invoke(std::index_sequence_for<Args...>());
136 } else {
Danil Chapovalova30439b2022-07-07 10:08:49 +0200137 t->PostTask([this] {
138 Invoke(std::index_sequence_for<Args...>());
139 event_.Set();
140 });
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200141 event_.Wait(rtc::Event::kForever);
142 }
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000143 return r_.moved_result();
144 }
145
146 private:
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000147 template <size_t... Is>
148 void Invoke(std::index_sequence<Is...>) {
149 r_.Invoke(c_, m_, std::move(std::get<Is>(args_))...);
150 }
151
152 C* c_;
153 Method m_;
154 ReturnType<R> r_;
155 std::tuple<Args&&...> args_;
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200156 rtc::Event event_;
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000157};
158
159template <typename C, typename R, typename... Args>
Danil Chapovalova30439b2022-07-07 10:08:49 +0200160class ConstMethodCall {
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000161 public:
162 typedef R (C::*Method)(Args...) const;
163 ConstMethodCall(const C* c, Method m, Args&&... args)
164 : c_(c),
165 m_(m),
166 args_(std::forward_as_tuple(std::forward<Args>(args)...)) {}
167
168 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200169 if (t->IsCurrent()) {
170 Invoke(std::index_sequence_for<Args...>());
171 } else {
Danil Chapovalova30439b2022-07-07 10:08:49 +0200172 t->PostTask([this] {
173 Invoke(std::index_sequence_for<Args...>());
174 event_.Set();
175 });
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200176 event_.Wait(rtc::Event::kForever);
177 }
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000178 return r_.moved_result();
179 }
180
181 private:
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000182 template <size_t... Is>
183 void Invoke(std::index_sequence<Is...>) {
184 r_.Invoke(c_, m_, std::move(std::get<Is>(args_))...);
185 }
186
187 const C* c_;
188 Method m_;
189 ReturnType<R> r_;
190 std::tuple<Args&&...> args_;
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200191 rtc::Event event_;
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000192};
193
Tommi1cb796f2021-05-21 08:50:09 +0200194#define PROXY_STRINGIZE_IMPL(x) #x
195#define PROXY_STRINGIZE(x) PROXY_STRINGIZE_IMPL(x)
196
deadbeefd99a2002017-01-18 08:55:23 -0800197// Helper macros to reduce code duplication.
Niels Möller7f761572022-01-25 16:18:53 +0100198#define PROXY_MAP_BOILERPLATE(class_name) \
199 template <class INTERNAL_CLASS> \
200 class class_name##ProxyWithInternal; \
201 typedef class_name##ProxyWithInternal<class_name##Interface> \
202 class_name##Proxy; \
203 template <class INTERNAL_CLASS> \
204 class class_name##ProxyWithInternal : public class_name##Interface { \
205 protected: \
206 static constexpr char proxy_name_[] = #class_name "Proxy"; \
207 typedef class_name##Interface C; \
208 \
209 public: \
210 const INTERNAL_CLASS* internal() const { return c(); } \
211 INTERNAL_CLASS* internal() { return c(); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000212
Yves Gerey665174f2018-06-19 15:03:05 +0200213// clang-format off
214// clang-format would put the semicolon alone,
215// leading to a presubmit error (cpplint.py)
Niels Möller7f761572022-01-25 16:18:53 +0100216#define END_PROXY_MAP(class_name) \
217 }; \
218 template <class INTERNAL_CLASS> \
219 constexpr char class_name##ProxyWithInternal<INTERNAL_CLASS>::proxy_name_[];
Yves Gerey665174f2018-06-19 15:03:05 +0200220// clang-format on
oprypin803dc292017-02-01 01:55:59 -0800221
Tomas Gunnarsson0d5ce622022-03-18 15:57:15 +0100222#define PRIMARY_PROXY_MAP_BOILERPLATE(class_name) \
223 protected: \
224 class_name##ProxyWithInternal(rtc::Thread* primary_thread, \
225 rtc::scoped_refptr<INTERNAL_CLASS> c) \
226 : primary_thread_(primary_thread), c_(std::move(c)) {} \
227 \
228 private: \
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100229 mutable rtc::Thread* primary_thread_;
230
Tomas Gunnarsson0d5ce622022-03-18 15:57:15 +0100231#define SECONDARY_PROXY_MAP_BOILERPLATE(class_name) \
232 protected: \
233 class_name##ProxyWithInternal(rtc::Thread* primary_thread, \
234 rtc::Thread* secondary_thread, \
235 rtc::scoped_refptr<INTERNAL_CLASS> c) \
236 : primary_thread_(primary_thread), \
237 secondary_thread_(secondary_thread), \
238 c_(std::move(c)) {} \
239 \
240 private: \
241 mutable rtc::Thread* primary_thread_; \
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100242 mutable rtc::Thread* secondary_thread_;
deadbeefd99a2002017-01-18 08:55:23 -0800243
244// Note that the destructor is protected so that the proxy can only be
245// destroyed via RefCountInterface.
Niels Möller7f761572022-01-25 16:18:53 +0100246#define REFCOUNTED_PROXY_MAP_BOILERPLATE(class_name) \
247 protected: \
248 ~class_name##ProxyWithInternal() { \
249 MethodCall<class_name##ProxyWithInternal, void> call( \
250 this, &class_name##ProxyWithInternal::DestroyInternal); \
251 call.Marshal(RTC_FROM_HERE, destructor_thread()); \
252 } \
253 \
254 private: \
255 const INTERNAL_CLASS* c() const { return c_.get(); } \
256 INTERNAL_CLASS* c() { return c_.get(); } \
257 void DestroyInternal() { c_ = nullptr; } \
deadbeefd99a2002017-01-18 08:55:23 -0800258 rtc::scoped_refptr<INTERNAL_CLASS> c_;
259
deadbeefe814a0d2017-02-25 18:15:09 -0800260// Note: This doesn't use a unique_ptr, because it intends to handle a corner
261// case where an object's deletion triggers a callback that calls back into
262// this proxy object. If relying on a unique_ptr to delete the object, its
263// inner pointer would be set to null before this reentrant callback would have
264// a chance to run, resulting in a segfault.
Niels Möller7f761572022-01-25 16:18:53 +0100265#define OWNED_PROXY_MAP_BOILERPLATE(class_name) \
266 public: \
267 ~class_name##ProxyWithInternal() { \
268 MethodCall<class_name##ProxyWithInternal, void> call( \
269 this, &class_name##ProxyWithInternal::DestroyInternal); \
270 call.Marshal(RTC_FROM_HERE, destructor_thread()); \
271 } \
272 \
273 private: \
274 const INTERNAL_CLASS* c() const { return c_; } \
275 INTERNAL_CLASS* c() { return c_; } \
276 void DestroyInternal() { delete c_; } \
deadbeefe814a0d2017-02-25 18:15:09 -0800277 INTERNAL_CLASS* c_;
deadbeefd99a2002017-01-18 08:55:23 -0800278
Tomas Gunnarsson0d5ce622022-03-18 15:57:15 +0100279#define BEGIN_PRIMARY_PROXY_MAP(class_name) \
280 PROXY_MAP_BOILERPLATE(class_name) \
281 PRIMARY_PROXY_MAP_BOILERPLATE(class_name) \
282 REFCOUNTED_PROXY_MAP_BOILERPLATE(class_name) \
283 public: \
284 static rtc::scoped_refptr<class_name##ProxyWithInternal> Create( \
285 rtc::Thread* primary_thread, rtc::scoped_refptr<INTERNAL_CLASS> c) { \
286 return rtc::make_ref_counted<class_name##ProxyWithInternal>( \
287 primary_thread, std::move(c)); \
Niels Möller7f761572022-01-25 16:18:53 +0100288 }
289
290#define BEGIN_PROXY_MAP(class_name) \
291 PROXY_MAP_BOILERPLATE(class_name) \
292 SECONDARY_PROXY_MAP_BOILERPLATE(class_name) \
293 REFCOUNTED_PROXY_MAP_BOILERPLATE(class_name) \
294 public: \
295 static rtc::scoped_refptr<class_name##ProxyWithInternal> Create( \
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100296 rtc::Thread* primary_thread, rtc::Thread* secondary_thread, \
Tomas Gunnarsson0d5ce622022-03-18 15:57:15 +0100297 rtc::scoped_refptr<INTERNAL_CLASS> c) { \
Niels Möller7f761572022-01-25 16:18:53 +0100298 return rtc::make_ref_counted<class_name##ProxyWithInternal>( \
Tomas Gunnarsson0d5ce622022-03-18 15:57:15 +0100299 primary_thread, secondary_thread, std::move(c)); \
Niels Möller7f761572022-01-25 16:18:53 +0100300 }
301
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100302#define PROXY_PRIMARY_THREAD_DESTRUCTOR() \
303 private: \
304 rtc::Thread* destructor_thread() const { return primary_thread_; } \
305 \
306 public: // NOLINTNEXTLINE
307
308#define PROXY_SECONDARY_THREAD_DESTRUCTOR() \
deadbeefd99a2002017-01-18 08:55:23 -0800309 private: \
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100310 rtc::Thread* destructor_thread() const { return secondary_thread_; } \
deadbeefd99a2002017-01-18 08:55:23 -0800311 \
oprypin803dc292017-02-01 01:55:59 -0800312 public: // NOLINTNEXTLINE
deadbeefd99a2002017-01-18 08:55:23 -0800313
Markus Handell3d46d0b2021-05-27 21:42:57 +0200314#if defined(RTC_DISABLE_PROXY_TRACE_EVENTS)
315#define TRACE_BOILERPLATE(method) \
316 do { \
317 } while (0)
318#else // if defined(RTC_DISABLE_PROXY_TRACE_EVENTS)
319#define TRACE_BOILERPLATE(method) \
320 static constexpr auto class_and_method_name = \
321 rtc::MakeCompileTimeString(proxy_name_) \
322 .Concat(rtc::MakeCompileTimeString("::")) \
323 .Concat(rtc::MakeCompileTimeString(#method)); \
324 proxy_internal::ScopedTrace scoped_trace(class_and_method_name.string)
325
326#endif // if defined(RTC_DISABLE_PROXY_TRACE_EVENTS)
327
328#define PROXY_METHOD0(r, method) \
329 r method() override { \
330 TRACE_BOILERPLATE(method); \
Niels Möller7f761572022-01-25 16:18:53 +0100331 MethodCall<C, r> call(c(), &C::method); \
Markus Handell3d46d0b2021-05-27 21:42:57 +0200332 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000333 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000334
Markus Handell3d46d0b2021-05-27 21:42:57 +0200335#define PROXY_CONSTMETHOD0(r, method) \
336 r method() const override { \
337 TRACE_BOILERPLATE(method); \
Niels Möller7f761572022-01-25 16:18:53 +0100338 ConstMethodCall<C, r> call(c(), &C::method); \
Markus Handell3d46d0b2021-05-27 21:42:57 +0200339 return call.Marshal(RTC_FROM_HERE, 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_METHOD1(r, method, t1) \
343 r method(t1 a1) override { \
344 TRACE_BOILERPLATE(method); \
345 MethodCall<C, r, t1> call(c(), &C::method, std::move(a1)); \
346 return call.Marshal(RTC_FROM_HERE, 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_CONSTMETHOD1(r, method, t1) \
350 r method(t1 a1) const override { \
351 TRACE_BOILERPLATE(method); \
352 ConstMethodCall<C, r, t1> call(c(), &C::method, std::move(a1)); \
353 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000354 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000355
Niels Möller7f761572022-01-25 16:18:53 +0100356#define PROXY_METHOD2(r, method, t1, t2) \
357 r method(t1 a1, t2 a2) override { \
358 TRACE_BOILERPLATE(method); \
359 MethodCall<C, r, t1, t2> call(c(), &C::method, std::move(a1), \
360 std::move(a2)); \
361 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000362 }
perkj@webrtc.org81134d02015-01-12 08:30:16 +0000363
Niels Möller7f761572022-01-25 16:18:53 +0100364#define PROXY_METHOD3(r, method, t1, t2, t3) \
365 r method(t1 a1, t2 a2, t3 a3) override { \
366 TRACE_BOILERPLATE(method); \
367 MethodCall<C, r, t1, t2, t3> call(c(), &C::method, std::move(a1), \
368 std::move(a2), std::move(a3)); \
369 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
deadbeefd99a2002017-01-18 08:55:23 -0800370 }
371
Niels Möller7f761572022-01-25 16:18:53 +0100372#define PROXY_METHOD4(r, method, t1, t2, t3, t4) \
373 r method(t1 a1, t2 a2, t3 a3, t4 a4) override { \
374 TRACE_BOILERPLATE(method); \
375 MethodCall<C, r, t1, t2, t3, t4> call(c(), &C::method, std::move(a1), \
376 std::move(a2), std::move(a3), \
377 std::move(a4)); \
378 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000379 }
deadbeefd99a2002017-01-18 08:55:23 -0800380
Niels Möller7f761572022-01-25 16:18:53 +0100381#define PROXY_METHOD5(r, method, t1, t2, t3, t4, t5) \
382 r method(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) override { \
383 TRACE_BOILERPLATE(method); \
384 MethodCall<C, r, t1, t2, t3, t4, t5> call(c(), &C::method, std::move(a1), \
385 std::move(a2), std::move(a3), \
386 std::move(a4), std::move(a5)); \
387 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000388 }
nisse5b68ab52016-04-07 07:45:54 -0700389
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100390// Define methods which should be invoked on the secondary thread.
Markus Handell3d46d0b2021-05-27 21:42:57 +0200391#define PROXY_SECONDARY_METHOD0(r, method) \
392 r method() override { \
393 TRACE_BOILERPLATE(method); \
Niels Möller7f761572022-01-25 16:18:53 +0100394 MethodCall<C, r> call(c(), &C::method); \
Markus Handell3d46d0b2021-05-27 21:42:57 +0200395 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000396 }
nisse5b68ab52016-04-07 07:45:54 -0700397
Markus Handell3d46d0b2021-05-27 21:42:57 +0200398#define PROXY_SECONDARY_CONSTMETHOD0(r, method) \
399 r method() const override { \
400 TRACE_BOILERPLATE(method); \
Niels Möller7f761572022-01-25 16:18:53 +0100401 ConstMethodCall<C, r> call(c(), &C::method); \
Markus Handell3d46d0b2021-05-27 21:42:57 +0200402 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000403 }
perkj@webrtc.org81134d02015-01-12 08:30:16 +0000404
Niels Möller7f761572022-01-25 16:18:53 +0100405#define PROXY_SECONDARY_METHOD1(r, method, t1) \
406 r method(t1 a1) override { \
407 TRACE_BOILERPLATE(method); \
408 MethodCall<C, r, t1> call(c(), &C::method, std::move(a1)); \
409 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000410 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000411
Niels Möller7f761572022-01-25 16:18:53 +0100412#define PROXY_SECONDARY_CONSTMETHOD1(r, method, t1) \
413 r method(t1 a1) const override { \
414 TRACE_BOILERPLATE(method); \
415 ConstMethodCall<C, r, t1> call(c(), &C::method, std::move(a1)); \
416 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000417 }
deadbeefd99a2002017-01-18 08:55:23 -0800418
Niels Möller7f761572022-01-25 16:18:53 +0100419#define PROXY_SECONDARY_METHOD2(r, method, t1, t2) \
420 r method(t1 a1, t2 a2) override { \
421 TRACE_BOILERPLATE(method); \
422 MethodCall<C, r, t1, t2> call(c(), &C::method, std::move(a1), \
423 std::move(a2)); \
424 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000425 }
deadbeefd99a2002017-01-18 08:55:23 -0800426
Niels Möller7f761572022-01-25 16:18:53 +0100427#define PROXY_SECONDARY_CONSTMETHOD2(r, method, t1, t2) \
428 r method(t1 a1, t2 a2) const override { \
429 TRACE_BOILERPLATE(method); \
430 ConstMethodCall<C, r, t1, t2> call(c(), &C::method, std::move(a1), \
431 std::move(a2)); \
432 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
433 }
434
435#define PROXY_SECONDARY_METHOD3(r, method, t1, t2, t3) \
436 r method(t1 a1, t2 a2, t3 a3) override { \
Markus Handell3d46d0b2021-05-27 21:42:57 +0200437 TRACE_BOILERPLATE(method); \
Niels Möller7f761572022-01-25 16:18:53 +0100438 MethodCall<C, r, t1, t2, t3> call(c(), &C::method, std::move(a1), \
439 std::move(a2), std::move(a3)); \
Markus Handell3d46d0b2021-05-27 21:42:57 +0200440 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000441 }
deadbeefe814a0d2017-02-25 18:15:09 -0800442
Niels Möller7f761572022-01-25 16:18:53 +0100443#define PROXY_SECONDARY_CONSTMETHOD3(r, method, t1, t2) \
444 r method(t1 a1, t2 a2, t3 a3) const override { \
445 TRACE_BOILERPLATE(method); \
446 ConstMethodCall<C, r, t1, t2, t3> call(c(), &C::method, std::move(a1), \
447 std::move(a2), std::move(a3)); \
448 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000449 }
deadbeefd99a2002017-01-18 08:55:23 -0800450
Tomas Gunnarsson0ca13d92020-06-10 12:17:50 +0200451// For use when returning purely const state (set during construction).
452// Use with caution. This method should only be used when the return value will
453// always be the same.
Markus Handell3d46d0b2021-05-27 21:42:57 +0200454#define BYPASS_PROXY_CONSTMETHOD0(r, method) \
455 r method() const override { \
456 TRACE_BOILERPLATE(method); \
457 return c_->method(); \
Tomas Gunnarsson0ca13d92020-06-10 12:17:50 +0200458 }
459
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000460} // namespace webrtc
461
Markus Handella1b82012021-05-26 18:56:30 +0200462#endif // PC_PROXY_H_