| 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_BINDING_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_ |
| 7 | 7 |
| 8 #include <utility> |
| 9 |
| 8 #include "base/macros.h" | 10 #include "base/macros.h" |
| 9 #include "mojo/public/c/environment/async_waiter.h" | 11 #include "mojo/public/c/environment/async_waiter.h" |
| 10 #include "mojo/public/cpp/bindings/callback.h" | 12 #include "mojo/public/cpp/bindings/callback.h" |
| 11 #include "mojo/public/cpp/bindings/interface_ptr.h" | 13 #include "mojo/public/cpp/bindings/interface_ptr.h" |
| 12 #include "mojo/public/cpp/bindings/interface_ptr_info.h" | 14 #include "mojo/public/cpp/bindings/interface_ptr_info.h" |
| 13 #include "mojo/public/cpp/bindings/interface_request.h" | 15 #include "mojo/public/cpp/bindings/interface_request.h" |
| 14 #include "mojo/public/cpp/bindings/lib/binding_state.h" | 16 #include "mojo/public/cpp/bindings/lib/binding_state.h" |
| 15 #include "mojo/public/cpp/system/core.h" | 17 #include "mojo/public/cpp/system/core.h" |
| 16 | 18 |
| 17 namespace mojo { | 19 namespace mojo { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 // Does not take ownership of |impl|, which must outlive the binding. | 68 // Does not take ownership of |impl|, which must outlive the binding. |
| 67 explicit Binding(Interface* impl) : internal_state_(impl) {} | 69 explicit Binding(Interface* impl) : internal_state_(impl) {} |
| 68 | 70 |
| 69 // Constructs a completed binding of message pipe |handle| to implementation | 71 // Constructs a completed binding of message pipe |handle| to implementation |
| 70 // |impl|. Does not take ownership of |impl|, which must outlive the binding. | 72 // |impl|. Does not take ownership of |impl|, which must outlive the binding. |
| 71 // See class comment for definition of |waiter|. | 73 // See class comment for definition of |waiter|. |
| 72 Binding(Interface* impl, | 74 Binding(Interface* impl, |
| 73 ScopedMessagePipeHandle handle, | 75 ScopedMessagePipeHandle handle, |
| 74 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) | 76 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) |
| 75 : Binding(impl) { | 77 : Binding(impl) { |
| 76 Bind(handle.Pass(), waiter); | 78 Bind(std::move(handle), waiter); |
| 77 } | 79 } |
| 78 | 80 |
| 79 // Constructs a completed binding of |impl| to a new message pipe, passing the | 81 // Constructs a completed binding of |impl| to a new message pipe, passing the |
| 80 // client end to |ptr|, which takes ownership of it. The caller is expected to | 82 // client end to |ptr|, which takes ownership of it. The caller is expected to |
| 81 // pass |ptr| on to the client of the service. Does not take ownership of any | 83 // pass |ptr| on to the client of the service. Does not take ownership of any |
| 82 // of the parameters. |impl| must outlive the binding. |ptr| only needs to | 84 // of the parameters. |impl| must outlive the binding. |ptr| only needs to |
| 83 // last until the constructor returns. See class comment for definition of | 85 // last until the constructor returns. See class comment for definition of |
| 84 // |waiter|. | 86 // |waiter|. |
| 85 Binding(Interface* impl, | 87 Binding(Interface* impl, |
| 86 InterfacePtr<Interface>* ptr, | 88 InterfacePtr<Interface>* ptr, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 103 // Tears down the binding, closing the message pipe and leaving the interface | 105 // Tears down the binding, closing the message pipe and leaving the interface |
| 104 // implementation unbound. | 106 // implementation unbound. |
| 105 ~Binding() {} | 107 ~Binding() {} |
| 106 | 108 |
| 107 // Completes a binding that was constructed with only an interface | 109 // Completes a binding that was constructed with only an interface |
| 108 // implementation. Takes ownership of |handle| and binds it to the previously | 110 // implementation. Takes ownership of |handle| and binds it to the previously |
| 109 // specified implementation. See class comment for definition of |waiter|. | 111 // specified implementation. See class comment for definition of |waiter|. |
| 110 void Bind( | 112 void Bind( |
| 111 ScopedMessagePipeHandle handle, | 113 ScopedMessagePipeHandle handle, |
| 112 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { | 114 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { |
| 113 internal_state_.Bind(handle.Pass(), waiter); | 115 internal_state_.Bind(std::move(handle), waiter); |
| 114 } | 116 } |
| 115 | 117 |
| 116 // Completes a binding that was constructed with only an interface | 118 // Completes a binding that was constructed with only an interface |
| 117 // implementation by creating a new message pipe, binding one end of it to the | 119 // implementation by creating a new message pipe, binding one end of it to the |
| 118 // previously specified implementation, and passing the other to |ptr|, which | 120 // previously specified implementation, and passing the other to |ptr|, which |
| 119 // takes ownership of it. The caller is expected to pass |ptr| on to the | 121 // takes ownership of it. The caller is expected to pass |ptr| on to the |
| 120 // eventual client of the service. Does not take ownership of |ptr|. See | 122 // eventual client of the service. Does not take ownership of |ptr|. See |
| 121 // class comment for definition of |waiter|. | 123 // class comment for definition of |waiter|. |
| 122 void Bind( | 124 void Bind( |
| 123 InterfacePtr<Interface>* ptr, | 125 InterfacePtr<Interface>* ptr, |
| 124 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { | 126 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { |
| 125 MessagePipe pipe; | 127 MessagePipe pipe; |
| 126 ptr->Bind( | 128 ptr->Bind(InterfacePtrInfo<Interface>(std::move(pipe.handle0), |
| 127 InterfacePtrInfo<Interface>(pipe.handle0.Pass(), Interface::Version_), | 129 Interface::Version_), |
| 128 waiter); | 130 waiter); |
| 129 Bind(pipe.handle1.Pass(), waiter); | 131 Bind(std::move(pipe.handle1), waiter); |
| 130 } | 132 } |
| 131 | 133 |
| 132 // Completes a binding that was constructed with only an interface | 134 // Completes a binding that was constructed with only an interface |
| 133 // implementation by removing the message pipe endpoint from |request| and | 135 // implementation by removing the message pipe endpoint from |request| and |
| 134 // binding it to the previously specified implementation. See class comment | 136 // binding it to the previously specified implementation. See class comment |
| 135 // for definition of |waiter|. | 137 // for definition of |waiter|. |
| 136 void Bind( | 138 void Bind( |
| 137 InterfaceRequest<GenericInterface> request, | 139 InterfaceRequest<GenericInterface> request, |
| 138 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { | 140 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { |
| 139 Bind(request.PassMessagePipe(), waiter); | 141 Bind(request.PassMessagePipe(), waiter); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 private: | 234 private: |
| 233 internal::BindingState<Interface, Interface::PassesAssociatedKinds_> | 235 internal::BindingState<Interface, Interface::PassesAssociatedKinds_> |
| 234 internal_state_; | 236 internal_state_; |
| 235 | 237 |
| 236 DISALLOW_COPY_AND_ASSIGN(Binding); | 238 DISALLOW_COPY_AND_ASSIGN(Binding); |
| 237 }; | 239 }; |
| 238 | 240 |
| 239 } // namespace mojo | 241 } // namespace mojo |
| 240 | 242 |
| 241 #endif // MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_ | 243 #endif // MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_ |
| OLD | NEW |