OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2013 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 // std::string FooC(bool arg1) = 0; | 21 // std::string FooC(bool arg1) = 0; |
22 // }; | 22 // }; |
23 // | 23 // |
24 // Note that return types can not be a const reference. | 24 // Note that return types can not be a const reference. |
25 // | 25 // |
26 // class Test : public TestInterface { | 26 // class Test : public TestInterface { |
27 // ... implementation of the interface. | 27 // ... implementation of the interface. |
28 // }; | 28 // }; |
29 // | 29 // |
30 // BEGIN_PROXY_MAP(Test) | 30 // BEGIN_PROXY_MAP(Test) |
| 31 // PROXY_SIGNALING_THREAD_DESTRUCTOR() |
31 // PROXY_METHOD0(std::string, FooA) | 32 // PROXY_METHOD0(std::string, FooA) |
32 // PROXY_CONSTMETHOD1(std::string, FooB, arg1) | 33 // PROXY_CONSTMETHOD1(std::string, FooB, arg1) |
33 // PROXY_WORKER_METHOD1(std::string, FooC, arg1) | 34 // PROXY_WORKER_METHOD1(std::string, FooC, arg1) |
34 // END_PROXY() | 35 // END_PROXY_MAP() |
35 // | 36 // |
36 // where the first two methods are invoked on the signaling thread, | 37 // Where the destructor and first two methods are invoked on the signaling |
37 // and the third is invoked on the worker thread. | 38 // thread, and the third is invoked on the worker thread. |
38 // | 39 // |
39 // The proxy can be created using | 40 // The proxy can be created using |
40 // | 41 // |
41 // TestProxy::Create(Thread* signaling_thread, Thread* worker_thread, | 42 // TestProxy::Create(Thread* signaling_thread, Thread* worker_thread, |
42 // TestInterface*). | 43 // TestInterface*). |
43 // | 44 // |
44 // The variant defined with BEGIN_SIGNALING_PROXY_MAP is unaware of | 45 // The variant defined with BEGIN_SIGNALING_PROXY_MAP is unaware of |
45 // the worker thread, and invokes all methods on the signaling thread. | 46 // the worker thread, and invokes all methods on the signaling thread. |
| 47 // |
| 48 // The variant defined with BEGIN_OWNED_PROXY_MAP does not use |
| 49 // refcounting, and instead just takes ownership of the object being proxied. |
46 | 50 |
47 #ifndef WEBRTC_API_PROXY_H_ | 51 #ifndef WEBRTC_API_PROXY_H_ |
48 #define WEBRTC_API_PROXY_H_ | 52 #define WEBRTC_API_PROXY_H_ |
49 | 53 |
50 #include <memory> | 54 #include <memory> |
51 | 55 |
52 #include "webrtc/base/event.h" | 56 #include "webrtc/base/event.h" |
53 #include "webrtc/base/thread.h" | 57 #include "webrtc/base/thread.h" |
54 | 58 |
55 namespace webrtc { | 59 namespace webrtc { |
56 | 60 |
57 template <typename R> | 61 template <typename R> |
58 class ReturnType { | 62 class ReturnType { |
59 public: | 63 public: |
60 template<typename C, typename M> | 64 template<typename C, typename M> |
61 void Invoke(C* c, M m) { r_ = (c->*m)(); } | 65 void Invoke(C* c, M m) { r_ = (c->*m)(); } |
62 template<typename C, typename M, typename T1> | 66 template <typename C, typename M, typename T1> |
63 void Invoke(C* c, M m, T1 a1) { r_ = (c->*m)(a1); } | 67 void Invoke(C* c, M m, T1 a1) { |
64 template<typename C, typename M, typename T1, typename T2> | 68 r_ = (c->*m)(std::move(a1)); |
65 void Invoke(C* c, M m, T1 a1, T2 a2) { r_ = (c->*m)(a1, a2); } | 69 } |
66 template<typename C, typename M, typename T1, typename T2, typename T3> | 70 template <typename C, typename M, typename T1, typename T2> |
67 void Invoke(C* c, M m, T1 a1, T2 a2, T3 a3) { r_ = (c->*m)(a1, a2, a3); } | 71 void Invoke(C* c, M m, T1 a1, T2 a2) { |
| 72 r_ = (c->*m)(std::move(a1), std::move(a2)); |
| 73 } |
| 74 template <typename C, typename M, typename T1, typename T2, typename T3> |
| 75 void Invoke(C* c, M m, T1 a1, T2 a2, T3 a3) { |
| 76 r_ = (c->*m)(std::move(a1), std::move(a2), std::move(a3)); |
| 77 } |
68 template<typename C, typename M, typename T1, typename T2, typename T3, | 78 template<typename C, typename M, typename T1, typename T2, typename T3, |
69 typename T4> | 79 typename T4> |
70 void Invoke(C* c, M m, T1 a1, T2 a2, T3 a3, T4 a4) { | 80 void Invoke(C* c, M m, T1 a1, T2 a2, T3 a3, T4 a4) { |
71 r_ = (c->*m)(a1, a2, a3, a4); | 81 r_ = (c->*m)(std::move(a1), std::move(a2), std::move(a3), std::move(a4)); |
72 } | 82 } |
73 template<typename C, typename M, typename T1, typename T2, typename T3, | 83 template<typename C, typename M, typename T1, typename T2, typename T3, |
74 typename T4, typename T5> | 84 typename T4, typename T5> |
75 void Invoke(C* c, M m, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) { | 85 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); | 86 r_ = (c->*m)(std::move(a1), std::move(a2), std::move(a3), std::move(a4), |
| 87 std::move(a5)); |
77 } | 88 } |
78 | 89 |
79 R value() { return r_; } | 90 R moved_result() { return std::move(r_); } |
80 | 91 |
81 private: | 92 private: |
82 R r_; | 93 R r_; |
83 }; | 94 }; |
84 | 95 |
85 template <> | 96 template <> |
86 class ReturnType<void> { | 97 class ReturnType<void> { |
87 public: | 98 public: |
88 template<typename C, typename M> | 99 template<typename C, typename M> |
89 void Invoke(C* c, M m) { (c->*m)(); } | 100 void Invoke(C* c, M m) { (c->*m)(); } |
90 template<typename C, typename M, typename T1> | 101 template <typename C, typename M, typename T1> |
91 void Invoke(C* c, M m, T1 a1) { (c->*m)(a1); } | 102 void Invoke(C* c, M m, T1 a1) { |
92 template<typename C, typename M, typename T1, typename T2> | 103 (c->*m)(std::move(a1)); |
93 void Invoke(C* c, M m, T1 a1, T2 a2) { (c->*m)(a1, a2); } | 104 } |
94 template<typename C, typename M, typename T1, typename T2, typename T3> | 105 template <typename C, typename M, typename T1, typename T2> |
95 void Invoke(C* c, M m, T1 a1, T2 a2, T3 a3) { (c->*m)(a1, a2, a3); } | 106 void Invoke(C* c, M m, T1 a1, T2 a2) { |
| 107 (c->*m)(std::move(a1), std::move(a2)); |
| 108 } |
| 109 template <typename C, typename M, typename T1, typename T2, typename T3> |
| 110 void Invoke(C* c, M m, T1 a1, T2 a2, T3 a3) { |
| 111 (c->*m)(std::move(a1), std::move(a2), std::move(a3)); |
| 112 } |
96 | 113 |
97 void value() {} | 114 void moved_result() {} |
98 }; | 115 }; |
99 | 116 |
100 namespace internal { | 117 namespace internal { |
101 | 118 |
102 class SynchronousMethodCall | 119 class SynchronousMethodCall |
103 : public rtc::MessageData, | 120 : public rtc::MessageData, |
104 public rtc::MessageHandler { | 121 public rtc::MessageHandler { |
105 public: | 122 public: |
106 explicit SynchronousMethodCall(rtc::MessageHandler* proxy) | 123 explicit SynchronousMethodCall(rtc::MessageHandler* proxy) |
107 : e_(), proxy_(proxy) {} | 124 : e_(), proxy_(proxy) {} |
(...skipping 19 matching lines...) Expand all Loading... |
127 | 144 |
128 template <typename C, typename R> | 145 template <typename C, typename R> |
129 class MethodCall0 : public rtc::Message, | 146 class MethodCall0 : public rtc::Message, |
130 public rtc::MessageHandler { | 147 public rtc::MessageHandler { |
131 public: | 148 public: |
132 typedef R (C::*Method)(); | 149 typedef R (C::*Method)(); |
133 MethodCall0(C* c, Method m) : c_(c), m_(m) {} | 150 MethodCall0(C* c, Method m) : c_(c), m_(m) {} |
134 | 151 |
135 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) { | 152 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) { |
136 internal::SynchronousMethodCall(this).Invoke(posted_from, t); | 153 internal::SynchronousMethodCall(this).Invoke(posted_from, t); |
137 return r_.value(); | 154 return r_.moved_result(); |
138 } | 155 } |
139 | 156 |
140 private: | 157 private: |
141 void OnMessage(rtc::Message*) { r_.Invoke(c_, m_); } | 158 void OnMessage(rtc::Message*) { r_.Invoke(c_, m_); } |
142 | 159 |
143 C* c_; | 160 C* c_; |
144 Method m_; | 161 Method m_; |
145 ReturnType<R> r_; | 162 ReturnType<R> r_; |
146 }; | 163 }; |
147 | 164 |
148 template <typename C, typename R> | 165 template <typename C, typename R> |
149 class ConstMethodCall0 : public rtc::Message, | 166 class ConstMethodCall0 : public rtc::Message, |
150 public rtc::MessageHandler { | 167 public rtc::MessageHandler { |
151 public: | 168 public: |
152 typedef R (C::*Method)() const; | 169 typedef R (C::*Method)() const; |
153 ConstMethodCall0(C* c, Method m) : c_(c), m_(m) {} | 170 ConstMethodCall0(C* c, Method m) : c_(c), m_(m) {} |
154 | 171 |
155 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) { | 172 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) { |
156 internal::SynchronousMethodCall(this).Invoke(posted_from, t); | 173 internal::SynchronousMethodCall(this).Invoke(posted_from, t); |
157 return r_.value(); | 174 return r_.moved_result(); |
158 } | 175 } |
159 | 176 |
160 private: | 177 private: |
161 void OnMessage(rtc::Message*) { r_.Invoke(c_, m_); } | 178 void OnMessage(rtc::Message*) { r_.Invoke(c_, m_); } |
162 | 179 |
163 C* c_; | 180 C* c_; |
164 Method m_; | 181 Method m_; |
165 ReturnType<R> r_; | 182 ReturnType<R> r_; |
166 }; | 183 }; |
167 | 184 |
168 template <typename C, typename R, typename T1> | 185 template <typename C, typename R, typename T1> |
169 class MethodCall1 : public rtc::Message, | 186 class MethodCall1 : public rtc::Message, |
170 public rtc::MessageHandler { | 187 public rtc::MessageHandler { |
171 public: | 188 public: |
172 typedef R (C::*Method)(T1 a1); | 189 typedef R (C::*Method)(T1 a1); |
173 MethodCall1(C* c, Method m, T1 a1) : c_(c), m_(m), a1_(a1) {} | 190 MethodCall1(C* c, Method m, T1 a1) : c_(c), m_(m), a1_(std::move(a1)) {} |
174 | 191 |
175 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) { | 192 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) { |
176 internal::SynchronousMethodCall(this).Invoke(posted_from, t); | 193 internal::SynchronousMethodCall(this).Invoke(posted_from, t); |
177 return r_.value(); | 194 return r_.moved_result(); |
178 } | 195 } |
179 | 196 |
180 private: | 197 private: |
181 void OnMessage(rtc::Message*) { r_.Invoke(c_, m_, a1_); } | 198 void OnMessage(rtc::Message*) { r_.Invoke(c_, m_, std::move(a1_)); } |
182 | 199 |
183 C* c_; | 200 C* c_; |
184 Method m_; | 201 Method m_; |
185 ReturnType<R> r_; | 202 ReturnType<R> r_; |
186 T1 a1_; | 203 T1 a1_; |
187 }; | 204 }; |
188 | 205 |
189 template <typename C, typename R, typename T1> | 206 template <typename C, typename R, typename T1> |
190 class ConstMethodCall1 : public rtc::Message, | 207 class ConstMethodCall1 : public rtc::Message, |
191 public rtc::MessageHandler { | 208 public rtc::MessageHandler { |
192 public: | 209 public: |
193 typedef R (C::*Method)(T1 a1) const; | 210 typedef R (C::*Method)(T1 a1) const; |
194 ConstMethodCall1(C* c, Method m, T1 a1) : c_(c), m_(m), a1_(a1) {} | 211 ConstMethodCall1(C* c, Method m, T1 a1) : c_(c), m_(m), a1_(std::move(a1)) {} |
195 | 212 |
196 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) { | 213 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) { |
197 internal::SynchronousMethodCall(this).Invoke(posted_from, t); | 214 internal::SynchronousMethodCall(this).Invoke(posted_from, t); |
198 return r_.value(); | 215 return r_.moved_result(); |
199 } | 216 } |
200 | 217 |
201 private: | 218 private: |
202 void OnMessage(rtc::Message*) { r_.Invoke(c_, m_, a1_); } | 219 void OnMessage(rtc::Message*) { r_.Invoke(c_, m_, std::move(a1_)); } |
203 | 220 |
204 C* c_; | 221 C* c_; |
205 Method m_; | 222 Method m_; |
206 ReturnType<R> r_; | 223 ReturnType<R> r_; |
207 T1 a1_; | 224 T1 a1_; |
208 }; | 225 }; |
209 | 226 |
210 template <typename C, typename R, typename T1, typename T2> | 227 template <typename C, typename R, typename T1, typename T2> |
211 class MethodCall2 : public rtc::Message, | 228 class MethodCall2 : public rtc::Message, |
212 public rtc::MessageHandler { | 229 public rtc::MessageHandler { |
213 public: | 230 public: |
214 typedef R (C::*Method)(T1 a1, T2 a2); | 231 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) {} | 232 MethodCall2(C* c, Method m, T1 a1, T2 a2) |
| 233 : c_(c), m_(m), a1_(std::move(a1)), a2_(std::move(a2)) {} |
216 | 234 |
217 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) { | 235 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) { |
218 internal::SynchronousMethodCall(this).Invoke(posted_from, t); | 236 internal::SynchronousMethodCall(this).Invoke(posted_from, t); |
219 return r_.value(); | 237 return r_.moved_result(); |
220 } | 238 } |
221 | 239 |
222 private: | 240 private: |
223 void OnMessage(rtc::Message*) { r_.Invoke(c_, m_, a1_, a2_); } | 241 void OnMessage(rtc::Message*) { |
| 242 r_.Invoke(c_, m_, std::move(a1_), std::move(a2_)); |
| 243 } |
224 | 244 |
225 C* c_; | 245 C* c_; |
226 Method m_; | 246 Method m_; |
227 ReturnType<R> r_; | 247 ReturnType<R> r_; |
228 T1 a1_; | 248 T1 a1_; |
229 T2 a2_; | 249 T2 a2_; |
230 }; | 250 }; |
231 | 251 |
232 template <typename C, typename R, typename T1, typename T2, typename T3> | 252 template <typename C, typename R, typename T1, typename T2, typename T3> |
233 class MethodCall3 : public rtc::Message, | 253 class MethodCall3 : public rtc::Message, |
234 public rtc::MessageHandler { | 254 public rtc::MessageHandler { |
235 public: | 255 public: |
236 typedef R (C::*Method)(T1 a1, T2 a2, T3 a3); | 256 typedef R (C::*Method)(T1 a1, T2 a2, T3 a3); |
237 MethodCall3(C* c, Method m, T1 a1, T2 a2, T3 a3) | 257 MethodCall3(C* c, Method m, T1 a1, T2 a2, T3 a3) |
238 : c_(c), m_(m), a1_(a1), a2_(a2), a3_(a3) {} | 258 : c_(c), |
| 259 m_(m), |
| 260 a1_(std::move(a1)), |
| 261 a2_(std::move(a2)), |
| 262 a3_(std::move(a3)) {} |
239 | 263 |
240 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) { | 264 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) { |
241 internal::SynchronousMethodCall(this).Invoke(posted_from, t); | 265 internal::SynchronousMethodCall(this).Invoke(posted_from, t); |
242 return r_.value(); | 266 return r_.moved_result(); |
243 } | 267 } |
244 | 268 |
245 private: | 269 private: |
246 void OnMessage(rtc::Message*) { r_.Invoke(c_, m_, a1_, a2_, a3_); } | 270 void OnMessage(rtc::Message*) { |
| 271 r_.Invoke(c_, m_, std::move(a1_), std::move(a2_), std::move(a3_)); |
| 272 } |
247 | 273 |
248 C* c_; | 274 C* c_; |
249 Method m_; | 275 Method m_; |
250 ReturnType<R> r_; | 276 ReturnType<R> r_; |
251 T1 a1_; | 277 T1 a1_; |
252 T2 a2_; | 278 T2 a2_; |
253 T3 a3_; | 279 T3 a3_; |
254 }; | 280 }; |
255 | 281 |
256 template <typename C, typename R, typename T1, typename T2, typename T3, | 282 template <typename C, typename R, typename T1, typename T2, typename T3, |
257 typename T4> | 283 typename T4> |
258 class MethodCall4 : public rtc::Message, | 284 class MethodCall4 : public rtc::Message, |
259 public rtc::MessageHandler { | 285 public rtc::MessageHandler { |
260 public: | 286 public: |
261 typedef R (C::*Method)(T1 a1, T2 a2, T3 a3, T4 a4); | 287 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) | 288 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) {} | 289 : c_(c), |
| 290 m_(m), |
| 291 a1_(std::move(a1)), |
| 292 a2_(std::move(a2)), |
| 293 a3_(std::move(a3)), |
| 294 a4_(std::move(a4)) {} |
264 | 295 |
265 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) { | 296 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) { |
266 internal::SynchronousMethodCall(this).Invoke(posted_from, t); | 297 internal::SynchronousMethodCall(this).Invoke(posted_from, t); |
267 return r_.value(); | 298 return r_.moved_result(); |
268 } | 299 } |
269 | 300 |
270 private: | 301 private: |
271 void OnMessage(rtc::Message*) { r_.Invoke(c_, m_, a1_, a2_, a3_, a4_); } | 302 void OnMessage(rtc::Message*) { |
| 303 r_.Invoke(c_, m_, std::move(a1_), std::move(a2_), std::move(a3_), |
| 304 std::move(a4_)); |
| 305 } |
272 | 306 |
273 C* c_; | 307 C* c_; |
274 Method m_; | 308 Method m_; |
275 ReturnType<R> r_; | 309 ReturnType<R> r_; |
276 T1 a1_; | 310 T1 a1_; |
277 T2 a2_; | 311 T2 a2_; |
278 T3 a3_; | 312 T3 a3_; |
279 T4 a4_; | 313 T4 a4_; |
280 }; | 314 }; |
281 | 315 |
282 template <typename C, typename R, typename T1, typename T2, typename T3, | 316 template <typename C, typename R, typename T1, typename T2, typename T3, |
283 typename T4, typename T5> | 317 typename T4, typename T5> |
284 class MethodCall5 : public rtc::Message, | 318 class MethodCall5 : public rtc::Message, |
285 public rtc::MessageHandler { | 319 public rtc::MessageHandler { |
286 public: | 320 public: |
287 typedef R (C::*Method)(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5); | 321 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) | 322 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) {} | 323 : c_(c), |
| 324 m_(m), |
| 325 a1_(std::move(a1)), |
| 326 a2_(std::move(a2)), |
| 327 a3_(std::move(a3)), |
| 328 a4_(std::move(a4)), |
| 329 a5_(std::move(a5)) {} |
290 | 330 |
291 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) { | 331 R Marshal(const rtc::Location& posted_from, rtc::Thread* t) { |
292 internal::SynchronousMethodCall(this).Invoke(posted_from, t); | 332 internal::SynchronousMethodCall(this).Invoke(posted_from, t); |
293 return r_.value(); | 333 return r_.moved_result(); |
294 } | 334 } |
295 | 335 |
296 private: | 336 private: |
297 void OnMessage(rtc::Message*) { r_.Invoke(c_, m_, a1_, a2_, a3_, a4_, a5_); } | 337 void OnMessage(rtc::Message*) { |
| 338 r_.Invoke(c_, m_, std::move(a1_), std::move(a2_), std::move(a3_), |
| 339 std::move(a4_), std::move(a5_)); |
| 340 } |
298 | 341 |
299 C* c_; | 342 C* c_; |
300 Method m_; | 343 Method m_; |
301 ReturnType<R> r_; | 344 ReturnType<R> r_; |
302 T1 a1_; | 345 T1 a1_; |
303 T2 a2_; | 346 T2 a2_; |
304 T3 a3_; | 347 T3 a3_; |
305 T4 a4_; | 348 T4 a4_; |
306 T5 a5_; | 349 T5 a5_; |
307 }; | 350 }; |
308 | 351 |
309 #define BEGIN_SIGNALING_PROXY_MAP(c) \ | 352 // Helper macros to reduce code duplication. |
310 template <class INTERNAL_CLASS> \ | 353 #define PROXY_MAP_BOILERPLATE(c) \ |
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); \ | |
322 call.Marshal(RTC_FROM_HERE, signaling_thread_); \ | |
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(); } | |
334 | |
335 #define BEGIN_PROXY_MAP(c) \ | |
336 template <class INTERNAL_CLASS> \ | 354 template <class INTERNAL_CLASS> \ |
337 class c##ProxyWithInternal; \ | 355 class c##ProxyWithInternal; \ |
338 typedef c##ProxyWithInternal<c##Interface> c##Proxy; \ | 356 typedef c##ProxyWithInternal<c##Interface> c##Proxy; \ |
339 template <class INTERNAL_CLASS> \ | 357 template <class INTERNAL_CLASS> \ |
340 class c##ProxyWithInternal : public c##Interface { \ | 358 class c##ProxyWithInternal : public c##Interface { \ |
341 protected: \ | 359 protected: \ |
342 typedef c##Interface C; \ | 360 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); \ | |
352 call.Marshal(RTC_FROM_HERE, signaling_thread_); \ | |
353 } \ | |
354 \ | 361 \ |
355 public: \ | 362 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(); } \ | 363 const INTERNAL_CLASS* internal() const { return c_.get(); } \ |
364 INTERNAL_CLASS* internal() { return c_.get(); } | 364 INTERNAL_CLASS* internal() { return c_.get(); } |
365 | 365 |
| 366 #define SIGNALING_PROXY_MAP_BOILERPLATE(c) \ |
| 367 protected: \ |
| 368 c##ProxyWithInternal(rtc::Thread* signaling_thread, INTERNAL_CLASS* c) \ |
| 369 : signaling_thread_(signaling_thread), c_(c) {} \ |
| 370 \ |
| 371 private: \ |
| 372 mutable rtc::Thread* signaling_thread_; |
| 373 |
| 374 #define WORKER_PROXY_MAP_BOILERPLATE(c) \ |
| 375 protected: \ |
| 376 c##ProxyWithInternal(rtc::Thread* signaling_thread, \ |
| 377 rtc::Thread* worker_thread, INTERNAL_CLASS* c) \ |
| 378 : signaling_thread_(signaling_thread), \ |
| 379 worker_thread_(worker_thread), \ |
| 380 c_(c) {} \ |
| 381 \ |
| 382 private: \ |
| 383 mutable rtc::Thread* signaling_thread_; \ |
| 384 mutable rtc::Thread* worker_thread_; |
| 385 |
| 386 // Note that the destructor is protected so that the proxy can only be |
| 387 // destroyed via RefCountInterface. |
| 388 #define REFCOUNTED_PROXY_MAP_BOILERPLATE(c) \ |
| 389 protected: \ |
| 390 ~c##ProxyWithInternal() { \ |
| 391 MethodCall0<c##ProxyWithInternal, void> call( \ |
| 392 this, &c##ProxyWithInternal::DestroyInternal); \ |
| 393 call.Marshal(RTC_FROM_HERE, destructor_thread()); \ |
| 394 } \ |
| 395 \ |
| 396 private: \ |
| 397 void DestroyInternal() { c_ = nullptr; } \ |
| 398 rtc::scoped_refptr<INTERNAL_CLASS> c_; |
| 399 |
| 400 #define OWNED_PROXY_MAP_BOILERPLATE(c) \ |
| 401 public: \ |
| 402 ~c##ProxyWithInternal() { \ |
| 403 MethodCall0<c##ProxyWithInternal, void> call( \ |
| 404 this, &c##ProxyWithInternal::DestroyInternal); \ |
| 405 call.Marshal(RTC_FROM_HERE, destructor_thread()); \ |
| 406 } \ |
| 407 \ |
| 408 private: \ |
| 409 void DestroyInternal() { c_.reset(nullptr); } \ |
| 410 std::unique_ptr<INTERNAL_CLASS> c_; |
| 411 |
| 412 #define BEGIN_SIGNALING_PROXY_MAP(c) \ |
| 413 PROXY_MAP_BOILERPLATE(c) \ |
| 414 SIGNALING_PROXY_MAP_BOILERPLATE(c) \ |
| 415 REFCOUNTED_PROXY_MAP_BOILERPLATE(c) \ |
| 416 public: \ |
| 417 static rtc::scoped_refptr<c##ProxyWithInternal> Create( \ |
| 418 rtc::Thread* signaling_thread, INTERNAL_CLASS* c) { \ |
| 419 return new rtc::RefCountedObject<c##ProxyWithInternal>(signaling_thread, \ |
| 420 c); \ |
| 421 } |
| 422 |
| 423 #define BEGIN_PROXY_MAP(c) \ |
| 424 PROXY_MAP_BOILERPLATE(c) \ |
| 425 WORKER_PROXY_MAP_BOILERPLATE(c) \ |
| 426 REFCOUNTED_PROXY_MAP_BOILERPLATE(c) \ |
| 427 public: \ |
| 428 static rtc::scoped_refptr<c##ProxyWithInternal> Create( \ |
| 429 rtc::Thread* signaling_thread, rtc::Thread* worker_thread, \ |
| 430 INTERNAL_CLASS* c) { \ |
| 431 return new rtc::RefCountedObject<c##ProxyWithInternal>(signaling_thread, \ |
| 432 worker_thread, c); \ |
| 433 } |
| 434 |
| 435 #define BEGIN_OWNED_PROXY_MAP(c) \ |
| 436 PROXY_MAP_BOILERPLATE(c) \ |
| 437 WORKER_PROXY_MAP_BOILERPLATE(c) \ |
| 438 OWNED_PROXY_MAP_BOILERPLATE(c) \ |
| 439 public: \ |
| 440 static std::unique_ptr<c##ProxyWithInternal> Create( \ |
| 441 rtc::Thread* signaling_thread, rtc::Thread* worker_thread, \ |
| 442 INTERNAL_CLASS* c) { \ |
| 443 return std::unique_ptr<c##ProxyWithInternal>( \ |
| 444 new c##ProxyWithInternal(signaling_thread, worker_thread, c)); \ |
| 445 } |
| 446 |
| 447 #define PROXY_SIGNALING_THREAD_DESTRUCTOR() \ |
| 448 private: \ |
| 449 rtc::Thread* destructor_thread() const { return signaling_thread_; } \ |
| 450 \ |
| 451 public: |
| 452 |
| 453 #define PROXY_WORKER_THREAD_DESTRUCTOR() \ |
| 454 private: \ |
| 455 rtc::Thread* destructor_thread() const { return worker_thread_; } \ |
| 456 \ |
| 457 public: |
| 458 |
366 #define PROXY_METHOD0(r, method) \ | 459 #define PROXY_METHOD0(r, method) \ |
367 r method() override { \ | 460 r method() override { \ |
368 MethodCall0<C, r> call(c_.get(), &C::method); \ | 461 MethodCall0<C, r> call(c_.get(), &C::method); \ |
369 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ | 462 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ |
370 } | 463 } |
371 | 464 |
372 #define PROXY_CONSTMETHOD0(r, method) \ | 465 #define PROXY_CONSTMETHOD0(r, method) \ |
373 r method() const override { \ | 466 r method() const override { \ |
374 ConstMethodCall0<C, r> call(c_.get(), &C::method); \ | 467 ConstMethodCall0<C, r> call(c_.get(), &C::method); \ |
375 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ | 468 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ |
376 } | 469 } |
377 | 470 |
378 #define PROXY_METHOD1(r, method, t1) \ | 471 #define PROXY_METHOD1(r, method, t1) \ |
379 r method(t1 a1) override { \ | 472 r method(t1 a1) override { \ |
380 MethodCall1<C, r, t1> call(c_.get(), &C::method, a1); \ | 473 MethodCall1<C, r, t1> call(c_.get(), &C::method, std::move(a1)); \ |
381 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ | 474 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ |
382 } | 475 } |
383 | 476 |
384 #define PROXY_CONSTMETHOD1(r, method, t1) \ | 477 #define PROXY_CONSTMETHOD1(r, method, t1) \ |
385 r method(t1 a1) const override { \ | 478 r method(t1 a1) const override { \ |
386 ConstMethodCall1<C, r, t1> call(c_.get(), &C::method, a1); \ | 479 ConstMethodCall1<C, r, t1> call(c_.get(), &C::method, std::move(a1)); \ |
387 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ | |
388 } | |
389 | |
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); \ | |
393 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ | |
394 } | |
395 | |
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); \ | |
399 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ | 480 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ |
400 } | 481 } |
401 | 482 |
402 #define PROXY_METHOD4(r, method, t1, t2, t3, t4) \ | 483 #define PROXY_METHOD2(r, method, t1, t2) \ |
403 r method(t1 a1, t2 a2, t3 a3, t4 a4) override { \ | 484 r method(t1 a1, t2 a2) override { \ |
404 MethodCall4<C, r, t1, t2, t3, t4> call(c_.get(), &C::method, a1, a2, a3, \ | 485 MethodCall2<C, r, t1, t2> call(c_.get(), &C::method, std::move(a1), \ |
405 a4); \ | 486 std::move(a2)); \ |
406 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ | 487 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ |
407 } | 488 } |
408 | 489 |
409 #define PROXY_METHOD5(r, method, t1, t2, t3, t4, t5) \ | 490 #define PROXY_METHOD3(r, method, t1, t2, t3) \ |
410 r method(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) override { \ | 491 r method(t1 a1, t2 a2, t3 a3) override { \ |
411 MethodCall5<C, r, t1, t2, t3, t4, t5> call(c_.get(), &C::method, a1, a2, \ | 492 MethodCall3<C, r, t1, t2, t3> call(c_.get(), &C::method, std::move(a1), \ |
412 a3, a4, a5); \ | 493 std::move(a2), std::move(a3)); \ |
413 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ | 494 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ |
| 495 } |
| 496 |
| 497 #define PROXY_METHOD4(r, method, t1, t2, t3, t4) \ |
| 498 r method(t1 a1, t2 a2, t3 a3, t4 a4) override { \ |
| 499 MethodCall4<C, r, t1, t2, t3, t4> call(c_.get(), &C::method, \ |
| 500 std::move(a1), std::move(a2), \ |
| 501 std::move(a3), std::move(a4)); \ |
| 502 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ |
| 503 } |
| 504 |
| 505 #define PROXY_METHOD5(r, method, t1, t2, t3, t4, t5) \ |
| 506 r method(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) override { \ |
| 507 MethodCall5<C, r, t1, t2, t3, t4, t5> call( \ |
| 508 c_.get(), &C::method, std::move(a1), std::move(a2), std::move(a3), \ |
| 509 std::move(a4), std::move(a5)); \ |
| 510 return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ |
414 } | 511 } |
415 | 512 |
416 // Define methods which should be invoked on the worker thread. | 513 // Define methods which should be invoked on the worker thread. |
417 #define PROXY_WORKER_METHOD1(r, method, t1) \ | 514 #define PROXY_WORKER_METHOD0(r, method) \ |
418 r method(t1 a1) override { \ | 515 r method() override { \ |
419 MethodCall1<C, r, t1> call(c_.get(), &C::method, a1); \ | 516 MethodCall0<C, r> call(c_.get(), &C::method); \ |
420 return call.Marshal(RTC_FROM_HERE, worker_thread_); \ | 517 return call.Marshal(RTC_FROM_HERE, worker_thread_); \ |
421 } | 518 } |
422 | 519 |
423 #define PROXY_WORKER_METHOD2(r, method, t1, t2) \ | 520 #define PROXY_WORKER_CONSTMETHOD0(r, method) \ |
424 r method(t1 a1, t2 a2) override { \ | 521 r method() const override { \ |
425 MethodCall2<C, r, t1, t2> call(c_.get(), &C::method, a1, a2); \ | 522 ConstMethodCall0<C, r> call(c_.get(), &C::method); \ |
426 return call.Marshal(RTC_FROM_HERE, worker_thread_); \ | 523 return call.Marshal(RTC_FROM_HERE, worker_thread_); \ |
427 } | 524 } |
428 | 525 |
429 #define END_SIGNALING_PROXY() \ | 526 #define PROXY_WORKER_METHOD1(r, method, t1) \ |
430 private: \ | 527 r method(t1 a1) override { \ |
431 void Release_s() { c_ = NULL; } \ | 528 MethodCall1<C, r, t1> call(c_.get(), &C::method, std::move(a1)); \ |
432 mutable rtc::Thread* signaling_thread_; \ | 529 return call.Marshal(RTC_FROM_HERE, worker_thread_); \ |
433 rtc::scoped_refptr<INTERNAL_CLASS> c_; \ | 530 } |
434 } \ | |
435 ; | |
436 | 531 |
437 #define END_PROXY() \ | 532 #define PROXY_WORKER_CONSTMETHOD1(r, method, t1) \ |
438 private: \ | 533 r method(t1 a1) const override { \ |
439 void Release_s() { c_ = NULL; } \ | 534 ConstMethodCall1<C, r, t1> call(c_.get(), &C::method, std::move(a1)); \ |
440 mutable rtc::Thread* signaling_thread_; \ | 535 return call.Marshal(RTC_FROM_HERE, worker_thread_); \ |
441 mutable rtc::Thread* worker_thread_; \ | 536 } |
442 rtc::scoped_refptr<INTERNAL_CLASS> c_; \ | 537 |
443 } \ | 538 #define PROXY_WORKER_METHOD2(r, method, t1, t2) \ |
| 539 r method(t1 a1, t2 a2) override { \ |
| 540 MethodCall2<C, r, t1, t2> call(c_.get(), &C::method, std::move(a1), \ |
| 541 std::move(a2)); \ |
| 542 return call.Marshal(RTC_FROM_HERE, worker_thread_); \ |
| 543 } |
| 544 |
| 545 #define PROXY_WORKER_CONSTMETHOD2(r, method, t1, t2) \ |
| 546 r method(t1 a1, t2 a2) const override { \ |
| 547 ConstMethodCall2<C, r, t1, t2> call(c_.get(), &C::method, std::move(a1), \ |
| 548 std::move(a2)); \ |
| 549 return call.Marshal(RTC_FROM_HERE, worker_thread_); \ |
| 550 } |
| 551 |
| 552 #define END_PROXY_MAP() \ |
| 553 } \ |
444 ; | 554 ; |
445 | 555 |
446 } // namespace webrtc | 556 } // namespace webrtc |
447 | 557 |
448 #endif // WEBRTC_API_PROXY_H_ | 558 #endif // WEBRTC_API_PROXY_H_ |
OLD | NEW |