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): Deprecate this in favor of the |InterfaceHandle<>| overload |
| 86 // below. |
85 Binding(Interface* impl, | 87 Binding(Interface* impl, |
86 InterfacePtr<Interface>* ptr, | 88 InterfacePtr<Interface>* ptr, |
87 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) | 89 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) |
88 : Binding(impl) { | 90 : Binding(impl) { |
89 Bind(ptr, waiter); | 91 Bind(ptr, waiter); |
90 } | 92 } |
91 | 93 |
| 94 // Constructs a completed binding of |impl| to a new message pipe, passing the |
| 95 // client end to |ptr|, which takes ownership of it. The caller is expected to |
| 96 // pass |ptr| on to the client of the service. Does not take ownership of any |
| 97 // of the parameters. |impl| must outlive the binding. |ptr| only needs to |
| 98 // last until the constructor returns. See class comment for definition of |
| 99 // |waiter|. |
| 100 Binding(Interface* impl, |
| 101 InterfaceHandle<Interface>* interface_handle, |
| 102 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) |
| 103 : Binding(impl) { |
| 104 Bind(interface_handle, waiter); |
| 105 } |
| 106 |
92 // Constructs a completed binding of |impl| to the message pipe endpoint in | 107 // Constructs a completed binding of |impl| to the message pipe endpoint in |
93 // |request|, taking ownership of the endpoint. Does not take ownership of | 108 // |request|, taking ownership of the endpoint. Does not take ownership of |
94 // |impl|, which must outlive the binding. See class comment for definition of | 109 // |impl|, which must outlive the binding. See class comment for definition of |
95 // |waiter|. | 110 // |waiter|. |
96 Binding(Interface* impl, | 111 Binding(Interface* impl, |
97 InterfaceRequest<Interface> request, | 112 InterfaceRequest<Interface> request, |
98 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) | 113 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) |
99 : Binding(impl) { | 114 : Binding(impl) { |
100 Bind(request.PassMessagePipe(), waiter); | 115 Bind(request.PassMessagePipe(), waiter); |
101 } | 116 } |
(...skipping 22 matching lines...) Expand all Loading... |
124 internal_router_->set_connection_error_handler( | 139 internal_router_->set_connection_error_handler( |
125 [this]() { connection_error_handler_.Run(); }); | 140 [this]() { connection_error_handler_.Run(); }); |
126 } | 141 } |
127 | 142 |
128 // Completes a binding that was constructed with only an interface | 143 // 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 | 144 // 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 | 145 // 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 | 146 // 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 | 147 // eventual client of the service. Does not take ownership of |ptr|. See |
133 // class comment for definition of |waiter|. | 148 // class comment for definition of |waiter|. |
| 149 // TODO(vardhan): Deprecate this in favor of the |InterfaceHandle<>| overload |
| 150 // below. |
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 |