| 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 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 ReturnType<R> r_; | 346 ReturnType<R> r_; |
| 347 T1 a1_; | 347 T1 a1_; |
| 348 T2 a2_; | 348 T2 a2_; |
| 349 T3 a3_; | 349 T3 a3_; |
| 350 T4 a4_; | 350 T4 a4_; |
| 351 T5 a5_; | 351 T5 a5_; |
| 352 }; | 352 }; |
| 353 | 353 |
| 354 | 354 |
| 355 // Helper macros to reduce code duplication. | 355 // Helper macros to reduce code duplication. |
| 356 #define PROXY_MAP_BOILERPLATE(c) \ | 356 #define PROXY_MAP_BOILERPLATE(c) \ |
| 357 template <class INTERNAL_CLASS> \ | 357 template <class INTERNAL_CLASS> \ |
| 358 class c##ProxyWithInternal; \ | 358 class c##ProxyWithInternal; \ |
| 359 typedef c##ProxyWithInternal<c##Interface> c##Proxy; \ | 359 typedef c##ProxyWithInternal<c##Interface> c##Proxy; \ |
| 360 template <class INTERNAL_CLASS> \ | 360 template <class INTERNAL_CLASS> \ |
| 361 class c##ProxyWithInternal : public c##Interface { \ | 361 class c##ProxyWithInternal : public c##Interface { \ |
| 362 protected: \ | 362 protected: \ |
| 363 typedef c##Interface C; \ | 363 typedef c##Interface C; \ |
| 364 \ | 364 \ |
| 365 public: \ | 365 public: \ |
| 366 const INTERNAL_CLASS* internal() const { return c_.get(); } \ | 366 const INTERNAL_CLASS* internal() const { return c_; } \ |
| 367 INTERNAL_CLASS* internal() { return c_.get(); } | 367 INTERNAL_CLASS* internal() { return c_; } |
| 368 | 368 |
| 369 #define END_PROXY_MAP() \ | 369 #define END_PROXY_MAP() \ |
| 370 }; | 370 }; |
| 371 | 371 |
| 372 #define SIGNALING_PROXY_MAP_BOILERPLATE(c) \ | 372 #define SIGNALING_PROXY_MAP_BOILERPLATE(c) \ |
| 373 protected: \ | 373 protected: \ |
| 374 c##ProxyWithInternal(rtc::Thread* signaling_thread, INTERNAL_CLASS* c) \ | 374 c##ProxyWithInternal(rtc::Thread* signaling_thread, INTERNAL_CLASS* c) \ |
| 375 : signaling_thread_(signaling_thread), c_(c) {} \ | 375 : signaling_thread_(signaling_thread), c_(c) {} \ |
| 376 \ | 376 \ |
| 377 private: \ | 377 private: \ |
| (...skipping 18 matching lines...) Expand all Loading... |
| 396 ~c##ProxyWithInternal() { \ | 396 ~c##ProxyWithInternal() { \ |
| 397 MethodCall0<c##ProxyWithInternal, void> call( \ | 397 MethodCall0<c##ProxyWithInternal, void> call( \ |
| 398 this, &c##ProxyWithInternal::DestroyInternal); \ | 398 this, &c##ProxyWithInternal::DestroyInternal); \ |
| 399 call.Marshal(RTC_FROM_HERE, destructor_thread()); \ | 399 call.Marshal(RTC_FROM_HERE, destructor_thread()); \ |
| 400 } \ | 400 } \ |
| 401 \ | 401 \ |
| 402 private: \ | 402 private: \ |
| 403 void DestroyInternal() { c_ = nullptr; } \ | 403 void DestroyInternal() { c_ = nullptr; } \ |
| 404 rtc::scoped_refptr<INTERNAL_CLASS> c_; | 404 rtc::scoped_refptr<INTERNAL_CLASS> c_; |
| 405 | 405 |
| 406 // Note: This doesn't use a unique_ptr, because it intends to handle a corner |
| 407 // case where an object's deletion triggers a callback that calls back into |
| 408 // this proxy object. If relying on a unique_ptr to delete the object, its |
| 409 // inner pointer would be set to null before this reentrant callback would have |
| 410 // a chance to run, resulting in a segfault. |
| 406 #define OWNED_PROXY_MAP_BOILERPLATE(c) \ | 411 #define OWNED_PROXY_MAP_BOILERPLATE(c) \ |
| 407 public: \ | 412 public: \ |
| 408 ~c##ProxyWithInternal() { \ | 413 ~c##ProxyWithInternal() { \ |
| 409 MethodCall0<c##ProxyWithInternal, void> call( \ | 414 MethodCall0<c##ProxyWithInternal, void> call( \ |
| 410 this, &c##ProxyWithInternal::DestroyInternal); \ | 415 this, &c##ProxyWithInternal::DestroyInternal); \ |
| 411 call.Marshal(RTC_FROM_HERE, destructor_thread()); \ | 416 call.Marshal(RTC_FROM_HERE, destructor_thread()); \ |
| 412 } \ | 417 } \ |
| 413 \ | 418 \ |
| 414 private: \ | 419 private: \ |
| 415 void DestroyInternal() { c_.reset(nullptr); } \ | 420 void DestroyInternal() { delete c_; } \ |
| 416 std::unique_ptr<INTERNAL_CLASS> c_; | 421 INTERNAL_CLASS* c_; |
| 417 | 422 |
| 418 #define BEGIN_SIGNALING_PROXY_MAP(c) \ | 423 #define BEGIN_SIGNALING_PROXY_MAP(c) \ |
| 419 PROXY_MAP_BOILERPLATE(c) \ | 424 PROXY_MAP_BOILERPLATE(c) \ |
| 420 SIGNALING_PROXY_MAP_BOILERPLATE(c) \ | 425 SIGNALING_PROXY_MAP_BOILERPLATE(c) \ |
| 421 REFCOUNTED_PROXY_MAP_BOILERPLATE(c) \ | 426 REFCOUNTED_PROXY_MAP_BOILERPLATE(c) \ |
| 422 public: \ | 427 public: \ |
| 423 static rtc::scoped_refptr<c##ProxyWithInternal> Create( \ | 428 static rtc::scoped_refptr<c##ProxyWithInternal> Create( \ |
| 424 rtc::Thread* signaling_thread, INTERNAL_CLASS* c) { \ | 429 rtc::Thread* signaling_thread, INTERNAL_CLASS* c) { \ |
| 425 return new rtc::RefCountedObject<c##ProxyWithInternal>(signaling_thread, \ | 430 return new rtc::RefCountedObject<c##ProxyWithInternal>(signaling_thread, \ |
| 426 c); \ | 431 c); \ |
| 427 } | 432 } |
| 428 | 433 |
| 429 #define BEGIN_PROXY_MAP(c) \ | 434 #define BEGIN_PROXY_MAP(c) \ |
| 430 PROXY_MAP_BOILERPLATE(c) \ | 435 PROXY_MAP_BOILERPLATE(c) \ |
| 431 WORKER_PROXY_MAP_BOILERPLATE(c) \ | 436 WORKER_PROXY_MAP_BOILERPLATE(c) \ |
| 432 REFCOUNTED_PROXY_MAP_BOILERPLATE(c) \ | 437 REFCOUNTED_PROXY_MAP_BOILERPLATE(c) \ |
| 433 public: \ | 438 public: \ |
| 434 static rtc::scoped_refptr<c##ProxyWithInternal> Create( \ | 439 static rtc::scoped_refptr<c##ProxyWithInternal> Create( \ |
| 435 rtc::Thread* signaling_thread, rtc::Thread* worker_thread, \ | 440 rtc::Thread* signaling_thread, rtc::Thread* worker_thread, \ |
| 436 INTERNAL_CLASS* c) { \ | 441 INTERNAL_CLASS* c) { \ |
| 437 return new rtc::RefCountedObject<c##ProxyWithInternal>(signaling_thread, \ | 442 return new rtc::RefCountedObject<c##ProxyWithInternal>(signaling_thread, \ |
| 438 worker_thread, c); \ | 443 worker_thread, c); \ |
| 439 } | 444 } |
| 440 | 445 |
| 441 #define BEGIN_OWNED_PROXY_MAP(c) \ | 446 #define BEGIN_OWNED_PROXY_MAP(c) \ |
| 442 PROXY_MAP_BOILERPLATE(c) \ | 447 PROXY_MAP_BOILERPLATE(c) \ |
| 443 WORKER_PROXY_MAP_BOILERPLATE(c) \ | 448 WORKER_PROXY_MAP_BOILERPLATE(c) \ |
| 444 OWNED_PROXY_MAP_BOILERPLATE(c) \ | 449 OWNED_PROXY_MAP_BOILERPLATE(c) \ |
| 445 public: \ | 450 public: \ |
| 446 static std::unique_ptr<c##ProxyWithInternal> Create( \ | 451 static std::unique_ptr<c##Interface> Create( \ |
| 447 rtc::Thread* signaling_thread, rtc::Thread* worker_thread, \ | 452 rtc::Thread* signaling_thread, rtc::Thread* worker_thread, \ |
| 448 INTERNAL_CLASS* c) { \ | 453 std::unique_ptr<INTERNAL_CLASS> c) { \ |
| 449 return std::unique_ptr<c##ProxyWithInternal>( \ | 454 return std::unique_ptr<c##Interface>(new c##ProxyWithInternal( \ |
| 450 new c##ProxyWithInternal(signaling_thread, worker_thread, c)); \ | 455 signaling_thread, worker_thread, c.release())); \ |
| 451 } | 456 } |
| 452 | 457 |
| 453 #define PROXY_SIGNALING_THREAD_DESTRUCTOR() \ | 458 #define PROXY_SIGNALING_THREAD_DESTRUCTOR() \ |
| 454 private: \ | 459 private: \ |
| 455 rtc::Thread* destructor_thread() const { return signaling_thread_; } \ | 460 rtc::Thread* destructor_thread() const { return signaling_thread_; } \ |
| 456 \ | 461 \ |
| 457 public: // NOLINTNEXTLINE | 462 public: // NOLINTNEXTLINE |
| 458 | 463 |
| 459 #define PROXY_WORKER_THREAD_DESTRUCTOR() \ | 464 #define PROXY_WORKER_THREAD_DESTRUCTOR() \ |
| 460 private: \ | 465 private: \ |
| 461 rtc::Thread* destructor_thread() const { return worker_thread_; } \ | 466 rtc::Thread* destructor_thread() const { return worker_thread_; } \ |
| 462 \ | 467 \ |
| 463 public: // NOLINTNEXTLINE | 468 public: // NOLINTNEXTLINE |
| 464 | 469 |
| 465 #define PROXY_METHOD0(r, method) \ | 470 #define PROXY_METHOD0(r, method) \ |
| 466 r method() override { \ | 471 r method() override { \ |
| 467 MethodCall0<C, r> call(c_.get(), &C::method); \ | 472 MethodCall0<C, r> call(c_, &C::method); \ |
| 468 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ | 473 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ |
| 469 } | 474 } |
| 470 | 475 |
| 471 #define PROXY_CONSTMETHOD0(r, method) \ | 476 #define PROXY_CONSTMETHOD0(r, method) \ |
| 472 r method() const override { \ | 477 r method() const override { \ |
| 473 ConstMethodCall0<C, r> call(c_.get(), &C::method); \ | 478 ConstMethodCall0<C, r> call(c_, &C::method); \ |
| 474 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ | 479 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ |
| 475 } | 480 } |
| 476 | 481 |
| 477 #define PROXY_METHOD1(r, method, t1) \ | 482 #define PROXY_METHOD1(r, method, t1) \ |
| 478 r method(t1 a1) override { \ | 483 r method(t1 a1) override { \ |
| 479 MethodCall1<C, r, t1> call(c_.get(), &C::method, std::move(a1)); \ | 484 MethodCall1<C, r, t1> call(c_, &C::method, std::move(a1)); \ |
| 480 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ | 485 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ |
| 481 } | 486 } |
| 482 | 487 |
| 483 #define PROXY_CONSTMETHOD1(r, method, t1) \ | 488 #define PROXY_CONSTMETHOD1(r, method, t1) \ |
| 484 r method(t1 a1) const override { \ | 489 r method(t1 a1) const override { \ |
| 485 ConstMethodCall1<C, r, t1> call(c_.get(), &C::method, std::move(a1)); \ | 490 ConstMethodCall1<C, r, t1> call(c_, &C::method, std::move(a1)); \ |
| 486 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ | 491 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ |
| 487 } | 492 } |
| 488 | 493 |
| 489 #define PROXY_METHOD2(r, method, t1, t2) \ | 494 #define PROXY_METHOD2(r, method, t1, t2) \ |
| 490 r method(t1 a1, t2 a2) override { \ | 495 r method(t1 a1, t2 a2) override { \ |
| 491 MethodCall2<C, r, t1, t2> call(c_.get(), &C::method, std::move(a1), \ | 496 MethodCall2<C, r, t1, t2> call(c_, &C::method, std::move(a1), \ |
| 492 std::move(a2)); \ | 497 std::move(a2)); \ |
| 493 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ | 498 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ |
| 494 } | 499 } |
| 495 | 500 |
| 496 #define PROXY_METHOD3(r, method, t1, t2, t3) \ | 501 #define PROXY_METHOD3(r, method, t1, t2, t3) \ |
| 497 r method(t1 a1, t2 a2, t3 a3) override { \ | 502 r method(t1 a1, t2 a2, t3 a3) override { \ |
| 498 MethodCall3<C, r, t1, t2, t3> call(c_.get(), &C::method, std::move(a1), \ | 503 MethodCall3<C, r, t1, t2, t3> call(c_, &C::method, std::move(a1), \ |
| 499 std::move(a2), std::move(a3)); \ | 504 std::move(a2), std::move(a3)); \ |
| 500 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ | 505 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ |
| 501 } | 506 } |
| 502 | 507 |
| 503 #define PROXY_METHOD4(r, method, t1, t2, t3, t4) \ | 508 #define PROXY_METHOD4(r, method, t1, t2, t3, t4) \ |
| 504 r method(t1 a1, t2 a2, t3 a3, t4 a4) override { \ | 509 r method(t1 a1, t2 a2, t3 a3, t4 a4) override { \ |
| 505 MethodCall4<C, r, t1, t2, t3, t4> call(c_.get(), &C::method, \ | 510 MethodCall4<C, r, t1, t2, t3, t4> call(c_, &C::method, std::move(a1), \ |
| 506 std::move(a1), std::move(a2), \ | 511 std::move(a2), std::move(a3), \ |
| 507 std::move(a3), std::move(a4)); \ | 512 std::move(a4)); \ |
| 508 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ | 513 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ |
| 509 } | 514 } |
| 510 | 515 |
| 511 #define PROXY_METHOD5(r, method, t1, t2, t3, t4, t5) \ | 516 #define PROXY_METHOD5(r, method, t1, t2, t3, t4, t5) \ |
| 512 r method(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) override { \ | 517 r method(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) override { \ |
| 513 MethodCall5<C, r, t1, t2, t3, t4, t5> call( \ | 518 MethodCall5<C, r, t1, t2, t3, t4, t5> call(c_, &C::method, std::move(a1), \ |
| 514 c_.get(), &C::method, std::move(a1), std::move(a2), std::move(a3), \ | 519 std::move(a2), std::move(a3), \ |
| 515 std::move(a4), std::move(a5)); \ | 520 std::move(a4), std::move(a5)); \ |
| 516 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ | 521 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ |
| 517 } | 522 } |
| 518 | 523 |
| 519 // Define methods which should be invoked on the worker thread. | 524 // Define methods which should be invoked on the worker thread. |
| 520 #define PROXY_WORKER_METHOD0(r, method) \ | 525 #define PROXY_WORKER_METHOD0(r, method) \ |
| 521 r method() override { \ | 526 r method() override { \ |
| 522 MethodCall0<C, r> call(c_.get(), &C::method); \ | 527 MethodCall0<C, r> call(c_, &C::method); \ |
| 523 return call.Marshal(RTC_FROM_HERE, worker_thread_); \ | 528 return call.Marshal(RTC_FROM_HERE, worker_thread_); \ |
| 524 } | 529 } |
| 525 | 530 |
| 526 #define PROXY_WORKER_CONSTMETHOD0(r, method) \ | 531 #define PROXY_WORKER_CONSTMETHOD0(r, method) \ |
| 527 r method() const override { \ | 532 r method() const override { \ |
| 528 ConstMethodCall0<C, r> call(c_.get(), &C::method); \ | 533 ConstMethodCall0<C, r> call(c_, &C::method); \ |
| 529 return call.Marshal(RTC_FROM_HERE, worker_thread_); \ | 534 return call.Marshal(RTC_FROM_HERE, worker_thread_); \ |
| 530 } | 535 } |
| 531 | 536 |
| 532 #define PROXY_WORKER_METHOD1(r, method, t1) \ | 537 #define PROXY_WORKER_METHOD1(r, method, t1) \ |
| 533 r method(t1 a1) override { \ | 538 r method(t1 a1) override { \ |
| 534 MethodCall1<C, r, t1> call(c_.get(), &C::method, std::move(a1)); \ | 539 MethodCall1<C, r, t1> call(c_, &C::method, std::move(a1)); \ |
| 535 return call.Marshal(RTC_FROM_HERE, worker_thread_); \ | 540 return call.Marshal(RTC_FROM_HERE, worker_thread_); \ |
| 536 } | 541 } |
| 537 | 542 |
| 538 #define PROXY_WORKER_CONSTMETHOD1(r, method, t1) \ | 543 #define PROXY_WORKER_CONSTMETHOD1(r, method, t1) \ |
| 539 r method(t1 a1) const override { \ | 544 r method(t1 a1) const override { \ |
| 540 ConstMethodCall1<C, r, t1> call(c_.get(), &C::method, std::move(a1)); \ | 545 ConstMethodCall1<C, r, t1> call(c_, &C::method, std::move(a1)); \ |
| 541 return call.Marshal(RTC_FROM_HERE, worker_thread_); \ | 546 return call.Marshal(RTC_FROM_HERE, worker_thread_); \ |
| 542 } | 547 } |
| 543 | 548 |
| 544 #define PROXY_WORKER_METHOD2(r, method, t1, t2) \ | 549 #define PROXY_WORKER_METHOD2(r, method, t1, t2) \ |
| 545 r method(t1 a1, t2 a2) override { \ | 550 r method(t1 a1, t2 a2) override { \ |
| 546 MethodCall2<C, r, t1, t2> call(c_.get(), &C::method, std::move(a1), \ | 551 MethodCall2<C, r, t1, t2> call(c_, &C::method, std::move(a1), \ |
| 547 std::move(a2)); \ | 552 std::move(a2)); \ |
| 548 return call.Marshal(RTC_FROM_HERE, worker_thread_); \ | 553 return call.Marshal(RTC_FROM_HERE, worker_thread_); \ |
| 549 } | 554 } |
| 550 | 555 |
| 551 #define PROXY_WORKER_CONSTMETHOD2(r, method, t1, t2) \ | 556 #define PROXY_WORKER_CONSTMETHOD2(r, method, t1, t2) \ |
| 552 r method(t1 a1, t2 a2) const override { \ | 557 r method(t1 a1, t2 a2) const override { \ |
| 553 ConstMethodCall2<C, r, t1, t2> call(c_.get(), &C::method, std::move(a1), \ | 558 ConstMethodCall2<C, r, t1, t2> call(c_, &C::method, std::move(a1), \ |
| 554 std::move(a2)); \ | 559 std::move(a2)); \ |
| 555 return call.Marshal(RTC_FROM_HERE, worker_thread_); \ | 560 return call.Marshal(RTC_FROM_HERE, worker_thread_); \ |
| 561 } |
| 562 |
| 563 #define PROXY_WORKER_METHOD3(r, method, t1, t2, t3) \ |
| 564 r method(t1 a1, t2 a2, t3 a3) override { \ |
| 565 MethodCall3<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_); \ |
| 568 } |
| 569 |
| 570 #define PROXY_WORKER_CONSTMETHOD3(r, method, t1, t2) \ |
| 571 r method(t1 a1, t2 a2, t3 a3) const override { \ |
| 572 ConstMethodCall3<C, r, t1, t2, t3> call(c_, &C::method, std::move(a1), \ |
| 573 std::move(a2), std::move(a3)); \ |
| 574 return call.Marshal(RTC_FROM_HERE, worker_thread_); \ |
| 556 } | 575 } |
| 557 | 576 |
| 558 } // namespace webrtc | 577 } // namespace webrtc |
| 559 | 578 |
| 560 #endif // WEBRTC_API_PROXY_H_ | 579 #endif // WEBRTC_API_PROXY_H_ |
| OLD | NEW |