| 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_INTERFACE_PTR_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ |
| 7 | 7 |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 | 9 |
| 10 #include "mojo/public/cpp/bindings/callback.h" | 10 #include "mojo/public/cpp/bindings/callback.h" |
| 11 #include "mojo/public/cpp/bindings/error_handler.h" | |
| 12 #include "mojo/public/cpp/bindings/interface_ptr_info.h" | 11 #include "mojo/public/cpp/bindings/interface_ptr_info.h" |
| 13 #include "mojo/public/cpp/bindings/lib/interface_ptr_internal.h" | 12 #include "mojo/public/cpp/bindings/lib/interface_ptr_internal.h" |
| 14 #include "mojo/public/cpp/environment/environment.h" | 13 #include "mojo/public/cpp/environment/environment.h" |
| 15 #include "mojo/public/cpp/system/macros.h" | 14 #include "mojo/public/cpp/system/macros.h" |
| 16 | 15 |
| 17 namespace mojo { | 16 namespace mojo { |
| 18 | 17 |
| 19 // A pointer to a local proxy of a remote Interface implementation. Uses a | 18 // A pointer to a local proxy of a remote Interface implementation. Uses a |
| 20 // message pipe to communicate with the remote implementation, and automatically | 19 // message pipe to communicate with the remote implementation, and automatically |
| 21 // closes the pipe and deletes the proxy on destruction. The pointer must be | 20 // closes the pipe and deletes the proxy on destruction. The pointer must be |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 // has the same effect as reset(). In this case, the InterfacePtr is not | 66 // has the same effect as reset(). In this case, the InterfacePtr is not |
| 68 // considered as bound. | 67 // considered as bound. |
| 69 void Bind( | 68 void Bind( |
| 70 InterfacePtrInfo<Interface> info, | 69 InterfacePtrInfo<Interface> info, |
| 71 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { | 70 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { |
| 72 reset(); | 71 reset(); |
| 73 if (info.is_valid()) | 72 if (info.is_valid()) |
| 74 internal_state_.Bind(info.Pass(), waiter); | 73 internal_state_.Bind(info.Pass(), waiter); |
| 75 } | 74 } |
| 76 | 75 |
| 76 // Returns whether or not this InterfacePtr is bound to a message pipe. |
| 77 bool is_bound() const { return internal_state_.is_bound(); } |
| 78 |
| 77 // Returns a raw pointer to the local proxy. Caller does not take ownership. | 79 // Returns a raw pointer to the local proxy. Caller does not take ownership. |
| 78 // Note that the local proxy is thread hostile, as stated above. | 80 // Note that the local proxy is thread hostile, as stated above. |
| 79 Interface* get() const { return internal_state_.instance(); } | 81 Interface* get() const { return internal_state_.instance(); } |
| 80 | 82 |
| 81 // Functions like a pointer to Interface. Must already be bound. | 83 // Functions like a pointer to Interface. Must already be bound. |
| 82 Interface* operator->() const { return get(); } | 84 Interface* operator->() const { return get(); } |
| 83 Interface& operator*() const { return *get(); } | 85 Interface& operator*() const { return *get(); } |
| 84 | 86 |
| 85 // Returns the version number of the interface that the remote side supports. | 87 // Returns the version number of the interface that the remote side supports. |
| 86 uint32_t version() const { return internal_state_.version(); } | 88 uint32_t version() const { return internal_state_.version(); } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 | 129 |
| 128 // Registers a handler to receive error notifications. The handler will be | 130 // Registers a handler to receive error notifications. The handler will be |
| 129 // called from the thread that owns this InterfacePtr. | 131 // called from the thread that owns this InterfacePtr. |
| 130 // | 132 // |
| 131 // This method may only be called after the InterfacePtr has been bound to a | 133 // This method may only be called after the InterfacePtr has been bound to a |
| 132 // message pipe. | 134 // message pipe. |
| 133 void set_connection_error_handler(const Closure& error_handler) { | 135 void set_connection_error_handler(const Closure& error_handler) { |
| 134 internal_state_.set_connection_error_handler(error_handler); | 136 internal_state_.set_connection_error_handler(error_handler); |
| 135 } | 137 } |
| 136 | 138 |
| 137 // Similar to the method above but uses the ErrorHandler interface instead of | |
| 138 // a callback. | |
| 139 // NOTE: Deprecated. Please use the method above. | |
| 140 // TODO(yzshen): Remove this method once all callsites are converted. | |
| 141 void set_error_handler(ErrorHandler* error_handler) { | |
| 142 if (error_handler) { | |
| 143 set_connection_error_handler( | |
| 144 [error_handler]() { error_handler->OnConnectionError(); }); | |
| 145 } else { | |
| 146 set_connection_error_handler(Closure()); | |
| 147 } | |
| 148 } | |
| 149 | |
| 150 // Unbinds the InterfacePtr and returns the information which could be used | 139 // Unbinds the InterfacePtr and returns the information which could be used |
| 151 // to setup an InterfacePtr again. This method may be used to move the proxy | 140 // to setup an InterfacePtr again. This method may be used to move the proxy |
| 152 // to a different thread (see class comments for details). | 141 // to a different thread (see class comments for details). |
| 153 InterfacePtrInfo<Interface> PassInterface() { | 142 InterfacePtrInfo<Interface> PassInterface() { |
| 154 State state; | 143 State state; |
| 155 internal_state_.Swap(&state); | 144 internal_state_.Swap(&state); |
| 156 | 145 |
| 157 return state.PassInterface(); | 146 return state.PassInterface(); |
| 158 } | 147 } |
| 159 | 148 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 187 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { | 176 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { |
| 188 InterfacePtr<Interface> ptr; | 177 InterfacePtr<Interface> ptr; |
| 189 if (info.is_valid()) | 178 if (info.is_valid()) |
| 190 ptr.Bind(info.Pass(), waiter); | 179 ptr.Bind(info.Pass(), waiter); |
| 191 return ptr.Pass(); | 180 return ptr.Pass(); |
| 192 } | 181 } |
| 193 | 182 |
| 194 } // namespace mojo | 183 } // namespace mojo |
| 195 | 184 |
| 196 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ | 185 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ |
| OLD | NEW |