OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_LIB_INTERFACE_PTR_INTERNAL_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_INTERNAL_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_INTERNAL_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_INTERNAL_H_ |
7 | 7 |
8 #include <algorithm> // For |std::swap()|. | 8 #include <algorithm> // For |std::swap()|. |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "mojo/public/cpp/bindings/callback.h" | 12 #include "mojo/public/cpp/bindings/callback.h" |
13 #include "mojo/public/cpp/bindings/interface_ptr_info.h" | 13 #include "mojo/public/cpp/bindings/interface_handle.h" |
14 #include "mojo/public/cpp/bindings/lib/control_message_proxy.h" | 14 #include "mojo/public/cpp/bindings/lib/control_message_proxy.h" |
15 #include "mojo/public/cpp/bindings/lib/message_header_validator.h" | 15 #include "mojo/public/cpp/bindings/lib/message_header_validator.h" |
16 #include "mojo/public/cpp/bindings/lib/router.h" | 16 #include "mojo/public/cpp/bindings/lib/router.h" |
17 #include "mojo/public/cpp/environment/logging.h" | 17 #include "mojo/public/cpp/environment/logging.h" |
18 | 18 |
19 struct MojoAsyncWaiter; | 19 struct MojoAsyncWaiter; |
20 | 20 |
21 namespace mojo { | 21 namespace mojo { |
22 namespace internal { | 22 namespace internal { |
23 | 23 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 | 73 |
74 void Swap(InterfacePtrState* other) { | 74 void Swap(InterfacePtrState* other) { |
75 using std::swap; | 75 using std::swap; |
76 swap(other->proxy_, proxy_); | 76 swap(other->proxy_, proxy_); |
77 swap(other->router_, router_); | 77 swap(other->router_, router_); |
78 handle_.swap(other->handle_); | 78 handle_.swap(other->handle_); |
79 swap(other->waiter_, waiter_); | 79 swap(other->waiter_, waiter_); |
80 swap(other->version_, version_); | 80 swap(other->version_, version_); |
81 } | 81 } |
82 | 82 |
83 void Bind(InterfacePtrInfo<Interface> info, const MojoAsyncWaiter* waiter) { | 83 void Bind(InterfaceHandle<Interface> info, const MojoAsyncWaiter* waiter) { |
84 MOJO_DCHECK(!proxy_); | 84 MOJO_DCHECK(!proxy_); |
85 MOJO_DCHECK(!router_); | 85 MOJO_DCHECK(!router_); |
86 MOJO_DCHECK(!handle_.is_valid()); | 86 MOJO_DCHECK(!handle_.is_valid()); |
87 MOJO_DCHECK(!waiter_); | 87 MOJO_DCHECK(!waiter_); |
88 MOJO_DCHECK(version_ == 0u); | 88 MOJO_DCHECK(version_ == 0u); |
89 MOJO_DCHECK(info.is_valid()); | 89 MOJO_DCHECK(info.is_valid()); |
90 | 90 |
91 handle_ = info.PassHandle(); | 91 handle_ = info.PassHandle(); |
92 waiter_ = waiter; | 92 waiter_ = waiter; |
93 version_ = info.version(); | 93 version_ = info.version(); |
94 } | 94 } |
95 | 95 |
96 bool WaitForIncomingResponse( | 96 bool WaitForIncomingResponse( |
97 MojoDeadline deadline = MOJO_DEADLINE_INDEFINITE) { | 97 MojoDeadline deadline = MOJO_DEADLINE_INDEFINITE) { |
98 ConfigureProxyIfNecessary(); | 98 ConfigureProxyIfNecessary(); |
99 | 99 |
100 MOJO_DCHECK(router_); | 100 MOJO_DCHECK(router_); |
101 return router_->WaitForIncomingMessage(deadline); | 101 return router_->WaitForIncomingMessage(deadline); |
102 } | 102 } |
103 | 103 |
104 // After this method is called, the object is in an invalid state and | 104 // After this method is called, the object is in an invalid state and |
105 // shouldn't be reused. | 105 // shouldn't be reused. |
106 InterfacePtrInfo<Interface> PassInterface() { | 106 InterfaceHandle<Interface> PassInterface() { |
107 return InterfacePtrInfo<Interface>( | 107 return InterfaceHandle<Interface>( |
108 router_ ? router_->PassMessagePipe() : handle_.Pass(), version_); | 108 router_ ? router_->PassMessagePipe() : handle_.Pass(), version_); |
109 } | 109 } |
110 | 110 |
111 bool is_bound() const { return handle_.is_valid() || router_; } | 111 bool is_bound() const { return handle_.is_valid() || router_; } |
112 | 112 |
113 bool encountered_error() const { | 113 bool encountered_error() const { |
114 return router_ ? router_->encountered_error() : false; | 114 return router_ ? router_->encountered_error() : false; |
115 } | 115 } |
116 | 116 |
117 void set_connection_error_handler(const Closure& error_handler) { | 117 void set_connection_error_handler(const Closure& error_handler) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 | 164 |
165 uint32_t version_; | 165 uint32_t version_; |
166 | 166 |
167 MOJO_DISALLOW_COPY_AND_ASSIGN(InterfacePtrState); | 167 MOJO_DISALLOW_COPY_AND_ASSIGN(InterfacePtrState); |
168 }; | 168 }; |
169 | 169 |
170 } // namespace internal | 170 } // namespace internal |
171 } // namespace mojo | 171 } // namespace mojo |
172 | 172 |
173 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_INTERNAL_H_ | 173 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_PTR_INTERNAL_H_ |
OLD | NEW |