blob: 746a758ba4315181cfb04688487fa1d70179eb0c [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.
13
14//
15// Example usage:
16//
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000017// class TestInterface : public rtc::RefCountInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000018// public:
19// std::string FooA() = 0;
20// std::string FooB(bool arg1) const = 0;
nisse72c8d2b2016-04-15 03:49:07 -070021// std::string FooC(bool arg1) = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000022// };
23//
24// Note that return types can not be a const reference.
25//
26// class Test : public TestInterface {
27// ... implementation of the interface.
28// };
29//
30// BEGIN_PROXY_MAP(Test)
31// PROXY_METHOD0(std::string, FooA)
32// PROXY_CONSTMETHOD1(std::string, FooB, arg1)
nisse72c8d2b2016-04-15 03:49:07 -070033// PROXY_WORKER_METHOD1(std::string, FooC, arg1)
henrike@webrtc.org28e20752013-07-10 00:45:36 +000034// END_PROXY()
35//
nisse72c8d2b2016-04-15 03:49:07 -070036// where the first two methods are invoked on the signaling thread,
37// and the third is invoked on the worker thread.
38//
39// The proxy can be created using
40//
41// TestProxy::Create(Thread* signaling_thread, Thread* worker_thread,
42// TestInterface*).
43//
44// The variant defined with BEGIN_SIGNALING_PROXY_MAP is unaware of
45// the worker thread, and invokes all methods on the signaling thread.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000046
Henrik Kjellander15583c12016-02-10 10:53:12 +010047#ifndef WEBRTC_API_PROXY_H_
48#define WEBRTC_API_PROXY_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000049
kwibergd1fe2812016-04-27 06:47:29 -070050#include <memory>
51
tommi@webrtc.org18de6f92014-11-04 12:08:48 +000052#include "webrtc/base/event.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000053#include "webrtc/base/thread.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000054
55namespace webrtc {
56
57template <typename R>
58class ReturnType {
59 public:
60 template<typename C, typename M>
61 void Invoke(C* c, M m) { r_ = (c->*m)(); }
62 template<typename C, typename M, typename T1>
63 void Invoke(C* c, M m, T1 a1) { r_ = (c->*m)(a1); }
64 template<typename C, typename M, typename T1, typename T2>
65 void Invoke(C* c, M m, T1 a1, T2 a2) { r_ = (c->*m)(a1, a2); }
66 template<typename C, typename M, typename T1, typename T2, typename T3>
67 void Invoke(C* c, M m, T1 a1, T2 a2, T3 a3) { r_ = (c->*m)(a1, a2, a3); }
perkj@webrtc.org81134d02015-01-12 08:30:16 +000068 template<typename C, typename M, typename T1, typename T2, typename T3,
69 typename T4>
70 void Invoke(C* c, M m, T1 a1, T2 a2, T3 a3, T4 a4) {
71 r_ = (c->*m)(a1, a2, a3, a4);
72 }
73 template<typename C, typename M, typename T1, typename T2, typename T3,
74 typename T4, typename T5>
75 void Invoke(C* c, M m, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) {
76 r_ = (c->*m)(a1, a2, a3, a4, a5);
77 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078
79 R value() { return r_; }
80
81 private:
82 R r_;
83};
84
85template <>
86class ReturnType<void> {
87 public:
88 template<typename C, typename M>
89 void Invoke(C* c, M m) { (c->*m)(); }
90 template<typename C, typename M, typename T1>
91 void Invoke(C* c, M m, T1 a1) { (c->*m)(a1); }
92 template<typename C, typename M, typename T1, typename T2>
93 void Invoke(C* c, M m, T1 a1, T2 a2) { (c->*m)(a1, a2); }
94 template<typename C, typename M, typename T1, typename T2, typename T3>
95 void Invoke(C* c, M m, T1 a1, T2 a2, T3 a3) { (c->*m)(a1, a2, a3); }
96
97 void value() {}
98};
99
tommi@webrtc.org18de6f92014-11-04 12:08:48 +0000100namespace internal {
101
102class SynchronousMethodCall
103 : public rtc::MessageData,
104 public rtc::MessageHandler {
105 public:
perkj@webrtc.org81134d02015-01-12 08:30:16 +0000106 explicit SynchronousMethodCall(rtc::MessageHandler* proxy)
tommi@webrtc.org18de6f92014-11-04 12:08:48 +0000107 : e_(), proxy_(proxy) {}
108 ~SynchronousMethodCall() {}
109
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700110 void Invoke(const rtc::Location& posted_from, rtc::Thread* t) {
tommi@webrtc.org18de6f92014-11-04 12:08:48 +0000111 if (t->IsCurrent()) {
112 proxy_->OnMessage(NULL);
113 } else {
114 e_.reset(new rtc::Event(false, false));
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700115 t->Post(posted_from, this, 0);
andresp@webrtc.org53d90122015-02-09 14:19:09 +0000116 e_->Wait(rtc::Event::kForever);
tommi@webrtc.org18de6f92014-11-04 12:08:48 +0000117 }
118 }
119
120 private:
121 void OnMessage(rtc::Message*) { proxy_->OnMessage(NULL); e_->Set(); }
kwibergd1fe2812016-04-27 06:47:29 -0700122 std::unique_ptr<rtc::Event> e_;
tommi@webrtc.org18de6f92014-11-04 12:08:48 +0000123 rtc::MessageHandler* proxy_;
124};
125
perkj@webrtc.org81134d02015-01-12 08:30:16 +0000126} // namespace internal
tommi@webrtc.org18de6f92014-11-04 12:08:48 +0000127
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000128template <typename C, typename R>
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000129class MethodCall0 : public rtc::Message,
130 public rtc::MessageHandler {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000131 public:
132 typedef R (C::*Method)();
133 MethodCall0(C* c, Method m) : c_(c), m_(m) {}
134
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700135 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
136 internal::SynchronousMethodCall(this).Invoke(posted_from, t);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000137 return r_.value();
138 }
139
140 private:
tommi@webrtc.org18de6f92014-11-04 12:08:48 +0000141 void OnMessage(rtc::Message*) { r_.Invoke(c_, m_); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000142
143 C* c_;
144 Method m_;
145 ReturnType<R> r_;
146};
147
148template <typename C, typename R>
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000149class ConstMethodCall0 : public rtc::Message,
150 public rtc::MessageHandler {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000151 public:
152 typedef R (C::*Method)() const;
153 ConstMethodCall0(C* c, Method m) : c_(c), m_(m) {}
154
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700155 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
156 internal::SynchronousMethodCall(this).Invoke(posted_from, t);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000157 return r_.value();
158 }
159
160 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000161 void OnMessage(rtc::Message*) { r_.Invoke(c_, m_); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000162
163 C* c_;
164 Method m_;
165 ReturnType<R> r_;
166};
167
168template <typename C, typename R, typename T1>
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000169class MethodCall1 : public rtc::Message,
170 public rtc::MessageHandler {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000171 public:
172 typedef R (C::*Method)(T1 a1);
173 MethodCall1(C* c, Method m, T1 a1) : c_(c), m_(m), a1_(a1) {}
174
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700175 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
176 internal::SynchronousMethodCall(this).Invoke(posted_from, t);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000177 return r_.value();
178 }
179
180 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000181 void OnMessage(rtc::Message*) { r_.Invoke(c_, m_, a1_); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000182
183 C* c_;
184 Method m_;
185 ReturnType<R> r_;
186 T1 a1_;
187};
188
189template <typename C, typename R, typename T1>
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000190class ConstMethodCall1 : public rtc::Message,
191 public rtc::MessageHandler {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000192 public:
193 typedef R (C::*Method)(T1 a1) const;
194 ConstMethodCall1(C* c, Method m, T1 a1) : c_(c), m_(m), a1_(a1) {}
195
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700196 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
197 internal::SynchronousMethodCall(this).Invoke(posted_from, t);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000198 return r_.value();
199 }
200
201 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000202 void OnMessage(rtc::Message*) { r_.Invoke(c_, m_, a1_); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000203
204 C* c_;
205 Method m_;
206 ReturnType<R> r_;
207 T1 a1_;
208};
209
210template <typename C, typename R, typename T1, typename T2>
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000211class MethodCall2 : public rtc::Message,
212 public rtc::MessageHandler {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000213 public:
214 typedef R (C::*Method)(T1 a1, T2 a2);
215 MethodCall2(C* c, Method m, T1 a1, T2 a2) : c_(c), m_(m), a1_(a1), a2_(a2) {}
216
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700217 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
218 internal::SynchronousMethodCall(this).Invoke(posted_from, t);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000219 return r_.value();
220 }
221
222 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000223 void OnMessage(rtc::Message*) { r_.Invoke(c_, m_, a1_, a2_); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000224
225 C* c_;
226 Method m_;
227 ReturnType<R> r_;
228 T1 a1_;
229 T2 a2_;
230};
231
232template <typename C, typename R, typename T1, typename T2, typename T3>
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000233class MethodCall3 : public rtc::Message,
234 public rtc::MessageHandler {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000235 public:
236 typedef R (C::*Method)(T1 a1, T2 a2, T3 a3);
237 MethodCall3(C* c, Method m, T1 a1, T2 a2, T3 a3)
238 : c_(c), m_(m), a1_(a1), a2_(a2), a3_(a3) {}
239
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700240 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
241 internal::SynchronousMethodCall(this).Invoke(posted_from, t);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000242 return r_.value();
243 }
244
245 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000246 void OnMessage(rtc::Message*) { r_.Invoke(c_, m_, a1_, a2_, a3_); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000247
248 C* c_;
249 Method m_;
250 ReturnType<R> r_;
251 T1 a1_;
252 T2 a2_;
253 T3 a3_;
254};
255
perkj@webrtc.org81134d02015-01-12 08:30:16 +0000256template <typename C, typename R, typename T1, typename T2, typename T3,
257 typename T4>
258class MethodCall4 : public rtc::Message,
259 public rtc::MessageHandler {
260 public:
261 typedef R (C::*Method)(T1 a1, T2 a2, T3 a3, T4 a4);
262 MethodCall4(C* c, Method m, T1 a1, T2 a2, T3 a3, T4 a4)
263 : c_(c), m_(m), a1_(a1), a2_(a2), a3_(a3), a4_(a4) {}
264
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700265 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
266 internal::SynchronousMethodCall(this).Invoke(posted_from, t);
perkj@webrtc.org81134d02015-01-12 08:30:16 +0000267 return r_.value();
268 }
269
270 private:
271 void OnMessage(rtc::Message*) { r_.Invoke(c_, m_, a1_, a2_, a3_, a4_); }
272
273 C* c_;
274 Method m_;
275 ReturnType<R> r_;
276 T1 a1_;
277 T2 a2_;
278 T3 a3_;
279 T4 a4_;
280};
281
282template <typename C, typename R, typename T1, typename T2, typename T3,
283 typename T4, typename T5>
284class MethodCall5 : public rtc::Message,
285 public rtc::MessageHandler {
286 public:
287 typedef R (C::*Method)(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
288 MethodCall5(C* c, Method m, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
289 : c_(c), m_(m), a1_(a1), a2_(a2), a3_(a3), a4_(a4), a5_(a5) {}
290
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);
perkj@webrtc.org81134d02015-01-12 08:30:16 +0000293 return r_.value();
294 }
295
296 private:
297 void OnMessage(rtc::Message*) { r_.Invoke(c_, m_, a1_, a2_, a3_, a4_, a5_); }
298
299 C* c_;
300 Method m_;
301 ReturnType<R> r_;
302 T1 a1_;
303 T2 a2_;
304 T3 a3_;
305 T4 a4_;
306 T5 a5_;
307};
308
deadbeefa601f5c2016-06-06 14:27:39 -0700309#define BEGIN_SIGNALING_PROXY_MAP(c) \
310 template <class INTERNAL_CLASS> \
311 class c##ProxyWithInternal; \
312 typedef c##ProxyWithInternal<c##Interface> c##Proxy; \
313 template <class INTERNAL_CLASS> \
314 class c##ProxyWithInternal : public c##Interface { \
315 protected: \
316 typedef c##Interface C; \
317 c##ProxyWithInternal(rtc::Thread* signaling_thread, INTERNAL_CLASS* c) \
318 : signaling_thread_(signaling_thread), c_(c) {} \
319 ~c##ProxyWithInternal() { \
320 MethodCall0<c##ProxyWithInternal, void> call( \
321 this, &c##ProxyWithInternal::Release_s); \
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700322 call.Marshal(RTC_FROM_HERE, signaling_thread_); \
deadbeefa601f5c2016-06-06 14:27:39 -0700323 } \
324 \
325 public: \
326 static rtc::scoped_refptr<c##ProxyWithInternal> Create( \
327 rtc::Thread* signaling_thread, \
328 INTERNAL_CLASS* c) { \
329 return new rtc::RefCountedObject<c##ProxyWithInternal>(signaling_thread, \
330 c); \
331 } \
332 const INTERNAL_CLASS* internal() const { return c_.get(); } \
333 INTERNAL_CLASS* internal() { return c_.get(); }
nisse5b68ab52016-04-07 07:45:54 -0700334
deadbeefa601f5c2016-06-06 14:27:39 -0700335#define BEGIN_PROXY_MAP(c) \
336 template <class INTERNAL_CLASS> \
337 class c##ProxyWithInternal; \
338 typedef c##ProxyWithInternal<c##Interface> c##Proxy; \
339 template <class INTERNAL_CLASS> \
340 class c##ProxyWithInternal : public c##Interface { \
341 protected: \
342 typedef c##Interface C; \
343 c##ProxyWithInternal(rtc::Thread* signaling_thread, \
344 rtc::Thread* worker_thread, \
345 INTERNAL_CLASS* c) \
346 : signaling_thread_(signaling_thread), \
347 worker_thread_(worker_thread), \
348 c_(c) {} \
349 ~c##ProxyWithInternal() { \
350 MethodCall0<c##ProxyWithInternal, void> call( \
351 this, &c##ProxyWithInternal::Release_s); \
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700352 call.Marshal(RTC_FROM_HERE, signaling_thread_); \
deadbeefa601f5c2016-06-06 14:27:39 -0700353 } \
354 \
355 public: \
356 static rtc::scoped_refptr<c##ProxyWithInternal> Create( \
357 rtc::Thread* signaling_thread, \
358 rtc::Thread* worker_thread, \
359 INTERNAL_CLASS* c) { \
360 return new rtc::RefCountedObject<c##ProxyWithInternal>( \
361 signaling_thread, worker_thread, c); \
362 } \
363 const INTERNAL_CLASS* internal() const { return c_.get(); } \
364 INTERNAL_CLASS* internal() { return c_.get(); }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000365
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700366#define PROXY_METHOD0(r, method) \
367 r method() override { \
368 MethodCall0<C, r> call(c_.get(), &C::method); \
369 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000370 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000371
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700372#define PROXY_CONSTMETHOD0(r, method) \
373 r method() const override { \
374 ConstMethodCall0<C, r> call(c_.get(), &C::method); \
375 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000376 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000377
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700378#define PROXY_METHOD1(r, method, t1) \
379 r method(t1 a1) override { \
380 MethodCall1<C, r, t1> call(c_.get(), &C::method, a1); \
381 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000382 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000383
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000384#define PROXY_CONSTMETHOD1(r, method, t1) \
385 r method(t1 a1) const override { \
386 ConstMethodCall1<C, r, t1> call(c_.get(), &C::method, a1); \
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700387 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000388 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000389
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000390#define PROXY_METHOD2(r, method, t1, t2) \
391 r method(t1 a1, t2 a2) override { \
392 MethodCall2<C, r, t1, t2> call(c_.get(), &C::method, a1, a2); \
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700393 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000394 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000395
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000396#define PROXY_METHOD3(r, method, t1, t2, t3) \
397 r method(t1 a1, t2 a2, t3 a3) override { \
398 MethodCall3<C, r, t1, t2, t3> call(c_.get(), &C::method, a1, a2, a3); \
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700399 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000400 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000401
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000402#define PROXY_METHOD4(r, method, t1, t2, t3, t4) \
403 r method(t1 a1, t2 a2, t3 a3, t4 a4) override { \
404 MethodCall4<C, r, t1, t2, t3, t4> call(c_.get(), &C::method, a1, a2, a3, \
405 a4); \
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700406 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000407 }
perkj@webrtc.org81134d02015-01-12 08:30:16 +0000408
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000409#define PROXY_METHOD5(r, method, t1, t2, t3, t4, t5) \
410 r method(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) override { \
411 MethodCall5<C, r, t1, t2, t3, t4, t5> call(c_.get(), &C::method, a1, a2, \
412 a3, a4, a5); \
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700413 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \
nisse5b68ab52016-04-07 07:45:54 -0700414 }
415
416// Define methods which should be invoked on the worker thread.
417#define PROXY_WORKER_METHOD1(r, method, t1) \
418 r method(t1 a1) override { \
419 MethodCall1<C, r, t1> call(c_.get(), &C::method, a1); \
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700420 return call.Marshal(RTC_FROM_HERE, worker_thread_); \
nisse5b68ab52016-04-07 07:45:54 -0700421 }
422
423#define PROXY_WORKER_METHOD2(r, method, t1, t2) \
424 r method(t1 a1, t2 a2) override { \
425 MethodCall2<C, r, t1, t2> call(c_.get(), &C::method, a1, a2); \
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700426 return call.Marshal(RTC_FROM_HERE, worker_thread_); \
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000427 }
perkj@webrtc.org81134d02015-01-12 08:30:16 +0000428
deadbeefa601f5c2016-06-06 14:27:39 -0700429#define END_SIGNALING_PROXY() \
430 private: \
431 void Release_s() { c_ = NULL; } \
432 mutable rtc::Thread* signaling_thread_; \
433 rtc::scoped_refptr<INTERNAL_CLASS> c_; \
434 } \
435 ;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000436
deadbeefa601f5c2016-06-06 14:27:39 -0700437#define END_PROXY() \
438 private: \
439 void Release_s() { c_ = NULL; } \
440 mutable rtc::Thread* signaling_thread_; \
441 mutable rtc::Thread* worker_thread_; \
442 rtc::scoped_refptr<INTERNAL_CLASS> c_; \
443 } \
444 ;
nisse5b68ab52016-04-07 07:45:54 -0700445
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000446} // namespace webrtc
447
Henrik Kjellander15583c12016-02-10 10:53:12 +0100448#endif // WEBRTC_API_PROXY_H_