OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_REQUEST_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_REQUEST_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_REQUEST_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_REQUEST_H_ |
7 | 7 |
| 8 #include <utility> |
| 9 |
8 #include "base/macros.h" | 10 #include "base/macros.h" |
9 #include "mojo/public/cpp/bindings/lib/scoped_interface_endpoint_handle.h" | 11 #include "mojo/public/cpp/bindings/lib/scoped_interface_endpoint_handle.h" |
10 | 12 |
11 namespace mojo { | 13 namespace mojo { |
12 | 14 |
13 namespace internal { | 15 namespace internal { |
14 class AssociatedInterfaceRequestHelper; | 16 class AssociatedInterfaceRequestHelper; |
15 } | 17 } |
16 | 18 |
17 // AssociatedInterfaceRequest represents an associated interface request. It is | 19 // AssociatedInterfaceRequest represents an associated interface request. It is |
18 // similar to InterfaceRequest except that it doesn't own a message pipe handle. | 20 // similar to InterfaceRequest except that it doesn't own a message pipe handle. |
19 template <typename Interface> | 21 template <typename Interface> |
20 class AssociatedInterfaceRequest { | 22 class AssociatedInterfaceRequest { |
21 DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND(AssociatedInterfaceRequest); | 23 DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND(AssociatedInterfaceRequest); |
22 | 24 |
23 public: | 25 public: |
24 // Constructs an empty AssociatedInterfaceRequest, representing that the | 26 // Constructs an empty AssociatedInterfaceRequest, representing that the |
25 // client is not requesting an implementation of Interface. | 27 // client is not requesting an implementation of Interface. |
26 AssociatedInterfaceRequest() {} | 28 AssociatedInterfaceRequest() {} |
27 AssociatedInterfaceRequest(decltype(nullptr)) {} | 29 AssociatedInterfaceRequest(decltype(nullptr)) {} |
28 | 30 |
29 // Takes the interface endpoint handle from another | 31 // Takes the interface endpoint handle from another |
30 // AssociatedInterfaceRequest. | 32 // AssociatedInterfaceRequest. |
31 AssociatedInterfaceRequest(AssociatedInterfaceRequest&& other) { | 33 AssociatedInterfaceRequest(AssociatedInterfaceRequest&& other) { |
32 handle_ = other.handle_.Pass(); | 34 handle_ = std::move(other.handle_); |
33 } | 35 } |
34 AssociatedInterfaceRequest& operator=(AssociatedInterfaceRequest&& other) { | 36 AssociatedInterfaceRequest& operator=(AssociatedInterfaceRequest&& other) { |
35 if (this != &other) | 37 if (this != &other) |
36 handle_ = other.handle_.Pass(); | 38 handle_ = std::move(other.handle_); |
37 return *this; | 39 return *this; |
38 } | 40 } |
39 | 41 |
40 // Assigning to nullptr resets the AssociatedInterfaceRequest to an empty | 42 // Assigning to nullptr resets the AssociatedInterfaceRequest to an empty |
41 // state, closing the interface endpoint handle currently bound to it (if | 43 // state, closing the interface endpoint handle currently bound to it (if |
42 // any). | 44 // any). |
43 AssociatedInterfaceRequest& operator=(decltype(nullptr)) { | 45 AssociatedInterfaceRequest& operator=(decltype(nullptr)) { |
44 handle_.reset(); | 46 handle_.reset(); |
45 return *this; | 47 return *this; |
46 } | 48 } |
(...skipping 11 matching lines...) Expand all Loading... |
58 namespace internal { | 60 namespace internal { |
59 | 61 |
60 // With this helper, AssociatedInterfaceRequest doesn't have to expose any | 62 // With this helper, AssociatedInterfaceRequest doesn't have to expose any |
61 // operations related to ScopedInterfaceEndpointHandle, which is an internal | 63 // operations related to ScopedInterfaceEndpointHandle, which is an internal |
62 // class. | 64 // class. |
63 class AssociatedInterfaceRequestHelper { | 65 class AssociatedInterfaceRequestHelper { |
64 public: | 66 public: |
65 template <typename Interface> | 67 template <typename Interface> |
66 static ScopedInterfaceEndpointHandle PassHandle( | 68 static ScopedInterfaceEndpointHandle PassHandle( |
67 AssociatedInterfaceRequest<Interface>* request) { | 69 AssociatedInterfaceRequest<Interface>* request) { |
68 return request->handle_.Pass(); | 70 return std::move(request->handle_); |
69 } | 71 } |
70 | 72 |
71 template <typename Interface> | 73 template <typename Interface> |
72 static const ScopedInterfaceEndpointHandle& GetHandle( | 74 static const ScopedInterfaceEndpointHandle& GetHandle( |
73 AssociatedInterfaceRequest<Interface>* request) { | 75 AssociatedInterfaceRequest<Interface>* request) { |
74 return request->handle_; | 76 return request->handle_; |
75 } | 77 } |
76 | 78 |
77 template <typename Interface> | 79 template <typename Interface> |
78 static void SetHandle(AssociatedInterfaceRequest<Interface>* request, | 80 static void SetHandle(AssociatedInterfaceRequest<Interface>* request, |
79 ScopedInterfaceEndpointHandle handle) { | 81 ScopedInterfaceEndpointHandle handle) { |
80 request->handle_ = handle.Pass(); | 82 request->handle_ = std::move(handle); |
81 } | 83 } |
82 }; | 84 }; |
83 | 85 |
84 } // namespace internal | 86 } // namespace internal |
85 } // namespace mojo | 87 } // namespace mojo |
86 | 88 |
87 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_REQUEST_H_ | 89 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_REQUEST_H_ |
OLD | NEW |