blob: 2f3865d5bcc9224e0b14f949a07c37dab626f539 [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>
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
Tomas Gunnarsson0d5ce622022-03-18 15:57:15 +0100229#define PRIMARY_PROXY_MAP_BOILERPLATE(class_name) \
230 protected: \
231 class_name##ProxyWithInternal(rtc::Thread* primary_thread, \
232 rtc::scoped_refptr<INTERNAL_CLASS> c) \
233 : primary_thread_(primary_thread), c_(std::move(c)) {} \
234 \
235 private: \
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100236 mutable rtc::Thread* primary_thread_;
237
Tomas Gunnarsson0d5ce622022-03-18 15:57:15 +0100238#define SECONDARY_PROXY_MAP_BOILERPLATE(class_name) \
239 protected: \
240 class_name##ProxyWithInternal(rtc::Thread* primary_thread, \
241 rtc::Thread* secondary_thread, \
242 rtc::scoped_refptr<INTERNAL_CLASS> c) \
243 : primary_thread_(primary_thread), \
244 secondary_thread_(secondary_thread), \
245 c_(std::move(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
Tomas Gunnarsson0d5ce622022-03-18 15:57:15 +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) \
290 public: \
291 static rtc::scoped_refptr<class_name##ProxyWithInternal> Create( \
292 rtc::Thread* primary_thread, rtc::scoped_refptr<INTERNAL_CLASS> c) { \
293 return rtc::make_ref_counted<class_name##ProxyWithInternal>( \
294 primary_thread, std::move(c)); \
Niels Möller7f761572022-01-25 16:18:53 +0100295 }
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, \
Tomas Gunnarsson0d5ce622022-03-18 15:57:15 +0100304 rtc::scoped_refptr<INTERNAL_CLASS> c) { \
Niels Möller7f761572022-01-25 16:18:53 +0100305 return rtc::make_ref_counted<class_name##ProxyWithInternal>( \
Tomas Gunnarsson0d5ce622022-03-18 15:57:15 +0100306 primary_thread, secondary_thread, std::move(c)); \
Niels Möller7f761572022-01-25 16:18:53 +0100307 }
308
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100309#define PROXY_PRIMARY_THREAD_DESTRUCTOR() \
310 private: \
311 rtc::Thread* destructor_thread() const { return primary_thread_; } \
312 \
313 public: // NOLINTNEXTLINE
314
315#define PROXY_SECONDARY_THREAD_DESTRUCTOR() \
deadbeefd99a2002017-01-18 08:55:23 -0800316 private: \
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100317 rtc::Thread* destructor_thread() const { return secondary_thread_; } \
deadbeefd99a2002017-01-18 08:55:23 -0800318 \
oprypin803dc292017-02-01 01:55:59 -0800319 public: // NOLINTNEXTLINE
deadbeefd99a2002017-01-18 08:55:23 -0800320
Markus Handell3d46d0b2021-05-27 21:42:57 +0200321#if defined(RTC_DISABLE_PROXY_TRACE_EVENTS)
322#define TRACE_BOILERPLATE(method) \
323 do { \
324 } while (0)
325#else // if defined(RTC_DISABLE_PROXY_TRACE_EVENTS)
326#define TRACE_BOILERPLATE(method) \
327 static constexpr auto class_and_method_name = \
328 rtc::MakeCompileTimeString(proxy_name_) \
329 .Concat(rtc::MakeCompileTimeString("::")) \
330 .Concat(rtc::MakeCompileTimeString(#method)); \
331 proxy_internal::ScopedTrace scoped_trace(class_and_method_name.string)
332
333#endif // if defined(RTC_DISABLE_PROXY_TRACE_EVENTS)
334
335#define PROXY_METHOD0(r, method) \
336 r method() override { \
337 TRACE_BOILERPLATE(method); \
Niels Möller7f761572022-01-25 16:18:53 +0100338 MethodCall<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
Markus Handell3d46d0b2021-05-27 21:42:57 +0200342#define PROXY_CONSTMETHOD0(r, method) \
343 r method() const override { \
344 TRACE_BOILERPLATE(method); \
Niels Möller7f761572022-01-25 16:18:53 +0100345 ConstMethodCall<C, r> call(c(), &C::method); \
Markus Handell3d46d0b2021-05-27 21:42:57 +0200346 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_METHOD1(r, method, t1) \
350 r method(t1 a1) override { \
351 TRACE_BOILERPLATE(method); \
352 MethodCall<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_CONSTMETHOD1(r, method, t1) \
357 r method(t1 a1) const override { \
358 TRACE_BOILERPLATE(method); \
359 ConstMethodCall<C, r, t1> call(c(), &C::method, std::move(a1)); \
360 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000361 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000362
Niels Möller7f761572022-01-25 16:18:53 +0100363#define PROXY_METHOD2(r, method, t1, t2) \
364 r method(t1 a1, t2 a2) override { \
365 TRACE_BOILERPLATE(method); \
366 MethodCall<C, r, t1, t2> call(c(), &C::method, std::move(a1), \
367 std::move(a2)); \
368 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000369 }
perkj@webrtc.org81134d02015-01-12 08:30:16 +0000370
Niels Möller7f761572022-01-25 16:18:53 +0100371#define PROXY_METHOD3(r, method, t1, t2, t3) \
372 r method(t1 a1, t2 a2, t3 a3) override { \
373 TRACE_BOILERPLATE(method); \
374 MethodCall<C, r, t1, t2, t3> call(c(), &C::method, std::move(a1), \
375 std::move(a2), std::move(a3)); \
376 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
deadbeefd99a2002017-01-18 08:55:23 -0800377 }
378
Niels Möller7f761572022-01-25 16:18:53 +0100379#define PROXY_METHOD4(r, method, t1, t2, t3, t4) \
380 r method(t1 a1, t2 a2, t3 a3, t4 a4) override { \
381 TRACE_BOILERPLATE(method); \
382 MethodCall<C, r, t1, t2, t3, t4> call(c(), &C::method, std::move(a1), \
383 std::move(a2), std::move(a3), \
384 std::move(a4)); \
385 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000386 }
deadbeefd99a2002017-01-18 08:55:23 -0800387
Niels Möller7f761572022-01-25 16:18:53 +0100388#define PROXY_METHOD5(r, method, t1, t2, t3, t4, t5) \
389 r method(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) override { \
390 TRACE_BOILERPLATE(method); \
391 MethodCall<C, r, t1, t2, t3, t4, t5> call(c(), &C::method, std::move(a1), \
392 std::move(a2), std::move(a3), \
393 std::move(a4), std::move(a5)); \
394 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000395 }
nisse5b68ab52016-04-07 07:45:54 -0700396
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100397// Define methods which should be invoked on the secondary thread.
Markus Handell3d46d0b2021-05-27 21:42:57 +0200398#define PROXY_SECONDARY_METHOD0(r, method) \
399 r method() override { \
400 TRACE_BOILERPLATE(method); \
Niels Möller7f761572022-01-25 16:18:53 +0100401 MethodCall<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 }
nisse5b68ab52016-04-07 07:45:54 -0700404
Markus Handell3d46d0b2021-05-27 21:42:57 +0200405#define PROXY_SECONDARY_CONSTMETHOD0(r, method) \
406 r method() const override { \
407 TRACE_BOILERPLATE(method); \
Niels Möller7f761572022-01-25 16:18:53 +0100408 ConstMethodCall<C, r> call(c(), &C::method); \
Markus Handell3d46d0b2021-05-27 21:42:57 +0200409 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000410 }
perkj@webrtc.org81134d02015-01-12 08:30:16 +0000411
Niels Möller7f761572022-01-25 16:18:53 +0100412#define PROXY_SECONDARY_METHOD1(r, method, t1) \
413 r method(t1 a1) override { \
414 TRACE_BOILERPLATE(method); \
415 MethodCall<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 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000418
Niels Möller7f761572022-01-25 16:18:53 +0100419#define PROXY_SECONDARY_CONSTMETHOD1(r, method, t1) \
420 r method(t1 a1) const override { \
421 TRACE_BOILERPLATE(method); \
422 ConstMethodCall<C, r, t1> call(c(), &C::method, std::move(a1)); \
423 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000424 }
deadbeefd99a2002017-01-18 08:55:23 -0800425
Niels Möller7f761572022-01-25 16:18:53 +0100426#define PROXY_SECONDARY_METHOD2(r, method, t1, t2) \
427 r method(t1 a1, t2 a2) override { \
428 TRACE_BOILERPLATE(method); \
429 MethodCall<C, r, t1, t2> call(c(), &C::method, std::move(a1), \
430 std::move(a2)); \
431 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000432 }
deadbeefd99a2002017-01-18 08:55:23 -0800433
Niels Möller7f761572022-01-25 16:18:53 +0100434#define PROXY_SECONDARY_CONSTMETHOD2(r, method, t1, t2) \
435 r method(t1 a1, t2 a2) const override { \
436 TRACE_BOILERPLATE(method); \
437 ConstMethodCall<C, r, t1, t2> call(c(), &C::method, std::move(a1), \
438 std::move(a2)); \
439 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
440 }
441
442#define PROXY_SECONDARY_METHOD3(r, method, t1, t2, t3) \
443 r method(t1 a1, t2 a2, t3 a3) override { \
Markus Handell3d46d0b2021-05-27 21:42:57 +0200444 TRACE_BOILERPLATE(method); \
Niels Möller7f761572022-01-25 16:18:53 +0100445 MethodCall<C, r, t1, t2, t3> call(c(), &C::method, std::move(a1), \
446 std::move(a2), std::move(a3)); \
Markus Handell3d46d0b2021-05-27 21:42:57 +0200447 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000448 }
deadbeefe814a0d2017-02-25 18:15:09 -0800449
Niels Möller7f761572022-01-25 16:18:53 +0100450#define PROXY_SECONDARY_CONSTMETHOD3(r, method, t1, t2) \
451 r method(t1 a1, t2 a2, t3 a3) const override { \
452 TRACE_BOILERPLATE(method); \
453 ConstMethodCall<C, r, t1, t2, t3> call(c(), &C::method, std::move(a1), \
454 std::move(a2), std::move(a3)); \
455 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000456 }
deadbeefd99a2002017-01-18 08:55:23 -0800457
Tomas Gunnarsson0ca13d92020-06-10 12:17:50 +0200458// For use when returning purely const state (set during construction).
459// Use with caution. This method should only be used when the return value will
460// always be the same.
Markus Handell3d46d0b2021-05-27 21:42:57 +0200461#define BYPASS_PROXY_CONSTMETHOD0(r, method) \
462 r method() const override { \
463 TRACE_BOILERPLATE(method); \
464 return c_->method(); \
Tomas Gunnarsson0ca13d92020-06-10 12:17:50 +0200465 }
466
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000467} // namespace webrtc
468
Markus Handella1b82012021-05-26 18:56:30 +0200469#endif // PC_PROXY_H_