blob: 85cb70d34c1574195f610d34c1d28f238f91b589 [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
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"
Steve Anton10542f22019-01-11 09:11:00 -080072#include "rtc_base/message_handler.h"
Steve Anton10542f22019-01-11 09:11:00 -080073#include "rtc_base/ref_counted_object.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:
96 const char* const class_and_method_name_;
97};
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>
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200126class MethodCall : public QueuedTask {
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 {
138 t->PostTask(std::unique_ptr<QueuedTask>(this));
139 event_.Wait(rtc::Event::kForever);
140 }
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000141 return r_.moved_result();
142 }
143
144 private:
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200145 bool Run() override {
146 Invoke(std::index_sequence_for<Args...>());
147 event_.Set();
148 return false;
149 }
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000150
151 template <size_t... Is>
152 void Invoke(std::index_sequence<Is...>) {
153 r_.Invoke(c_, m_, std::move(std::get<Is>(args_))...);
154 }
155
156 C* c_;
157 Method m_;
158 ReturnType<R> r_;
159 std::tuple<Args&&...> args_;
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200160 rtc::Event event_;
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000161};
162
163template <typename C, typename R, typename... Args>
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200164class ConstMethodCall : public QueuedTask {
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000165 public:
166 typedef R (C::*Method)(Args...) const;
167 ConstMethodCall(const C* c, Method m, Args&&... args)
168 : c_(c),
169 m_(m),
170 args_(std::forward_as_tuple(std::forward<Args>(args)...)) {}
171
172 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200173 if (t->IsCurrent()) {
174 Invoke(std::index_sequence_for<Args...>());
175 } else {
176 t->PostTask(std::unique_ptr<QueuedTask>(this));
177 event_.Wait(rtc::Event::kForever);
178 }
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000179 return r_.moved_result();
180 }
181
182 private:
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200183 bool Run() override {
184 Invoke(std::index_sequence_for<Args...>());
185 event_.Set();
186 return false;
187 }
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000188
189 template <size_t... Is>
190 void Invoke(std::index_sequence<Is...>) {
191 r_.Invoke(c_, m_, std::move(std::get<Is>(args_))...);
192 }
193
194 const C* c_;
195 Method m_;
196 ReturnType<R> r_;
197 std::tuple<Args&&...> args_;
Tomas Gunnarssonabdb4702020-09-05 18:43:36 +0200198 rtc::Event event_;
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000199};
200
Tommi1cb796f2021-05-21 08:50:09 +0200201#define PROXY_STRINGIZE_IMPL(x) #x
202#define PROXY_STRINGIZE(x) PROXY_STRINGIZE_IMPL(x)
203
deadbeefd99a2002017-01-18 08:55:23 -0800204// Helper macros to reduce code duplication.
Niels Möller7f761572022-01-25 16:18:53 +0100205#define PROXY_MAP_BOILERPLATE(class_name) \
206 template <class INTERNAL_CLASS> \
207 class class_name##ProxyWithInternal; \
208 typedef class_name##ProxyWithInternal<class_name##Interface> \
209 class_name##Proxy; \
210 template <class INTERNAL_CLASS> \
211 class class_name##ProxyWithInternal : public class_name##Interface { \
212 protected: \
213 static constexpr char proxy_name_[] = #class_name "Proxy"; \
214 typedef class_name##Interface C; \
215 \
216 public: \
217 const INTERNAL_CLASS* internal() const { return c(); } \
218 INTERNAL_CLASS* internal() { return c(); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000219
Yves Gerey665174f2018-06-19 15:03:05 +0200220// clang-format off
221// clang-format would put the semicolon alone,
222// leading to a presubmit error (cpplint.py)
Niels Möller7f761572022-01-25 16:18:53 +0100223#define END_PROXY_MAP(class_name) \
224 }; \
225 template <class INTERNAL_CLASS> \
226 constexpr char class_name##ProxyWithInternal<INTERNAL_CLASS>::proxy_name_[];
Yves Gerey665174f2018-06-19 15:03:05 +0200227// clang-format on
oprypin803dc292017-02-01 01:55:59 -0800228
Niels Möller7f761572022-01-25 16:18:53 +0100229#define PRIMARY_PROXY_MAP_BOILERPLATE(class_name) \
230 protected: \
231 class_name##ProxyWithInternal(rtc::Thread* primary_thread, \
232 INTERNAL_CLASS* c) \
233 : primary_thread_(primary_thread), c_(c) {} \
234 \
235 private: \
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100236 mutable rtc::Thread* primary_thread_;
237
Niels Möller7f761572022-01-25 16:18:53 +0100238#define SECONDARY_PROXY_MAP_BOILERPLATE(class_name) \
239 protected: \
240 class_name##ProxyWithInternal(rtc::Thread* primary_thread, \
241 rtc::Thread* secondary_thread, \
242 INTERNAL_CLASS* c) \
243 : primary_thread_(primary_thread), \
244 secondary_thread_(secondary_thread), \
245 c_(c) {} \
246 \
247 private: \
248 mutable rtc::Thread* primary_thread_; \
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100249 mutable rtc::Thread* secondary_thread_;
deadbeefd99a2002017-01-18 08:55:23 -0800250
251// Note that the destructor is protected so that the proxy can only be
252// destroyed via RefCountInterface.
Niels Möller7f761572022-01-25 16:18:53 +0100253#define REFCOUNTED_PROXY_MAP_BOILERPLATE(class_name) \
254 protected: \
255 ~class_name##ProxyWithInternal() { \
256 MethodCall<class_name##ProxyWithInternal, void> call( \
257 this, &class_name##ProxyWithInternal::DestroyInternal); \
258 call.Marshal(RTC_FROM_HERE, destructor_thread()); \
259 } \
260 \
261 private: \
262 const INTERNAL_CLASS* c() const { return c_.get(); } \
263 INTERNAL_CLASS* c() { return c_.get(); } \
264 void DestroyInternal() { c_ = nullptr; } \
deadbeefd99a2002017-01-18 08:55:23 -0800265 rtc::scoped_refptr<INTERNAL_CLASS> c_;
266
deadbeefe814a0d2017-02-25 18:15:09 -0800267// Note: This doesn't use a unique_ptr, because it intends to handle a corner
268// case where an object's deletion triggers a callback that calls back into
269// this proxy object. If relying on a unique_ptr to delete the object, its
270// inner pointer would be set to null before this reentrant callback would have
271// a chance to run, resulting in a segfault.
Niels Möller7f761572022-01-25 16:18:53 +0100272#define OWNED_PROXY_MAP_BOILERPLATE(class_name) \
273 public: \
274 ~class_name##ProxyWithInternal() { \
275 MethodCall<class_name##ProxyWithInternal, void> call( \
276 this, &class_name##ProxyWithInternal::DestroyInternal); \
277 call.Marshal(RTC_FROM_HERE, destructor_thread()); \
278 } \
279 \
280 private: \
281 const INTERNAL_CLASS* c() const { return c_; } \
282 INTERNAL_CLASS* c() { return c_; } \
283 void DestroyInternal() { delete c_; } \
deadbeefe814a0d2017-02-25 18:15:09 -0800284 INTERNAL_CLASS* c_;
deadbeefd99a2002017-01-18 08:55:23 -0800285
Niels Möller7f761572022-01-25 16:18:53 +0100286#define BEGIN_PRIMARY_PROXY_MAP(class_name) \
287 PROXY_MAP_BOILERPLATE(class_name) \
288 PRIMARY_PROXY_MAP_BOILERPLATE(class_name) \
289 REFCOUNTED_PROXY_MAP_BOILERPLATE(class_name) \
deadbeefe814a0d2017-02-25 18:15:09 -0800290 public: \
Niels Möller7f761572022-01-25 16:18:53 +0100291 static rtc::scoped_refptr<class_name##ProxyWithInternal> Create( \
292 rtc::Thread* primary_thread, INTERNAL_CLASS* c) { \
293 return rtc::make_ref_counted<class_name##ProxyWithInternal>( \
294 primary_thread, c); \
295 }
296
297#define BEGIN_PROXY_MAP(class_name) \
298 PROXY_MAP_BOILERPLATE(class_name) \
299 SECONDARY_PROXY_MAP_BOILERPLATE(class_name) \
300 REFCOUNTED_PROXY_MAP_BOILERPLATE(class_name) \
301 public: \
302 static rtc::scoped_refptr<class_name##ProxyWithInternal> Create( \
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100303 rtc::Thread* primary_thread, rtc::Thread* secondary_thread, \
Niels Möller7f761572022-01-25 16:18:53 +0100304 INTERNAL_CLASS* c) { \
305 return rtc::make_ref_counted<class_name##ProxyWithInternal>( \
306 primary_thread, secondary_thread, c); \
307 }
308
309#define BEGIN_OWNED_PROXY_MAP(class_name) \
310 PROXY_MAP_BOILERPLATE(class_name) \
311 SECONDARY_PROXY_MAP_BOILERPLATE(class_name) \
312 OWNED_PROXY_MAP_BOILERPLATE(class_name) \
313 public: \
314 static std::unique_ptr<class_name##Interface> Create( \
315 rtc::Thread* primary_thread, rtc::Thread* secondary_thread, \
316 std::unique_ptr<INTERNAL_CLASS> c) { \
317 return std::unique_ptr<class_name##Interface>( \
318 new class_name##ProxyWithInternal(primary_thread, secondary_thread, \
319 c.release())); \
deadbeefd99a2002017-01-18 08:55:23 -0800320 }
321
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100322#define PROXY_PRIMARY_THREAD_DESTRUCTOR() \
323 private: \
324 rtc::Thread* destructor_thread() const { return primary_thread_; } \
325 \
326 public: // NOLINTNEXTLINE
327
328#define PROXY_SECONDARY_THREAD_DESTRUCTOR() \
deadbeefd99a2002017-01-18 08:55:23 -0800329 private: \
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100330 rtc::Thread* destructor_thread() const { return secondary_thread_; } \
deadbeefd99a2002017-01-18 08:55:23 -0800331 \
oprypin803dc292017-02-01 01:55:59 -0800332 public: // NOLINTNEXTLINE
deadbeefd99a2002017-01-18 08:55:23 -0800333
Markus Handell3d46d0b2021-05-27 21:42:57 +0200334#if defined(RTC_DISABLE_PROXY_TRACE_EVENTS)
335#define TRACE_BOILERPLATE(method) \
336 do { \
337 } while (0)
338#else // if defined(RTC_DISABLE_PROXY_TRACE_EVENTS)
339#define TRACE_BOILERPLATE(method) \
340 static constexpr auto class_and_method_name = \
341 rtc::MakeCompileTimeString(proxy_name_) \
342 .Concat(rtc::MakeCompileTimeString("::")) \
343 .Concat(rtc::MakeCompileTimeString(#method)); \
344 proxy_internal::ScopedTrace scoped_trace(class_and_method_name.string)
345
346#endif // if defined(RTC_DISABLE_PROXY_TRACE_EVENTS)
347
348#define PROXY_METHOD0(r, method) \
349 r method() override { \
350 TRACE_BOILERPLATE(method); \
Niels Möller7f761572022-01-25 16:18:53 +0100351 MethodCall<C, r> call(c(), &C::method); \
Markus Handell3d46d0b2021-05-27 21:42:57 +0200352 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000353 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000354
Markus Handell3d46d0b2021-05-27 21:42:57 +0200355#define PROXY_CONSTMETHOD0(r, method) \
356 r method() const override { \
357 TRACE_BOILERPLATE(method); \
Niels Möller7f761572022-01-25 16:18:53 +0100358 ConstMethodCall<C, r> call(c(), &C::method); \
Markus Handell3d46d0b2021-05-27 21:42:57 +0200359 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000360 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000361
Niels Möller7f761572022-01-25 16:18:53 +0100362#define PROXY_METHOD1(r, method, t1) \
363 r method(t1 a1) override { \
364 TRACE_BOILERPLATE(method); \
365 MethodCall<C, r, t1> call(c(), &C::method, std::move(a1)); \
366 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000367 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000368
Niels Möller7f761572022-01-25 16:18:53 +0100369#define PROXY_CONSTMETHOD1(r, method, t1) \
370 r method(t1 a1) const override { \
371 TRACE_BOILERPLATE(method); \
372 ConstMethodCall<C, r, t1> call(c(), &C::method, std::move(a1)); \
373 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000374 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000375
Niels Möller7f761572022-01-25 16:18:53 +0100376#define PROXY_METHOD2(r, method, t1, t2) \
377 r method(t1 a1, t2 a2) override { \
378 TRACE_BOILERPLATE(method); \
379 MethodCall<C, r, t1, t2> call(c(), &C::method, std::move(a1), \
380 std::move(a2)); \
381 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000382 }
perkj@webrtc.org81134d02015-01-12 08:30:16 +0000383
Niels Möller7f761572022-01-25 16:18:53 +0100384#define PROXY_METHOD3(r, method, t1, t2, t3) \
385 r method(t1 a1, t2 a2, t3 a3) override { \
386 TRACE_BOILERPLATE(method); \
387 MethodCall<C, r, t1, t2, t3> call(c(), &C::method, std::move(a1), \
388 std::move(a2), std::move(a3)); \
389 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
deadbeefd99a2002017-01-18 08:55:23 -0800390 }
391
Niels Möller7f761572022-01-25 16:18:53 +0100392#define PROXY_METHOD4(r, method, t1, t2, t3, t4) \
393 r method(t1 a1, t2 a2, t3 a3, t4 a4) override { \
394 TRACE_BOILERPLATE(method); \
395 MethodCall<C, r, t1, t2, t3, t4> call(c(), &C::method, std::move(a1), \
396 std::move(a2), std::move(a3), \
397 std::move(a4)); \
398 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000399 }
deadbeefd99a2002017-01-18 08:55:23 -0800400
Niels Möller7f761572022-01-25 16:18:53 +0100401#define PROXY_METHOD5(r, method, t1, t2, t3, t4, t5) \
402 r method(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) override { \
403 TRACE_BOILERPLATE(method); \
404 MethodCall<C, r, t1, t2, t3, t4, t5> call(c(), &C::method, std::move(a1), \
405 std::move(a2), std::move(a3), \
406 std::move(a4), std::move(a5)); \
407 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000408 }
nisse5b68ab52016-04-07 07:45:54 -0700409
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100410// Define methods which should be invoked on the secondary thread.
Markus Handell3d46d0b2021-05-27 21:42:57 +0200411#define PROXY_SECONDARY_METHOD0(r, method) \
412 r method() override { \
413 TRACE_BOILERPLATE(method); \
Niels Möller7f761572022-01-25 16:18:53 +0100414 MethodCall<C, r> call(c(), &C::method); \
Markus Handell3d46d0b2021-05-27 21:42:57 +0200415 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000416 }
nisse5b68ab52016-04-07 07:45:54 -0700417
Markus Handell3d46d0b2021-05-27 21:42:57 +0200418#define PROXY_SECONDARY_CONSTMETHOD0(r, method) \
419 r method() const override { \
420 TRACE_BOILERPLATE(method); \
Niels Möller7f761572022-01-25 16:18:53 +0100421 ConstMethodCall<C, r> call(c(), &C::method); \
Markus Handell3d46d0b2021-05-27 21:42:57 +0200422 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000423 }
perkj@webrtc.org81134d02015-01-12 08:30:16 +0000424
Niels Möller7f761572022-01-25 16:18:53 +0100425#define PROXY_SECONDARY_METHOD1(r, method, t1) \
426 r method(t1 a1) override { \
427 TRACE_BOILERPLATE(method); \
428 MethodCall<C, r, t1> call(c(), &C::method, std::move(a1)); \
429 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000430 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000431
Niels Möller7f761572022-01-25 16:18:53 +0100432#define PROXY_SECONDARY_CONSTMETHOD1(r, method, t1) \
433 r method(t1 a1) const override { \
434 TRACE_BOILERPLATE(method); \
435 ConstMethodCall<C, r, t1> call(c(), &C::method, std::move(a1)); \
436 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000437 }
deadbeefd99a2002017-01-18 08:55:23 -0800438
Niels Möller7f761572022-01-25 16:18:53 +0100439#define PROXY_SECONDARY_METHOD2(r, method, t1, t2) \
440 r method(t1 a1, t2 a2) override { \
441 TRACE_BOILERPLATE(method); \
442 MethodCall<C, r, t1, t2> call(c(), &C::method, std::move(a1), \
443 std::move(a2)); \
444 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000445 }
deadbeefd99a2002017-01-18 08:55:23 -0800446
Niels Möller7f761572022-01-25 16:18:53 +0100447#define PROXY_SECONDARY_CONSTMETHOD2(r, method, t1, t2) \
448 r method(t1 a1, t2 a2) const override { \
449 TRACE_BOILERPLATE(method); \
450 ConstMethodCall<C, r, t1, t2> call(c(), &C::method, std::move(a1), \
451 std::move(a2)); \
452 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
453 }
454
455#define PROXY_SECONDARY_METHOD3(r, method, t1, t2, t3) \
456 r method(t1 a1, t2 a2, t3 a3) override { \
Markus Handell3d46d0b2021-05-27 21:42:57 +0200457 TRACE_BOILERPLATE(method); \
Niels Möller7f761572022-01-25 16:18:53 +0100458 MethodCall<C, r, t1, t2, t3> call(c(), &C::method, std::move(a1), \
459 std::move(a2), std::move(a3)); \
Markus Handell3d46d0b2021-05-27 21:42:57 +0200460 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000461 }
deadbeefe814a0d2017-02-25 18:15:09 -0800462
Niels Möller7f761572022-01-25 16:18:53 +0100463#define PROXY_SECONDARY_CONSTMETHOD3(r, method, t1, t2) \
464 r method(t1 a1, t2 a2, t3 a3) const override { \
465 TRACE_BOILERPLATE(method); \
466 ConstMethodCall<C, r, t1, t2, t3> call(c(), &C::method, std::move(a1), \
467 std::move(a2), std::move(a3)); \
468 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000469 }
deadbeefd99a2002017-01-18 08:55:23 -0800470
Tomas Gunnarsson0ca13d92020-06-10 12:17:50 +0200471// For use when returning purely const state (set during construction).
472// Use with caution. This method should only be used when the return value will
473// always be the same.
Markus Handell3d46d0b2021-05-27 21:42:57 +0200474#define BYPASS_PROXY_CONSTMETHOD0(r, method) \
475 r method() const override { \
476 TRACE_BOILERPLATE(method); \
477 return c_->method(); \
Tomas Gunnarsson0ca13d92020-06-10 12:17:50 +0200478 }
479
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000480} // namespace webrtc
481
Markus Handella1b82012021-05-26 18:56:30 +0200482#endif // PC_PROXY_H_