blob: 6627aac7d471e1734d2d5b5d310ff2202bd9378e [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
15//
16// Example usage:
17//
buildbot@webrtc.orgd4e598d2014-07-29 17:36:5218// class TestInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:3619// public:
20// std::string FooA() = 0;
21// std::string FooB(bool arg1) const = 0;
nisse72c8d2b2016-04-15 10:49:0722// std::string FooC(bool arg1) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:3623// };
24//
25// Note that return types can not be a const reference.
26//
27// class Test : public TestInterface {
28// ... implementation of the interface.
29// };
30//
31// BEGIN_PROXY_MAP(Test)
deadbeefd99a2002017-01-18 16:55:2332// PROXY_SIGNALING_THREAD_DESTRUCTOR()
henrike@webrtc.org28e20752013-07-10 00:45:3633// PROXY_METHOD0(std::string, FooA)
34// PROXY_CONSTMETHOD1(std::string, FooB, arg1)
nisse72c8d2b2016-04-15 10:49:0735// PROXY_WORKER_METHOD1(std::string, FooC, arg1)
deadbeefd99a2002017-01-18 16:55:2336// END_PROXY_MAP()
henrike@webrtc.org28e20752013-07-10 00:45:3637//
deadbeefd99a2002017-01-18 16:55:2338// Where the destructor and first two methods are invoked on the signaling
39// thread, and the third is invoked on the worker thread.
nisse72c8d2b2016-04-15 10:49:0740//
41// The proxy can be created using
42//
43// TestProxy::Create(Thread* signaling_thread, Thread* worker_thread,
44// TestInterface*).
45//
46// The variant defined with BEGIN_SIGNALING_PROXY_MAP is unaware of
47// the worker thread, and invokes all methods on the signaling thread.
deadbeefd99a2002017-01-18 16:55:2348//
49// The variant defined with BEGIN_OWNED_PROXY_MAP does not use
50// refcounting, and instead just takes ownership of the object being proxied.
henrike@webrtc.org28e20752013-07-10 00:45:3651
Mirko Bonadei92ea95e2017-09-15 04:47:3152#ifndef API_PROXY_H_
53#define API_PROXY_H_
henrike@webrtc.org28e20752013-07-10 00:45:3654
kwibergd1fe2812016-04-27 13:47:2955#include <memory>
Yves Gerey3e707812018-11-28 15:47:4956#include <string>
oprypin803dc292017-02-01 09:55:5957#include <utility>
kwibergd1fe2812016-04-27 13:47:2958
Mirko Bonadeid9708072019-01-25 19:26:4859#include "api/scoped_refptr.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3160#include "rtc_base/event.h"
Steve Anton10542f22019-01-11 17:11:0061#include "rtc_base/message_handler.h"
62#include "rtc_base/message_queue.h"
63#include "rtc_base/ref_counted_object.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3164#include "rtc_base/thread.h"
henrike@webrtc.org28e20752013-07-10 00:45:3665
Yves Gerey3e707812018-11-28 15:47:4966namespace rtc {
67class Location;
68}
69
henrike@webrtc.org28e20752013-07-10 00:45:3670namespace webrtc {
71
72template <typename R>
73class ReturnType {
74 public:
Yves Gerey665174f2018-06-19 13:03:0575 template <typename C, typename M>
76 void Invoke(C* c, M m) {
77 r_ = (c->*m)();
78 }
deadbeefd99a2002017-01-18 16:55:2379 template <typename C, typename M, typename T1>
80 void Invoke(C* c, M m, T1 a1) {
81 r_ = (c->*m)(std::move(a1));
82 }
83 template <typename C, typename M, typename T1, typename T2>
84 void Invoke(C* c, M m, T1 a1, T2 a2) {
85 r_ = (c->*m)(std::move(a1), std::move(a2));
86 }
87 template <typename C, typename M, typename T1, typename T2, typename T3>
88 void Invoke(C* c, M m, T1 a1, T2 a2, T3 a3) {
89 r_ = (c->*m)(std::move(a1), std::move(a2), std::move(a3));
90 }
Yves Gerey665174f2018-06-19 13:03:0591 template <typename C,
92 typename M,
93 typename T1,
94 typename T2,
95 typename T3,
96 typename T4>
perkj@webrtc.org81134d02015-01-12 08:30:1697 void Invoke(C* c, M m, T1 a1, T2 a2, T3 a3, T4 a4) {
deadbeefd99a2002017-01-18 16:55:2398 r_ = (c->*m)(std::move(a1), std::move(a2), std::move(a3), std::move(a4));
perkj@webrtc.org81134d02015-01-12 08:30:1699 }
Yves Gerey665174f2018-06-19 13:03:05100 template <typename C,
101 typename M,
102 typename T1,
103 typename T2,
104 typename T3,
105 typename T4,
106 typename T5>
perkj@webrtc.org81134d02015-01-12 08:30:16107 void Invoke(C* c, M m, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) {
deadbeefd99a2002017-01-18 16:55:23108 r_ = (c->*m)(std::move(a1), std::move(a2), std::move(a3), std::move(a4),
109 std::move(a5));
perkj@webrtc.org81134d02015-01-12 08:30:16110 }
henrike@webrtc.org28e20752013-07-10 00:45:36111
deadbeefd99a2002017-01-18 16:55:23112 R moved_result() { return std::move(r_); }
henrike@webrtc.org28e20752013-07-10 00:45:36113
114 private:
115 R r_;
116};
117
118template <>
119class ReturnType<void> {
120 public:
Yves Gerey665174f2018-06-19 13:03:05121 template <typename C, typename M>
122 void Invoke(C* c, M m) {
123 (c->*m)();
124 }
deadbeefd99a2002017-01-18 16:55:23125 template <typename C, typename M, typename T1>
126 void Invoke(C* c, M m, T1 a1) {
127 (c->*m)(std::move(a1));
128 }
129 template <typename C, typename M, typename T1, typename T2>
130 void Invoke(C* c, M m, T1 a1, T2 a2) {
131 (c->*m)(std::move(a1), std::move(a2));
132 }
133 template <typename C, typename M, typename T1, typename T2, typename T3>
134 void Invoke(C* c, M m, T1 a1, T2 a2, T3 a3) {
135 (c->*m)(std::move(a1), std::move(a2), std::move(a3));
136 }
henrike@webrtc.org28e20752013-07-10 00:45:36137
deadbeefd99a2002017-01-18 16:55:23138 void moved_result() {}
henrike@webrtc.org28e20752013-07-10 00:45:36139};
140
tommi@webrtc.org18de6f92014-11-04 12:08:48141namespace internal {
142
Yves Gerey665174f2018-06-19 13:03:05143class SynchronousMethodCall : public rtc::MessageData,
144 public rtc::MessageHandler {
tommi@webrtc.org18de6f92014-11-04 12:08:48145 public:
Steve Antonf2737d22017-10-31 23:27:34146 explicit SynchronousMethodCall(rtc::MessageHandler* proxy);
147 ~SynchronousMethodCall() override;
tommi@webrtc.org18de6f92014-11-04 12:08:48148
Steve Antonf2737d22017-10-31 23:27:34149 void Invoke(const rtc::Location& posted_from, rtc::Thread* t);
tommi@webrtc.org18de6f92014-11-04 12:08:48150
151 private:
Steve Antonf2737d22017-10-31 23:27:34152 void OnMessage(rtc::Message*) override;
153
Niels Möller58376f32018-11-15 08:31:38154 rtc::Event e_;
tommi@webrtc.org18de6f92014-11-04 12:08:48155 rtc::MessageHandler* proxy_;
156};
157
perkj@webrtc.org81134d02015-01-12 08:30:16158} // namespace internal
tommi@webrtc.org18de6f92014-11-04 12:08:48159
henrike@webrtc.org28e20752013-07-10 00:45:36160template <typename C, typename R>
Yves Gerey665174f2018-06-19 13:03:05161class MethodCall0 : public rtc::Message, public rtc::MessageHandler {
henrike@webrtc.org28e20752013-07-10 00:45:36162 public:
163 typedef R (C::*Method)();
164 MethodCall0(C* c, Method m) : c_(c), m_(m) {}
165
Taylor Brandstetter5d97a9a2016-06-10 21:17:27166 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
167 internal::SynchronousMethodCall(this).Invoke(posted_from, t);
deadbeefd99a2002017-01-18 16:55:23168 return r_.moved_result();
henrike@webrtc.org28e20752013-07-10 00:45:36169 }
170
171 private:
Yves Gerey665174f2018-06-19 13:03:05172 void OnMessage(rtc::Message*) { r_.Invoke(c_, m_); }
henrike@webrtc.org28e20752013-07-10 00:45:36173
174 C* c_;
175 Method m_;
176 ReturnType<R> r_;
177};
178
179template <typename C, typename R>
Yves Gerey665174f2018-06-19 13:03:05180class ConstMethodCall0 : public rtc::Message, public rtc::MessageHandler {
henrike@webrtc.org28e20752013-07-10 00:45:36181 public:
182 typedef R (C::*Method)() const;
183 ConstMethodCall0(C* c, Method m) : c_(c), m_(m) {}
184
Taylor Brandstetter5d97a9a2016-06-10 21:17:27185 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
186 internal::SynchronousMethodCall(this).Invoke(posted_from, t);
deadbeefd99a2002017-01-18 16:55:23187 return r_.moved_result();
henrike@webrtc.org28e20752013-07-10 00:45:36188 }
189
190 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52191 void OnMessage(rtc::Message*) { r_.Invoke(c_, m_); }
henrike@webrtc.org28e20752013-07-10 00:45:36192
193 C* c_;
194 Method m_;
195 ReturnType<R> r_;
196};
197
Yves Gerey665174f2018-06-19 13:03:05198template <typename C, typename R, typename T1>
199class MethodCall1 : public rtc::Message, public rtc::MessageHandler {
henrike@webrtc.org28e20752013-07-10 00:45:36200 public:
201 typedef R (C::*Method)(T1 a1);
deadbeefd99a2002017-01-18 16:55:23202 MethodCall1(C* c, Method m, T1 a1) : c_(c), m_(m), a1_(std::move(a1)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36203
Taylor Brandstetter5d97a9a2016-06-10 21:17:27204 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
205 internal::SynchronousMethodCall(this).Invoke(posted_from, t);
deadbeefd99a2002017-01-18 16:55:23206 return r_.moved_result();
henrike@webrtc.org28e20752013-07-10 00:45:36207 }
208
209 private:
deadbeefd99a2002017-01-18 16:55:23210 void OnMessage(rtc::Message*) { r_.Invoke(c_, m_, std::move(a1_)); }
henrike@webrtc.org28e20752013-07-10 00:45:36211
212 C* c_;
213 Method m_;
214 ReturnType<R> r_;
215 T1 a1_;
216};
217
Yves Gerey665174f2018-06-19 13:03:05218template <typename C, typename R, typename T1>
219class ConstMethodCall1 : public rtc::Message, public rtc::MessageHandler {
henrike@webrtc.org28e20752013-07-10 00:45:36220 public:
221 typedef R (C::*Method)(T1 a1) const;
deadbeefd99a2002017-01-18 16:55:23222 ConstMethodCall1(C* c, Method m, T1 a1) : c_(c), m_(m), a1_(std::move(a1)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36223
Taylor Brandstetter5d97a9a2016-06-10 21:17:27224 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
225 internal::SynchronousMethodCall(this).Invoke(posted_from, t);
deadbeefd99a2002017-01-18 16:55:23226 return r_.moved_result();
henrike@webrtc.org28e20752013-07-10 00:45:36227 }
228
229 private:
deadbeefd99a2002017-01-18 16:55:23230 void OnMessage(rtc::Message*) { r_.Invoke(c_, m_, std::move(a1_)); }
henrike@webrtc.org28e20752013-07-10 00:45:36231
232 C* c_;
233 Method m_;
234 ReturnType<R> r_;
235 T1 a1_;
236};
237
238template <typename C, typename R, typename T1, typename T2>
Yves Gerey665174f2018-06-19 13:03:05239class MethodCall2 : public rtc::Message, public rtc::MessageHandler {
henrike@webrtc.org28e20752013-07-10 00:45:36240 public:
241 typedef R (C::*Method)(T1 a1, T2 a2);
deadbeefd99a2002017-01-18 16:55:23242 MethodCall2(C* c, Method m, T1 a1, T2 a2)
243 : c_(c), m_(m), a1_(std::move(a1)), a2_(std::move(a2)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36244
Taylor Brandstetter5d97a9a2016-06-10 21:17:27245 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
246 internal::SynchronousMethodCall(this).Invoke(posted_from, t);
deadbeefd99a2002017-01-18 16:55:23247 return r_.moved_result();
henrike@webrtc.org28e20752013-07-10 00:45:36248 }
249
250 private:
deadbeefd99a2002017-01-18 16:55:23251 void OnMessage(rtc::Message*) {
252 r_.Invoke(c_, m_, std::move(a1_), std::move(a2_));
253 }
henrike@webrtc.org28e20752013-07-10 00:45:36254
255 C* c_;
256 Method m_;
257 ReturnType<R> r_;
258 T1 a1_;
259 T2 a2_;
260};
261
262template <typename C, typename R, typename T1, typename T2, typename T3>
Yves Gerey665174f2018-06-19 13:03:05263class MethodCall3 : public rtc::Message, public rtc::MessageHandler {
henrike@webrtc.org28e20752013-07-10 00:45:36264 public:
265 typedef R (C::*Method)(T1 a1, T2 a2, T3 a3);
266 MethodCall3(C* c, Method m, T1 a1, T2 a2, T3 a3)
deadbeefd99a2002017-01-18 16:55:23267 : c_(c),
268 m_(m),
269 a1_(std::move(a1)),
270 a2_(std::move(a2)),
271 a3_(std::move(a3)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36272
Taylor Brandstetter5d97a9a2016-06-10 21:17:27273 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
274 internal::SynchronousMethodCall(this).Invoke(posted_from, t);
deadbeefd99a2002017-01-18 16:55:23275 return r_.moved_result();
henrike@webrtc.org28e20752013-07-10 00:45:36276 }
277
278 private:
deadbeefd99a2002017-01-18 16:55:23279 void OnMessage(rtc::Message*) {
280 r_.Invoke(c_, m_, std::move(a1_), std::move(a2_), std::move(a3_));
281 }
henrike@webrtc.org28e20752013-07-10 00:45:36282
283 C* c_;
284 Method m_;
285 ReturnType<R> r_;
286 T1 a1_;
287 T2 a2_;
288 T3 a3_;
289};
290
Yves Gerey665174f2018-06-19 13:03:05291template <typename C,
292 typename R,
293 typename T1,
294 typename T2,
295 typename T3,
296 typename T4>
297class MethodCall4 : public rtc::Message, public rtc::MessageHandler {
perkj@webrtc.org81134d02015-01-12 08:30:16298 public:
299 typedef R (C::*Method)(T1 a1, T2 a2, T3 a3, T4 a4);
300 MethodCall4(C* c, Method m, T1 a1, T2 a2, T3 a3, T4 a4)
deadbeefd99a2002017-01-18 16:55:23301 : c_(c),
302 m_(m),
303 a1_(std::move(a1)),
304 a2_(std::move(a2)),
305 a3_(std::move(a3)),
306 a4_(std::move(a4)) {}
perkj@webrtc.org81134d02015-01-12 08:30:16307
Taylor Brandstetter5d97a9a2016-06-10 21:17:27308 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
309 internal::SynchronousMethodCall(this).Invoke(posted_from, t);
deadbeefd99a2002017-01-18 16:55:23310 return r_.moved_result();
perkj@webrtc.org81134d02015-01-12 08:30:16311 }
312
313 private:
deadbeefd99a2002017-01-18 16:55:23314 void OnMessage(rtc::Message*) {
315 r_.Invoke(c_, m_, std::move(a1_), std::move(a2_), std::move(a3_),
316 std::move(a4_));
317 }
perkj@webrtc.org81134d02015-01-12 08:30:16318
319 C* c_;
320 Method m_;
321 ReturnType<R> r_;
322 T1 a1_;
323 T2 a2_;
324 T3 a3_;
325 T4 a4_;
326};
327
Yves Gerey665174f2018-06-19 13:03:05328template <typename C,
329 typename R,
330 typename T1,
331 typename T2,
332 typename T3,
333 typename T4,
334 typename T5>
335class MethodCall5 : public rtc::Message, public rtc::MessageHandler {
perkj@webrtc.org81134d02015-01-12 08:30:16336 public:
337 typedef R (C::*Method)(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
338 MethodCall5(C* c, Method m, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
deadbeefd99a2002017-01-18 16:55:23339 : c_(c),
340 m_(m),
341 a1_(std::move(a1)),
342 a2_(std::move(a2)),
343 a3_(std::move(a3)),
344 a4_(std::move(a4)),
345 a5_(std::move(a5)) {}
perkj@webrtc.org81134d02015-01-12 08:30:16346
Taylor Brandstetter5d97a9a2016-06-10 21:17:27347 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
348 internal::SynchronousMethodCall(this).Invoke(posted_from, t);
deadbeefd99a2002017-01-18 16:55:23349 return r_.moved_result();
perkj@webrtc.org81134d02015-01-12 08:30:16350 }
351
352 private:
deadbeefd99a2002017-01-18 16:55:23353 void OnMessage(rtc::Message*) {
354 r_.Invoke(c_, m_, std::move(a1_), std::move(a2_), std::move(a3_),
355 std::move(a4_), std::move(a5_));
356 }
perkj@webrtc.org81134d02015-01-12 08:30:16357
358 C* c_;
359 Method m_;
360 ReturnType<R> r_;
361 T1 a1_;
362 T2 a2_;
363 T3 a3_;
364 T4 a4_;
365 T5 a5_;
366};
367
deadbeefd99a2002017-01-18 16:55:23368// Helper macros to reduce code duplication.
deadbeefe814a0d2017-02-26 02:15:09369#define PROXY_MAP_BOILERPLATE(c) \
370 template <class INTERNAL_CLASS> \
371 class c##ProxyWithInternal; \
372 typedef c##ProxyWithInternal<c##Interface> c##Proxy; \
373 template <class INTERNAL_CLASS> \
374 class c##ProxyWithInternal : public c##Interface { \
375 protected: \
376 typedef c##Interface C; \
377 \
378 public: \
379 const INTERNAL_CLASS* internal() const { return c_; } \
380 INTERNAL_CLASS* internal() { return c_; }
henrike@webrtc.org28e20752013-07-10 00:45:36381
Yves Gerey665174f2018-06-19 13:03:05382// clang-format off
383// clang-format would put the semicolon alone,
384// leading to a presubmit error (cpplint.py)
oprypin803dc292017-02-01 09:55:59385#define END_PROXY_MAP() \
386 };
Yves Gerey665174f2018-06-19 13:03:05387// clang-format on
oprypin803dc292017-02-01 09:55:59388
deadbeefd99a2002017-01-18 16:55:23389#define SIGNALING_PROXY_MAP_BOILERPLATE(c) \
390 protected: \
391 c##ProxyWithInternal(rtc::Thread* signaling_thread, INTERNAL_CLASS* c) \
392 : signaling_thread_(signaling_thread), c_(c) {} \
393 \
394 private: \
395 mutable rtc::Thread* signaling_thread_;
396
397#define WORKER_PROXY_MAP_BOILERPLATE(c) \
398 protected: \
399 c##ProxyWithInternal(rtc::Thread* signaling_thread, \
400 rtc::Thread* worker_thread, INTERNAL_CLASS* c) \
401 : signaling_thread_(signaling_thread), \
402 worker_thread_(worker_thread), \
403 c_(c) {} \
404 \
405 private: \
406 mutable rtc::Thread* signaling_thread_; \
407 mutable rtc::Thread* worker_thread_;
408
409// Note that the destructor is protected so that the proxy can only be
410// destroyed via RefCountInterface.
411#define REFCOUNTED_PROXY_MAP_BOILERPLATE(c) \
412 protected: \
413 ~c##ProxyWithInternal() { \
414 MethodCall0<c##ProxyWithInternal, void> call( \
415 this, &c##ProxyWithInternal::DestroyInternal); \
416 call.Marshal(RTC_FROM_HERE, destructor_thread()); \
417 } \
418 \
419 private: \
420 void DestroyInternal() { c_ = nullptr; } \
421 rtc::scoped_refptr<INTERNAL_CLASS> c_;
422
deadbeefe814a0d2017-02-26 02:15:09423// Note: This doesn't use a unique_ptr, because it intends to handle a corner
424// case where an object's deletion triggers a callback that calls back into
425// this proxy object. If relying on a unique_ptr to delete the object, its
426// inner pointer would be set to null before this reentrant callback would have
427// a chance to run, resulting in a segfault.
deadbeefd99a2002017-01-18 16:55:23428#define OWNED_PROXY_MAP_BOILERPLATE(c) \
429 public: \
430 ~c##ProxyWithInternal() { \
431 MethodCall0<c##ProxyWithInternal, void> call( \
432 this, &c##ProxyWithInternal::DestroyInternal); \
433 call.Marshal(RTC_FROM_HERE, destructor_thread()); \
434 } \
435 \
436 private: \
deadbeefe814a0d2017-02-26 02:15:09437 void DestroyInternal() { delete c_; } \
438 INTERNAL_CLASS* c_;
deadbeefd99a2002017-01-18 16:55:23439
440#define BEGIN_SIGNALING_PROXY_MAP(c) \
441 PROXY_MAP_BOILERPLATE(c) \
442 SIGNALING_PROXY_MAP_BOILERPLATE(c) \
443 REFCOUNTED_PROXY_MAP_BOILERPLATE(c) \
444 public: \
445 static rtc::scoped_refptr<c##ProxyWithInternal> Create( \
446 rtc::Thread* signaling_thread, INTERNAL_CLASS* c) { \
447 return new rtc::RefCountedObject<c##ProxyWithInternal>(signaling_thread, \
448 c); \
449 }
450
451#define BEGIN_PROXY_MAP(c) \
452 PROXY_MAP_BOILERPLATE(c) \
453 WORKER_PROXY_MAP_BOILERPLATE(c) \
454 REFCOUNTED_PROXY_MAP_BOILERPLATE(c) \
455 public: \
456 static rtc::scoped_refptr<c##ProxyWithInternal> Create( \
457 rtc::Thread* signaling_thread, rtc::Thread* worker_thread, \
458 INTERNAL_CLASS* c) { \
459 return new rtc::RefCountedObject<c##ProxyWithInternal>(signaling_thread, \
460 worker_thread, c); \
461 }
462
deadbeefe814a0d2017-02-26 02:15:09463#define BEGIN_OWNED_PROXY_MAP(c) \
464 PROXY_MAP_BOILERPLATE(c) \
465 WORKER_PROXY_MAP_BOILERPLATE(c) \
466 OWNED_PROXY_MAP_BOILERPLATE(c) \
467 public: \
468 static std::unique_ptr<c##Interface> Create( \
469 rtc::Thread* signaling_thread, rtc::Thread* worker_thread, \
470 std::unique_ptr<INTERNAL_CLASS> c) { \
471 return std::unique_ptr<c##Interface>(new c##ProxyWithInternal( \
472 signaling_thread, worker_thread, c.release())); \
deadbeefd99a2002017-01-18 16:55:23473 }
474
475#define PROXY_SIGNALING_THREAD_DESTRUCTOR() \
476 private: \
477 rtc::Thread* destructor_thread() const { return signaling_thread_; } \
478 \
oprypin803dc292017-02-01 09:55:59479 public: // NOLINTNEXTLINE
deadbeefd99a2002017-01-18 16:55:23480
481#define PROXY_WORKER_THREAD_DESTRUCTOR() \
482 private: \
483 rtc::Thread* destructor_thread() const { return worker_thread_; } \
484 \
oprypin803dc292017-02-01 09:55:59485 public: // NOLINTNEXTLINE
deadbeefd99a2002017-01-18 16:55:23486
Taylor Brandstetter5d97a9a2016-06-10 21:17:27487#define PROXY_METHOD0(r, method) \
488 r method() override { \
deadbeefe814a0d2017-02-26 02:15:09489 MethodCall0<C, r> call(c_, &C::method); \
Taylor Brandstetter5d97a9a2016-06-10 21:17:27490 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35491 }
henrike@webrtc.org28e20752013-07-10 00:45:36492
Taylor Brandstetter5d97a9a2016-06-10 21:17:27493#define PROXY_CONSTMETHOD0(r, method) \
494 r method() const override { \
deadbeefe814a0d2017-02-26 02:15:09495 ConstMethodCall0<C, r> call(c_, &C::method); \
Taylor Brandstetter5d97a9a2016-06-10 21:17:27496 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35497 }
henrike@webrtc.org28e20752013-07-10 00:45:36498
deadbeefe814a0d2017-02-26 02:15:09499#define PROXY_METHOD1(r, method, t1) \
500 r method(t1 a1) override { \
501 MethodCall1<C, r, t1> call(c_, &C::method, std::move(a1)); \
502 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35503 }
henrike@webrtc.org28e20752013-07-10 00:45:36504
deadbeefe814a0d2017-02-26 02:15:09505#define PROXY_CONSTMETHOD1(r, method, t1) \
506 r method(t1 a1) const override { \
507 ConstMethodCall1<C, r, t1> call(c_, &C::method, std::move(a1)); \
508 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35509 }
henrike@webrtc.org28e20752013-07-10 00:45:36510
deadbeefe814a0d2017-02-26 02:15:09511#define PROXY_METHOD2(r, method, t1, t2) \
512 r method(t1 a1, t2 a2) override { \
513 MethodCall2<C, r, t1, t2> call(c_, &C::method, std::move(a1), \
514 std::move(a2)); \
515 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35516 }
perkj@webrtc.org81134d02015-01-12 08:30:16517
deadbeefe814a0d2017-02-26 02:15:09518#define PROXY_METHOD3(r, method, t1, t2, t3) \
519 r method(t1 a1, t2 a2, t3 a3) override { \
520 MethodCall3<C, r, t1, t2, t3> call(c_, &C::method, std::move(a1), \
521 std::move(a2), std::move(a3)); \
522 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \
deadbeefd99a2002017-01-18 16:55:23523 }
524
525#define PROXY_METHOD4(r, method, t1, t2, t3, t4) \
526 r method(t1 a1, t2 a2, t3 a3, t4 a4) override { \
deadbeefe814a0d2017-02-26 02:15:09527 MethodCall4<C, r, t1, t2, t3, t4> call(c_, &C::method, std::move(a1), \
528 std::move(a2), std::move(a3), \
529 std::move(a4)); \
deadbeefd99a2002017-01-18 16:55:23530 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \
531 }
532
deadbeefe814a0d2017-02-26 02:15:09533#define PROXY_METHOD5(r, method, t1, t2, t3, t4, t5) \
534 r method(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) override { \
535 MethodCall5<C, r, t1, t2, t3, t4, t5> call(c_, &C::method, std::move(a1), \
536 std::move(a2), std::move(a3), \
537 std::move(a4), std::move(a5)); \
538 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \
nisse5b68ab52016-04-07 14:45:54539 }
540
541// Define methods which should be invoked on the worker thread.
deadbeefd99a2002017-01-18 16:55:23542#define PROXY_WORKER_METHOD0(r, method) \
543 r method() override { \
deadbeefe814a0d2017-02-26 02:15:09544 MethodCall0<C, r> call(c_, &C::method); \
deadbeefd99a2002017-01-18 16:55:23545 return call.Marshal(RTC_FROM_HERE, worker_thread_); \
nisse5b68ab52016-04-07 14:45:54546 }
547
deadbeefd99a2002017-01-18 16:55:23548#define PROXY_WORKER_CONSTMETHOD0(r, method) \
549 r method() const override { \
deadbeefe814a0d2017-02-26 02:15:09550 ConstMethodCall0<C, r> call(c_, &C::method); \
deadbeefd99a2002017-01-18 16:55:23551 return call.Marshal(RTC_FROM_HERE, worker_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35552 }
perkj@webrtc.org81134d02015-01-12 08:30:16553
deadbeefe814a0d2017-02-26 02:15:09554#define PROXY_WORKER_METHOD1(r, method, t1) \
555 r method(t1 a1) override { \
556 MethodCall1<C, r, t1> call(c_, &C::method, std::move(a1)); \
557 return call.Marshal(RTC_FROM_HERE, worker_thread_); \
deadbeefd99a2002017-01-18 16:55:23558 }
henrike@webrtc.org28e20752013-07-10 00:45:36559
deadbeefe814a0d2017-02-26 02:15:09560#define PROXY_WORKER_CONSTMETHOD1(r, method, t1) \
561 r method(t1 a1) const override { \
562 ConstMethodCall1<C, r, t1> call(c_, &C::method, std::move(a1)); \
563 return call.Marshal(RTC_FROM_HERE, worker_thread_); \
deadbeefd99a2002017-01-18 16:55:23564 }
565
deadbeefe814a0d2017-02-26 02:15:09566#define PROXY_WORKER_METHOD2(r, method, t1, t2) \
567 r method(t1 a1, t2 a2) override { \
568 MethodCall2<C, r, t1, t2> call(c_, &C::method, std::move(a1), \
569 std::move(a2)); \
570 return call.Marshal(RTC_FROM_HERE, worker_thread_); \
deadbeefd99a2002017-01-18 16:55:23571 }
572
deadbeefe814a0d2017-02-26 02:15:09573#define PROXY_WORKER_CONSTMETHOD2(r, method, t1, t2) \
574 r method(t1 a1, t2 a2) const override { \
575 ConstMethodCall2<C, r, t1, t2> call(c_, &C::method, std::move(a1), \
576 std::move(a2)); \
577 return call.Marshal(RTC_FROM_HERE, worker_thread_); \
578 }
579
580#define PROXY_WORKER_METHOD3(r, method, t1, t2, t3) \
581 r method(t1 a1, t2 a2, t3 a3) override { \
582 MethodCall3<C, r, t1, t2, t3> call(c_, &C::method, std::move(a1), \
583 std::move(a2), std::move(a3)); \
584 return call.Marshal(RTC_FROM_HERE, worker_thread_); \
585 }
586
587#define PROXY_WORKER_CONSTMETHOD3(r, method, t1, t2) \
588 r method(t1 a1, t2 a2, t3 a3) const override { \
589 ConstMethodCall3<C, r, t1, t2, t3> call(c_, &C::method, std::move(a1), \
590 std::move(a2), std::move(a3)); \
591 return call.Marshal(RTC_FROM_HERE, worker_thread_); \
deadbeefd99a2002017-01-18 16:55:23592 }
593
henrike@webrtc.org28e20752013-07-10 00:45:36594} // namespace webrtc
595
Mirko Bonadei92ea95e2017-09-15 04:47:31596#endif // API_PROXY_H_