| 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 |
| 11 // This file contains Macros for creating proxies for webrtc MediaStream and | 11 // This file contains Macros for creating proxies for webrtc MediaStream and |
| 12 // PeerConnection classes. | 12 // PeerConnection classes. |
| 13 | 13 |
| 14 // | 14 // |
| 15 // Example usage: | 15 // Example usage: |
| 16 // | 16 // |
| 17 // class TestInterface : public rtc::RefCountInterface { | 17 // class TestInterface : public rtc::RefCountInterface { |
| 18 // public: | 18 // public: |
| 19 // std::string FooA() = 0; | 19 // std::string FooA() = 0; |
| 20 // std::string FooB(bool arg1) const = 0; | 20 // std::string FooB(bool arg1) const = 0; |
| 21 // std::string FooC(bool arg1)= 0; | 21 // std::string FooC(bool arg1) = 0; |
| 22 // }; | 22 // }; |
| 23 // | 23 // |
| 24 // Note that return types can not be a const reference. | 24 // Note that return types can not be a const reference. |
| 25 // | 25 // |
| 26 // class Test : public TestInterface { | 26 // class Test : public TestInterface { |
| 27 // ... implementation of the interface. | 27 // ... implementation of the interface. |
| 28 // }; | 28 // }; |
| 29 // | 29 // |
| 30 // BEGIN_PROXY_MAP(Test) | 30 // BEGIN_PROXY_MAP(Test) |
| 31 // PROXY_METHOD0(std::string, FooA) | 31 // PROXY_METHOD0(std::string, FooA) |
| 32 // PROXY_CONSTMETHOD1(std::string, FooB, arg1) | 32 // PROXY_CONSTMETHOD1(std::string, FooB, arg1) |
| 33 // PROXY_METHOD1(std::string, FooC, arg1) | 33 // PROXY_WORKER_METHOD1(std::string, FooC, arg1) |
| 34 // END_PROXY() | 34 // END_PROXY() |
| 35 // | 35 // |
| 36 // The proxy can be created using TestProxy::Create(Thread*, TestInterface*). | 36 // 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. |
| 37 | 46 |
| 38 #ifndef WEBRTC_API_PROXY_H_ | 47 #ifndef WEBRTC_API_PROXY_H_ |
| 39 #define WEBRTC_API_PROXY_H_ | 48 #define WEBRTC_API_PROXY_H_ |
| 40 | 49 |
| 41 #include "webrtc/base/event.h" | 50 #include "webrtc/base/event.h" |
| 42 #include "webrtc/base/thread.h" | 51 #include "webrtc/base/thread.h" |
| 43 | 52 |
| 44 namespace webrtc { | 53 namespace webrtc { |
| 45 | 54 |
| 46 template <typename R> | 55 template <typename R> |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 C* c_; | 297 C* c_; |
| 289 Method m_; | 298 Method m_; |
| 290 ReturnType<R> r_; | 299 ReturnType<R> r_; |
| 291 T1 a1_; | 300 T1 a1_; |
| 292 T2 a2_; | 301 T2 a2_; |
| 293 T3 a3_; | 302 T3 a3_; |
| 294 T4 a4_; | 303 T4 a4_; |
| 295 T5 a5_; | 304 T5 a5_; |
| 296 }; | 305 }; |
| 297 | 306 |
| 298 // TODO(nisse): Rename this to {BEGIN|END}_SIGNALLING_PROXY_MAP, and | 307 #define BEGIN_SIGNALING_PROXY_MAP(c) \ |
| 299 // the below to {BEGIN|END}_PROXY_MAP. Also rename the class to | |
| 300 // c##SignallingProxy. | |
| 301 #define BEGIN_PROXY_MAP(c) \ | |
| 302 class c##Proxy : public c##Interface { \ | 308 class c##Proxy : public c##Interface { \ |
| 303 protected: \ | 309 protected: \ |
| 304 typedef c##Interface C; \ | 310 typedef c##Interface C; \ |
| 305 c##Proxy(rtc::Thread* signaling_thread, C* c) \ | 311 c##Proxy(rtc::Thread* signaling_thread, C* c) \ |
| 306 : signaling_thread_(signaling_thread), c_(c) {} \ | 312 : signaling_thread_(signaling_thread), c_(c) {} \ |
| 307 ~c##Proxy() { \ | 313 ~c##Proxy() { \ |
| 308 MethodCall0<c##Proxy, void> call(this, &c##Proxy::Release_s); \ | 314 MethodCall0<c##Proxy, void> call( \ |
| 315 this, &c##Proxy::Release_s); \ |
| 309 call.Marshal(signaling_thread_); \ | 316 call.Marshal(signaling_thread_); \ |
| 310 } \ | 317 } \ |
| 311 \ | 318 \ |
| 312 public: \ | 319 public: \ |
| 313 static rtc::scoped_refptr<C> Create(rtc::Thread* signaling_thread, C* c) { \ | 320 static rtc::scoped_refptr<C> Create(rtc::Thread* signaling_thread, C* c) { \ |
| 314 return new rtc::RefCountedObject<c##Proxy>(signaling_thread, c); \ | 321 return new rtc::RefCountedObject<c##Proxy>( \ |
| 322 signaling_thread, c); \ |
| 315 } | 323 } |
| 316 | 324 |
| 317 #define BEGIN_WORKER_PROXY_MAP(c) \ | 325 #define BEGIN_PROXY_MAP(c) \ |
| 318 class c##Proxy : public c##Interface { \ | 326 class c##Proxy : public c##Interface { \ |
| 319 protected: \ | 327 protected: \ |
| 320 typedef c##Interface C; \ | 328 typedef c##Interface C; \ |
| 321 c##Proxy(rtc::Thread* signaling_thread, rtc::Thread* worker_thread, C* c) \ | 329 c##Proxy(rtc::Thread* signaling_thread, rtc::Thread* worker_thread, C* c) \ |
| 322 : signaling_thread_(signaling_thread), \ | 330 : signaling_thread_(signaling_thread), \ |
| 323 worker_thread_(worker_thread), \ | 331 worker_thread_(worker_thread), \ |
| 324 c_(c) {} \ | 332 c_(c) {} \ |
| 325 ~c##Proxy() { \ | 333 ~c##Proxy() { \ |
| 326 MethodCall0<c##Proxy, void> call(this, &c##Proxy::Release_s); \ | 334 MethodCall0<c##Proxy, void> call(this, &c##Proxy::Release_s); \ |
| 327 call.Marshal(signaling_thread_); \ | 335 call.Marshal(signaling_thread_); \ |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 MethodCall1<C, r, t1> call(c_.get(), &C::method, a1); \ | 398 MethodCall1<C, r, t1> call(c_.get(), &C::method, a1); \ |
| 391 return call.Marshal(worker_thread_); \ | 399 return call.Marshal(worker_thread_); \ |
| 392 } | 400 } |
| 393 | 401 |
| 394 #define PROXY_WORKER_METHOD2(r, method, t1, t2) \ | 402 #define PROXY_WORKER_METHOD2(r, method, t1, t2) \ |
| 395 r method(t1 a1, t2 a2) override { \ | 403 r method(t1 a1, t2 a2) override { \ |
| 396 MethodCall2<C, r, t1, t2> call(c_.get(), &C::method, a1, a2); \ | 404 MethodCall2<C, r, t1, t2> call(c_.get(), &C::method, a1, a2); \ |
| 397 return call.Marshal(worker_thread_); \ | 405 return call.Marshal(worker_thread_); \ |
| 398 } | 406 } |
| 399 | 407 |
| 400 #define END_PROXY() \ | 408 #define END_SIGNALING_PROXY() \ |
| 401 private:\ | 409 private:\ |
| 402 void Release_s() {\ | 410 void Release_s() {\ |
| 403 c_ = NULL;\ | 411 c_ = NULL;\ |
| 404 }\ | 412 }\ |
| 405 mutable rtc::Thread* signaling_thread_;\ | 413 mutable rtc::Thread* signaling_thread_;\ |
| 406 rtc::scoped_refptr<C> c_;\ | 414 rtc::scoped_refptr<C> c_;\ |
| 407 };\ | 415 }; |
| 408 | 416 |
| 409 #define END_WORKER_PROXY() \ | 417 #define END_PROXY() \ |
| 410 private: \ | 418 private: \ |
| 411 void Release_s() { \ | 419 void Release_s() { \ |
| 412 c_ = NULL; \ | 420 c_ = NULL; \ |
| 413 } \ | 421 } \ |
| 414 mutable rtc::Thread* signaling_thread_; \ | 422 mutable rtc::Thread* signaling_thread_; \ |
| 415 mutable rtc::Thread* worker_thread_; \ | 423 mutable rtc::Thread* worker_thread_; \ |
| 416 rtc::scoped_refptr<C> c_; \ | 424 rtc::scoped_refptr<C> c_; \ |
| 417 }; \ | 425 }; \ |
| 418 | 426 |
| 419 } // namespace webrtc | 427 } // namespace webrtc |
| 420 | 428 |
| 421 #endif // WEBRTC_API_PROXY_H_ | 429 #endif // WEBRTC_API_PROXY_H_ |
| OLD | NEW |