Chromium Code Reviews| 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 <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 : Binding(impl) { | 75 : Binding(impl) { |
| 76 Bind(handle.Pass(), waiter); | 76 Bind(handle.Pass(), waiter); |
| 77 } | 77 } |
| 78 | 78 |
| 79 // Constructs a completed binding of |impl| to a new message pipe, passing the | 79 // 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 | 80 // 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 | 81 // 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 | 82 // of the parameters. |impl| must outlive the binding. |ptr| only needs to |
| 83 // last until the constructor returns. See class comment for definition of | 83 // last until the constructor returns. See class comment for definition of |
| 84 // |waiter|. | 84 // |waiter|. |
| 85 // TODO(vardhan): Considering deprecating this since it takes |InterfacePtr|. | |
|
viettrungluu
2016/02/11 18:26:29
Deprecating this sounds good. Logically, its inter
vardhan
2016/02/11 22:47:53
oh true! but i guess this won't be a problem once
| |
| 86 // It would be nice to only accept |InterfaceHandle<>| so that |Binding<>| | |
| 87 // can abstract away details about the client's implementation. | |
| 85 Binding(Interface* impl, | 88 Binding(Interface* impl, |
| 86 InterfacePtr<Interface>* ptr, | 89 InterfacePtr<Interface>* ptr, |
| 87 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) | 90 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) |
| 88 : Binding(impl) { | 91 : Binding(impl) { |
| 89 Bind(ptr, waiter); | 92 Bind(ptr, waiter); |
| 90 } | 93 } |
| 91 | 94 |
| 95 // Constructs a completed binding of |impl| to a new message pipe, passing the | |
| 96 // client end to |ptr|, which takes ownership of it. The caller is expected to | |
| 97 // pass |ptr| on to the client of the service. Does not take ownership of any | |
| 98 // of the parameters. |impl| must outlive the binding. |ptr| only needs to | |
| 99 // last until the constructor returns. See class comment for definition of | |
| 100 // |waiter|. | |
| 101 Binding(Interface* impl, | |
| 102 InterfaceHandle<Interface>* interface_handle, | |
| 103 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) | |
| 104 : Binding(impl) { | |
| 105 Bind(interface_handle, waiter); | |
| 106 } | |
| 107 | |
| 92 // Constructs a completed binding of |impl| to the message pipe endpoint in | 108 // Constructs a completed binding of |impl| to the message pipe endpoint in |
| 93 // |request|, taking ownership of the endpoint. Does not take ownership of | 109 // |request|, taking ownership of the endpoint. Does not take ownership of |
| 94 // |impl|, which must outlive the binding. See class comment for definition of | 110 // |impl|, which must outlive the binding. See class comment for definition of |
| 95 // |waiter|. | 111 // |waiter|. |
| 96 Binding(Interface* impl, | 112 Binding(Interface* impl, |
| 97 InterfaceRequest<Interface> request, | 113 InterfaceRequest<Interface> request, |
| 98 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) | 114 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) |
| 99 : Binding(impl) { | 115 : Binding(impl) { |
| 100 Bind(request.PassMessagePipe(), waiter); | 116 Bind(request.PassMessagePipe(), waiter); |
| 101 } | 117 } |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 124 internal_router_->set_connection_error_handler( | 140 internal_router_->set_connection_error_handler( |
| 125 [this]() { connection_error_handler_.Run(); }); | 141 [this]() { connection_error_handler_.Run(); }); |
| 126 } | 142 } |
| 127 | 143 |
| 128 // Completes a binding that was constructed with only an interface | 144 // Completes a binding that was constructed with only an interface |
| 129 // implementation by creating a new message pipe, binding one end of it to the | 145 // implementation by creating a new message pipe, binding one end of it to the |
| 130 // previously specified implementation, and passing the other to |ptr|, which | 146 // previously specified implementation, and passing the other to |ptr|, which |
| 131 // takes ownership of it. The caller is expected to pass |ptr| on to the | 147 // takes ownership of it. The caller is expected to pass |ptr| on to the |
| 132 // eventual client of the service. Does not take ownership of |ptr|. See | 148 // eventual client of the service. Does not take ownership of |ptr|. See |
| 133 // class comment for definition of |waiter|. | 149 // class comment for definition of |waiter|. |
| 150 // TODO(vardhan): Deprecate this? | |
|
viettrungluu
2016/02/11 18:26:29
Ditto.
(Also, why are there two spaces after the
vardhan
2016/02/11 22:47:53
Done.
| |
| 134 void Bind( | 151 void Bind( |
| 135 InterfacePtr<Interface>* ptr, | 152 InterfacePtr<Interface>* ptr, |
| 136 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { | 153 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { |
| 137 MessagePipe pipe; | 154 MessagePipe pipe; |
| 138 ptr->Bind( | 155 ptr->Bind( |
| 139 InterfaceHandle<Interface>(pipe.handle0.Pass(), Interface::Version_), | 156 InterfaceHandle<Interface>(pipe.handle0.Pass(), Interface::Version_), |
| 140 waiter); | 157 waiter); |
| 141 Bind(pipe.handle1.Pass(), waiter); | 158 Bind(pipe.handle1.Pass(), waiter); |
| 142 } | 159 } |
| 143 | 160 |
| 144 // Completes a binding that was constructed with only an interface | 161 // Completes a binding that was constructed with only an interface |
| 162 // implementation by creating a new message pipe, binding one end of it to the | |
| 163 // previously specified implementation, and passing the other to |ptr|, which | |
| 164 // takes ownership of it. The caller is expected to pass |ptr| on to the | |
| 165 // eventual client of the service. Does not take ownership of |ptr|. See | |
| 166 // class comment for definition of |waiter|. | |
| 167 void Bind( | |
| 168 InterfaceHandle<Interface>* interface_handle, | |
| 169 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { | |
| 170 MessagePipe pipe; | |
| 171 *interface_handle = | |
| 172 InterfaceHandle<Interface>(pipe.handle0.Pass(), Interface::Version_); | |
| 173 Bind(pipe.handle1.Pass(), waiter); | |
| 174 } | |
| 175 | |
| 176 // Completes a binding that was constructed with only an interface | |
| 145 // implementation by removing the message pipe endpoint from |request| and | 177 // implementation by removing the message pipe endpoint from |request| and |
| 146 // binding it to the previously specified implementation. See class comment | 178 // binding it to the previously specified implementation. See class comment |
| 147 // for definition of |waiter|. | 179 // for definition of |waiter|. |
| 148 void Bind( | 180 void Bind( |
| 149 InterfaceRequest<Interface> request, | 181 InterfaceRequest<Interface> request, |
| 150 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { | 182 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { |
| 151 Bind(request.PassMessagePipe(), waiter); | 183 Bind(request.PassMessagePipe(), waiter); |
| 152 } | 184 } |
| 153 | 185 |
| 154 // Blocks the calling thread until either a call arrives on the previously | 186 // Blocks the calling thread until either a call arrives on the previously |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 typename Interface::Stub_ stub_; | 240 typename Interface::Stub_ stub_; |
| 209 Interface* impl_; | 241 Interface* impl_; |
| 210 Closure connection_error_handler_; | 242 Closure connection_error_handler_; |
| 211 | 243 |
| 212 MOJO_DISALLOW_COPY_AND_ASSIGN(Binding); | 244 MOJO_DISALLOW_COPY_AND_ASSIGN(Binding); |
| 213 }; | 245 }; |
| 214 | 246 |
| 215 } // namespace mojo | 247 } // namespace mojo |
| 216 | 248 |
| 217 #endif // MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_ | 249 #endif // MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_ |
| OLD | NEW |