blob: 565ae801755dc6b3747c081b75c7a97348ad6842 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:361/*
kjellanderb24317b2016-02-10 15:54:432 * Copyright 2013 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:363 *
kjellanderb24317b2016-02-10 15:54:434 * 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:369 */
10
11// This file contains Macros for creating proxies for webrtc MediaStream and
12// PeerConnection classes.
deadbeefb10f32f2017-02-08 09:38:2113// TODO(deadbeef): Move this to pc/; this is part of the implementation.
henrike@webrtc.org28e20752013-07-10 00:45:3614
Mirko Bonadei9d9b8de2021-02-26 08:51:2615// 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:3622//
23// Example usage:
24//
buildbot@webrtc.orgd4e598d2014-07-29 17:36:5225// class TestInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:3626// public:
27// std::string FooA() = 0;
28// std::string FooB(bool arg1) const = 0;
nisse72c8d2b2016-04-15 10:49:0729// std::string FooC(bool arg1) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:3630// };
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 08:51:2639// PROXY_PRIMARY_THREAD_DESTRUCTOR()
henrike@webrtc.org28e20752013-07-10 00:45:3640// PROXY_METHOD0(std::string, FooA)
41// PROXY_CONSTMETHOD1(std::string, FooB, arg1)
Mirko Bonadei9d9b8de2021-02-26 08:51:2642// PROXY_SECONDARY_METHOD1(std::string, FooC, arg1)
deadbeefd99a2002017-01-18 16:55:2343// END_PROXY_MAP()
henrike@webrtc.org28e20752013-07-10 00:45:3644//
Mirko Bonadei9d9b8de2021-02-26 08:51:2645// 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 10:49:0747//
48// The proxy can be created using
49//
50// TestProxy::Create(Thread* signaling_thread, Thread* worker_thread,
51// TestInterface*).
52//
Mirko Bonadei9d9b8de2021-02-26 08:51:2653// 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 16:55:2355//
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:3658
Markus Handella1b82012021-05-26 16:56:3059#ifndef PC_PROXY_H_
60#define PC_PROXY_H_
henrike@webrtc.org28e20752013-07-10 00:45:3661
kwibergd1fe2812016-04-27 13:47:2962#include <memory>
Yves Gerey3e707812018-11-28 15:47:4963#include <string>
Steve Antonc3639822019-11-26 23:27:5064#include <tuple>
Tomas Gunnarsson0ca13d92020-06-10 10:17:5065#include <type_traits>
oprypin803dc292017-02-01 09:55:5966#include <utility>
kwibergd1fe2812016-04-27 13:47:2967
Mirko Bonadeid9708072019-01-25 19:26:4868#include "api/scoped_refptr.h"
Tomas Gunnarssonabdb4702020-09-05 16:43:3669#include "api/task_queue/queued_task.h"
70#include "api/task_queue/task_queue_base.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3171#include "rtc_base/event.h"
Steve Anton10542f22019-01-11 17:11:0072#include "rtc_base/message_handler.h"
Steve Anton10542f22019-01-11 17:11:0073#include "rtc_base/ref_counted_object.h"
Markus Handell3d46d0b2021-05-27 19:42:5774#include "rtc_base/string_utils.h"
Mirko Bonadei35214fc2019-09-23 12:54:2875#include "rtc_base/system/rtc_export.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3176#include "rtc_base/thread.h"
henrike@webrtc.org28e20752013-07-10 00:45:3677
Markus Handell3d46d0b2021-05-27 19:42:5778#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 15:47:4982namespace rtc {
83class Location;
84}
85
henrike@webrtc.org28e20752013-07-10 00:45:3686namespace webrtc {
Tommi1cb796f2021-05-21 06:50:0987namespace proxy_internal {
Markus Handell3d46d0b2021-05-27 19:42:5788
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 06:50:0998} // namespace proxy_internal
henrike@webrtc.org28e20752013-07-10 00:45:3699
Guido Urdanetaccab06f2020-01-15 11:30:29100template <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:29125template <typename C, typename R, typename... Args>
Tomas Gunnarssonabdb4702020-09-05 16:43:36126class MethodCall : public QueuedTask {
Guido Urdanetaccab06f2020-01-15 11:30:29127 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 16:43:36135 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:29141 return r_.moved_result();
142 }
143
144 private:
Tomas Gunnarssonabdb4702020-09-05 16:43:36145 bool Run() override {
146 Invoke(std::index_sequence_for<Args...>());
147 event_.Set();
148 return false;
149 }
Guido Urdanetaccab06f2020-01-15 11:30:29150
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 16:43:36160 rtc::Event event_;
Guido Urdanetaccab06f2020-01-15 11:30:29161};
162
163template <typename C, typename R, typename... Args>
Tomas Gunnarssonabdb4702020-09-05 16:43:36164class ConstMethodCall : public QueuedTask {
Guido Urdanetaccab06f2020-01-15 11:30:29165 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 16:43:36173 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:29179 return r_.moved_result();
180 }
181
182 private:
Tomas Gunnarssonabdb4702020-09-05 16:43:36183 bool Run() override {
184 Invoke(std::index_sequence_for<Args...>());
185 event_.Set();
186 return false;
187 }
Guido Urdanetaccab06f2020-01-15 11:30:29188
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 16:43:36198 rtc::Event event_;
Guido Urdanetaccab06f2020-01-15 11:30:29199};
200
Tommi1cb796f2021-05-21 06:50:09201#define PROXY_STRINGIZE_IMPL(x) #x
202#define PROXY_STRINGIZE(x) PROXY_STRINGIZE_IMPL(x)
203
deadbeefd99a2002017-01-18 16:55:23204// Helper macros to reduce code duplication.
deadbeefe814a0d2017-02-26 02:15:09205#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 19:42:57212 static constexpr char proxy_name_[] = #c "Proxy"; \
deadbeefe814a0d2017-02-26 02:15:09213 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:36218
Yves Gerey665174f2018-06-19 13:03:05219// clang-format off
220// clang-format would put the semicolon alone,
221// leading to a presubmit error (cpplint.py)
Markus Handell3d46d0b2021-05-27 19:42:57222#define END_PROXY_MAP(c) \
223 }; \
224 template <class INTERNAL_CLASS> \
225 constexpr char c##ProxyWithInternal<INTERNAL_CLASS>::proxy_name_[];
Yves Gerey665174f2018-06-19 13:03:05226// clang-format on
oprypin803dc292017-02-01 09:55:59227
Mirko Bonadei9d9b8de2021-02-26 08:51:26228#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 16:55:23237 protected: \
Mirko Bonadei9d9b8de2021-02-26 08:51:26238 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 16:55:23243 \
244 private: \
Mirko Bonadei9d9b8de2021-02-26 08:51:26245 mutable rtc::Thread* primary_thread_; \
246 mutable rtc::Thread* secondary_thread_;
deadbeefd99a2002017-01-18 16:55:23247
248// Note that the destructor is protected so that the proxy can only be
249// destroyed via RefCountInterface.
Guido Urdanetaccab06f2020-01-15 11:30:29250#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 16:55:23260 rtc::scoped_refptr<INTERNAL_CLASS> c_;
261
deadbeefe814a0d2017-02-26 02:15:09262// 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:29267#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-26 02:15:09277 INTERNAL_CLASS* c_;
deadbeefd99a2002017-01-18 16:55:23278
Tomas Gunnarssonc1d58912021-04-22 17:21:43279#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 16:55:23287 }
288
Tomas Gunnarssonc1d58912021-04-22 17:21:43289#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 16:55:23299 }
300
deadbeefe814a0d2017-02-26 02:15:09301#define BEGIN_OWNED_PROXY_MAP(c) \
302 PROXY_MAP_BOILERPLATE(c) \
Mirko Bonadei9d9b8de2021-02-26 08:51:26303 SECONDARY_PROXY_MAP_BOILERPLATE(c) \
deadbeefe814a0d2017-02-26 02:15:09304 OWNED_PROXY_MAP_BOILERPLATE(c) \
305 public: \
306 static std::unique_ptr<c##Interface> Create( \
Mirko Bonadei9d9b8de2021-02-26 08:51:26307 rtc::Thread* primary_thread, rtc::Thread* secondary_thread, \
deadbeefe814a0d2017-02-26 02:15:09308 std::unique_ptr<INTERNAL_CLASS> c) { \
309 return std::unique_ptr<c##Interface>(new c##ProxyWithInternal( \
Mirko Bonadei9d9b8de2021-02-26 08:51:26310 primary_thread, secondary_thread, c.release())); \
deadbeefd99a2002017-01-18 16:55:23311 }
312
Mirko Bonadei9d9b8de2021-02-26 08:51:26313#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 16:55:23320 private: \
Mirko Bonadei9d9b8de2021-02-26 08:51:26321 rtc::Thread* destructor_thread() const { return secondary_thread_; } \
deadbeefd99a2002017-01-18 16:55:23322 \
oprypin803dc292017-02-01 09:55:59323 public: // NOLINTNEXTLINE
deadbeefd99a2002017-01-18 16:55:23324
Markus Handell3d46d0b2021-05-27 19:42:57325#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:35344 }
henrike@webrtc.org28e20752013-07-10 00:45:36345
Markus Handell3d46d0b2021-05-27 19:42:57346#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:35351 }
henrike@webrtc.org28e20752013-07-10 00:45:36352
Markus Handell3d46d0b2021-05-27 19:42:57353#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:35358 }
henrike@webrtc.org28e20752013-07-10 00:45:36359
Markus Handell3d46d0b2021-05-27 19:42:57360#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:35365 }
henrike@webrtc.org28e20752013-07-10 00:45:36366
Markus Handell3d46d0b2021-05-27 19:42:57367#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:35373 }
perkj@webrtc.org81134d02015-01-12 08:30:16374
Markus Handell3d46d0b2021-05-27 19:42:57375#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 16:55:23381 }
382
Guido Urdanetaccab06f2020-01-15 11:30:29383#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 19:42:57385 TRACE_BOILERPLATE(method); \
Guido Urdanetaccab06f2020-01-15 11:30:29386 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 08:51:26389 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29390 }
deadbeefd99a2002017-01-18 16:55:23391
Guido Urdanetaccab06f2020-01-15 11:30:29392#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 19:42:57394 TRACE_BOILERPLATE(method); \
Guido Urdanetaccab06f2020-01-15 11:30:29395 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 08:51:26398 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29399 }
nisse5b68ab52016-04-07 14:45:54400
Mirko Bonadei9d9b8de2021-02-26 08:51:26401// Define methods which should be invoked on the secondary thread.
Markus Handell3d46d0b2021-05-27 19:42:57402#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:29407 }
nisse5b68ab52016-04-07 14:45:54408
Markus Handell3d46d0b2021-05-27 19:42:57409#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:29414 }
perkj@webrtc.org81134d02015-01-12 08:30:16415
Markus Handell3d46d0b2021-05-27 19:42:57416#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:29421 }
henrike@webrtc.org28e20752013-07-10 00:45:36422
Markus Handell3d46d0b2021-05-27 19:42:57423#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:29428 }
deadbeefd99a2002017-01-18 16:55:23429
Markus Handell3d46d0b2021-05-27 19:42:57430#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:29436 }
deadbeefd99a2002017-01-18 16:55:23437
Markus Handell3d46d0b2021-05-27 19:42:57438#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:29444 }
deadbeefe814a0d2017-02-26 02:15:09445
Markus Handell3d46d0b2021-05-27 19:42:57446#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:29452 }
Steve Antonc3639822019-11-26 23:27:50453
Mirko Bonadei9d9b8de2021-02-26 08:51:26454#define PROXY_SECONDARY_CONSTMETHOD3(r, method, t1, t2) \
Guido Urdanetaccab06f2020-01-15 11:30:29455 r method(t1 a1, t2 a2, t3 a3) const override { \
Markus Handell3d46d0b2021-05-27 19:42:57456 TRACE_BOILERPLATE(method); \
Guido Urdanetaccab06f2020-01-15 11:30:29457 ConstMethodCall<C, r, t1, t2, t3> call(c_, &C::method, std::move(a1), \
458 std::move(a2), std::move(a3)); \
Mirko Bonadei9d9b8de2021-02-26 08:51:26459 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29460 }
deadbeefd99a2002017-01-18 16:55:23461
Tomas Gunnarsson0ca13d92020-06-10 10:17:50462// 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 19:42:57465#define BYPASS_PROXY_CONSTMETHOD0(r, method) \
466 r method() const override { \
467 TRACE_BOILERPLATE(method); \
468 return c_->method(); \
Tomas Gunnarsson0ca13d92020-06-10 10:17:50469 }
470
henrike@webrtc.org28e20752013-07-10 00:45:36471} // namespace webrtc
472
Markus Handella1b82012021-05-26 16:56:30473#endif // PC_PROXY_H_