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