blob: 565ae801755dc6b3747c081b75c7a97348ad6842 [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.
deadbeefe814a0d2017-02-25 18:15:09 -0800205#define PROXY_MAP_BOILERPLATE(c) \
206 template <class INTERNAL_CLASS> \
207 class c##ProxyWithInternal; \
208 typedef c##ProxyWithInternal<c##Interface> c##Proxy; \
209 template <class INTERNAL_CLASS> \
210 class c##ProxyWithInternal : public c##Interface { \
211 protected: \
Markus Handell3d46d0b2021-05-27 21:42:57 +0200212 static constexpr char proxy_name_[] = #c "Proxy"; \
deadbeefe814a0d2017-02-25 18:15:09 -0800213 typedef c##Interface C; \
214 \
215 public: \
216 const INTERNAL_CLASS* internal() const { return c_; } \
217 INTERNAL_CLASS* internal() { return c_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000218
Yves Gerey665174f2018-06-19 15:03:05 +0200219// clang-format off
220// clang-format would put the semicolon alone,
221// leading to a presubmit error (cpplint.py)
Markus Handell3d46d0b2021-05-27 21:42:57 +0200222#define END_PROXY_MAP(c) \
223 }; \
224 template <class INTERNAL_CLASS> \
225 constexpr char c##ProxyWithInternal<INTERNAL_CLASS>::proxy_name_[];
Yves Gerey665174f2018-06-19 15:03:05 +0200226// clang-format on
oprypin803dc292017-02-01 01:55:59 -0800227
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100228#define PRIMARY_PROXY_MAP_BOILERPLATE(c) \
229 protected: \
230 c##ProxyWithInternal(rtc::Thread* primary_thread, INTERNAL_CLASS* c) \
231 : primary_thread_(primary_thread), c_(c) {} \
232 \
233 private: \
234 mutable rtc::Thread* primary_thread_;
235
236#define SECONDARY_PROXY_MAP_BOILERPLATE(c) \
deadbeefd99a2002017-01-18 08:55:23 -0800237 protected: \
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100238 c##ProxyWithInternal(rtc::Thread* primary_thread, \
239 rtc::Thread* secondary_thread, INTERNAL_CLASS* c) \
240 : primary_thread_(primary_thread), \
241 secondary_thread_(secondary_thread), \
242 c_(c) {} \
deadbeefd99a2002017-01-18 08:55:23 -0800243 \
244 private: \
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100245 mutable rtc::Thread* primary_thread_; \
246 mutable rtc::Thread* secondary_thread_;
deadbeefd99a2002017-01-18 08:55:23 -0800247
248// Note that the destructor is protected so that the proxy can only be
249// destroyed via RefCountInterface.
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000250#define REFCOUNTED_PROXY_MAP_BOILERPLATE(c) \
251 protected: \
252 ~c##ProxyWithInternal() { \
253 MethodCall<c##ProxyWithInternal, void> call( \
254 this, &c##ProxyWithInternal::DestroyInternal); \
255 call.Marshal(RTC_FROM_HERE, destructor_thread()); \
256 } \
257 \
258 private: \
259 void DestroyInternal() { c_ = nullptr; } \
deadbeefd99a2002017-01-18 08:55:23 -0800260 rtc::scoped_refptr<INTERNAL_CLASS> c_;
261
deadbeefe814a0d2017-02-25 18:15:09 -0800262// Note: This doesn't use a unique_ptr, because it intends to handle a corner
263// case where an object's deletion triggers a callback that calls back into
264// this proxy object. If relying on a unique_ptr to delete the object, its
265// inner pointer would be set to null before this reentrant callback would have
266// a chance to run, resulting in a segfault.
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000267#define OWNED_PROXY_MAP_BOILERPLATE(c) \
268 public: \
269 ~c##ProxyWithInternal() { \
270 MethodCall<c##ProxyWithInternal, void> call( \
271 this, &c##ProxyWithInternal::DestroyInternal); \
272 call.Marshal(RTC_FROM_HERE, destructor_thread()); \
273 } \
274 \
275 private: \
276 void DestroyInternal() { delete c_; } \
deadbeefe814a0d2017-02-25 18:15:09 -0800277 INTERNAL_CLASS* c_;
deadbeefd99a2002017-01-18 08:55:23 -0800278
Tomas Gunnarssonc1d58912021-04-22 19:21:43 +0200279#define BEGIN_PRIMARY_PROXY_MAP(c) \
280 PROXY_MAP_BOILERPLATE(c) \
281 PRIMARY_PROXY_MAP_BOILERPLATE(c) \
282 REFCOUNTED_PROXY_MAP_BOILERPLATE(c) \
283 public: \
284 static rtc::scoped_refptr<c##ProxyWithInternal> Create( \
285 rtc::Thread* primary_thread, INTERNAL_CLASS* c) { \
286 return rtc::make_ref_counted<c##ProxyWithInternal>(primary_thread, c); \
deadbeefd99a2002017-01-18 08:55:23 -0800287 }
288
Tomas Gunnarssonc1d58912021-04-22 19:21:43 +0200289#define BEGIN_PROXY_MAP(c) \
290 PROXY_MAP_BOILERPLATE(c) \
291 SECONDARY_PROXY_MAP_BOILERPLATE(c) \
292 REFCOUNTED_PROXY_MAP_BOILERPLATE(c) \
293 public: \
294 static rtc::scoped_refptr<c##ProxyWithInternal> Create( \
295 rtc::Thread* primary_thread, rtc::Thread* secondary_thread, \
296 INTERNAL_CLASS* c) { \
297 return rtc::make_ref_counted<c##ProxyWithInternal>(primary_thread, \
298 secondary_thread, c); \
deadbeefd99a2002017-01-18 08:55:23 -0800299 }
300
deadbeefe814a0d2017-02-25 18:15:09 -0800301#define BEGIN_OWNED_PROXY_MAP(c) \
302 PROXY_MAP_BOILERPLATE(c) \
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100303 SECONDARY_PROXY_MAP_BOILERPLATE(c) \
deadbeefe814a0d2017-02-25 18:15:09 -0800304 OWNED_PROXY_MAP_BOILERPLATE(c) \
305 public: \
306 static std::unique_ptr<c##Interface> Create( \
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100307 rtc::Thread* primary_thread, rtc::Thread* secondary_thread, \
deadbeefe814a0d2017-02-25 18:15:09 -0800308 std::unique_ptr<INTERNAL_CLASS> c) { \
309 return std::unique_ptr<c##Interface>(new c##ProxyWithInternal( \
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100310 primary_thread, secondary_thread, c.release())); \
deadbeefd99a2002017-01-18 08:55:23 -0800311 }
312
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100313#define PROXY_PRIMARY_THREAD_DESTRUCTOR() \
314 private: \
315 rtc::Thread* destructor_thread() const { return primary_thread_; } \
316 \
317 public: // NOLINTNEXTLINE
318
319#define PROXY_SECONDARY_THREAD_DESTRUCTOR() \
deadbeefd99a2002017-01-18 08:55:23 -0800320 private: \
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100321 rtc::Thread* destructor_thread() const { return secondary_thread_; } \
deadbeefd99a2002017-01-18 08:55:23 -0800322 \
oprypin803dc292017-02-01 01:55:59 -0800323 public: // NOLINTNEXTLINE
deadbeefd99a2002017-01-18 08:55:23 -0800324
Markus Handell3d46d0b2021-05-27 21:42:57 +0200325#if defined(RTC_DISABLE_PROXY_TRACE_EVENTS)
326#define TRACE_BOILERPLATE(method) \
327 do { \
328 } while (0)
329#else // if defined(RTC_DISABLE_PROXY_TRACE_EVENTS)
330#define TRACE_BOILERPLATE(method) \
331 static constexpr auto class_and_method_name = \
332 rtc::MakeCompileTimeString(proxy_name_) \
333 .Concat(rtc::MakeCompileTimeString("::")) \
334 .Concat(rtc::MakeCompileTimeString(#method)); \
335 proxy_internal::ScopedTrace scoped_trace(class_and_method_name.string)
336
337#endif // if defined(RTC_DISABLE_PROXY_TRACE_EVENTS)
338
339#define PROXY_METHOD0(r, method) \
340 r method() override { \
341 TRACE_BOILERPLATE(method); \
342 MethodCall<C, r> call(c_, &C::method); \
343 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000344 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000345
Markus Handell3d46d0b2021-05-27 21:42:57 +0200346#define PROXY_CONSTMETHOD0(r, method) \
347 r method() const override { \
348 TRACE_BOILERPLATE(method); \
349 ConstMethodCall<C, r> call(c_, &C::method); \
350 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000351 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000352
Markus Handell3d46d0b2021-05-27 21:42:57 +0200353#define PROXY_METHOD1(r, method, t1) \
354 r method(t1 a1) override { \
355 TRACE_BOILERPLATE(method); \
356 MethodCall<C, r, t1> call(c_, &C::method, std::move(a1)); \
357 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000358 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000359
Markus Handell3d46d0b2021-05-27 21:42:57 +0200360#define PROXY_CONSTMETHOD1(r, method, t1) \
361 r method(t1 a1) const override { \
362 TRACE_BOILERPLATE(method); \
363 ConstMethodCall<C, r, t1> call(c_, &C::method, std::move(a1)); \
364 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000365 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000366
Markus Handell3d46d0b2021-05-27 21:42:57 +0200367#define PROXY_METHOD2(r, method, t1, t2) \
368 r method(t1 a1, t2 a2) override { \
369 TRACE_BOILERPLATE(method); \
370 MethodCall<C, r, t1, t2> call(c_, &C::method, std::move(a1), \
371 std::move(a2)); \
372 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000373 }
perkj@webrtc.org81134d02015-01-12 08:30:16 +0000374
Markus Handell3d46d0b2021-05-27 21:42:57 +0200375#define PROXY_METHOD3(r, method, t1, t2, t3) \
376 r method(t1 a1, t2 a2, t3 a3) override { \
377 TRACE_BOILERPLATE(method); \
378 MethodCall<C, r, t1, t2, t3> call(c_, &C::method, std::move(a1), \
379 std::move(a2), std::move(a3)); \
380 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
deadbeefd99a2002017-01-18 08:55:23 -0800381 }
382
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000383#define PROXY_METHOD4(r, method, t1, t2, t3, t4) \
384 r method(t1 a1, t2 a2, t3 a3, t4 a4) override { \
Markus Handell3d46d0b2021-05-27 21:42:57 +0200385 TRACE_BOILERPLATE(method); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000386 MethodCall<C, r, t1, t2, t3, t4> call(c_, &C::method, std::move(a1), \
387 std::move(a2), std::move(a3), \
388 std::move(a4)); \
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100389 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000390 }
deadbeefd99a2002017-01-18 08:55:23 -0800391
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000392#define PROXY_METHOD5(r, method, t1, t2, t3, t4, t5) \
393 r method(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) override { \
Markus Handell3d46d0b2021-05-27 21:42:57 +0200394 TRACE_BOILERPLATE(method); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000395 MethodCall<C, r, t1, t2, t3, t4, t5> call(c_, &C::method, std::move(a1), \
396 std::move(a2), std::move(a3), \
397 std::move(a4), std::move(a5)); \
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100398 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000399 }
nisse5b68ab52016-04-07 07:45:54 -0700400
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100401// Define methods which should be invoked on the secondary thread.
Markus Handell3d46d0b2021-05-27 21:42:57 +0200402#define PROXY_SECONDARY_METHOD0(r, method) \
403 r method() override { \
404 TRACE_BOILERPLATE(method); \
405 MethodCall<C, r> call(c_, &C::method); \
406 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000407 }
nisse5b68ab52016-04-07 07:45:54 -0700408
Markus Handell3d46d0b2021-05-27 21:42:57 +0200409#define PROXY_SECONDARY_CONSTMETHOD0(r, method) \
410 r method() const override { \
411 TRACE_BOILERPLATE(method); \
412 ConstMethodCall<C, r> call(c_, &C::method); \
413 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000414 }
perkj@webrtc.org81134d02015-01-12 08:30:16 +0000415
Markus Handell3d46d0b2021-05-27 21:42:57 +0200416#define PROXY_SECONDARY_METHOD1(r, method, t1) \
417 r method(t1 a1) override { \
418 TRACE_BOILERPLATE(method); \
419 MethodCall<C, r, t1> call(c_, &C::method, std::move(a1)); \
420 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000421 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000422
Markus Handell3d46d0b2021-05-27 21:42:57 +0200423#define PROXY_SECONDARY_CONSTMETHOD1(r, method, t1) \
424 r method(t1 a1) const override { \
425 TRACE_BOILERPLATE(method); \
426 ConstMethodCall<C, r, t1> call(c_, &C::method, std::move(a1)); \
427 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000428 }
deadbeefd99a2002017-01-18 08:55:23 -0800429
Markus Handell3d46d0b2021-05-27 21:42:57 +0200430#define PROXY_SECONDARY_METHOD2(r, method, t1, t2) \
431 r method(t1 a1, t2 a2) override { \
432 TRACE_BOILERPLATE(method); \
433 MethodCall<C, r, t1, t2> call(c_, &C::method, std::move(a1), \
434 std::move(a2)); \
435 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000436 }
deadbeefd99a2002017-01-18 08:55:23 -0800437
Markus Handell3d46d0b2021-05-27 21:42:57 +0200438#define PROXY_SECONDARY_CONSTMETHOD2(r, method, t1, t2) \
439 r method(t1 a1, t2 a2) const override { \
440 TRACE_BOILERPLATE(method); \
441 ConstMethodCall<C, r, t1, t2> call(c_, &C::method, std::move(a1), \
442 std::move(a2)); \
443 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000444 }
deadbeefe814a0d2017-02-25 18:15:09 -0800445
Markus Handell3d46d0b2021-05-27 21:42:57 +0200446#define PROXY_SECONDARY_METHOD3(r, method, t1, t2, t3) \
447 r method(t1 a1, t2 a2, t3 a3) override { \
448 TRACE_BOILERPLATE(method); \
449 MethodCall<C, r, t1, t2, t3> call(c_, &C::method, std::move(a1), \
450 std::move(a2), std::move(a3)); \
451 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000452 }
Steve Antonc3639822019-11-26 15:27:50 -0800453
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100454#define PROXY_SECONDARY_CONSTMETHOD3(r, method, t1, t2) \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000455 r method(t1 a1, t2 a2, t3 a3) const override { \
Markus Handell3d46d0b2021-05-27 21:42:57 +0200456 TRACE_BOILERPLATE(method); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000457 ConstMethodCall<C, r, t1, t2, t3> call(c_, &C::method, std::move(a1), \
458 std::move(a2), std::move(a3)); \
Mirko Bonadei9d9b8de2021-02-26 09:51:26 +0100459 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29 +0000460 }
deadbeefd99a2002017-01-18 08:55:23 -0800461
Tomas Gunnarsson0ca13d92020-06-10 12:17:50 +0200462// For use when returning purely const state (set during construction).
463// Use with caution. This method should only be used when the return value will
464// always be the same.
Markus Handell3d46d0b2021-05-27 21:42:57 +0200465#define BYPASS_PROXY_CONSTMETHOD0(r, method) \
466 r method() const override { \
467 TRACE_BOILERPLATE(method); \
468 return c_->method(); \
Tomas Gunnarsson0ca13d92020-06-10 12:17:50 +0200469 }
470
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000471} // namespace webrtc
472
Markus Handella1b82012021-05-26 18:56:30 +0200473#endif // PC_PROXY_H_