blob: dd7182e5546038d1a72b85cee65301475227cab2 [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
15//
16// Example usage:
17//
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000018// class TestInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000019// public:
20// std::string FooA() = 0;
21// std::string FooB(bool arg1) const = 0;
nisse72c8d2b2016-04-15 03:49:07 -070022// std::string FooC(bool arg1) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000023// };
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 08:55:23 -080032// PROXY_SIGNALING_THREAD_DESTRUCTOR()
henrike@webrtc.org28e20752013-07-10 00:45:36 +000033// PROXY_METHOD0(std::string, FooA)
34// PROXY_CONSTMETHOD1(std::string, FooB, arg1)
nisse72c8d2b2016-04-15 03:49:07 -070035// PROXY_WORKER_METHOD1(std::string, FooC, arg1)
deadbeefd99a2002017-01-18 08:55:23 -080036// END_PROXY_MAP()
henrike@webrtc.org28e20752013-07-10 00:45:36 +000037//
deadbeefd99a2002017-01-18 08:55:23 -080038// 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 03:49:07 -070040//
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 08:55:23 -080048//
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:36 +000051
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020052#ifndef API_PROXY_H_
53#define API_PROXY_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000054
kwibergd1fe2812016-04-27 06:47:29 -070055#include <memory>
oprypin803dc292017-02-01 01:55:59 -080056#include <utility>
kwibergd1fe2812016-04-27 06:47:29 -070057
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020058#include "rtc_base/event.h"
Niels Möller84255bb2017-10-06 13:43:23 +020059#include "rtc_base/refcountedobject.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020060#include "rtc_base/thread.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061
62namespace webrtc {
63
64template <typename R>
65class ReturnType {
66 public:
67 template<typename C, typename M>
68 void Invoke(C* c, M m) { r_ = (c->*m)(); }
deadbeefd99a2002017-01-18 08:55:23 -080069 template <typename C, typename M, typename T1>
70 void Invoke(C* c, M m, T1 a1) {
71 r_ = (c->*m)(std::move(a1));
72 }
73 template <typename C, typename M, typename T1, typename T2>
74 void Invoke(C* c, M m, T1 a1, T2 a2) {
75 r_ = (c->*m)(std::move(a1), std::move(a2));
76 }
77 template <typename C, typename M, typename T1, typename T2, typename T3>
78 void Invoke(C* c, M m, T1 a1, T2 a2, T3 a3) {
79 r_ = (c->*m)(std::move(a1), std::move(a2), std::move(a3));
80 }
perkj@webrtc.org81134d02015-01-12 08:30:16 +000081 template<typename C, typename M, typename T1, typename T2, typename T3,
82 typename T4>
83 void Invoke(C* c, M m, T1 a1, T2 a2, T3 a3, T4 a4) {
deadbeefd99a2002017-01-18 08:55:23 -080084 r_ = (c->*m)(std::move(a1), std::move(a2), std::move(a3), std::move(a4));
perkj@webrtc.org81134d02015-01-12 08:30:16 +000085 }
86 template<typename C, typename M, typename T1, typename T2, typename T3,
87 typename T4, typename T5>
88 void Invoke(C* c, M m, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) {
deadbeefd99a2002017-01-18 08:55:23 -080089 r_ = (c->*m)(std::move(a1), std::move(a2), std::move(a3), std::move(a4),
90 std::move(a5));
perkj@webrtc.org81134d02015-01-12 08:30:16 +000091 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092
deadbeefd99a2002017-01-18 08:55:23 -080093 R moved_result() { return std::move(r_); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000094
95 private:
96 R r_;
97};
98
99template <>
100class ReturnType<void> {
101 public:
102 template<typename C, typename M>
103 void Invoke(C* c, M m) { (c->*m)(); }
deadbeefd99a2002017-01-18 08:55:23 -0800104 template <typename C, typename M, typename T1>
105 void Invoke(C* c, M m, T1 a1) {
106 (c->*m)(std::move(a1));
107 }
108 template <typename C, typename M, typename T1, typename T2>
109 void Invoke(C* c, M m, T1 a1, T2 a2) {
110 (c->*m)(std::move(a1), std::move(a2));
111 }
112 template <typename C, typename M, typename T1, typename T2, typename T3>
113 void Invoke(C* c, M m, T1 a1, T2 a2, T3 a3) {
114 (c->*m)(std::move(a1), std::move(a2), std::move(a3));
115 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000116
deadbeefd99a2002017-01-18 08:55:23 -0800117 void moved_result() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000118};
119
tommi@webrtc.org18de6f92014-11-04 12:08:48 +0000120namespace internal {
121
122class SynchronousMethodCall
123 : public rtc::MessageData,
124 public rtc::MessageHandler {
125 public:
Steve Antonf2737d22017-10-31 16:27:34 -0700126 explicit SynchronousMethodCall(rtc::MessageHandler* proxy);
127 ~SynchronousMethodCall() override;
tommi@webrtc.org18de6f92014-11-04 12:08:48 +0000128
Steve Antonf2737d22017-10-31 16:27:34 -0700129 void Invoke(const rtc::Location& posted_from, rtc::Thread* t);
tommi@webrtc.org18de6f92014-11-04 12:08:48 +0000130
131 private:
Steve Antonf2737d22017-10-31 16:27:34 -0700132 void OnMessage(rtc::Message*) override;
133
kwibergd1fe2812016-04-27 06:47:29 -0700134 std::unique_ptr<rtc::Event> e_;
tommi@webrtc.org18de6f92014-11-04 12:08:48 +0000135 rtc::MessageHandler* proxy_;
136};
137
perkj@webrtc.org81134d02015-01-12 08:30:16 +0000138} // namespace internal
tommi@webrtc.org18de6f92014-11-04 12:08:48 +0000139
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000140template <typename C, typename R>
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000141class MethodCall0 : public rtc::Message,
142 public rtc::MessageHandler {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000143 public:
144 typedef R (C::*Method)();
145 MethodCall0(C* c, Method m) : c_(c), m_(m) {}
146
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700147 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
148 internal::SynchronousMethodCall(this).Invoke(posted_from, t);
deadbeefd99a2002017-01-18 08:55:23 -0800149 return r_.moved_result();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000150 }
151
152 private:
tommi@webrtc.org18de6f92014-11-04 12:08:48 +0000153 void OnMessage(rtc::Message*) { r_.Invoke(c_, m_); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000154
155 C* c_;
156 Method m_;
157 ReturnType<R> r_;
158};
159
160template <typename C, typename R>
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000161class ConstMethodCall0 : public rtc::Message,
162 public rtc::MessageHandler {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000163 public:
164 typedef R (C::*Method)() const;
165 ConstMethodCall0(C* c, Method m) : c_(c), m_(m) {}
166
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700167 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
168 internal::SynchronousMethodCall(this).Invoke(posted_from, t);
deadbeefd99a2002017-01-18 08:55:23 -0800169 return r_.moved_result();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000170 }
171
172 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000173 void OnMessage(rtc::Message*) { r_.Invoke(c_, m_); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000174
175 C* c_;
176 Method m_;
177 ReturnType<R> r_;
178};
179
180template <typename C, typename R, typename T1>
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000181class MethodCall1 : public rtc::Message,
182 public rtc::MessageHandler {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000183 public:
184 typedef R (C::*Method)(T1 a1);
deadbeefd99a2002017-01-18 08:55:23 -0800185 MethodCall1(C* c, Method m, T1 a1) : c_(c), m_(m), a1_(std::move(a1)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000186
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700187 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
188 internal::SynchronousMethodCall(this).Invoke(posted_from, t);
deadbeefd99a2002017-01-18 08:55:23 -0800189 return r_.moved_result();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000190 }
191
192 private:
deadbeefd99a2002017-01-18 08:55:23 -0800193 void OnMessage(rtc::Message*) { r_.Invoke(c_, m_, std::move(a1_)); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000194
195 C* c_;
196 Method m_;
197 ReturnType<R> r_;
198 T1 a1_;
199};
200
201template <typename C, typename R, typename T1>
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000202class ConstMethodCall1 : public rtc::Message,
203 public rtc::MessageHandler {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000204 public:
205 typedef R (C::*Method)(T1 a1) const;
deadbeefd99a2002017-01-18 08:55:23 -0800206 ConstMethodCall1(C* c, Method m, T1 a1) : c_(c), m_(m), a1_(std::move(a1)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000207
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700208 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
209 internal::SynchronousMethodCall(this).Invoke(posted_from, t);
deadbeefd99a2002017-01-18 08:55:23 -0800210 return r_.moved_result();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211 }
212
213 private:
deadbeefd99a2002017-01-18 08:55:23 -0800214 void OnMessage(rtc::Message*) { r_.Invoke(c_, m_, std::move(a1_)); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000215
216 C* c_;
217 Method m_;
218 ReturnType<R> r_;
219 T1 a1_;
220};
221
222template <typename C, typename R, typename T1, typename T2>
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000223class MethodCall2 : public rtc::Message,
224 public rtc::MessageHandler {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000225 public:
226 typedef R (C::*Method)(T1 a1, T2 a2);
deadbeefd99a2002017-01-18 08:55:23 -0800227 MethodCall2(C* c, Method m, T1 a1, T2 a2)
228 : c_(c), m_(m), a1_(std::move(a1)), a2_(std::move(a2)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000229
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700230 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
231 internal::SynchronousMethodCall(this).Invoke(posted_from, t);
deadbeefd99a2002017-01-18 08:55:23 -0800232 return r_.moved_result();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000233 }
234
235 private:
deadbeefd99a2002017-01-18 08:55:23 -0800236 void OnMessage(rtc::Message*) {
237 r_.Invoke(c_, m_, std::move(a1_), std::move(a2_));
238 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000239
240 C* c_;
241 Method m_;
242 ReturnType<R> r_;
243 T1 a1_;
244 T2 a2_;
245};
246
247template <typename C, typename R, typename T1, typename T2, typename T3>
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000248class MethodCall3 : public rtc::Message,
249 public rtc::MessageHandler {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000250 public:
251 typedef R (C::*Method)(T1 a1, T2 a2, T3 a3);
252 MethodCall3(C* c, Method m, T1 a1, T2 a2, T3 a3)
deadbeefd99a2002017-01-18 08:55:23 -0800253 : c_(c),
254 m_(m),
255 a1_(std::move(a1)),
256 a2_(std::move(a2)),
257 a3_(std::move(a3)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000258
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700259 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
260 internal::SynchronousMethodCall(this).Invoke(posted_from, t);
deadbeefd99a2002017-01-18 08:55:23 -0800261 return r_.moved_result();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000262 }
263
264 private:
deadbeefd99a2002017-01-18 08:55:23 -0800265 void OnMessage(rtc::Message*) {
266 r_.Invoke(c_, m_, std::move(a1_), std::move(a2_), std::move(a3_));
267 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000268
269 C* c_;
270 Method m_;
271 ReturnType<R> r_;
272 T1 a1_;
273 T2 a2_;
274 T3 a3_;
275};
276
perkj@webrtc.org81134d02015-01-12 08:30:16 +0000277template <typename C, typename R, typename T1, typename T2, typename T3,
278 typename T4>
279class MethodCall4 : public rtc::Message,
280 public rtc::MessageHandler {
281 public:
282 typedef R (C::*Method)(T1 a1, T2 a2, T3 a3, T4 a4);
283 MethodCall4(C* c, Method m, T1 a1, T2 a2, T3 a3, T4 a4)
deadbeefd99a2002017-01-18 08:55:23 -0800284 : c_(c),
285 m_(m),
286 a1_(std::move(a1)),
287 a2_(std::move(a2)),
288 a3_(std::move(a3)),
289 a4_(std::move(a4)) {}
perkj@webrtc.org81134d02015-01-12 08:30:16 +0000290
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700291 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
292 internal::SynchronousMethodCall(this).Invoke(posted_from, t);
deadbeefd99a2002017-01-18 08:55:23 -0800293 return r_.moved_result();
perkj@webrtc.org81134d02015-01-12 08:30:16 +0000294 }
295
296 private:
deadbeefd99a2002017-01-18 08:55:23 -0800297 void OnMessage(rtc::Message*) {
298 r_.Invoke(c_, m_, std::move(a1_), std::move(a2_), std::move(a3_),
299 std::move(a4_));
300 }
perkj@webrtc.org81134d02015-01-12 08:30:16 +0000301
302 C* c_;
303 Method m_;
304 ReturnType<R> r_;
305 T1 a1_;
306 T2 a2_;
307 T3 a3_;
308 T4 a4_;
309};
310
311template <typename C, typename R, typename T1, typename T2, typename T3,
312 typename T4, typename T5>
313class MethodCall5 : public rtc::Message,
314 public rtc::MessageHandler {
315 public:
316 typedef R (C::*Method)(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
317 MethodCall5(C* c, Method m, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
deadbeefd99a2002017-01-18 08:55:23 -0800318 : c_(c),
319 m_(m),
320 a1_(std::move(a1)),
321 a2_(std::move(a2)),
322 a3_(std::move(a3)),
323 a4_(std::move(a4)),
324 a5_(std::move(a5)) {}
perkj@webrtc.org81134d02015-01-12 08:30:16 +0000325
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700326 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
327 internal::SynchronousMethodCall(this).Invoke(posted_from, t);
deadbeefd99a2002017-01-18 08:55:23 -0800328 return r_.moved_result();
perkj@webrtc.org81134d02015-01-12 08:30:16 +0000329 }
330
331 private:
deadbeefd99a2002017-01-18 08:55:23 -0800332 void OnMessage(rtc::Message*) {
333 r_.Invoke(c_, m_, std::move(a1_), std::move(a2_), std::move(a3_),
334 std::move(a4_), std::move(a5_));
335 }
perkj@webrtc.org81134d02015-01-12 08:30:16 +0000336
337 C* c_;
338 Method m_;
339 ReturnType<R> r_;
340 T1 a1_;
341 T2 a2_;
342 T3 a3_;
343 T4 a4_;
344 T5 a5_;
345};
346
oprypin803dc292017-02-01 01:55:59 -0800347
deadbeefd99a2002017-01-18 08:55:23 -0800348// Helper macros to reduce code duplication.
deadbeefe814a0d2017-02-25 18:15:09 -0800349#define PROXY_MAP_BOILERPLATE(c) \
350 template <class INTERNAL_CLASS> \
351 class c##ProxyWithInternal; \
352 typedef c##ProxyWithInternal<c##Interface> c##Proxy; \
353 template <class INTERNAL_CLASS> \
354 class c##ProxyWithInternal : public c##Interface { \
355 protected: \
356 typedef c##Interface C; \
357 \
358 public: \
359 const INTERNAL_CLASS* internal() const { return c_; } \
360 INTERNAL_CLASS* internal() { return c_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000361
oprypin803dc292017-02-01 01:55:59 -0800362#define END_PROXY_MAP() \
363 };
364
deadbeefd99a2002017-01-18 08:55:23 -0800365#define SIGNALING_PROXY_MAP_BOILERPLATE(c) \
366 protected: \
367 c##ProxyWithInternal(rtc::Thread* signaling_thread, INTERNAL_CLASS* c) \
368 : signaling_thread_(signaling_thread), c_(c) {} \
369 \
370 private: \
371 mutable rtc::Thread* signaling_thread_;
372
373#define WORKER_PROXY_MAP_BOILERPLATE(c) \
374 protected: \
375 c##ProxyWithInternal(rtc::Thread* signaling_thread, \
376 rtc::Thread* worker_thread, INTERNAL_CLASS* c) \
377 : signaling_thread_(signaling_thread), \
378 worker_thread_(worker_thread), \
379 c_(c) {} \
380 \
381 private: \
382 mutable rtc::Thread* signaling_thread_; \
383 mutable rtc::Thread* worker_thread_;
384
385// Note that the destructor is protected so that the proxy can only be
386// destroyed via RefCountInterface.
387#define REFCOUNTED_PROXY_MAP_BOILERPLATE(c) \
388 protected: \
389 ~c##ProxyWithInternal() { \
390 MethodCall0<c##ProxyWithInternal, void> call( \
391 this, &c##ProxyWithInternal::DestroyInternal); \
392 call.Marshal(RTC_FROM_HERE, destructor_thread()); \
393 } \
394 \
395 private: \
396 void DestroyInternal() { c_ = nullptr; } \
397 rtc::scoped_refptr<INTERNAL_CLASS> c_;
398
deadbeefe814a0d2017-02-25 18:15:09 -0800399// Note: This doesn't use a unique_ptr, because it intends to handle a corner
400// case where an object's deletion triggers a callback that calls back into
401// this proxy object. If relying on a unique_ptr to delete the object, its
402// inner pointer would be set to null before this reentrant callback would have
403// a chance to run, resulting in a segfault.
deadbeefd99a2002017-01-18 08:55:23 -0800404#define OWNED_PROXY_MAP_BOILERPLATE(c) \
405 public: \
406 ~c##ProxyWithInternal() { \
407 MethodCall0<c##ProxyWithInternal, void> call( \
408 this, &c##ProxyWithInternal::DestroyInternal); \
409 call.Marshal(RTC_FROM_HERE, destructor_thread()); \
410 } \
411 \
412 private: \
deadbeefe814a0d2017-02-25 18:15:09 -0800413 void DestroyInternal() { delete c_; } \
414 INTERNAL_CLASS* c_;
deadbeefd99a2002017-01-18 08:55:23 -0800415
416#define BEGIN_SIGNALING_PROXY_MAP(c) \
417 PROXY_MAP_BOILERPLATE(c) \
418 SIGNALING_PROXY_MAP_BOILERPLATE(c) \
419 REFCOUNTED_PROXY_MAP_BOILERPLATE(c) \
420 public: \
421 static rtc::scoped_refptr<c##ProxyWithInternal> Create( \
422 rtc::Thread* signaling_thread, INTERNAL_CLASS* c) { \
423 return new rtc::RefCountedObject<c##ProxyWithInternal>(signaling_thread, \
424 c); \
425 }
426
427#define BEGIN_PROXY_MAP(c) \
428 PROXY_MAP_BOILERPLATE(c) \
429 WORKER_PROXY_MAP_BOILERPLATE(c) \
430 REFCOUNTED_PROXY_MAP_BOILERPLATE(c) \
431 public: \
432 static rtc::scoped_refptr<c##ProxyWithInternal> Create( \
433 rtc::Thread* signaling_thread, rtc::Thread* worker_thread, \
434 INTERNAL_CLASS* c) { \
435 return new rtc::RefCountedObject<c##ProxyWithInternal>(signaling_thread, \
436 worker_thread, c); \
437 }
438
deadbeefe814a0d2017-02-25 18:15:09 -0800439#define BEGIN_OWNED_PROXY_MAP(c) \
440 PROXY_MAP_BOILERPLATE(c) \
441 WORKER_PROXY_MAP_BOILERPLATE(c) \
442 OWNED_PROXY_MAP_BOILERPLATE(c) \
443 public: \
444 static std::unique_ptr<c##Interface> Create( \
445 rtc::Thread* signaling_thread, rtc::Thread* worker_thread, \
446 std::unique_ptr<INTERNAL_CLASS> c) { \
447 return std::unique_ptr<c##Interface>(new c##ProxyWithInternal( \
448 signaling_thread, worker_thread, c.release())); \
deadbeefd99a2002017-01-18 08:55:23 -0800449 }
450
451#define PROXY_SIGNALING_THREAD_DESTRUCTOR() \
452 private: \
453 rtc::Thread* destructor_thread() const { return signaling_thread_; } \
454 \
oprypin803dc292017-02-01 01:55:59 -0800455 public: // NOLINTNEXTLINE
deadbeefd99a2002017-01-18 08:55:23 -0800456
457#define PROXY_WORKER_THREAD_DESTRUCTOR() \
458 private: \
459 rtc::Thread* destructor_thread() const { return worker_thread_; } \
460 \
oprypin803dc292017-02-01 01:55:59 -0800461 public: // NOLINTNEXTLINE
deadbeefd99a2002017-01-18 08:55:23 -0800462
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700463#define PROXY_METHOD0(r, method) \
464 r method() override { \
deadbeefe814a0d2017-02-25 18:15:09 -0800465 MethodCall0<C, r> call(c_, &C::method); \
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700466 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000467 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000468
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700469#define PROXY_CONSTMETHOD0(r, method) \
470 r method() const override { \
deadbeefe814a0d2017-02-25 18:15:09 -0800471 ConstMethodCall0<C, r> call(c_, &C::method); \
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700472 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000473 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000474
deadbeefe814a0d2017-02-25 18:15:09 -0800475#define PROXY_METHOD1(r, method, t1) \
476 r method(t1 a1) override { \
477 MethodCall1<C, r, t1> call(c_, &C::method, std::move(a1)); \
478 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000479 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000480
deadbeefe814a0d2017-02-25 18:15:09 -0800481#define PROXY_CONSTMETHOD1(r, method, t1) \
482 r method(t1 a1) const override { \
483 ConstMethodCall1<C, r, t1> call(c_, &C::method, std::move(a1)); \
484 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000485 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000486
deadbeefe814a0d2017-02-25 18:15:09 -0800487#define PROXY_METHOD2(r, method, t1, t2) \
488 r method(t1 a1, t2 a2) override { \
489 MethodCall2<C, r, t1, t2> call(c_, &C::method, std::move(a1), \
490 std::move(a2)); \
491 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000492 }
perkj@webrtc.org81134d02015-01-12 08:30:16 +0000493
deadbeefe814a0d2017-02-25 18:15:09 -0800494#define PROXY_METHOD3(r, method, t1, t2, t3) \
495 r method(t1 a1, t2 a2, t3 a3) override { \
496 MethodCall3<C, r, t1, t2, t3> call(c_, &C::method, std::move(a1), \
497 std::move(a2), std::move(a3)); \
498 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \
deadbeefd99a2002017-01-18 08:55:23 -0800499 }
500
501#define PROXY_METHOD4(r, method, t1, t2, t3, t4) \
502 r method(t1 a1, t2 a2, t3 a3, t4 a4) override { \
deadbeefe814a0d2017-02-25 18:15:09 -0800503 MethodCall4<C, r, t1, t2, t3, t4> call(c_, &C::method, std::move(a1), \
504 std::move(a2), std::move(a3), \
505 std::move(a4)); \
deadbeefd99a2002017-01-18 08:55:23 -0800506 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \
507 }
508
deadbeefe814a0d2017-02-25 18:15:09 -0800509#define PROXY_METHOD5(r, method, t1, t2, t3, t4, t5) \
510 r method(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) override { \
511 MethodCall5<C, r, t1, t2, t3, t4, t5> call(c_, &C::method, std::move(a1), \
512 std::move(a2), std::move(a3), \
513 std::move(a4), std::move(a5)); \
514 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \
nisse5b68ab52016-04-07 07:45:54 -0700515 }
516
517// Define methods which should be invoked on the worker thread.
deadbeefd99a2002017-01-18 08:55:23 -0800518#define PROXY_WORKER_METHOD0(r, method) \
519 r method() override { \
deadbeefe814a0d2017-02-25 18:15:09 -0800520 MethodCall0<C, r> call(c_, &C::method); \
deadbeefd99a2002017-01-18 08:55:23 -0800521 return call.Marshal(RTC_FROM_HERE, worker_thread_); \
nisse5b68ab52016-04-07 07:45:54 -0700522 }
523
deadbeefd99a2002017-01-18 08:55:23 -0800524#define PROXY_WORKER_CONSTMETHOD0(r, method) \
525 r method() const override { \
deadbeefe814a0d2017-02-25 18:15:09 -0800526 ConstMethodCall0<C, r> call(c_, &C::method); \
deadbeefd99a2002017-01-18 08:55:23 -0800527 return call.Marshal(RTC_FROM_HERE, worker_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000528 }
perkj@webrtc.org81134d02015-01-12 08:30:16 +0000529
deadbeefe814a0d2017-02-25 18:15:09 -0800530#define PROXY_WORKER_METHOD1(r, method, t1) \
531 r method(t1 a1) override { \
532 MethodCall1<C, r, t1> call(c_, &C::method, std::move(a1)); \
533 return call.Marshal(RTC_FROM_HERE, worker_thread_); \
deadbeefd99a2002017-01-18 08:55:23 -0800534 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000535
deadbeefe814a0d2017-02-25 18:15:09 -0800536#define PROXY_WORKER_CONSTMETHOD1(r, method, t1) \
537 r method(t1 a1) const override { \
538 ConstMethodCall1<C, r, t1> call(c_, &C::method, std::move(a1)); \
539 return call.Marshal(RTC_FROM_HERE, worker_thread_); \
deadbeefd99a2002017-01-18 08:55:23 -0800540 }
541
deadbeefe814a0d2017-02-25 18:15:09 -0800542#define PROXY_WORKER_METHOD2(r, method, t1, t2) \
543 r method(t1 a1, t2 a2) override { \
544 MethodCall2<C, r, t1, t2> call(c_, &C::method, std::move(a1), \
545 std::move(a2)); \
546 return call.Marshal(RTC_FROM_HERE, worker_thread_); \
deadbeefd99a2002017-01-18 08:55:23 -0800547 }
548
deadbeefe814a0d2017-02-25 18:15:09 -0800549#define PROXY_WORKER_CONSTMETHOD2(r, method, t1, t2) \
550 r method(t1 a1, t2 a2) const override { \
551 ConstMethodCall2<C, r, t1, t2> call(c_, &C::method, std::move(a1), \
552 std::move(a2)); \
553 return call.Marshal(RTC_FROM_HERE, worker_thread_); \
554 }
555
556#define PROXY_WORKER_METHOD3(r, method, t1, t2, t3) \
557 r method(t1 a1, t2 a2, t3 a3) override { \
558 MethodCall3<C, r, t1, t2, t3> call(c_, &C::method, std::move(a1), \
559 std::move(a2), std::move(a3)); \
560 return call.Marshal(RTC_FROM_HERE, worker_thread_); \
561 }
562
563#define PROXY_WORKER_CONSTMETHOD3(r, method, t1, t2) \
564 r method(t1 a1, t2 a2, t3 a3) const override { \
565 ConstMethodCall3<C, r, t1, t2, t3> call(c_, &C::method, std::move(a1), \
566 std::move(a2), std::move(a3)); \
567 return call.Marshal(RTC_FROM_HERE, worker_thread_); \
deadbeefd99a2002017-01-18 08:55:23 -0800568 }
569
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000570} // namespace webrtc
571
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200572#endif // API_PROXY_H_