blob: 3be9f93764c34d47acb997dec0dac7e84438d2e1 [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
Mirko Bonadei92ea95e2017-09-15 04:47:3159#ifndef API_PROXY_H_
60#define API_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"
Mirko Bonadei35214fc2019-09-23 12:54:2874#include "rtc_base/system/rtc_export.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3175#include "rtc_base/thread.h"
henrike@webrtc.org28e20752013-07-10 00:45:3676
Yves Gerey3e707812018-11-28 15:47:4977namespace rtc {
78class Location;
79}
80
henrike@webrtc.org28e20752013-07-10 00:45:3681namespace webrtc {
82
Guido Urdanetaccab06f2020-01-15 11:30:2983template <typename R>
84class ReturnType {
85 public:
86 template <typename C, typename M, typename... Args>
87 void Invoke(C* c, M m, Args&&... args) {
88 r_ = (c->*m)(std::forward<Args>(args)...);
89 }
90
91 R moved_result() { return std::move(r_); }
92
93 private:
94 R r_;
95};
96
97template <>
98class ReturnType<void> {
99 public:
100 template <typename C, typename M, typename... Args>
101 void Invoke(C* c, M m, Args&&... args) {
102 (c->*m)(std::forward<Args>(args)...);
103 }
104
105 void moved_result() {}
106};
107
Guido Urdanetaccab06f2020-01-15 11:30:29108template <typename C, typename R, typename... Args>
Tomas Gunnarssonabdb4702020-09-05 16:43:36109class MethodCall : public QueuedTask {
Guido Urdanetaccab06f2020-01-15 11:30:29110 public:
111 typedef R (C::*Method)(Args...);
112 MethodCall(C* c, Method m, Args&&... args)
113 : c_(c),
114 m_(m),
115 args_(std::forward_as_tuple(std::forward<Args>(args)...)) {}
116
117 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
Tomas Gunnarssonabdb4702020-09-05 16:43:36118 if (t->IsCurrent()) {
119 Invoke(std::index_sequence_for<Args...>());
120 } else {
121 t->PostTask(std::unique_ptr<QueuedTask>(this));
122 event_.Wait(rtc::Event::kForever);
123 }
Guido Urdanetaccab06f2020-01-15 11:30:29124 return r_.moved_result();
125 }
126
127 private:
Tomas Gunnarssonabdb4702020-09-05 16:43:36128 bool Run() override {
129 Invoke(std::index_sequence_for<Args...>());
130 event_.Set();
131 return false;
132 }
Guido Urdanetaccab06f2020-01-15 11:30:29133
134 template <size_t... Is>
135 void Invoke(std::index_sequence<Is...>) {
136 r_.Invoke(c_, m_, std::move(std::get<Is>(args_))...);
137 }
138
139 C* c_;
140 Method m_;
141 ReturnType<R> r_;
142 std::tuple<Args&&...> args_;
Tomas Gunnarssonabdb4702020-09-05 16:43:36143 rtc::Event event_;
Guido Urdanetaccab06f2020-01-15 11:30:29144};
145
146template <typename C, typename R, typename... Args>
Tomas Gunnarssonabdb4702020-09-05 16:43:36147class ConstMethodCall : public QueuedTask {
Guido Urdanetaccab06f2020-01-15 11:30:29148 public:
149 typedef R (C::*Method)(Args...) const;
150 ConstMethodCall(const C* c, Method m, Args&&... args)
151 : c_(c),
152 m_(m),
153 args_(std::forward_as_tuple(std::forward<Args>(args)...)) {}
154
155 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
Tomas Gunnarssonabdb4702020-09-05 16:43:36156 if (t->IsCurrent()) {
157 Invoke(std::index_sequence_for<Args...>());
158 } else {
159 t->PostTask(std::unique_ptr<QueuedTask>(this));
160 event_.Wait(rtc::Event::kForever);
161 }
Guido Urdanetaccab06f2020-01-15 11:30:29162 return r_.moved_result();
163 }
164
165 private:
Tomas Gunnarssonabdb4702020-09-05 16:43:36166 bool Run() override {
167 Invoke(std::index_sequence_for<Args...>());
168 event_.Set();
169 return false;
170 }
Guido Urdanetaccab06f2020-01-15 11:30:29171
172 template <size_t... Is>
173 void Invoke(std::index_sequence<Is...>) {
174 r_.Invoke(c_, m_, std::move(std::get<Is>(args_))...);
175 }
176
177 const C* c_;
178 Method m_;
179 ReturnType<R> r_;
180 std::tuple<Args&&...> args_;
Tomas Gunnarssonabdb4702020-09-05 16:43:36181 rtc::Event event_;
Guido Urdanetaccab06f2020-01-15 11:30:29182};
183
deadbeefd99a2002017-01-18 16:55:23184// Helper macros to reduce code duplication.
deadbeefe814a0d2017-02-26 02:15:09185#define PROXY_MAP_BOILERPLATE(c) \
186 template <class INTERNAL_CLASS> \
187 class c##ProxyWithInternal; \
188 typedef c##ProxyWithInternal<c##Interface> c##Proxy; \
189 template <class INTERNAL_CLASS> \
190 class c##ProxyWithInternal : public c##Interface { \
191 protected: \
192 typedef c##Interface C; \
193 \
194 public: \
195 const INTERNAL_CLASS* internal() const { return c_; } \
196 INTERNAL_CLASS* internal() { return c_; }
henrike@webrtc.org28e20752013-07-10 00:45:36197
Yves Gerey665174f2018-06-19 13:03:05198// clang-format off
199// clang-format would put the semicolon alone,
200// leading to a presubmit error (cpplint.py)
oprypin803dc292017-02-01 09:55:59201#define END_PROXY_MAP() \
202 };
Yves Gerey665174f2018-06-19 13:03:05203// clang-format on
oprypin803dc292017-02-01 09:55:59204
Mirko Bonadei9d9b8de2021-02-26 08:51:26205#define PRIMARY_PROXY_MAP_BOILERPLATE(c) \
206 protected: \
207 c##ProxyWithInternal(rtc::Thread* primary_thread, INTERNAL_CLASS* c) \
208 : primary_thread_(primary_thread), c_(c) {} \
209 \
210 private: \
211 mutable rtc::Thread* primary_thread_;
212
213#define SECONDARY_PROXY_MAP_BOILERPLATE(c) \
deadbeefd99a2002017-01-18 16:55:23214 protected: \
Mirko Bonadei9d9b8de2021-02-26 08:51:26215 c##ProxyWithInternal(rtc::Thread* primary_thread, \
216 rtc::Thread* secondary_thread, INTERNAL_CLASS* c) \
217 : primary_thread_(primary_thread), \
218 secondary_thread_(secondary_thread), \
219 c_(c) {} \
deadbeefd99a2002017-01-18 16:55:23220 \
221 private: \
Mirko Bonadei9d9b8de2021-02-26 08:51:26222 mutable rtc::Thread* primary_thread_; \
223 mutable rtc::Thread* secondary_thread_;
deadbeefd99a2002017-01-18 16:55:23224
225// Note that the destructor is protected so that the proxy can only be
226// destroyed via RefCountInterface.
Guido Urdanetaccab06f2020-01-15 11:30:29227#define REFCOUNTED_PROXY_MAP_BOILERPLATE(c) \
228 protected: \
229 ~c##ProxyWithInternal() { \
230 MethodCall<c##ProxyWithInternal, void> call( \
231 this, &c##ProxyWithInternal::DestroyInternal); \
232 call.Marshal(RTC_FROM_HERE, destructor_thread()); \
233 } \
234 \
235 private: \
236 void DestroyInternal() { c_ = nullptr; } \
deadbeefd99a2002017-01-18 16:55:23237 rtc::scoped_refptr<INTERNAL_CLASS> c_;
238
deadbeefe814a0d2017-02-26 02:15:09239// Note: This doesn't use a unique_ptr, because it intends to handle a corner
240// case where an object's deletion triggers a callback that calls back into
241// this proxy object. If relying on a unique_ptr to delete the object, its
242// inner pointer would be set to null before this reentrant callback would have
243// a chance to run, resulting in a segfault.
Guido Urdanetaccab06f2020-01-15 11:30:29244#define OWNED_PROXY_MAP_BOILERPLATE(c) \
245 public: \
246 ~c##ProxyWithInternal() { \
247 MethodCall<c##ProxyWithInternal, void> call( \
248 this, &c##ProxyWithInternal::DestroyInternal); \
249 call.Marshal(RTC_FROM_HERE, destructor_thread()); \
250 } \
251 \
252 private: \
253 void DestroyInternal() { delete c_; } \
deadbeefe814a0d2017-02-26 02:15:09254 INTERNAL_CLASS* c_;
deadbeefd99a2002017-01-18 16:55:23255
Mirko Bonadei9d9b8de2021-02-26 08:51:26256#define BEGIN_PRIMARY_PROXY_MAP(c) \
257 PROXY_MAP_BOILERPLATE(c) \
258 PRIMARY_PROXY_MAP_BOILERPLATE(c) \
259 REFCOUNTED_PROXY_MAP_BOILERPLATE(c) \
260 public: \
261 static rtc::scoped_refptr<c##ProxyWithInternal> Create( \
262 rtc::Thread* primary_thread, INTERNAL_CLASS* c) { \
263 return new rtc::RefCountedObject<c##ProxyWithInternal>(primary_thread, c); \
deadbeefd99a2002017-01-18 16:55:23264 }
265
Mirko Bonadei9d9b8de2021-02-26 08:51:26266#define BEGIN_PROXY_MAP(c) \
267 PROXY_MAP_BOILERPLATE(c) \
268 SECONDARY_PROXY_MAP_BOILERPLATE(c) \
269 REFCOUNTED_PROXY_MAP_BOILERPLATE(c) \
270 public: \
271 static rtc::scoped_refptr<c##ProxyWithInternal> Create( \
272 rtc::Thread* primary_thread, rtc::Thread* secondary_thread, \
273 INTERNAL_CLASS* c) { \
274 return new rtc::RefCountedObject<c##ProxyWithInternal>( \
275 primary_thread, secondary_thread, c); \
deadbeefd99a2002017-01-18 16:55:23276 }
277
deadbeefe814a0d2017-02-26 02:15:09278#define BEGIN_OWNED_PROXY_MAP(c) \
279 PROXY_MAP_BOILERPLATE(c) \
Mirko Bonadei9d9b8de2021-02-26 08:51:26280 SECONDARY_PROXY_MAP_BOILERPLATE(c) \
deadbeefe814a0d2017-02-26 02:15:09281 OWNED_PROXY_MAP_BOILERPLATE(c) \
282 public: \
283 static std::unique_ptr<c##Interface> Create( \
Mirko Bonadei9d9b8de2021-02-26 08:51:26284 rtc::Thread* primary_thread, rtc::Thread* secondary_thread, \
deadbeefe814a0d2017-02-26 02:15:09285 std::unique_ptr<INTERNAL_CLASS> c) { \
286 return std::unique_ptr<c##Interface>(new c##ProxyWithInternal( \
Mirko Bonadei9d9b8de2021-02-26 08:51:26287 primary_thread, secondary_thread, c.release())); \
deadbeefd99a2002017-01-18 16:55:23288 }
289
Mirko Bonadei9d9b8de2021-02-26 08:51:26290#define PROXY_PRIMARY_THREAD_DESTRUCTOR() \
291 private: \
292 rtc::Thread* destructor_thread() const { return primary_thread_; } \
293 \
294 public: // NOLINTNEXTLINE
295
296#define PROXY_SECONDARY_THREAD_DESTRUCTOR() \
deadbeefd99a2002017-01-18 16:55:23297 private: \
Mirko Bonadei9d9b8de2021-02-26 08:51:26298 rtc::Thread* destructor_thread() const { return secondary_thread_; } \
deadbeefd99a2002017-01-18 16:55:23299 \
oprypin803dc292017-02-01 09:55:59300 public: // NOLINTNEXTLINE
deadbeefd99a2002017-01-18 16:55:23301
Mirko Bonadei9d9b8de2021-02-26 08:51:26302#define PROXY_METHOD0(r, method) \
303 r method() override { \
304 MethodCall<C, r> call(c_, &C::method); \
305 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35306 }
henrike@webrtc.org28e20752013-07-10 00:45:36307
Mirko Bonadei9d9b8de2021-02-26 08:51:26308#define PROXY_CONSTMETHOD0(r, method) \
309 r method() const override { \
310 ConstMethodCall<C, r> call(c_, &C::method); \
311 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35312 }
henrike@webrtc.org28e20752013-07-10 00:45:36313
Guido Urdanetaccab06f2020-01-15 11:30:29314#define PROXY_METHOD1(r, method, t1) \
315 r method(t1 a1) override { \
316 MethodCall<C, r, t1> call(c_, &C::method, std::move(a1)); \
Mirko Bonadei9d9b8de2021-02-26 08:51:26317 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35318 }
henrike@webrtc.org28e20752013-07-10 00:45:36319
Guido Urdanetaccab06f2020-01-15 11:30:29320#define PROXY_CONSTMETHOD1(r, method, t1) \
321 r method(t1 a1) const override { \
322 ConstMethodCall<C, r, t1> call(c_, &C::method, std::move(a1)); \
Mirko Bonadei9d9b8de2021-02-26 08:51:26323 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35324 }
henrike@webrtc.org28e20752013-07-10 00:45:36325
Guido Urdanetaccab06f2020-01-15 11:30:29326#define PROXY_METHOD2(r, method, t1, t2) \
327 r method(t1 a1, t2 a2) override { \
328 MethodCall<C, r, t1, t2> call(c_, &C::method, std::move(a1), \
329 std::move(a2)); \
Mirko Bonadei9d9b8de2021-02-26 08:51:26330 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35331 }
perkj@webrtc.org81134d02015-01-12 08:30:16332
Guido Urdanetaccab06f2020-01-15 11:30:29333#define PROXY_METHOD3(r, method, t1, t2, t3) \
334 r method(t1 a1, t2 a2, t3 a3) override { \
335 MethodCall<C, r, t1, t2, t3> call(c_, &C::method, std::move(a1), \
336 std::move(a2), std::move(a3)); \
Mirko Bonadei9d9b8de2021-02-26 08:51:26337 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
deadbeefd99a2002017-01-18 16:55:23338 }
339
Guido Urdanetaccab06f2020-01-15 11:30:29340#define PROXY_METHOD4(r, method, t1, t2, t3, t4) \
341 r method(t1 a1, t2 a2, t3 a3, t4 a4) override { \
342 MethodCall<C, r, t1, t2, t3, t4> call(c_, &C::method, std::move(a1), \
343 std::move(a2), std::move(a3), \
344 std::move(a4)); \
Mirko Bonadei9d9b8de2021-02-26 08:51:26345 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29346 }
deadbeefd99a2002017-01-18 16:55:23347
Guido Urdanetaccab06f2020-01-15 11:30:29348#define PROXY_METHOD5(r, method, t1, t2, t3, t4, t5) \
349 r method(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) override { \
350 MethodCall<C, r, t1, t2, t3, t4, t5> call(c_, &C::method, std::move(a1), \
351 std::move(a2), std::move(a3), \
352 std::move(a4), std::move(a5)); \
Mirko Bonadei9d9b8de2021-02-26 08:51:26353 return call.Marshal(RTC_FROM_HERE, primary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29354 }
nisse5b68ab52016-04-07 14:45:54355
Mirko Bonadei9d9b8de2021-02-26 08:51:26356// Define methods which should be invoked on the secondary thread.
357#define PROXY_SECONDARY_METHOD0(r, method) \
358 r method() override { \
359 MethodCall<C, r> call(c_, &C::method); \
360 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29361 }
nisse5b68ab52016-04-07 14:45:54362
Mirko Bonadei9d9b8de2021-02-26 08:51:26363#define PROXY_SECONDARY_CONSTMETHOD0(r, method) \
364 r method() const override { \
365 ConstMethodCall<C, r> call(c_, &C::method); \
366 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29367 }
perkj@webrtc.org81134d02015-01-12 08:30:16368
Mirko Bonadei9d9b8de2021-02-26 08:51:26369#define PROXY_SECONDARY_METHOD1(r, method, t1) \
Guido Urdanetaccab06f2020-01-15 11:30:29370 r method(t1 a1) override { \
371 MethodCall<C, r, t1> call(c_, &C::method, std::move(a1)); \
Mirko Bonadei9d9b8de2021-02-26 08:51:26372 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29373 }
henrike@webrtc.org28e20752013-07-10 00:45:36374
Mirko Bonadei9d9b8de2021-02-26 08:51:26375#define PROXY_SECONDARY_CONSTMETHOD1(r, method, t1) \
Guido Urdanetaccab06f2020-01-15 11:30:29376 r method(t1 a1) const override { \
377 ConstMethodCall<C, r, t1> call(c_, &C::method, std::move(a1)); \
Mirko Bonadei9d9b8de2021-02-26 08:51:26378 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29379 }
deadbeefd99a2002017-01-18 16:55:23380
Mirko Bonadei9d9b8de2021-02-26 08:51:26381#define PROXY_SECONDARY_METHOD2(r, method, t1, t2) \
Guido Urdanetaccab06f2020-01-15 11:30:29382 r method(t1 a1, t2 a2) override { \
383 MethodCall<C, r, t1, t2> call(c_, &C::method, std::move(a1), \
384 std::move(a2)); \
Mirko Bonadei9d9b8de2021-02-26 08:51:26385 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29386 }
deadbeefd99a2002017-01-18 16:55:23387
Mirko Bonadei9d9b8de2021-02-26 08:51:26388#define PROXY_SECONDARY_CONSTMETHOD2(r, method, t1, t2) \
Guido Urdanetaccab06f2020-01-15 11:30:29389 r method(t1 a1, t2 a2) const override { \
390 ConstMethodCall<C, r, t1, t2> call(c_, &C::method, std::move(a1), \
391 std::move(a2)); \
Mirko Bonadei9d9b8de2021-02-26 08:51:26392 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29393 }
deadbeefe814a0d2017-02-26 02:15:09394
Mirko Bonadei9d9b8de2021-02-26 08:51:26395#define PROXY_SECONDARY_METHOD3(r, method, t1, t2, t3) \
Guido Urdanetaccab06f2020-01-15 11:30:29396 r method(t1 a1, t2 a2, t3 a3) override { \
397 MethodCall<C, r, t1, t2, t3> call(c_, &C::method, std::move(a1), \
398 std::move(a2), std::move(a3)); \
Mirko Bonadei9d9b8de2021-02-26 08:51:26399 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29400 }
Steve Antonc3639822019-11-26 23:27:50401
Mirko Bonadei9d9b8de2021-02-26 08:51:26402#define PROXY_SECONDARY_CONSTMETHOD3(r, method, t1, t2) \
Guido Urdanetaccab06f2020-01-15 11:30:29403 r method(t1 a1, t2 a2, t3 a3) const override { \
404 ConstMethodCall<C, r, t1, t2, t3> call(c_, &C::method, std::move(a1), \
405 std::move(a2), std::move(a3)); \
Mirko Bonadei9d9b8de2021-02-26 08:51:26406 return call.Marshal(RTC_FROM_HERE, secondary_thread_); \
Guido Urdanetaccab06f2020-01-15 11:30:29407 }
deadbeefd99a2002017-01-18 16:55:23408
Tomas Gunnarsson0ca13d92020-06-10 10:17:50409// For use when returning purely const state (set during construction).
410// Use with caution. This method should only be used when the return value will
411// always be the same.
Taylor Brandstetterc88fe702020-08-03 23:36:16412#define BYPASS_PROXY_CONSTMETHOD0(r, method) \
413 r method() const override { \
414 static_assert( \
415 std::is_same<r, rtc::Thread*>::value || !std::is_pointer<r>::value, \
416 "Type is a pointer"); \
417 static_assert(!std::is_reference<r>::value, "Type is a reference"); \
418 return c_->method(); \
Tomas Gunnarsson0ca13d92020-06-10 10:17:50419 }
420
henrike@webrtc.org28e20752013-07-10 00:45:36421} // namespace webrtc
422
Mirko Bonadei92ea95e2017-09-15 04:47:31423#endif // API_PROXY_H_