Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(247)

Side by Side Diff: mojo/public/cpp/bindings/interface_request.h

Issue 2855303003: Mojo C++ bindings: add a MakeRequest overload that binds InterfacePtrInfo. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 28 matching lines...) Expand all
39 // MakeRequest(InterfacePtr*) below. 39 // MakeRequest(InterfacePtr*) below.
40 explicit InterfaceRequest(InterfacePtr<Interface>* ptr, 40 explicit InterfaceRequest(InterfacePtr<Interface>* ptr,
41 scoped_refptr<base::SingleThreadTaskRunner> runner = 41 scoped_refptr<base::SingleThreadTaskRunner> runner =
42 base::ThreadTaskRunnerHandle::Get()) { 42 base::ThreadTaskRunnerHandle::Get()) {
43 MessagePipe pipe; 43 MessagePipe pipe;
44 ptr->Bind(InterfacePtrInfo<Interface>(std::move(pipe.handle0), 0u), 44 ptr->Bind(InterfacePtrInfo<Interface>(std::move(pipe.handle0), 0u),
45 std::move(runner)); 45 std::move(runner));
46 Bind(std::move(pipe.handle1)); 46 Bind(std::move(pipe.handle1));
47 } 47 }
48 48
49 // Similar to the constructor above, but binds one end of the message pipe to
50 // an InterfacePtrInfo instance.
51 explicit InterfaceRequest(InterfacePtrInfo<Interface>* ptr_info) {
52 MessagePipe pipe;
53 ptr_info->set_handle(std::move(pipe.handle0));
54 ptr_info->set_version(0u);
55 Bind(std::move(pipe.handle1));
56 }
57
49 // Takes the message pipe from another InterfaceRequest. 58 // Takes the message pipe from another InterfaceRequest.
50 InterfaceRequest(InterfaceRequest&& other) { 59 InterfaceRequest(InterfaceRequest&& other) {
51 handle_ = std::move(other.handle_); 60 handle_ = std::move(other.handle_);
52 } 61 }
53 InterfaceRequest& operator=(InterfaceRequest&& other) { 62 InterfaceRequest& operator=(InterfaceRequest&& other) {
54 handle_ = std::move(other.handle_); 63 handle_ = std::move(other.handle_);
55 return *this; 64 return *this;
56 } 65 }
57 66
58 // Assigning to nullptr resets the InterfaceRequest to an empty state, 67 // Assigning to nullptr resets the InterfaceRequest to an empty state,
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 // CreateSource(std::move(source_request)); // Create implementation locally. 165 // CreateSource(std::move(source_request)); // Create implementation locally.
157 // 166 //
158 template <typename Interface> 167 template <typename Interface>
159 InterfaceRequest<Interface> MakeRequest( 168 InterfaceRequest<Interface> MakeRequest(
160 InterfacePtr<Interface>* ptr, 169 InterfacePtr<Interface>* ptr,
161 scoped_refptr<base::SingleThreadTaskRunner> runner = 170 scoped_refptr<base::SingleThreadTaskRunner> runner =
162 base::ThreadTaskRunnerHandle::Get()) { 171 base::ThreadTaskRunnerHandle::Get()) {
163 return InterfaceRequest<Interface>(ptr, runner); 172 return InterfaceRequest<Interface>(ptr, runner);
164 } 173 }
165 174
175 // Similar to the constructor above, but binds one end of the message pipe to
176 // an InterfacePtrInfo instance.
177 template <typename Interface>
178 InterfaceRequest<Interface> MakeRequest(InterfacePtrInfo<Interface>* ptr_info) {
179 return InterfaceRequest<Interface>(ptr_info);
180 }
181
166 // Fuses an InterfaceRequest<T> endpoint with an InterfacePtrInfo<T> endpoint. 182 // Fuses an InterfaceRequest<T> endpoint with an InterfacePtrInfo<T> endpoint.
167 // Returns |true| on success or |false| on failure. 183 // Returns |true| on success or |false| on failure.
168 template <typename Interface> 184 template <typename Interface>
169 bool FuseInterface(InterfaceRequest<Interface> request, 185 bool FuseInterface(InterfaceRequest<Interface> request,
170 InterfacePtrInfo<Interface> proxy_info) { 186 InterfacePtrInfo<Interface> proxy_info) {
171 MojoResult result = FuseMessagePipes(request.PassMessagePipe(), 187 MojoResult result = FuseMessagePipes(request.PassMessagePipe(),
172 proxy_info.PassHandle()); 188 proxy_info.PassHandle());
173 return result == MOJO_RESULT_OK; 189 return result == MOJO_RESULT_OK;
174 } 190 }
175 191
176 } // namespace mojo 192 } // namespace mojo
177 193
178 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_REQUEST_H_ 194 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_REQUEST_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/interface_ptr.h ('k') | mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698