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_REQUEST_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_REQUEST_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_REQUEST_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_REQUEST_H_ |
7 | 7 |
8 #include <cstddef> | 8 #include <cstddef> |
9 | 9 |
10 #include "mojo/public/cpp/system/message_pipe.h" | 10 #include "mojo/public/cpp/system/message_pipe.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 // collector->RegisterSource(source.Pass()); | 115 // collector->RegisterSource(source.Pass()); |
116 // CreateSource(source_request.Pass()); // Create implementation locally. | 116 // CreateSource(source_request.Pass()); // Create implementation locally. |
117 // | 117 // |
118 template <typename Interface> | 118 template <typename Interface> |
119 InterfaceRequest<Interface> GetProxy(InterfacePtr<Interface>* ptr) { | 119 InterfaceRequest<Interface> GetProxy(InterfacePtr<Interface>* ptr) { |
120 MessagePipe pipe; | 120 MessagePipe pipe; |
121 ptr->Bind(InterfaceHandle<Interface>(pipe.handle0.Pass(), 0u)); | 121 ptr->Bind(InterfaceHandle<Interface>(pipe.handle0.Pass(), 0u)); |
122 return MakeRequest<Interface>(pipe.handle1.Pass()); | 122 return MakeRequest<Interface>(pipe.handle1.Pass()); |
123 } | 123 } |
124 | 124 |
| 125 // This is an overload of GetProxy() that assumes that the client end of the |
| 126 // handle is an InterfaceHandle<>. It creates a new message pipe over which the |
| 127 // Interface is to be served. InterfaceHandle<> represents the client's end, |
| 128 // and InterfaceRequest<> should be used to bind to an implementation. |
| 129 template <typename Interface> |
| 130 InterfaceRequest<Interface> GetProxy(InterfaceHandle<Interface>* ptr) { |
| 131 MessagePipe pipe; |
| 132 *ptr = InterfaceHandle<Interface>(pipe.handle0.Pass(), 0u); |
| 133 return MakeRequest<Interface>(pipe.handle1.Pass()); |
| 134 } |
| 135 |
125 } // namespace mojo | 136 } // namespace mojo |
126 | 137 |
127 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_REQUEST_H_ | 138 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_REQUEST_H_ |
OLD | NEW |