| 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 <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 // Given the following interface: | 113 // Given the following interface: |
| 114 // | 114 // |
| 115 // interface Database { | 115 // interface Database { |
| 116 // OpenTable(Table& table); | 116 // OpenTable(Table& table); |
| 117 // } | 117 // } |
| 118 // | 118 // |
| 119 // The client would have code similar to the following: | 119 // The client would have code similar to the following: |
| 120 // | 120 // |
| 121 // DatabasePtr database = ...; // Connect to database. | 121 // DatabasePtr database = ...; // Connect to database. |
| 122 // TablePtr table; | 122 // TablePtr table; |
| 123 // database->OpenTable(GetProxy(&table)); | 123 // database->OpenTable(MakeRequest(&table)); |
| 124 // | 124 // |
| 125 // Upon return from GetProxy, |table| is ready to have methods called on it. | 125 // Upon return from MakeRequest, |table| is ready to have methods called on it. |
| 126 // | 126 // |
| 127 // Example #2: Registering a local implementation with a remote service. | 127 // Example #2: Registering a local implementation with a remote service. |
| 128 // ===================================================================== | 128 // ===================================================================== |
| 129 // | 129 // |
| 130 // Given the following interface | 130 // Given the following interface |
| 131 // interface Collector { | 131 // interface Collector { |
| 132 // RegisterSource(Source source); | 132 // RegisterSource(Source source); |
| 133 // } | 133 // } |
| 134 // | 134 // |
| 135 // The client would have code similar to the following: | 135 // The client would have code similar to the following: |
| 136 // | 136 // |
| 137 // CollectorPtr collector = ...; // Connect to Collector. | 137 // CollectorPtr collector = ...; // Connect to Collector. |
| 138 // SourcePtr source; | 138 // SourcePtr source; |
| 139 // InterfaceRequest<Source> source_request = GetProxy(&source); | 139 // InterfaceRequest<Source> source_request = MakeRequest(&source); |
| 140 // collector->RegisterSource(std::move(source)); | 140 // collector->RegisterSource(std::move(source)); |
| 141 // CreateSource(std::move(source_request)); // Create implementation locally. | 141 // CreateSource(std::move(source_request)); // Create implementation locally. |
| 142 // | 142 // |
| 143 template <typename Interface> | 143 template <typename Interface> |
| 144 InterfaceRequest<Interface> GetProxy( | 144 InterfaceRequest<Interface> MakeRequest( |
| 145 InterfacePtr<Interface>* ptr, | 145 InterfacePtr<Interface>* ptr, |
| 146 scoped_refptr<base::SingleThreadTaskRunner> runner = | 146 scoped_refptr<base::SingleThreadTaskRunner> runner = |
| 147 base::ThreadTaskRunnerHandle::Get()) { | 147 base::ThreadTaskRunnerHandle::Get()) { |
| 148 MessagePipe pipe; | 148 MessagePipe pipe; |
| 149 ptr->Bind(InterfacePtrInfo<Interface>(std::move(pipe.handle0), 0u), | 149 ptr->Bind(InterfacePtrInfo<Interface>(std::move(pipe.handle0), 0u), |
| 150 std::move(runner)); | 150 std::move(runner)); |
| 151 return MakeRequest<Interface>(std::move(pipe.handle1)); | 151 return MakeRequest<Interface>(std::move(pipe.handle1)); |
| 152 } | 152 } |
| 153 | 153 |
| 154 // Fuses an InterfaceRequest<T> endpoint with an InterfacePtrInfo<T> endpoint. | 154 // Fuses an InterfaceRequest<T> endpoint with an InterfacePtrInfo<T> endpoint. |
| 155 // Returns |true| on success or |false| on failure. | 155 // Returns |true| on success or |false| on failure. |
| 156 template <typename Interface> | 156 template <typename Interface> |
| 157 bool FuseInterface(InterfaceRequest<Interface> request, | 157 bool FuseInterface(InterfaceRequest<Interface> request, |
| 158 InterfacePtrInfo<Interface> proxy_info) { | 158 InterfacePtrInfo<Interface> proxy_info) { |
| 159 MojoResult result = FuseMessagePipes(request.PassMessagePipe(), | 159 MojoResult result = FuseMessagePipes(request.PassMessagePipe(), |
| 160 proxy_info.PassHandle()); | 160 proxy_info.PassHandle()); |
| 161 return result == MOJO_RESULT_OK; | 161 return result == MOJO_RESULT_OK; |
| 162 } | 162 } |
| 163 | 163 |
| 164 } // namespace mojo | 164 } // namespace mojo |
| 165 | 165 |
| 166 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_REQUEST_H_ | 166 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_REQUEST_H_ |
| OLD | NEW |