| 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 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 C* c_; | 288 C* c_; |
| 289 Method m_; | 289 Method m_; |
| 290 ReturnType<R> r_; | 290 ReturnType<R> r_; |
| 291 T1 a1_; | 291 T1 a1_; |
| 292 T2 a2_; | 292 T2 a2_; |
| 293 T3 a3_; | 293 T3 a3_; |
| 294 T4 a4_; | 294 T4 a4_; |
| 295 T5 a5_; | 295 T5 a5_; |
| 296 }; | 296 }; |
| 297 | 297 |
| 298 // TODO(nisse): Rename this to {BEGIN|END}_SIGNALLING_PROXY_MAP, and |
| 299 // the below to {BEGIN|END}_PROXY_MAP. Also rename the class to |
| 300 // c##SignallingProxy. |
| 298 #define BEGIN_PROXY_MAP(c) \ | 301 #define BEGIN_PROXY_MAP(c) \ |
| 299 class c##Proxy : public c##Interface { \ | 302 class c##Proxy : public c##Interface { \ |
| 300 protected: \ | 303 protected: \ |
| 301 typedef c##Interface C; \ | 304 typedef c##Interface C; \ |
| 302 c##Proxy(rtc::Thread* thread, C* c) : owner_thread_(thread), c_(c) {} \ | 305 c##Proxy(rtc::Thread* signaling_thread, C* c) \ |
| 306 : signaling_thread_(signaling_thread), c_(c) {} \ |
| 303 ~c##Proxy() { \ | 307 ~c##Proxy() { \ |
| 304 MethodCall0<c##Proxy, void> call(this, &c##Proxy::Release_s); \ | 308 MethodCall0<c##Proxy, void> call(this, &c##Proxy::Release_s); \ |
| 305 call.Marshal(owner_thread_); \ | 309 call.Marshal(signaling_thread_); \ |
| 306 } \ | 310 } \ |
| 307 \ | 311 \ |
| 308 public: \ | 312 public: \ |
| 309 static rtc::scoped_refptr<C> Create(rtc::Thread* thread, C* c) { \ | 313 static rtc::scoped_refptr<C> Create(rtc::Thread* signaling_thread, C* c) { \ |
| 310 return new rtc::RefCountedObject<c##Proxy>(thread, c); \ | 314 return new rtc::RefCountedObject<c##Proxy>(signaling_thread, c); \ |
| 315 } |
| 316 |
| 317 #define BEGIN_WORKER_PROXY_MAP(c) \ |
| 318 class c##Proxy : public c##Interface { \ |
| 319 protected: \ |
| 320 typedef c##Interface C; \ |
| 321 c##Proxy(rtc::Thread* signaling_thread, rtc::Thread* worker_thread, C* c) \ |
| 322 : signaling_thread_(signaling_thread), \ |
| 323 worker_thread_(worker_thread), \ |
| 324 c_(c) {} \ |
| 325 ~c##Proxy() { \ |
| 326 MethodCall0<c##Proxy, void> call(this, &c##Proxy::Release_s); \ |
| 327 call.Marshal(signaling_thread_); \ |
| 328 } \ |
| 329 \ |
| 330 public: \ |
| 331 static rtc::scoped_refptr<C> Create( \ |
| 332 rtc::Thread* signaling_thread, rtc::Thread* worker_thread, C* c) { \ |
| 333 return new rtc::RefCountedObject<c##Proxy>( \ |
| 334 signaling_thread, worker_thread, c); \ |
| 311 } | 335 } |
| 312 | 336 |
| 313 #define PROXY_METHOD0(r, method) \ | 337 #define PROXY_METHOD0(r, method) \ |
| 314 r method() override { \ | 338 r method() override { \ |
| 315 MethodCall0<C, r> call(c_.get(), &C::method); \ | 339 MethodCall0<C, r> call(c_.get(), &C::method); \ |
| 316 return call.Marshal(owner_thread_); \ | 340 return call.Marshal(signaling_thread_); \ |
| 317 } | 341 } |
| 318 | 342 |
| 319 #define PROXY_CONSTMETHOD0(r, method) \ | 343 #define PROXY_CONSTMETHOD0(r, method) \ |
| 320 r method() const override { \ | 344 r method() const override { \ |
| 321 ConstMethodCall0<C, r> call(c_.get(), &C::method); \ | 345 ConstMethodCall0<C, r> call(c_.get(), &C::method); \ |
| 322 return call.Marshal(owner_thread_); \ | 346 return call.Marshal(signaling_thread_); \ |
| 323 } | 347 } |
| 324 | 348 |
| 325 #define PROXY_METHOD1(r, method, t1) \ | 349 #define PROXY_METHOD1(r, method, t1) \ |
| 326 r method(t1 a1) override { \ | 350 r method(t1 a1) override { \ |
| 327 MethodCall1<C, r, t1> call(c_.get(), &C::method, a1); \ | 351 MethodCall1<C, r, t1> call(c_.get(), &C::method, a1); \ |
| 328 return call.Marshal(owner_thread_); \ | 352 return call.Marshal(signaling_thread_); \ |
| 329 } | 353 } |
| 330 | 354 |
| 331 #define PROXY_CONSTMETHOD1(r, method, t1) \ | 355 #define PROXY_CONSTMETHOD1(r, method, t1) \ |
| 332 r method(t1 a1) const override { \ | 356 r method(t1 a1) const override { \ |
| 333 ConstMethodCall1<C, r, t1> call(c_.get(), &C::method, a1); \ | 357 ConstMethodCall1<C, r, t1> call(c_.get(), &C::method, a1); \ |
| 334 return call.Marshal(owner_thread_); \ | 358 return call.Marshal(signaling_thread_); \ |
| 335 } | 359 } |
| 336 | 360 |
| 337 #define PROXY_METHOD2(r, method, t1, t2) \ | 361 #define PROXY_METHOD2(r, method, t1, t2) \ |
| 338 r method(t1 a1, t2 a2) override { \ | 362 r method(t1 a1, t2 a2) override { \ |
| 339 MethodCall2<C, r, t1, t2> call(c_.get(), &C::method, a1, a2); \ | 363 MethodCall2<C, r, t1, t2> call(c_.get(), &C::method, a1, a2); \ |
| 340 return call.Marshal(owner_thread_); \ | 364 return call.Marshal(signaling_thread_); \ |
| 341 } | 365 } |
| 342 | 366 |
| 343 #define PROXY_METHOD3(r, method, t1, t2, t3) \ | 367 #define PROXY_METHOD3(r, method, t1, t2, t3) \ |
| 344 r method(t1 a1, t2 a2, t3 a3) override { \ | 368 r method(t1 a1, t2 a2, t3 a3) override { \ |
| 345 MethodCall3<C, r, t1, t2, t3> call(c_.get(), &C::method, a1, a2, a3); \ | 369 MethodCall3<C, r, t1, t2, t3> call(c_.get(), &C::method, a1, a2, a3); \ |
| 346 return call.Marshal(owner_thread_); \ | 370 return call.Marshal(signaling_thread_); \ |
| 347 } | 371 } |
| 348 | 372 |
| 349 #define PROXY_METHOD4(r, method, t1, t2, t3, t4) \ | 373 #define PROXY_METHOD4(r, method, t1, t2, t3, t4) \ |
| 350 r method(t1 a1, t2 a2, t3 a3, t4 a4) override { \ | 374 r method(t1 a1, t2 a2, t3 a3, t4 a4) override { \ |
| 351 MethodCall4<C, r, t1, t2, t3, t4> call(c_.get(), &C::method, a1, a2, a3, \ | 375 MethodCall4<C, r, t1, t2, t3, t4> call(c_.get(), &C::method, a1, a2, a3, \ |
| 352 a4); \ | 376 a4); \ |
| 353 return call.Marshal(owner_thread_); \ | 377 return call.Marshal(signaling_thread_); \ |
| 354 } | 378 } |
| 355 | 379 |
| 356 #define PROXY_METHOD5(r, method, t1, t2, t3, t4, t5) \ | 380 #define PROXY_METHOD5(r, method, t1, t2, t3, t4, t5) \ |
| 357 r method(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) override { \ | 381 r method(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) override { \ |
| 358 MethodCall5<C, r, t1, t2, t3, t4, t5> call(c_.get(), &C::method, a1, a2, \ | 382 MethodCall5<C, r, t1, t2, t3, t4, t5> call(c_.get(), &C::method, a1, a2, \ |
| 359 a3, a4, a5); \ | 383 a3, a4, a5); \ |
| 360 return call.Marshal(owner_thread_); \ | 384 return call.Marshal(signaling_thread_); \ |
| 385 } |
| 386 |
| 387 // Define methods which should be invoked on the worker thread. |
| 388 #define PROXY_WORKER_METHOD1(r, method, t1) \ |
| 389 r method(t1 a1) override { \ |
| 390 MethodCall1<C, r, t1> call(c_.get(), &C::method, a1); \ |
| 391 return call.Marshal(worker_thread_); \ |
| 392 } |
| 393 |
| 394 #define PROXY_WORKER_METHOD2(r, method, t1, t2) \ |
| 395 r method(t1 a1, t2 a2) override { \ |
| 396 MethodCall2<C, r, t1, t2> call(c_.get(), &C::method, a1, a2); \ |
| 397 return call.Marshal(worker_thread_); \ |
| 361 } | 398 } |
| 362 | 399 |
| 363 #define END_PROXY() \ | 400 #define END_PROXY() \ |
| 364 private:\ | 401 private:\ |
| 365 void Release_s() {\ | 402 void Release_s() {\ |
| 366 c_ = NULL;\ | 403 c_ = NULL;\ |
| 367 }\ | 404 }\ |
| 368 mutable rtc::Thread* owner_thread_;\ | 405 mutable rtc::Thread* signaling_thread_;\ |
| 369 rtc::scoped_refptr<C> c_;\ | 406 rtc::scoped_refptr<C> c_;\ |
| 370 };\ | 407 };\ |
| 371 | 408 |
| 409 #define END_WORKER_PROXY() \ |
| 410 private: \ |
| 411 void Release_s() { \ |
| 412 c_ = NULL; \ |
| 413 } \ |
| 414 mutable rtc::Thread* signaling_thread_; \ |
| 415 mutable rtc::Thread* worker_thread_; \ |
| 416 rtc::scoped_refptr<C> c_; \ |
| 417 }; \ |
| 418 |
| 372 } // namespace webrtc | 419 } // namespace webrtc |
| 373 | 420 |
| 374 #endif // WEBRTC_API_PROXY_H_ | 421 #endif // WEBRTC_API_PROXY_H_ |
| OLD | NEW |