blob: 2c347d62493972847ec5f6b399661853cbd7437e [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"
Steve Anton10542f22019-01-11 09:11:00 -080074#include "rtc_base/ref_counted_object.h"
Markus Handell3d46d0b2021-05-27 21:42:57 +020075#include "rtc_base/string_utils.h"
Mirko Bonadei35214fc2019-09-23 14:54:28 +020076#include "rtc_base/system/rtc_export.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020077#include "rtc_base/thread.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078
Markus Handell3d46d0b2021-05-27 21:42:57 +020079#if !defined(RTC_DISABLE_PROXY_TRACE_EVENTS) && !defined(WEBRTC_CHROMIUM_BUILD)
80#define RTC_DISABLE_PROXY_TRACE_EVENTS
81#endif
82
Yves Gerey3e707812018-11-28 16:47:49 +010083namespace rtc {
84class Location;
85}
86
henrike@webrtc.org28e20752013-07-10 00:45:36 +000087namespace webrtc {
Tommi1cb796f2021-05-21 08:50:09 +020088namespace proxy_internal {
Markus Handell3d46d0b2021-05-27 21:42:57 +020089
90// Class for tracing the lifetime of MethodCall::Marshal.
91class ScopedTrace {
92 public:
93 explicit ScopedTrace(const char* class_and_method_name);
94 ~ScopedTrace();
95
96 private:
97 const char* const class_and_method_name_;
98};
Tommi1cb796f2021-05-21 08:50:09 +020099} // namespace proxy_internal
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000101template <typename R>
102class ReturnType {
103 public:
104 template <typename C, typename M, typename... Args>
105 void Invoke(C* c, M m, Args&&... args) {
106 r_ = (c->*m)(std::forward<Args>(args)...);
107 }
108
109 R moved_result() { return std::move(r_); }
110
111 private:
112 R r_;
113};
114
115template <>
116class ReturnType<void> {
117 public:
118 template <typename C, typename M, typename... Args>
119 void Invoke(C* c, M m, Args&&... args) {
120 (c->*m)(std::forward<Args>(args)...);
121 }
122
123 void moved_result() {}
124};
125
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000126template <typename C, typename R, typename... Args>
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200127class MethodCall : public QueuedTask {
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000128 public:
129 typedef R (C::*Method)(Args...);
130 MethodCall(C* c, Method m, Args&&... args)
131 : c_(c),
132 m_(m),
133 args_(std::forward_as_tuple(std::forward<Args>(args)...)) {}
134
135 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200136 if (t->IsCurrent()) {
137 Invoke(std::index_sequence_for<Args...>());
138 } else {
139 t->PostTask(std::unique_ptr<QueuedTask>(this));
140 event_.Wait(rtc::Event::kForever);
141 }
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000142 return r_.moved_result();
143 }
144
145 private:
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200146 bool Run() override {
147 Invoke(std::index_sequence_for<Args...>());
148 event_.Set();
149 return false;
150 }
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000151
152 template <size_t... Is>
153 void Invoke(std::index_sequence<Is...>) {
154 r_.Invoke(c_, m_, std::move(std::get<Is>(args_))...);
155 }
156
157 C* c_;
158 Method m_;
159 ReturnType<R> r_;
160 std::tuple<Args&&...> args_;
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200161 rtc::Event event_;
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000162};
163
164template <typename C, typename R, typename... Args>
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200165class ConstMethodCall : public QueuedTask {
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000166 public:
167 typedef R (C::*Method)(Args...) const;
168 ConstMethodCall(const C* c, Method m, Args&&... args)
169 : c_(c),
170 m_(m),
171 args_(std::forward_as_tuple(std::forward<Args>(args)...)) {}
172
173 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200174 if (t->IsCurrent()) {
175 Invoke(std::index_sequence_for<Args...>());
176 } else {
177 t->PostTask(std::unique_ptr<QueuedTask>(this));
178 event_.Wait(rtc::Event::kForever);
179 }
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000180 return r_.moved_result();
181 }
182
183 private:
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200184 bool Run() override {
185 Invoke(std::index_sequence_for<Args...>());
186 event_.Set();
187 return false;
188 }
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000189
190 template <size_t... Is>
191 void Invoke(std::index_sequence<Is...>) {
192 r_.Invoke(c_, m_, std::move(std::get<Is>(args_))...);
193 }
194
195 const C* c_;
196 Method m_;
197 ReturnType<R> r_;
198 std::tuple<Args&&...> args_;
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200199 rtc::Event event_;
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000200};
201
Tommi1cb796f2021-05-21 08:50:09 +0200202#define PROXY_STRINGIZE_IMPL(x) #x
203#define PROXY_STRINGIZE(x) PROXY_STRINGIZE_IMPL(x)
204
deadbeefd99a2002017-01-18 08:55:23 -0800205// Helper macros to reduce code duplication.
Niels Möller7f761572022-01-25 16:18:53 +0100206#define PROXY_MAP_BOILERPLATE(class_name) \
207 template <class INTERNAL_CLASS> \
208 class class_name##ProxyWithInternal; \
209 typedef class_name##ProxyWithInternal<class_name##Interface> \
210 class_name##Proxy; \
211 template <class INTERNAL_CLASS> \
212 class class_name##ProxyWithInternal : public class_name##Interface { \
213 protected: \
214 static constexpr char proxy_name_[] = #class_name "Proxy"; \
215 typedef class_name##Interface C; \
216 \
217 public: \
218 const INTERNAL_CLASS* internal() const { return c(); } \
219 INTERNAL_CLASS* internal() { return c(); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000220
Yves Gerey665174f2018-06-19 15:03:05 +0200221// clang-format off
222// clang-format would put the semicolon alone,
223// leading to a presubmit error (cpplint.py)
Niels Möller7f761572022-01-25 16:18:53 +0100224#define END_PROXY_MAP(class_name) \
225 }; \
226 template <class INTERNAL_CLASS> \
227 constexpr char class_name##ProxyWithInternal<INTERNAL_CLASS>::proxy_name_[];
Yves Gerey665174f2018-06-19 15:03:05 +0200228// clang-format on
oprypin803dc292017-02-01 01:55:59 -0800229
Tomas Gunnarsson0d5ce622022-03-18 15:57:15 +0100230#define PRIMARY_PROXY_MAP_BOILERPLATE(class_name) \
231 protected: \
232 class_name##ProxyWithInternal(rtc::Thread* primary_thread, \
233 rtc::scoped_refptr<INTERNAL_CLASS> c) \
234 : primary_thread_(primary_thread), c_(std::move(c)) {} \
235 \
236 private: \
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100237 mutable rtc::Thread* primary_thread_;
238
Tomas Gunnarsson0d5ce622022-03-18 15:57:15 +0100239#define SECONDARY_PROXY_MAP_BOILERPLATE(class_name) \
240 protected: \
241 class_name##ProxyWithInternal(rtc::Thread* primary_thread, \
242 rtc::Thread* secondary_thread, \
243 rtc::scoped_refptr<INTERNAL_CLASS> c) \
244 : primary_thread_(primary_thread), \
245 secondary_thread_(secondary_thread), \
246 c_(std::move(c)) {} \
247 \
248 private: \
249 mutable rtc::Thread* primary_thread_; \
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100250 mutable rtc::Thread* secondary_thread_;
deadbeefd99a2002017-01-18 08:55:23 -0800251
252// Note that the destructor is protected so that the proxy can only be
253// destroyed via RefCountInterface.
Niels Möller7f761572022-01-25 16:18:53 +0100254#define REFCOUNTED_PROXY_MAP_BOILERPLATE(class_name) \
255 protected: \
256 ~class_name##ProxyWithInternal() { \
257 MethodCall<class_name##ProxyWithInternal, void> call( \
258 this, &class_name##ProxyWithInternal::DestroyInternal); \
259 call.Marshal(RTC_FROM_HERE, destructor_thread()); \
260 } \
261 \
262 private: \
263 const INTERNAL_CLASS* c() const { return c_.get(); } \
264 INTERNAL_CLASS* c() { return c_.get(); } \
265 void DestroyInternal() { c_ = nullptr; } \
deadbeefd99a2002017-01-18 08:55:23 -0800266 rtc::scoped_refptr<INTERNAL_CLASS> c_;
267
deadbeefe814a0d2017-02-25 18:15:09 -0800268// Note: This doesn't use a unique_ptr, because it intends to handle a corner
269// case where an object's deletion triggers a callback that calls back into
270// this proxy object. If relying on a unique_ptr to delete the object, its
271// inner pointer would be set to null before this reentrant callback would have
272// a chance to run, resulting in a segfault.
Niels Möller7f761572022-01-25 16:18:53 +0100273#define OWNED_PROXY_MAP_BOILERPLATE(class_name) \
274 public: \
275 ~class_name##ProxyWithInternal() { \
276 MethodCall<class_name##ProxyWithInternal, void> call( \
277 this, &class_name##ProxyWithInternal::DestroyInternal); \
278 call.Marshal(RTC_FROM_HERE, destructor_thread()); \
279 } \
280 \
281 private: \
282 const INTERNAL_CLASS* c() const { return c_; } \
283 INTERNAL_CLASS* c() { return c_; } \
284 void DestroyInternal() { delete c_; } \
deadbeefe814a0d2017-02-25 18:15:09 -0800285 INTERNAL_CLASS* c_;
deadbeefd99a2002017-01-18 08:55:23 -0800286
Tomas Gunnarsson0d5ce622022-03-18 15:57:15 +0100287#define BEGIN_PRIMARY_PROXY_MAP(class_name) \
288 PROXY_MAP_BOILERPLATE(class_name) \
289 PRIMARY_PROXY_MAP_BOILERPLATE(class_name) \
290 REFCOUNTED_PROXY_MAP_BOILERPLATE(class_name) \
291 public: \
292 static rtc::scoped_refptr<class_name##ProxyWithInternal> Create( \
293 rtc::Thread* primary_thread, rtc::scoped_refptr<INTERNAL_CLASS> c) { \
294 return rtc::make_ref_counted<class_name##ProxyWithInternal>( \
295 primary_thread, std::move(c)); \
Niels Möller7f761572022-01-25 16:18:53 +0100296 }
297
298#define BEGIN_PROXY_MAP(class_name) \
299 PROXY_MAP_BOILERPLATE(class_name) \
300 SECONDARY_PROXY_MAP_BOILERPLATE(class_name) \
301 REFCOUNTED_PROXY_MAP_BOILERPLATE(class_name) \
302 public: \
303 static rtc::scoped_refptr<class_name##ProxyWithInternal> Create( \
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100304 rtc::Thread* primary_thread, rtc::Thread* secondary_thread, \
Tomas Gunnarsson0d5ce622022-03-18 15:57:15 +0100305 rtc::scoped_refptr<INTERNAL_CLASS> c) { \
Niels Möller7f761572022-01-25 16:18:53 +0100306 return rtc::make_ref_counted<class_name##ProxyWithInternal>( \
Tomas Gunnarsson0d5ce622022-03-18 15:57:15 +0100307 primary_thread, secondary_thread, std::move(c)); \
Niels Möller7f761572022-01-25 16:18:53 +0100308 }
309
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100310#define PROXY_PRIMARY_THREAD_DESTRUCTOR() \
311 private: \
312 rtc::Thread* destructor_thread() const { return primary_thread_; } \
313 \
314 public: // NOLINTNEXTLINE
315
316#define PROXY_SECONDARY_THREAD_DESTRUCTOR() \
deadbeefd99a2002017-01-18 08:55:23 -0800317 private: \
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100318 rtc::Thread* destructor_thread() const { return secondary_thread_; } \
deadbeefd99a2002017-01-18 08:55:23 -0800319 \
oprypin803dc292017-02-01 01:55:59 -0800320 public: // NOLINTNEXTLINE
deadbeefd99a2002017-01-18 08:55:23 -0800321
Markus Handell3d46d0b2021-05-27 21:42:57 +0200322#if defined(RTC_DISABLE_PROXY_TRACE_EVENTS)
323#define TRACE_BOILERPLATE(method) \
324 do { \
325 } while (0)
326#else // if defined(RTC_DISABLE_PROXY_TRACE_EVENTS)
327#define TRACE_BOILERPLATE(method) \
328 static constexpr auto class_and_method_name = \
329 rtc::MakeCompileTimeString(proxy_name_) \
330 .Concat(rtc::MakeCompileTimeString("::")) \
331 .Concat(rtc::MakeCompileTimeString(#method)); \
332 proxy_internal::ScopedTrace scoped_trace(class_and_method_name.string)
333
334#endif // if defined(RTC_DISABLE_PROXY_TRACE_EVENTS)
335
336#define PROXY_METHOD0(r, method) \
337 r method() override { \
338 TRACE_BOILERPLATE(method); \
Niels Möller7f761572022-01-25 16:18:53 +0100339 MethodCall<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
Markus Handell3d46d0b2021-05-27 21:42:57 +0200343#define PROXY_CONSTMETHOD0(r, method) \
344 r method() const override { \
345 TRACE_BOILERPLATE(method); \
Niels Möller7f761572022-01-25 16:18:53 +0100346 ConstMethodCall<C, r> call(c(), &C::method); \
Markus Handell3d46d0b2021-05-27 21:42:57 +0200347 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_METHOD1(r, method, t1) \
351 r method(t1 a1) override { \
352 TRACE_BOILERPLATE(method); \
353 MethodCall<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_CONSTMETHOD1(r, method, t1) \
358 r method(t1 a1) const override { \
359 TRACE_BOILERPLATE(method); \
360 ConstMethodCall<C, r, t1> call(c(), &C::method, std::move(a1)); \
361 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000362 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000363
Niels Möller7f761572022-01-25 16:18:53 +0100364#define PROXY_METHOD2(r, method, t1, t2) \
365 r method(t1 a1, t2 a2) override { \
366 TRACE_BOILERPLATE(method); \
367 MethodCall<C, r, t1, t2> call(c(), &C::method, std::move(a1), \
368 std::move(a2)); \
369 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000370 }
perkj@webrtc.org81134d02015-01-12 08:30:16 +0000371
Niels Möller7f761572022-01-25 16:18:53 +0100372#define PROXY_METHOD3(r, method, t1, t2, t3) \
373 r method(t1 a1, t2 a2, t3 a3) override { \
374 TRACE_BOILERPLATE(method); \
375 MethodCall<C, r, t1, t2, t3> call(c(), &C::method, std::move(a1), \
376 std::move(a2), std::move(a3)); \
377 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
deadbeefd99a2002017-01-18 08:55:23 -0800378 }
379
Niels Möller7f761572022-01-25 16:18:53 +0100380#define PROXY_METHOD4(r, method, t1, t2, t3, t4) \
381 r method(t1 a1, t2 a2, t3 a3, t4 a4) override { \
382 TRACE_BOILERPLATE(method); \
383 MethodCall<C, r, t1, t2, t3, t4> call(c(), &C::method, std::move(a1), \
384 std::move(a2), std::move(a3), \
385 std::move(a4)); \
386 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000387 }
deadbeefd99a2002017-01-18 08:55:23 -0800388
Niels Möller7f761572022-01-25 16:18:53 +0100389#define PROXY_METHOD5(r, method, t1, t2, t3, t4, t5) \
390 r method(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) override { \
391 TRACE_BOILERPLATE(method); \
392 MethodCall<C, r, t1, t2, t3, t4, t5> call(c(), &C::method, std::move(a1), \
393 std::move(a2), std::move(a3), \
394 std::move(a4), std::move(a5)); \
395 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000396 }
nisse5b68ab52016-04-07 07:45:54 -0700397
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100398// Define methods which should be invoked on the secondary thread.
Markus Handell3d46d0b2021-05-27 21:42:57 +0200399#define PROXY_SECONDARY_METHOD0(r, method) \
400 r method() override { \
401 TRACE_BOILERPLATE(method); \
Niels Möller7f761572022-01-25 16:18:53 +0100402 MethodCall<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 }
nisse5b68ab52016-04-07 07:45:54 -0700405
Markus Handell3d46d0b2021-05-27 21:42:57 +0200406#define PROXY_SECONDARY_CONSTMETHOD0(r, method) \
407 r method() const override { \
408 TRACE_BOILERPLATE(method); \
Niels Möller7f761572022-01-25 16:18:53 +0100409 ConstMethodCall<C, r> call(c(), &C::method); \
Markus Handell3d46d0b2021-05-27 21:42:57 +0200410 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000411 }
perkj@webrtc.org81134d02015-01-12 08:30:16 +0000412
Niels Möller7f761572022-01-25 16:18:53 +0100413#define PROXY_SECONDARY_METHOD1(r, method, t1) \
414 r method(t1 a1) override { \
415 TRACE_BOILERPLATE(method); \
416 MethodCall<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 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000419
Niels Möller7f761572022-01-25 16:18:53 +0100420#define PROXY_SECONDARY_CONSTMETHOD1(r, method, t1) \
421 r method(t1 a1) const override { \
422 TRACE_BOILERPLATE(method); \
423 ConstMethodCall<C, r, t1> call(c(), &C::method, std::move(a1)); \
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_METHOD2(r, method, t1, t2) \
428 r method(t1 a1, t2 a2) override { \
429 TRACE_BOILERPLATE(method); \
430 MethodCall<C, r, t1, t2> call(c(), &C::method, std::move(a1), \
431 std::move(a2)); \
432 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000433 }
deadbeefd99a2002017-01-18 08:55:23 -0800434
Niels Möller7f761572022-01-25 16:18:53 +0100435#define PROXY_SECONDARY_CONSTMETHOD2(r, method, t1, t2) \
436 r method(t1 a1, t2 a2) const override { \
437 TRACE_BOILERPLATE(method); \
438 ConstMethodCall<C, r, t1, t2> call(c(), &C::method, std::move(a1), \
439 std::move(a2)); \
440 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
441 }
442
443#define PROXY_SECONDARY_METHOD3(r, method, t1, t2, t3) \
444 r method(t1 a1, t2 a2, t3 a3) override { \
Markus Handell3d46d0b2021-05-27 21:42:57 +0200445 TRACE_BOILERPLATE(method); \
Niels Möller7f761572022-01-25 16:18:53 +0100446 MethodCall<C, r, t1, t2, t3> call(c(), &C::method, std::move(a1), \
447 std::move(a2), std::move(a3)); \
Markus Handell3d46d0b2021-05-27 21:42:57 +0200448 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000449 }
deadbeefe814a0d2017-02-25 18:15:09 -0800450
Niels Möller7f761572022-01-25 16:18:53 +0100451#define PROXY_SECONDARY_CONSTMETHOD3(r, method, t1, t2) \
452 r method(t1 a1, t2 a2, t3 a3) const override { \
453 TRACE_BOILERPLATE(method); \
454 ConstMethodCall<C, r, t1, t2, t3> call(c(), &C::method, std::move(a1), \
455 std::move(a2), std::move(a3)); \
456 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000457 }
deadbeefd99a2002017-01-18 08:55:23 -0800458
Tomas Gunnarsson0ca13d92020-06-10 12:17:50 +0200459// For use when returning purely const state (set during construction).
460// Use with caution. This method should only be used when the return value will
461// always be the same.
Markus Handell3d46d0b2021-05-27 21:42:57 +0200462#define BYPASS_PROXY_CONSTMETHOD0(r, method) \
463 r method() const override { \
464 TRACE_BOILERPLATE(method); \
465 return c_->method(); \
Tomas Gunnarsson0ca13d92020-06-10 12:17:50 +0200466 }
467
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000468} // namespace webrtc
469
Markus Handella1b82012021-05-26 18:56:30 +0200470#endif // PC_PROXY_H_