henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2013 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | // This file contains Macros for creating proxies for webrtc MediaStream and |
| 12 | // PeerConnection classes. |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [diff] [blame] | 13 | // TODO(deadbeef): Move this to pc/; this is part of the implementation. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 14 | |
| 15 | // |
| 16 | // Example usage: |
| 17 | // |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 18 | // class TestInterface : public rtc::RefCountInterface { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 19 | // public: |
| 20 | // std::string FooA() = 0; |
| 21 | // std::string FooB(bool arg1) const = 0; |
nisse | 72c8d2b | 2016-04-15 03:49:07 -0700 | [diff] [blame] | 22 | // std::string FooC(bool arg1) = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 23 | // }; |
| 24 | // |
| 25 | // Note that return types can not be a const reference. |
| 26 | // |
| 27 | // class Test : public TestInterface { |
| 28 | // ... implementation of the interface. |
| 29 | // }; |
| 30 | // |
| 31 | // BEGIN_PROXY_MAP(Test) |
deadbeef | d99a200 | 2017-01-18 08:55:23 -0800 | [diff] [blame] | 32 | // PROXY_SIGNALING_THREAD_DESTRUCTOR() |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 33 | // PROXY_METHOD0(std::string, FooA) |
| 34 | // PROXY_CONSTMETHOD1(std::string, FooB, arg1) |
nisse | 72c8d2b | 2016-04-15 03:49:07 -0700 | [diff] [blame] | 35 | // PROXY_WORKER_METHOD1(std::string, FooC, arg1) |
deadbeef | d99a200 | 2017-01-18 08:55:23 -0800 | [diff] [blame] | 36 | // END_PROXY_MAP() |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 37 | // |
deadbeef | d99a200 | 2017-01-18 08:55:23 -0800 | [diff] [blame] | 38 | // Where the destructor and first two methods are invoked on the signaling |
| 39 | // thread, and the third is invoked on the worker thread. |
nisse | 72c8d2b | 2016-04-15 03:49:07 -0700 | [diff] [blame] | 40 | // |
| 41 | // The proxy can be created using |
| 42 | // |
| 43 | // TestProxy::Create(Thread* signaling_thread, Thread* worker_thread, |
| 44 | // TestInterface*). |
| 45 | // |
| 46 | // The variant defined with BEGIN_SIGNALING_PROXY_MAP is unaware of |
| 47 | // the worker thread, and invokes all methods on the signaling thread. |
deadbeef | d99a200 | 2017-01-18 08:55:23 -0800 | [diff] [blame] | 48 | // |
| 49 | // The variant defined with BEGIN_OWNED_PROXY_MAP does not use |
| 50 | // refcounting, and instead just takes ownership of the object being proxied. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 51 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 52 | #ifndef API_PROXY_H_ |
| 53 | #define API_PROXY_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 54 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 55 | #include <memory> |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 56 | #include <string> |
Steve Anton | c363982 | 2019-11-26 15:27:50 -0800 | [diff] [blame] | 57 | #include <tuple> |
oprypin | 803dc29 | 2017-02-01 01:55:59 -0800 | [diff] [blame] | 58 | #include <utility> |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 59 | |
Mirko Bonadei | d970807 | 2019-01-25 20:26:48 +0100 | [diff] [blame] | 60 | #include "api/scoped_refptr.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 61 | #include "rtc_base/event.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 62 | #include "rtc_base/message_handler.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 63 | #include "rtc_base/ref_counted_object.h" |
Mirko Bonadei | 35214fc | 2019-09-23 14:54:28 +0200 | [diff] [blame] | 64 | #include "rtc_base/system/rtc_export.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 65 | #include "rtc_base/thread.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 66 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 67 | namespace rtc { |
| 68 | class Location; |
| 69 | } |
| 70 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 71 | namespace webrtc { |
| 72 | |
Guido Urdaneta | ccab06f | 2020-01-15 11:30:29 +0000 | [diff] [blame] | 73 | template <typename R> |
| 74 | class ReturnType { |
| 75 | public: |
| 76 | template <typename C, typename M, typename... Args> |
| 77 | void Invoke(C* c, M m, Args&&... args) { |
| 78 | r_ = (c->*m)(std::forward<Args>(args)...); |
| 79 | } |
| 80 | |
| 81 | R moved_result() { return std::move(r_); } |
| 82 | |
| 83 | private: |
| 84 | R r_; |
| 85 | }; |
| 86 | |
| 87 | template <> |
| 88 | class ReturnType<void> { |
| 89 | public: |
| 90 | template <typename C, typename M, typename... Args> |
| 91 | void Invoke(C* c, M m, Args&&... args) { |
| 92 | (c->*m)(std::forward<Args>(args)...); |
| 93 | } |
| 94 | |
| 95 | void moved_result() {} |
| 96 | }; |
| 97 | |
| 98 | namespace internal { |
| 99 | |
| 100 | class RTC_EXPORT SynchronousMethodCall : public rtc::MessageData, |
| 101 | public rtc::MessageHandler { |
| 102 | public: |
| 103 | explicit SynchronousMethodCall(rtc::MessageHandler* proxy); |
| 104 | ~SynchronousMethodCall() override; |
| 105 | |
| 106 | void Invoke(const rtc::Location& posted_from, rtc::Thread* t); |
| 107 | |
| 108 | private: |
| 109 | void OnMessage(rtc::Message*) override; |
| 110 | |
| 111 | rtc::Event e_; |
| 112 | rtc::MessageHandler* proxy_; |
| 113 | }; |
| 114 | |
| 115 | } // namespace internal |
| 116 | |
| 117 | template <typename C, typename R, typename... Args> |
| 118 | class MethodCall : public rtc::Message, public rtc::MessageHandler { |
| 119 | public: |
| 120 | typedef R (C::*Method)(Args...); |
| 121 | MethodCall(C* c, Method m, Args&&... args) |
| 122 | : c_(c), |
| 123 | m_(m), |
| 124 | args_(std::forward_as_tuple(std::forward<Args>(args)...)) {} |
| 125 | |
| 126 | R Marshal(const rtc::Location& posted_from, rtc::Thread* t) { |
| 127 | internal::SynchronousMethodCall(this).Invoke(posted_from, t); |
| 128 | return r_.moved_result(); |
| 129 | } |
| 130 | |
| 131 | private: |
| 132 | void OnMessage(rtc::Message*) { Invoke(std::index_sequence_for<Args...>()); } |
| 133 | |
| 134 | template <size_t... Is> |
| 135 | void Invoke(std::index_sequence<Is...>) { |
| 136 | r_.Invoke(c_, m_, std::move(std::get<Is>(args_))...); |
| 137 | } |
| 138 | |
| 139 | C* c_; |
| 140 | Method m_; |
| 141 | ReturnType<R> r_; |
| 142 | std::tuple<Args&&...> args_; |
| 143 | }; |
| 144 | |
| 145 | template <typename C, typename R, typename... Args> |
| 146 | class ConstMethodCall : public rtc::Message, public rtc::MessageHandler { |
| 147 | public: |
| 148 | typedef R (C::*Method)(Args...) const; |
| 149 | ConstMethodCall(const C* c, Method m, Args&&... args) |
| 150 | : c_(c), |
| 151 | m_(m), |
| 152 | args_(std::forward_as_tuple(std::forward<Args>(args)...)) {} |
| 153 | |
| 154 | R Marshal(const rtc::Location& posted_from, rtc::Thread* t) { |
| 155 | internal::SynchronousMethodCall(this).Invoke(posted_from, t); |
| 156 | return r_.moved_result(); |
| 157 | } |
| 158 | |
| 159 | private: |
| 160 | void OnMessage(rtc::Message*) { Invoke(std::index_sequence_for<Args...>()); } |
| 161 | |
| 162 | template <size_t... Is> |
| 163 | void Invoke(std::index_sequence<Is...>) { |
| 164 | r_.Invoke(c_, m_, std::move(std::get<Is>(args_))...); |
| 165 | } |
| 166 | |
| 167 | const C* c_; |
| 168 | Method m_; |
| 169 | ReturnType<R> r_; |
| 170 | std::tuple<Args&&...> args_; |
| 171 | }; |
| 172 | |
deadbeef | d99a200 | 2017-01-18 08:55:23 -0800 | [diff] [blame] | 173 | // Helper macros to reduce code duplication. |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 174 | #define PROXY_MAP_BOILERPLATE(c) \ |
| 175 | template <class INTERNAL_CLASS> \ |
| 176 | class c##ProxyWithInternal; \ |
| 177 | typedef c##ProxyWithInternal<c##Interface> c##Proxy; \ |
| 178 | template <class INTERNAL_CLASS> \ |
| 179 | class c##ProxyWithInternal : public c##Interface { \ |
| 180 | protected: \ |
| 181 | typedef c##Interface C; \ |
| 182 | \ |
| 183 | public: \ |
| 184 | const INTERNAL_CLASS* internal() const { return c_; } \ |
| 185 | INTERNAL_CLASS* internal() { return c_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 186 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 187 | // clang-format off |
| 188 | // clang-format would put the semicolon alone, |
| 189 | // leading to a presubmit error (cpplint.py) |
oprypin | 803dc29 | 2017-02-01 01:55:59 -0800 | [diff] [blame] | 190 | #define END_PROXY_MAP() \ |
| 191 | }; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 192 | // clang-format on |
oprypin | 803dc29 | 2017-02-01 01:55:59 -0800 | [diff] [blame] | 193 | |
deadbeef | d99a200 | 2017-01-18 08:55:23 -0800 | [diff] [blame] | 194 | #define SIGNALING_PROXY_MAP_BOILERPLATE(c) \ |
| 195 | protected: \ |
| 196 | c##ProxyWithInternal(rtc::Thread* signaling_thread, INTERNAL_CLASS* c) \ |
| 197 | : signaling_thread_(signaling_thread), c_(c) {} \ |
| 198 | \ |
| 199 | private: \ |
| 200 | mutable rtc::Thread* signaling_thread_; |
| 201 | |
| 202 | #define WORKER_PROXY_MAP_BOILERPLATE(c) \ |
| 203 | protected: \ |
| 204 | c##ProxyWithInternal(rtc::Thread* signaling_thread, \ |
| 205 | rtc::Thread* worker_thread, INTERNAL_CLASS* c) \ |
| 206 | : signaling_thread_(signaling_thread), \ |
| 207 | worker_thread_(worker_thread), \ |
| 208 | c_(c) {} \ |
| 209 | \ |
| 210 | private: \ |
| 211 | mutable rtc::Thread* signaling_thread_; \ |
| 212 | mutable rtc::Thread* worker_thread_; |
| 213 | |
| 214 | // Note that the destructor is protected so that the proxy can only be |
| 215 | // destroyed via RefCountInterface. |
Guido Urdaneta | ccab06f | 2020-01-15 11:30:29 +0000 | [diff] [blame] | 216 | #define REFCOUNTED_PROXY_MAP_BOILERPLATE(c) \ |
| 217 | protected: \ |
| 218 | ~c##ProxyWithInternal() { \ |
| 219 | MethodCall<c##ProxyWithInternal, void> call( \ |
| 220 | this, &c##ProxyWithInternal::DestroyInternal); \ |
| 221 | call.Marshal(RTC_FROM_HERE, destructor_thread()); \ |
| 222 | } \ |
| 223 | \ |
| 224 | private: \ |
| 225 | void DestroyInternal() { c_ = nullptr; } \ |
deadbeef | d99a200 | 2017-01-18 08:55:23 -0800 | [diff] [blame] | 226 | rtc::scoped_refptr<INTERNAL_CLASS> c_; |
| 227 | |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 228 | // Note: This doesn't use a unique_ptr, because it intends to handle a corner |
| 229 | // case where an object's deletion triggers a callback that calls back into |
| 230 | // this proxy object. If relying on a unique_ptr to delete the object, its |
| 231 | // inner pointer would be set to null before this reentrant callback would have |
| 232 | // a chance to run, resulting in a segfault. |
Guido Urdaneta | ccab06f | 2020-01-15 11:30:29 +0000 | [diff] [blame] | 233 | #define OWNED_PROXY_MAP_BOILERPLATE(c) \ |
| 234 | public: \ |
| 235 | ~c##ProxyWithInternal() { \ |
| 236 | MethodCall<c##ProxyWithInternal, void> call( \ |
| 237 | this, &c##ProxyWithInternal::DestroyInternal); \ |
| 238 | call.Marshal(RTC_FROM_HERE, destructor_thread()); \ |
| 239 | } \ |
| 240 | \ |
| 241 | private: \ |
| 242 | void DestroyInternal() { delete c_; } \ |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 243 | INTERNAL_CLASS* c_; |
deadbeef | d99a200 | 2017-01-18 08:55:23 -0800 | [diff] [blame] | 244 | |
| 245 | #define BEGIN_SIGNALING_PROXY_MAP(c) \ |
| 246 | PROXY_MAP_BOILERPLATE(c) \ |
| 247 | SIGNALING_PROXY_MAP_BOILERPLATE(c) \ |
| 248 | REFCOUNTED_PROXY_MAP_BOILERPLATE(c) \ |
| 249 | public: \ |
| 250 | static rtc::scoped_refptr<c##ProxyWithInternal> Create( \ |
| 251 | rtc::Thread* signaling_thread, INTERNAL_CLASS* c) { \ |
| 252 | return new rtc::RefCountedObject<c##ProxyWithInternal>(signaling_thread, \ |
| 253 | c); \ |
| 254 | } |
| 255 | |
| 256 | #define BEGIN_PROXY_MAP(c) \ |
| 257 | PROXY_MAP_BOILERPLATE(c) \ |
| 258 | WORKER_PROXY_MAP_BOILERPLATE(c) \ |
| 259 | REFCOUNTED_PROXY_MAP_BOILERPLATE(c) \ |
| 260 | public: \ |
| 261 | static rtc::scoped_refptr<c##ProxyWithInternal> Create( \ |
| 262 | rtc::Thread* signaling_thread, rtc::Thread* worker_thread, \ |
| 263 | INTERNAL_CLASS* c) { \ |
| 264 | return new rtc::RefCountedObject<c##ProxyWithInternal>(signaling_thread, \ |
| 265 | worker_thread, c); \ |
| 266 | } |
| 267 | |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 268 | #define BEGIN_OWNED_PROXY_MAP(c) \ |
| 269 | PROXY_MAP_BOILERPLATE(c) \ |
| 270 | WORKER_PROXY_MAP_BOILERPLATE(c) \ |
| 271 | OWNED_PROXY_MAP_BOILERPLATE(c) \ |
| 272 | public: \ |
| 273 | static std::unique_ptr<c##Interface> Create( \ |
| 274 | rtc::Thread* signaling_thread, rtc::Thread* worker_thread, \ |
| 275 | std::unique_ptr<INTERNAL_CLASS> c) { \ |
| 276 | return std::unique_ptr<c##Interface>(new c##ProxyWithInternal( \ |
| 277 | signaling_thread, worker_thread, c.release())); \ |
deadbeef | d99a200 | 2017-01-18 08:55:23 -0800 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | #define PROXY_SIGNALING_THREAD_DESTRUCTOR() \ |
| 281 | private: \ |
| 282 | rtc::Thread* destructor_thread() const { return signaling_thread_; } \ |
| 283 | \ |
oprypin | 803dc29 | 2017-02-01 01:55:59 -0800 | [diff] [blame] | 284 | public: // NOLINTNEXTLINE |
deadbeef | d99a200 | 2017-01-18 08:55:23 -0800 | [diff] [blame] | 285 | |
| 286 | #define PROXY_WORKER_THREAD_DESTRUCTOR() \ |
| 287 | private: \ |
| 288 | rtc::Thread* destructor_thread() const { return worker_thread_; } \ |
| 289 | \ |
oprypin | 803dc29 | 2017-02-01 01:55:59 -0800 | [diff] [blame] | 290 | public: // NOLINTNEXTLINE |
deadbeef | d99a200 | 2017-01-18 08:55:23 -0800 | [diff] [blame] | 291 | |
Guido Urdaneta | ccab06f | 2020-01-15 11:30:29 +0000 | [diff] [blame] | 292 | #define PROXY_METHOD0(r, method) \ |
| 293 | r method() override { \ |
| 294 | MethodCall<C, r> call(c_, &C::method); \ |
| 295 | return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 296 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 297 | |
Guido Urdaneta | ccab06f | 2020-01-15 11:30:29 +0000 | [diff] [blame] | 298 | #define PROXY_CONSTMETHOD0(r, method) \ |
| 299 | r method() const override { \ |
| 300 | ConstMethodCall<C, r> call(c_, &C::method); \ |
| 301 | return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 302 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 303 | |
Guido Urdaneta | ccab06f | 2020-01-15 11:30:29 +0000 | [diff] [blame] | 304 | #define PROXY_METHOD1(r, method, t1) \ |
| 305 | r method(t1 a1) override { \ |
| 306 | MethodCall<C, r, t1> call(c_, &C::method, std::move(a1)); \ |
| 307 | return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 308 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 309 | |
Guido Urdaneta | ccab06f | 2020-01-15 11:30:29 +0000 | [diff] [blame] | 310 | #define PROXY_CONSTMETHOD1(r, method, t1) \ |
| 311 | r method(t1 a1) const override { \ |
| 312 | ConstMethodCall<C, r, t1> call(c_, &C::method, std::move(a1)); \ |
| 313 | return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 314 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 315 | |
Guido Urdaneta | ccab06f | 2020-01-15 11:30:29 +0000 | [diff] [blame] | 316 | #define PROXY_METHOD2(r, method, t1, t2) \ |
| 317 | r method(t1 a1, t2 a2) override { \ |
| 318 | MethodCall<C, r, t1, t2> call(c_, &C::method, std::move(a1), \ |
| 319 | std::move(a2)); \ |
| 320 | return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 321 | } |
perkj@webrtc.org | 81134d0 | 2015-01-12 08:30:16 +0000 | [diff] [blame] | 322 | |
Guido Urdaneta | ccab06f | 2020-01-15 11:30:29 +0000 | [diff] [blame] | 323 | #define PROXY_METHOD3(r, method, t1, t2, t3) \ |
| 324 | r method(t1 a1, t2 a2, t3 a3) override { \ |
| 325 | MethodCall<C, r, t1, t2, t3> call(c_, &C::method, std::move(a1), \ |
| 326 | std::move(a2), std::move(a3)); \ |
| 327 | return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ |
deadbeef | d99a200 | 2017-01-18 08:55:23 -0800 | [diff] [blame] | 328 | } |
| 329 | |
Guido Urdaneta | ccab06f | 2020-01-15 11:30:29 +0000 | [diff] [blame] | 330 | #define PROXY_METHOD4(r, method, t1, t2, t3, t4) \ |
| 331 | r method(t1 a1, t2 a2, t3 a3, t4 a4) override { \ |
| 332 | MethodCall<C, r, t1, t2, t3, t4> call(c_, &C::method, std::move(a1), \ |
| 333 | std::move(a2), std::move(a3), \ |
| 334 | std::move(a4)); \ |
| 335 | return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ |
| 336 | } |
deadbeef | d99a200 | 2017-01-18 08:55:23 -0800 | [diff] [blame] | 337 | |
Guido Urdaneta | ccab06f | 2020-01-15 11:30:29 +0000 | [diff] [blame] | 338 | #define PROXY_METHOD5(r, method, t1, t2, t3, t4, t5) \ |
| 339 | r method(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) override { \ |
| 340 | MethodCall<C, r, t1, t2, t3, t4, t5> call(c_, &C::method, std::move(a1), \ |
| 341 | std::move(a2), std::move(a3), \ |
| 342 | std::move(a4), std::move(a5)); \ |
| 343 | return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ |
| 344 | } |
nisse | 5b68ab5 | 2016-04-07 07:45:54 -0700 | [diff] [blame] | 345 | |
| 346 | // Define methods which should be invoked on the worker thread. |
Guido Urdaneta | ccab06f | 2020-01-15 11:30:29 +0000 | [diff] [blame] | 347 | #define PROXY_WORKER_METHOD0(r, method) \ |
| 348 | r method() override { \ |
| 349 | MethodCall<C, r> call(c_, &C::method); \ |
| 350 | return call.Marshal(RTC_FROM_HERE, worker_thread_); \ |
| 351 | } |
nisse | 5b68ab5 | 2016-04-07 07:45:54 -0700 | [diff] [blame] | 352 | |
Guido Urdaneta | ccab06f | 2020-01-15 11:30:29 +0000 | [diff] [blame] | 353 | #define PROXY_WORKER_CONSTMETHOD0(r, method) \ |
| 354 | r method() const override { \ |
| 355 | ConstMethodCall<C, r> call(c_, &C::method); \ |
| 356 | return call.Marshal(RTC_FROM_HERE, worker_thread_); \ |
| 357 | } |
perkj@webrtc.org | 81134d0 | 2015-01-12 08:30:16 +0000 | [diff] [blame] | 358 | |
Guido Urdaneta | ccab06f | 2020-01-15 11:30:29 +0000 | [diff] [blame] | 359 | #define PROXY_WORKER_METHOD1(r, method, t1) \ |
| 360 | r method(t1 a1) override { \ |
| 361 | MethodCall<C, r, t1> call(c_, &C::method, std::move(a1)); \ |
| 362 | return call.Marshal(RTC_FROM_HERE, worker_thread_); \ |
| 363 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 364 | |
Guido Urdaneta | ccab06f | 2020-01-15 11:30:29 +0000 | [diff] [blame] | 365 | #define PROXY_WORKER_CONSTMETHOD1(r, method, t1) \ |
| 366 | r method(t1 a1) const override { \ |
| 367 | ConstMethodCall<C, r, t1> call(c_, &C::method, std::move(a1)); \ |
| 368 | return call.Marshal(RTC_FROM_HERE, worker_thread_); \ |
| 369 | } |
deadbeef | d99a200 | 2017-01-18 08:55:23 -0800 | [diff] [blame] | 370 | |
Guido Urdaneta | ccab06f | 2020-01-15 11:30:29 +0000 | [diff] [blame] | 371 | #define PROXY_WORKER_METHOD2(r, method, t1, t2) \ |
| 372 | r method(t1 a1, t2 a2) override { \ |
| 373 | MethodCall<C, r, t1, t2> call(c_, &C::method, std::move(a1), \ |
| 374 | std::move(a2)); \ |
| 375 | return call.Marshal(RTC_FROM_HERE, worker_thread_); \ |
| 376 | } |
deadbeef | d99a200 | 2017-01-18 08:55:23 -0800 | [diff] [blame] | 377 | |
Guido Urdaneta | ccab06f | 2020-01-15 11:30:29 +0000 | [diff] [blame] | 378 | #define PROXY_WORKER_CONSTMETHOD2(r, method, t1, t2) \ |
| 379 | r method(t1 a1, t2 a2) const override { \ |
| 380 | ConstMethodCall<C, r, t1, t2> call(c_, &C::method, std::move(a1), \ |
| 381 | std::move(a2)); \ |
| 382 | return call.Marshal(RTC_FROM_HERE, worker_thread_); \ |
| 383 | } |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 384 | |
Guido Urdaneta | ccab06f | 2020-01-15 11:30:29 +0000 | [diff] [blame] | 385 | #define PROXY_WORKER_METHOD3(r, method, t1, t2, t3) \ |
| 386 | r method(t1 a1, t2 a2, t3 a3) override { \ |
| 387 | MethodCall<C, r, t1, t2, t3> call(c_, &C::method, std::move(a1), \ |
| 388 | std::move(a2), std::move(a3)); \ |
| 389 | return call.Marshal(RTC_FROM_HERE, worker_thread_); \ |
| 390 | } |
Steve Anton | c363982 | 2019-11-26 15:27:50 -0800 | [diff] [blame] | 391 | |
Guido Urdaneta | ccab06f | 2020-01-15 11:30:29 +0000 | [diff] [blame] | 392 | #define PROXY_WORKER_CONSTMETHOD3(r, method, t1, t2) \ |
| 393 | r method(t1 a1, t2 a2, t3 a3) const override { \ |
| 394 | ConstMethodCall<C, r, t1, t2, t3> call(c_, &C::method, std::move(a1), \ |
| 395 | std::move(a2), std::move(a3)); \ |
| 396 | return call.Marshal(RTC_FROM_HERE, worker_thread_); \ |
| 397 | } |
deadbeef | d99a200 | 2017-01-18 08:55:23 -0800 | [diff] [blame] | 398 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 399 | } // namespace webrtc |
| 400 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 401 | #endif // API_PROXY_H_ |