OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 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 |
11 #ifndef WEBRTC_BASE_MESSAGEHANDLER_H_ | 11 #ifndef WEBRTC_BASE_MESSAGEHANDLER_H_ |
12 #define WEBRTC_BASE_MESSAGEHANDLER_H_ | 12 #define WEBRTC_BASE_MESSAGEHANDLER_H_ |
13 | 13 |
| 14 #include <utility> |
| 15 |
14 #include "webrtc/base/constructormagic.h" | 16 #include "webrtc/base/constructormagic.h" |
15 #include "webrtc/base/scoped_ptr.h" | 17 #include "webrtc/base/scoped_ptr.h" |
16 | 18 |
17 namespace rtc { | 19 namespace rtc { |
18 | 20 |
19 struct Message; | 21 struct Message; |
20 | 22 |
21 // Messages get dispatched to a MessageHandler | 23 // Messages get dispatched to a MessageHandler |
22 | 24 |
23 class MessageHandler { | 25 class MessageHandler { |
(...skipping 23 matching lines...) Expand all Loading... |
47 FunctorT functor_; | 49 FunctorT functor_; |
48 ReturnT result_; | 50 ReturnT result_; |
49 }; | 51 }; |
50 | 52 |
51 // Specialization for rtc::scoped_ptr<ReturnT>. | 53 // Specialization for rtc::scoped_ptr<ReturnT>. |
52 template <class ReturnT, class FunctorT> | 54 template <class ReturnT, class FunctorT> |
53 class FunctorMessageHandler<class rtc::scoped_ptr<ReturnT>, FunctorT> | 55 class FunctorMessageHandler<class rtc::scoped_ptr<ReturnT>, FunctorT> |
54 : public MessageHandler { | 56 : public MessageHandler { |
55 public: | 57 public: |
56 explicit FunctorMessageHandler(const FunctorT& functor) : functor_(functor) {} | 58 explicit FunctorMessageHandler(const FunctorT& functor) : functor_(functor) {} |
57 virtual void OnMessage(Message* msg) { result_ = functor_().Pass(); } | 59 virtual void OnMessage(Message* msg) { result_ = std::move(functor_()); } |
58 rtc::scoped_ptr<ReturnT> result() { return result_.Pass(); } | 60 rtc::scoped_ptr<ReturnT> result() { return std::move(result_); } |
59 | 61 |
60 private: | 62 private: |
61 FunctorT functor_; | 63 FunctorT functor_; |
62 rtc::scoped_ptr<ReturnT> result_; | 64 rtc::scoped_ptr<ReturnT> result_; |
63 }; | 65 }; |
64 | 66 |
65 // Specialization for ReturnT of void. | 67 // Specialization for ReturnT of void. |
66 template <class FunctorT> | 68 template <class FunctorT> |
67 class FunctorMessageHandler<void, FunctorT> : public MessageHandler { | 69 class FunctorMessageHandler<void, FunctorT> : public MessageHandler { |
68 public: | 70 public: |
69 explicit FunctorMessageHandler(const FunctorT& functor) | 71 explicit FunctorMessageHandler(const FunctorT& functor) |
70 : functor_(functor) {} | 72 : functor_(functor) {} |
71 virtual void OnMessage(Message* msg) { | 73 virtual void OnMessage(Message* msg) { |
72 functor_(); | 74 functor_(); |
73 } | 75 } |
74 void result() const {} | 76 void result() const {} |
75 | 77 |
76 private: | 78 private: |
77 FunctorT functor_; | 79 FunctorT functor_; |
78 }; | 80 }; |
79 | 81 |
80 } // namespace rtc | 82 } // namespace rtc |
81 | 83 |
82 #endif // WEBRTC_BASE_MESSAGEHANDLER_H_ | 84 #endif // WEBRTC_BASE_MESSAGEHANDLER_H_ |
OLD | NEW |