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