OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2013 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
311 class c##ProxyWithInternal; \ | 311 class c##ProxyWithInternal; \ |
312 typedef c##ProxyWithInternal<c##Interface> c##Proxy; \ | 312 typedef c##ProxyWithInternal<c##Interface> c##Proxy; \ |
313 template <class INTERNAL_CLASS> \ | 313 template <class INTERNAL_CLASS> \ |
314 class c##ProxyWithInternal : public c##Interface { \ | 314 class c##ProxyWithInternal : public c##Interface { \ |
315 protected: \ | 315 protected: \ |
316 typedef c##Interface C; \ | 316 typedef c##Interface C; \ |
317 c##ProxyWithInternal(rtc::Thread* signaling_thread, INTERNAL_CLASS* c) \ | 317 c##ProxyWithInternal(rtc::Thread* signaling_thread, INTERNAL_CLASS* c) \ |
318 : signaling_thread_(signaling_thread), c_(c) {} \ | 318 : signaling_thread_(signaling_thread), c_(c) {} \ |
319 ~c##ProxyWithInternal() { \ | 319 ~c##ProxyWithInternal() { \ |
320 MethodCall0<c##ProxyWithInternal, void> call( \ | 320 MethodCall0<c##ProxyWithInternal, void> call( \ |
321 this, &c##ProxyWithInternal::Release_s); \ | 321 this, &c##ProxyWithInternal::ReleaseOnCorrectThread); \ |
322 call.Marshal(RTC_FROM_HERE, signaling_thread_); \ | 322 call.Marshal(RTC_FROM_HERE, signaling_thread_); \ |
323 } \ | 323 } \ |
324 \ | 324 \ |
325 public: \ | 325 public: \ |
326 static rtc::scoped_refptr<c##ProxyWithInternal> Create( \ | 326 static rtc::scoped_refptr<c##ProxyWithInternal> Create( \ |
327 rtc::Thread* signaling_thread, \ | 327 rtc::Thread* signaling_thread, \ |
328 INTERNAL_CLASS* c) { \ | 328 INTERNAL_CLASS* c) { \ |
329 return new rtc::RefCountedObject<c##ProxyWithInternal>(signaling_thread, \ | 329 return new rtc::RefCountedObject<c##ProxyWithInternal>(signaling_thread, \ |
330 c); \ | 330 c); \ |
331 } \ | 331 } \ |
332 const INTERNAL_CLASS* internal() const { return c_.get(); } \ | 332 const INTERNAL_CLASS* internal() const { return c_.get(); } \ |
333 INTERNAL_CLASS* internal() { return c_.get(); } | 333 INTERNAL_CLASS* internal() { return c_.get(); } |
334 | 334 |
335 #define BEGIN_PROXY_MAP(c) \ | 335 #define BEGIN_PROXY_MAP(c) \ |
336 template <class INTERNAL_CLASS> \ | 336 template <class INTERNAL_CLASS> \ |
337 class c##ProxyWithInternal; \ | 337 class c##ProxyWithInternal; \ |
338 typedef c##ProxyWithInternal<c##Interface> c##Proxy; \ | 338 typedef c##ProxyWithInternal<c##Interface> c##Proxy; \ |
339 template <class INTERNAL_CLASS> \ | 339 template <class INTERNAL_CLASS> \ |
340 class c##ProxyWithInternal : public c##Interface { \ | 340 class c##ProxyWithInternal : public c##Interface { \ |
341 protected: \ | 341 protected: \ |
342 typedef c##Interface C; \ | 342 typedef c##Interface C; \ |
343 c##ProxyWithInternal(rtc::Thread* signaling_thread, \ | 343 c##ProxyWithInternal(rtc::Thread* signaling_thread, \ |
344 rtc::Thread* worker_thread, \ | 344 rtc::Thread* worker_thread, \ |
345 INTERNAL_CLASS* c) \ | 345 INTERNAL_CLASS* c) \ |
346 : signaling_thread_(signaling_thread), \ | 346 : signaling_thread_(signaling_thread), \ |
347 worker_thread_(worker_thread), \ | 347 worker_thread_(worker_thread), \ |
348 c_(c) {} \ | 348 c_(c) {} \ |
349 ~c##ProxyWithInternal() { \ | 349 ~c##ProxyWithInternal() { \ |
350 MethodCall0<c##ProxyWithInternal, void> call( \ | 350 MethodCall0<c##ProxyWithInternal, void> call( \ |
351 this, &c##ProxyWithInternal::Release_s); \ | 351 this, &c##ProxyWithInternal::ReleaseOnCorrectThread); \ |
352 call.Marshal(RTC_FROM_HERE, signaling_thread_); \ | 352 call.Marshal(RTC_FROM_HERE, signaling_thread_); \ |
353 } \ | 353 } \ |
354 \ | 354 \ |
355 public: \ | 355 public: \ |
356 static rtc::scoped_refptr<c##ProxyWithInternal> Create( \ | 356 static rtc::scoped_refptr<c##ProxyWithInternal> Create( \ |
357 rtc::Thread* signaling_thread, \ | 357 rtc::Thread* signaling_thread, \ |
358 rtc::Thread* worker_thread, \ | 358 rtc::Thread* worker_thread, \ |
359 INTERNAL_CLASS* c) { \ | 359 INTERNAL_CLASS* c) { \ |
360 return new rtc::RefCountedObject<c##ProxyWithInternal>( \ | 360 return new rtc::RefCountedObject<c##ProxyWithInternal>( \ |
361 signaling_thread, worker_thread, c); \ | 361 signaling_thread, worker_thread, c); \ |
362 } \ | 362 } \ |
363 const INTERNAL_CLASS* internal() const { return c_.get(); } \ | 363 const INTERNAL_CLASS* internal() const { return c_.get(); } \ |
364 INTERNAL_CLASS* internal() { return c_.get(); } | 364 INTERNAL_CLASS* internal() { return c_.get(); } |
365 | 365 |
366 #define BEGIN_NON_REFCOUNTED_PROXY_MAP(c) \ | |
Taylor Brandstetter
2017/01/13 07:52:29
Before you say "wow these macros are getting out o
| |
367 template <class INTERNAL_CLASS> \ | |
368 class c##ProxyWithInternal; \ | |
369 typedef c##ProxyWithInternal<c##Interface> c##Proxy; \ | |
370 template <class INTERNAL_CLASS> \ | |
371 class c##ProxyWithInternal : public c##Interface { \ | |
372 protected: \ | |
373 typedef c##Interface C; \ | |
374 c##ProxyWithInternal(rtc::Thread* signaling_thread, \ | |
375 rtc::Thread* worker_thread, \ | |
376 INTERNAL_CLASS* c) \ | |
377 : signaling_thread_(signaling_thread), \ | |
378 worker_thread_(worker_thread), \ | |
379 c_(c) {} \ | |
380 \ | |
381 public: \ | |
382 ~c##ProxyWithInternal() { \ | |
383 MethodCall0<c##ProxyWithInternal, void> call( \ | |
384 this, &c##ProxyWithInternal::ReleaseOnCorrectThread); \ | |
385 call.Marshal(RTC_FROM_HERE, signaling_thread_); \ | |
386 } \ | |
387 \ | |
388 static std::unique_ptr<c##ProxyWithInternal> Create( \ | |
389 rtc::Thread* signaling_thread, \ | |
390 rtc::Thread* worker_thread, \ | |
391 INTERNAL_CLASS* c) { \ | |
392 return std::unique_ptr<c##ProxyWithInternal>( \ | |
393 new c##ProxyWithInternal(signaling_thread, worker_thread, c)); \ | |
394 } \ | |
395 const INTERNAL_CLASS* internal() const { return c_.get(); } \ | |
396 INTERNAL_CLASS* internal() { return c_.get(); } | |
397 | |
398 // Object that should be destroyed on the worker thread. | |
399 #define BEGIN_NON_REFCOUNTED_WORKER_PROXY_MAP(c) \ | |
400 template <class INTERNAL_CLASS> \ | |
401 class c##ProxyWithInternal; \ | |
402 typedef c##ProxyWithInternal<c##Interface> c##Proxy; \ | |
403 template <class INTERNAL_CLASS> \ | |
404 class c##ProxyWithInternal : public c##Interface { \ | |
405 protected: \ | |
406 typedef c##Interface C; \ | |
407 c##ProxyWithInternal(rtc::Thread* signaling_thread, \ | |
408 rtc::Thread* worker_thread, \ | |
409 INTERNAL_CLASS* c) \ | |
410 : signaling_thread_(signaling_thread), \ | |
411 worker_thread_(worker_thread), \ | |
412 c_(c) {} \ | |
413 \ | |
414 public: \ | |
415 ~c##ProxyWithInternal() { \ | |
416 MethodCall0<c##ProxyWithInternal, void> call( \ | |
417 this, &c##ProxyWithInternal::ReleaseOnCorrectThread); \ | |
418 call.Marshal(RTC_FROM_HERE, worker_thread_); \ | |
419 } \ | |
420 \ | |
421 static std::unique_ptr<c##ProxyWithInternal> Create( \ | |
422 rtc::Thread* signaling_thread, \ | |
423 rtc::Thread* worker_thread, \ | |
424 INTERNAL_CLASS* c) { \ | |
425 return std::unique_ptr<c##ProxyWithInternal>( \ | |
426 new c##ProxyWithInternal(signaling_thread, worker_thread, c)); \ | |
427 } \ | |
428 const INTERNAL_CLASS* internal() const { return c_.get(); } \ | |
429 INTERNAL_CLASS* internal() { return c_.get(); } | |
430 | |
366 #define PROXY_METHOD0(r, method) \ | 431 #define PROXY_METHOD0(r, method) \ |
367 r method() override { \ | 432 r method() override { \ |
368 MethodCall0<C, r> call(c_.get(), &C::method); \ | 433 MethodCall0<C, r> call(c_.get(), &C::method); \ |
369 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ | 434 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ |
370 } | 435 } |
371 | 436 |
372 #define PROXY_CONSTMETHOD0(r, method) \ | 437 #define PROXY_CONSTMETHOD0(r, method) \ |
373 r method() const override { \ | 438 r method() const override { \ |
374 ConstMethodCall0<C, r> call(c_.get(), &C::method); \ | 439 ConstMethodCall0<C, r> call(c_.get(), &C::method); \ |
375 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ | 440 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
407 } | 472 } |
408 | 473 |
409 #define PROXY_METHOD5(r, method, t1, t2, t3, t4, t5) \ | 474 #define PROXY_METHOD5(r, method, t1, t2, t3, t4, t5) \ |
410 r method(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) override { \ | 475 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, \ | 476 MethodCall5<C, r, t1, t2, t3, t4, t5> call(c_.get(), &C::method, a1, a2, \ |
412 a3, a4, a5); \ | 477 a3, a4, a5); \ |
413 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ | 478 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ |
414 } | 479 } |
415 | 480 |
416 // Define methods which should be invoked on the worker thread. | 481 // Define methods which should be invoked on the worker thread. |
482 #define PROXY_WORKER_METHOD0(r, method) \ | |
483 r method() override { \ | |
484 MethodCall0<C, r> call(c_.get(), &C::method); \ | |
485 return call.Marshal(RTC_FROM_HERE, worker_thread_); \ | |
486 } | |
487 | |
488 #define PROXY_WORKER_CONSTMETHOD0(r, method) \ | |
489 r method() const override { \ | |
490 ConstMethodCall0<C, r> call(c_.get(), &C::method); \ | |
491 return call.Marshal(RTC_FROM_HERE, worker_thread_); \ | |
492 } | |
493 | |
417 #define PROXY_WORKER_METHOD1(r, method, t1) \ | 494 #define PROXY_WORKER_METHOD1(r, method, t1) \ |
418 r method(t1 a1) override { \ | 495 r method(t1 a1) override { \ |
419 MethodCall1<C, r, t1> call(c_.get(), &C::method, a1); \ | 496 MethodCall1<C, r, t1> call(c_.get(), &C::method, a1); \ |
420 return call.Marshal(RTC_FROM_HERE, worker_thread_); \ | 497 return call.Marshal(RTC_FROM_HERE, worker_thread_); \ |
421 } | 498 } |
422 | 499 |
500 #define PROXY_WORKER_CONSTMETHOD1(r, method, t1) \ | |
501 r method(t1 a1) const override { \ | |
502 ConstMethodCall1<C, r, t1> call(c_.get(), &C::method, a1); \ | |
503 return call.Marshal(RTC_FROM_HERE, worker_thread_); \ | |
504 } | |
505 | |
423 #define PROXY_WORKER_METHOD2(r, method, t1, t2) \ | 506 #define PROXY_WORKER_METHOD2(r, method, t1, t2) \ |
424 r method(t1 a1, t2 a2) override { \ | 507 r method(t1 a1, t2 a2) override { \ |
425 MethodCall2<C, r, t1, t2> call(c_.get(), &C::method, a1, a2); \ | 508 MethodCall2<C, r, t1, t2> call(c_.get(), &C::method, a1, a2); \ |
426 return call.Marshal(RTC_FROM_HERE, worker_thread_); \ | 509 return call.Marshal(RTC_FROM_HERE, worker_thread_); \ |
427 } | 510 } |
428 | 511 |
429 #define END_SIGNALING_PROXY() \ | 512 #define PROXY_WORKER_CONSTMETHOD2(r, method, t1, t2) \ |
430 private: \ | 513 r method(t1 a1, t2 a2) const override { \ |
431 void Release_s() { c_ = NULL; } \ | 514 ConstMethodCall2<C, r, t1, t2> call(c_.get(), &C::method, a1, a2); \ |
432 mutable rtc::Thread* signaling_thread_; \ | 515 return call.Marshal(RTC_FROM_HERE, worker_thread_); \ |
433 rtc::scoped_refptr<INTERNAL_CLASS> c_; \ | 516 } |
434 } \ | 517 |
518 #define END_SIGNALING_PROXY() \ | |
519 private: \ | |
520 void ReleaseOnCorrectThread() { c_ = NULL; } \ | |
521 mutable rtc::Thread* signaling_thread_; \ | |
522 rtc::scoped_refptr<INTERNAL_CLASS> c_; \ | |
523 } \ | |
435 ; | 524 ; |
436 | 525 |
437 #define END_PROXY() \ | 526 #define END_PROXY() \ |
438 private: \ | 527 private: \ |
439 void Release_s() { c_ = NULL; } \ | 528 void ReleaseOnCorrectThread() { c_ = NULL; } \ |
440 mutable rtc::Thread* signaling_thread_; \ | 529 mutable rtc::Thread* signaling_thread_; \ |
441 mutable rtc::Thread* worker_thread_; \ | 530 mutable rtc::Thread* worker_thread_; \ |
442 rtc::scoped_refptr<INTERNAL_CLASS> c_; \ | 531 rtc::scoped_refptr<INTERNAL_CLASS> c_; \ |
443 } \ | 532 } \ |
533 ; | |
534 | |
535 #define END_NON_REFCOUNTED_PROXY() \ | |
536 private: \ | |
537 void ReleaseOnCorrectThread() { c_.reset(nullptr); } \ | |
538 mutable rtc::Thread* signaling_thread_; \ | |
539 mutable rtc::Thread* worker_thread_; \ | |
540 std::unique_ptr<INTERNAL_CLASS> c_; \ | |
541 } \ | |
444 ; | 542 ; |
445 | 543 |
446 } // namespace webrtc | 544 } // namespace webrtc |
447 | 545 |
448 #endif // WEBRTC_API_PROXY_H_ | 546 #endif // WEBRTC_API_PROXY_H_ |
OLD | NEW |