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. |
| 13 | |
| 14 | // |
| 15 | // Example usage: |
| 16 | // |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 17 | // class TestInterface : public rtc::RefCountInterface { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 18 | // public: |
| 19 | // std::string FooA() = 0; |
| 20 | // std::string FooB(bool arg1) const = 0; |
| 21 | // std::string FooC(bool arg1)= 0; |
| 22 | // }; |
| 23 | // |
| 24 | // Note that return types can not be a const reference. |
| 25 | // |
| 26 | // class Test : public TestInterface { |
| 27 | // ... implementation of the interface. |
| 28 | // }; |
| 29 | // |
| 30 | // BEGIN_PROXY_MAP(Test) |
| 31 | // PROXY_METHOD0(std::string, FooA) |
| 32 | // PROXY_CONSTMETHOD1(std::string, FooB, arg1) |
| 33 | // PROXY_METHOD1(std::string, FooC, arg1) |
| 34 | // END_PROXY() |
| 35 | // |
| 36 | // The proxy can be created using TestProxy::Create(Thread*, TestInterface*). |
| 37 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 38 | #ifndef WEBRTC_API_PROXY_H_ |
| 39 | #define WEBRTC_API_PROXY_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 40 | |
tommi@webrtc.org | 18de6f9 | 2014-11-04 12:08:48 +0000 | [diff] [blame] | 41 | #include "webrtc/base/event.h" |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 42 | #include "webrtc/base/thread.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 43 | |
| 44 | namespace webrtc { |
| 45 | |
| 46 | template <typename R> |
| 47 | class ReturnType { |
| 48 | public: |
| 49 | template<typename C, typename M> |
| 50 | void Invoke(C* c, M m) { r_ = (c->*m)(); } |
| 51 | template<typename C, typename M, typename T1> |
| 52 | void Invoke(C* c, M m, T1 a1) { r_ = (c->*m)(a1); } |
| 53 | template<typename C, typename M, typename T1, typename T2> |
| 54 | void Invoke(C* c, M m, T1 a1, T2 a2) { r_ = (c->*m)(a1, a2); } |
| 55 | template<typename C, typename M, typename T1, typename T2, typename T3> |
| 56 | void Invoke(C* c, M m, T1 a1, T2 a2, T3 a3) { r_ = (c->*m)(a1, a2, a3); } |
perkj@webrtc.org | 81134d0 | 2015-01-12 08:30:16 +0000 | [diff] [blame] | 57 | template<typename C, typename M, typename T1, typename T2, typename T3, |
| 58 | typename T4> |
| 59 | void Invoke(C* c, M m, T1 a1, T2 a2, T3 a3, T4 a4) { |
| 60 | r_ = (c->*m)(a1, a2, a3, a4); |
| 61 | } |
| 62 | template<typename C, typename M, typename T1, typename T2, typename T3, |
| 63 | typename T4, typename T5> |
| 64 | void Invoke(C* c, M m, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) { |
| 65 | r_ = (c->*m)(a1, a2, a3, a4, a5); |
| 66 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 67 | |
| 68 | R value() { return r_; } |
| 69 | |
| 70 | private: |
| 71 | R r_; |
| 72 | }; |
| 73 | |
| 74 | template <> |
| 75 | class ReturnType<void> { |
| 76 | public: |
| 77 | template<typename C, typename M> |
| 78 | void Invoke(C* c, M m) { (c->*m)(); } |
| 79 | template<typename C, typename M, typename T1> |
| 80 | void Invoke(C* c, M m, T1 a1) { (c->*m)(a1); } |
| 81 | template<typename C, typename M, typename T1, typename T2> |
| 82 | void Invoke(C* c, M m, T1 a1, T2 a2) { (c->*m)(a1, a2); } |
| 83 | template<typename C, typename M, typename T1, typename T2, typename T3> |
| 84 | void Invoke(C* c, M m, T1 a1, T2 a2, T3 a3) { (c->*m)(a1, a2, a3); } |
| 85 | |
| 86 | void value() {} |
| 87 | }; |
| 88 | |
tommi@webrtc.org | 18de6f9 | 2014-11-04 12:08:48 +0000 | [diff] [blame] | 89 | namespace internal { |
| 90 | |
| 91 | class SynchronousMethodCall |
| 92 | : public rtc::MessageData, |
| 93 | public rtc::MessageHandler { |
| 94 | public: |
perkj@webrtc.org | 81134d0 | 2015-01-12 08:30:16 +0000 | [diff] [blame] | 95 | explicit SynchronousMethodCall(rtc::MessageHandler* proxy) |
tommi@webrtc.org | 18de6f9 | 2014-11-04 12:08:48 +0000 | [diff] [blame] | 96 | : e_(), proxy_(proxy) {} |
| 97 | ~SynchronousMethodCall() {} |
| 98 | |
| 99 | void Invoke(rtc::Thread* t) { |
| 100 | if (t->IsCurrent()) { |
| 101 | proxy_->OnMessage(NULL); |
| 102 | } else { |
| 103 | e_.reset(new rtc::Event(false, false)); |
| 104 | t->Post(this, 0); |
andresp@webrtc.org | 53d9012 | 2015-02-09 14:19:09 +0000 | [diff] [blame] | 105 | e_->Wait(rtc::Event::kForever); |
tommi@webrtc.org | 18de6f9 | 2014-11-04 12:08:48 +0000 | [diff] [blame] | 106 | } |
| 107 | } |
| 108 | |
| 109 | private: |
| 110 | void OnMessage(rtc::Message*) { proxy_->OnMessage(NULL); e_->Set(); } |
| 111 | rtc::scoped_ptr<rtc::Event> e_; |
| 112 | rtc::MessageHandler* proxy_; |
| 113 | }; |
| 114 | |
perkj@webrtc.org | 81134d0 | 2015-01-12 08:30:16 +0000 | [diff] [blame] | 115 | } // namespace internal |
tommi@webrtc.org | 18de6f9 | 2014-11-04 12:08:48 +0000 | [diff] [blame] | 116 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 117 | template <typename C, typename R> |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 118 | class MethodCall0 : public rtc::Message, |
| 119 | public rtc::MessageHandler { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 120 | public: |
| 121 | typedef R (C::*Method)(); |
| 122 | MethodCall0(C* c, Method m) : c_(c), m_(m) {} |
| 123 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 124 | R Marshal(rtc::Thread* t) { |
tommi@webrtc.org | 18de6f9 | 2014-11-04 12:08:48 +0000 | [diff] [blame] | 125 | internal::SynchronousMethodCall(this).Invoke(t); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 126 | return r_.value(); |
| 127 | } |
| 128 | |
| 129 | private: |
tommi@webrtc.org | 18de6f9 | 2014-11-04 12:08:48 +0000 | [diff] [blame] | 130 | void OnMessage(rtc::Message*) { r_.Invoke(c_, m_); } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 131 | |
| 132 | C* c_; |
| 133 | Method m_; |
| 134 | ReturnType<R> r_; |
| 135 | }; |
| 136 | |
| 137 | template <typename C, typename R> |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 138 | class ConstMethodCall0 : public rtc::Message, |
| 139 | public rtc::MessageHandler { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 140 | public: |
| 141 | typedef R (C::*Method)() const; |
| 142 | ConstMethodCall0(C* c, Method m) : c_(c), m_(m) {} |
| 143 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 144 | R Marshal(rtc::Thread* t) { |
tommi@webrtc.org | 18de6f9 | 2014-11-04 12:08:48 +0000 | [diff] [blame] | 145 | internal::SynchronousMethodCall(this).Invoke(t); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 146 | return r_.value(); |
| 147 | } |
| 148 | |
| 149 | private: |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 150 | void OnMessage(rtc::Message*) { r_.Invoke(c_, m_); } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 151 | |
| 152 | C* c_; |
| 153 | Method m_; |
| 154 | ReturnType<R> r_; |
| 155 | }; |
| 156 | |
| 157 | template <typename C, typename R, typename T1> |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 158 | class MethodCall1 : public rtc::Message, |
| 159 | public rtc::MessageHandler { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 160 | public: |
| 161 | typedef R (C::*Method)(T1 a1); |
| 162 | MethodCall1(C* c, Method m, T1 a1) : c_(c), m_(m), a1_(a1) {} |
| 163 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 164 | R Marshal(rtc::Thread* t) { |
tommi@webrtc.org | 18de6f9 | 2014-11-04 12:08:48 +0000 | [diff] [blame] | 165 | internal::SynchronousMethodCall(this).Invoke(t); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 166 | return r_.value(); |
| 167 | } |
| 168 | |
| 169 | private: |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 170 | void OnMessage(rtc::Message*) { r_.Invoke(c_, m_, a1_); } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 171 | |
| 172 | C* c_; |
| 173 | Method m_; |
| 174 | ReturnType<R> r_; |
| 175 | T1 a1_; |
| 176 | }; |
| 177 | |
| 178 | template <typename C, typename R, typename T1> |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 179 | class ConstMethodCall1 : public rtc::Message, |
| 180 | public rtc::MessageHandler { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 181 | public: |
| 182 | typedef R (C::*Method)(T1 a1) const; |
| 183 | ConstMethodCall1(C* c, Method m, T1 a1) : c_(c), m_(m), a1_(a1) {} |
| 184 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 185 | R Marshal(rtc::Thread* t) { |
tommi@webrtc.org | 18de6f9 | 2014-11-04 12:08:48 +0000 | [diff] [blame] | 186 | internal::SynchronousMethodCall(this).Invoke(t); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 187 | return r_.value(); |
| 188 | } |
| 189 | |
| 190 | private: |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 191 | void OnMessage(rtc::Message*) { r_.Invoke(c_, m_, a1_); } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 192 | |
| 193 | C* c_; |
| 194 | Method m_; |
| 195 | ReturnType<R> r_; |
| 196 | T1 a1_; |
| 197 | }; |
| 198 | |
| 199 | template <typename C, typename R, typename T1, typename T2> |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 200 | class MethodCall2 : public rtc::Message, |
| 201 | public rtc::MessageHandler { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 202 | public: |
| 203 | typedef R (C::*Method)(T1 a1, T2 a2); |
| 204 | MethodCall2(C* c, Method m, T1 a1, T2 a2) : c_(c), m_(m), a1_(a1), a2_(a2) {} |
| 205 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 206 | R Marshal(rtc::Thread* t) { |
tommi@webrtc.org | 18de6f9 | 2014-11-04 12:08:48 +0000 | [diff] [blame] | 207 | internal::SynchronousMethodCall(this).Invoke(t); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 208 | return r_.value(); |
| 209 | } |
| 210 | |
| 211 | private: |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 212 | void OnMessage(rtc::Message*) { r_.Invoke(c_, m_, a1_, a2_); } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 213 | |
| 214 | C* c_; |
| 215 | Method m_; |
| 216 | ReturnType<R> r_; |
| 217 | T1 a1_; |
| 218 | T2 a2_; |
| 219 | }; |
| 220 | |
| 221 | template <typename C, typename R, typename T1, typename T2, typename T3> |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 222 | class MethodCall3 : public rtc::Message, |
| 223 | public rtc::MessageHandler { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 224 | public: |
| 225 | typedef R (C::*Method)(T1 a1, T2 a2, T3 a3); |
| 226 | MethodCall3(C* c, Method m, T1 a1, T2 a2, T3 a3) |
| 227 | : c_(c), m_(m), a1_(a1), a2_(a2), a3_(a3) {} |
| 228 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 229 | R Marshal(rtc::Thread* t) { |
tommi@webrtc.org | 18de6f9 | 2014-11-04 12:08:48 +0000 | [diff] [blame] | 230 | internal::SynchronousMethodCall(this).Invoke(t); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 231 | return r_.value(); |
| 232 | } |
| 233 | |
| 234 | private: |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 235 | void OnMessage(rtc::Message*) { r_.Invoke(c_, m_, a1_, a2_, a3_); } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 236 | |
| 237 | C* c_; |
| 238 | Method m_; |
| 239 | ReturnType<R> r_; |
| 240 | T1 a1_; |
| 241 | T2 a2_; |
| 242 | T3 a3_; |
| 243 | }; |
| 244 | |
perkj@webrtc.org | 81134d0 | 2015-01-12 08:30:16 +0000 | [diff] [blame] | 245 | template <typename C, typename R, typename T1, typename T2, typename T3, |
| 246 | typename T4> |
| 247 | class MethodCall4 : public rtc::Message, |
| 248 | public rtc::MessageHandler { |
| 249 | public: |
| 250 | typedef R (C::*Method)(T1 a1, T2 a2, T3 a3, T4 a4); |
| 251 | MethodCall4(C* c, Method m, T1 a1, T2 a2, T3 a3, T4 a4) |
| 252 | : c_(c), m_(m), a1_(a1), a2_(a2), a3_(a3), a4_(a4) {} |
| 253 | |
| 254 | R Marshal(rtc::Thread* t) { |
| 255 | internal::SynchronousMethodCall(this).Invoke(t); |
| 256 | return r_.value(); |
| 257 | } |
| 258 | |
| 259 | private: |
| 260 | void OnMessage(rtc::Message*) { r_.Invoke(c_, m_, a1_, a2_, a3_, a4_); } |
| 261 | |
| 262 | C* c_; |
| 263 | Method m_; |
| 264 | ReturnType<R> r_; |
| 265 | T1 a1_; |
| 266 | T2 a2_; |
| 267 | T3 a3_; |
| 268 | T4 a4_; |
| 269 | }; |
| 270 | |
| 271 | template <typename C, typename R, typename T1, typename T2, typename T3, |
| 272 | typename T4, typename T5> |
| 273 | class MethodCall5 : public rtc::Message, |
| 274 | public rtc::MessageHandler { |
| 275 | public: |
| 276 | typedef R (C::*Method)(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5); |
| 277 | MethodCall5(C* c, Method m, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) |
| 278 | : c_(c), m_(m), a1_(a1), a2_(a2), a3_(a3), a4_(a4), a5_(a5) {} |
| 279 | |
| 280 | R Marshal(rtc::Thread* t) { |
| 281 | internal::SynchronousMethodCall(this).Invoke(t); |
| 282 | return r_.value(); |
| 283 | } |
| 284 | |
| 285 | private: |
| 286 | void OnMessage(rtc::Message*) { r_.Invoke(c_, m_, a1_, a2_, a3_, a4_, a5_); } |
| 287 | |
| 288 | C* c_; |
| 289 | Method m_; |
| 290 | ReturnType<R> r_; |
| 291 | T1 a1_; |
| 292 | T2 a2_; |
| 293 | T3 a3_; |
| 294 | T4 a4_; |
| 295 | T5 a5_; |
| 296 | }; |
| 297 | |
nisse | 5b68ab5 | 2016-04-07 07:45:54 -0700 | [diff] [blame^] | 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. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 301 | #define BEGIN_PROXY_MAP(c) \ |
| 302 | class c##Proxy : public c##Interface { \ |
| 303 | protected: \ |
| 304 | typedef c##Interface C; \ |
nisse | 5b68ab5 | 2016-04-07 07:45:54 -0700 | [diff] [blame^] | 305 | c##Proxy(rtc::Thread* signaling_thread, C* c) \ |
| 306 | : signaling_thread_(signaling_thread), c_(c) {} \ |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 307 | ~c##Proxy() { \ |
| 308 | MethodCall0<c##Proxy, void> call(this, &c##Proxy::Release_s); \ |
nisse | 5b68ab5 | 2016-04-07 07:45:54 -0700 | [diff] [blame^] | 309 | call.Marshal(signaling_thread_); \ |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 310 | } \ |
| 311 | \ |
| 312 | public: \ |
nisse | 5b68ab5 | 2016-04-07 07:45:54 -0700 | [diff] [blame^] | 313 | static rtc::scoped_refptr<C> Create(rtc::Thread* signaling_thread, C* 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); \ |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 335 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 336 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 337 | #define PROXY_METHOD0(r, method) \ |
| 338 | r method() override { \ |
| 339 | MethodCall0<C, r> call(c_.get(), &C::method); \ |
nisse | 5b68ab5 | 2016-04-07 07:45:54 -0700 | [diff] [blame^] | 340 | return call.Marshal(signaling_thread_); \ |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 341 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 342 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 343 | #define PROXY_CONSTMETHOD0(r, method) \ |
| 344 | r method() const override { \ |
| 345 | ConstMethodCall0<C, r> call(c_.get(), &C::method); \ |
nisse | 5b68ab5 | 2016-04-07 07:45:54 -0700 | [diff] [blame^] | 346 | return call.Marshal(signaling_thread_); \ |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 347 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 348 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 349 | #define PROXY_METHOD1(r, method, t1) \ |
| 350 | r method(t1 a1) override { \ |
| 351 | MethodCall1<C, r, t1> call(c_.get(), &C::method, a1); \ |
nisse | 5b68ab5 | 2016-04-07 07:45:54 -0700 | [diff] [blame^] | 352 | return call.Marshal(signaling_thread_); \ |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 353 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 354 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 355 | #define PROXY_CONSTMETHOD1(r, method, t1) \ |
| 356 | r method(t1 a1) const override { \ |
| 357 | ConstMethodCall1<C, r, t1> call(c_.get(), &C::method, a1); \ |
nisse | 5b68ab5 | 2016-04-07 07:45:54 -0700 | [diff] [blame^] | 358 | return call.Marshal(signaling_thread_); \ |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 359 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 360 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 361 | #define PROXY_METHOD2(r, method, t1, t2) \ |
| 362 | r method(t1 a1, t2 a2) override { \ |
| 363 | MethodCall2<C, r, t1, t2> call(c_.get(), &C::method, a1, a2); \ |
nisse | 5b68ab5 | 2016-04-07 07:45:54 -0700 | [diff] [blame^] | 364 | return call.Marshal(signaling_thread_); \ |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 365 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 366 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 367 | #define PROXY_METHOD3(r, method, t1, t2, t3) \ |
| 368 | r method(t1 a1, t2 a2, t3 a3) override { \ |
| 369 | MethodCall3<C, r, t1, t2, t3> call(c_.get(), &C::method, a1, a2, a3); \ |
nisse | 5b68ab5 | 2016-04-07 07:45:54 -0700 | [diff] [blame^] | 370 | return call.Marshal(signaling_thread_); \ |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 371 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 372 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 373 | #define PROXY_METHOD4(r, method, t1, t2, t3, t4) \ |
| 374 | r method(t1 a1, t2 a2, t3 a3, t4 a4) override { \ |
| 375 | MethodCall4<C, r, t1, t2, t3, t4> call(c_.get(), &C::method, a1, a2, a3, \ |
| 376 | a4); \ |
nisse | 5b68ab5 | 2016-04-07 07:45:54 -0700 | [diff] [blame^] | 377 | return call.Marshal(signaling_thread_); \ |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 378 | } |
perkj@webrtc.org | 81134d0 | 2015-01-12 08:30:16 +0000 | [diff] [blame] | 379 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 380 | #define PROXY_METHOD5(r, method, t1, t2, t3, t4, t5) \ |
| 381 | r method(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) override { \ |
| 382 | MethodCall5<C, r, t1, t2, t3, t4, t5> call(c_.get(), &C::method, a1, a2, \ |
| 383 | a3, a4, a5); \ |
nisse | 5b68ab5 | 2016-04-07 07:45:54 -0700 | [diff] [blame^] | 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_); \ |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 398 | } |
perkj@webrtc.org | 81134d0 | 2015-01-12 08:30:16 +0000 | [diff] [blame] | 399 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 400 | #define END_PROXY() \ |
| 401 | private:\ |
| 402 | void Release_s() {\ |
| 403 | c_ = NULL;\ |
| 404 | }\ |
nisse | 5b68ab5 | 2016-04-07 07:45:54 -0700 | [diff] [blame^] | 405 | mutable rtc::Thread* signaling_thread_;\ |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 406 | rtc::scoped_refptr<C> c_;\ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 407 | };\ |
| 408 | |
nisse | 5b68ab5 | 2016-04-07 07:45:54 -0700 | [diff] [blame^] | 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 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 419 | } // namespace webrtc |
| 420 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 421 | #endif // WEBRTC_API_PROXY_H_ |