| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 // The variant defined with BEGIN_SIGNALING_PROXY_MAP is unaware of | 45 // The variant defined with BEGIN_SIGNALING_PROXY_MAP is unaware of |
| 46 // the worker thread, and invokes all methods on the signaling thread. | 46 // the worker thread, and invokes all methods on the signaling thread. |
| 47 // | 47 // |
| 48 // The variant defined with BEGIN_OWNED_PROXY_MAP does not use | 48 // The variant defined with BEGIN_OWNED_PROXY_MAP does not use |
| 49 // refcounting, and instead just takes ownership of the object being proxied. | 49 // refcounting, and instead just takes ownership of the object being proxied. |
| 50 | 50 |
| 51 #ifndef WEBRTC_API_PROXY_H_ | 51 #ifndef WEBRTC_API_PROXY_H_ |
| 52 #define WEBRTC_API_PROXY_H_ | 52 #define WEBRTC_API_PROXY_H_ |
| 53 | 53 |
| 54 #include <memory> | 54 #include <memory> |
| 55 #include <utility> |
| 55 | 56 |
| 56 #include "webrtc/base/event.h" | 57 #include "webrtc/base/event.h" |
| 57 #include "webrtc/base/thread.h" | 58 #include "webrtc/base/thread.h" |
| 58 | 59 |
| 59 namespace webrtc { | 60 namespace webrtc { |
| 60 | 61 |
| 61 template <typename R> | 62 template <typename R> |
| 62 class ReturnType { | 63 class ReturnType { |
| 63 public: | 64 public: |
| 64 template<typename C, typename M> | 65 template<typename C, typename M> |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 C* c_; | 343 C* c_; |
| 343 Method m_; | 344 Method m_; |
| 344 ReturnType<R> r_; | 345 ReturnType<R> r_; |
| 345 T1 a1_; | 346 T1 a1_; |
| 346 T2 a2_; | 347 T2 a2_; |
| 347 T3 a3_; | 348 T3 a3_; |
| 348 T4 a4_; | 349 T4 a4_; |
| 349 T5 a5_; | 350 T5 a5_; |
| 350 }; | 351 }; |
| 351 | 352 |
| 353 |
| 352 // Helper macros to reduce code duplication. | 354 // Helper macros to reduce code duplication. |
| 353 #define PROXY_MAP_BOILERPLATE(c) \ | 355 #define PROXY_MAP_BOILERPLATE(c) \ |
| 354 template <class INTERNAL_CLASS> \ | 356 template <class INTERNAL_CLASS> \ |
| 355 class c##ProxyWithInternal; \ | 357 class c##ProxyWithInternal; \ |
| 356 typedef c##ProxyWithInternal<c##Interface> c##Proxy; \ | 358 typedef c##ProxyWithInternal<c##Interface> c##Proxy; \ |
| 357 template <class INTERNAL_CLASS> \ | 359 template <class INTERNAL_CLASS> \ |
| 358 class c##ProxyWithInternal : public c##Interface { \ | 360 class c##ProxyWithInternal : public c##Interface { \ |
| 359 protected: \ | 361 protected: \ |
| 360 typedef c##Interface C; \ | 362 typedef c##Interface C; \ |
| 361 \ | 363 \ |
| 362 public: \ | 364 public: \ |
| 363 const INTERNAL_CLASS* internal() const { return c_.get(); } \ | 365 const INTERNAL_CLASS* internal() const { return c_.get(); } \ |
| 364 INTERNAL_CLASS* internal() { return c_.get(); } | 366 INTERNAL_CLASS* internal() { return c_.get(); } |
| 365 | 367 |
| 368 #define END_PROXY_MAP() \ |
| 369 }; |
| 370 |
| 366 #define SIGNALING_PROXY_MAP_BOILERPLATE(c) \ | 371 #define SIGNALING_PROXY_MAP_BOILERPLATE(c) \ |
| 367 protected: \ | 372 protected: \ |
| 368 c##ProxyWithInternal(rtc::Thread* signaling_thread, INTERNAL_CLASS* c) \ | 373 c##ProxyWithInternal(rtc::Thread* signaling_thread, INTERNAL_CLASS* c) \ |
| 369 : signaling_thread_(signaling_thread), c_(c) {} \ | 374 : signaling_thread_(signaling_thread), c_(c) {} \ |
| 370 \ | 375 \ |
| 371 private: \ | 376 private: \ |
| 372 mutable rtc::Thread* signaling_thread_; | 377 mutable rtc::Thread* signaling_thread_; |
| 373 | 378 |
| 374 #define WORKER_PROXY_MAP_BOILERPLATE(c) \ | 379 #define WORKER_PROXY_MAP_BOILERPLATE(c) \ |
| 375 protected: \ | 380 protected: \ |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 rtc::Thread* signaling_thread, rtc::Thread* worker_thread, \ | 446 rtc::Thread* signaling_thread, rtc::Thread* worker_thread, \ |
| 442 INTERNAL_CLASS* c) { \ | 447 INTERNAL_CLASS* c) { \ |
| 443 return std::unique_ptr<c##ProxyWithInternal>( \ | 448 return std::unique_ptr<c##ProxyWithInternal>( \ |
| 444 new c##ProxyWithInternal(signaling_thread, worker_thread, c)); \ | 449 new c##ProxyWithInternal(signaling_thread, worker_thread, c)); \ |
| 445 } | 450 } |
| 446 | 451 |
| 447 #define PROXY_SIGNALING_THREAD_DESTRUCTOR() \ | 452 #define PROXY_SIGNALING_THREAD_DESTRUCTOR() \ |
| 448 private: \ | 453 private: \ |
| 449 rtc::Thread* destructor_thread() const { return signaling_thread_; } \ | 454 rtc::Thread* destructor_thread() const { return signaling_thread_; } \ |
| 450 \ | 455 \ |
| 451 public: | 456 public: // NOLINTNEXTLINE |
| 452 | 457 |
| 453 #define PROXY_WORKER_THREAD_DESTRUCTOR() \ | 458 #define PROXY_WORKER_THREAD_DESTRUCTOR() \ |
| 454 private: \ | 459 private: \ |
| 455 rtc::Thread* destructor_thread() const { return worker_thread_; } \ | 460 rtc::Thread* destructor_thread() const { return worker_thread_; } \ |
| 456 \ | 461 \ |
| 457 public: | 462 public: // NOLINTNEXTLINE |
| 458 | 463 |
| 459 #define PROXY_METHOD0(r, method) \ | 464 #define PROXY_METHOD0(r, method) \ |
| 460 r method() override { \ | 465 r method() override { \ |
| 461 MethodCall0<C, r> call(c_.get(), &C::method); \ | 466 MethodCall0<C, r> call(c_.get(), &C::method); \ |
| 462 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ | 467 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ |
| 463 } | 468 } |
| 464 | 469 |
| 465 #define PROXY_CONSTMETHOD0(r, method) \ | 470 #define PROXY_CONSTMETHOD0(r, method) \ |
| 466 r method() const override { \ | 471 r method() const override { \ |
| 467 ConstMethodCall0<C, r> call(c_.get(), &C::method); \ | 472 ConstMethodCall0<C, r> call(c_.get(), &C::method); \ |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 return call.Marshal(RTC_FROM_HERE, worker_thread_); \ | 547 return call.Marshal(RTC_FROM_HERE, worker_thread_); \ |
| 543 } | 548 } |
| 544 | 549 |
| 545 #define PROXY_WORKER_CONSTMETHOD2(r, method, t1, t2) \ | 550 #define PROXY_WORKER_CONSTMETHOD2(r, method, t1, t2) \ |
| 546 r method(t1 a1, t2 a2) const override { \ | 551 r method(t1 a1, t2 a2) const override { \ |
| 547 ConstMethodCall2<C, r, t1, t2> call(c_.get(), &C::method, std::move(a1), \ | 552 ConstMethodCall2<C, r, t1, t2> call(c_.get(), &C::method, std::move(a1), \ |
| 548 std::move(a2)); \ | 553 std::move(a2)); \ |
| 549 return call.Marshal(RTC_FROM_HERE, worker_thread_); \ | 554 return call.Marshal(RTC_FROM_HERE, worker_thread_); \ |
| 550 } | 555 } |
| 551 | 556 |
| 552 #define END_PROXY_MAP() \ | |
| 553 } \ | |
| 554 ; | |
| 555 | |
| 556 } // namespace webrtc | 557 } // namespace webrtc |
| 557 | 558 |
| 558 #endif // WEBRTC_API_PROXY_H_ | 559 #endif // WEBRTC_API_PROXY_H_ |
| OLD | NEW |