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

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

Issue 272323003: Mojo: Implement support for |Foo&| mojom syntax (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « mojo/public/cpp/bindings/interface_ptr.h ('k') | mojo/public/cpp/bindings/lib/connector.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_REQUEST_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_REQUEST_H_
7
8 #include "mojo/public/cpp/bindings/interface_ptr.h"
9
10 namespace mojo {
11
12 // Used in methods that return instances of remote objects.
13 template <typename Interface>
14 class InterfaceRequest {
15 MOJO_MOVE_ONLY_TYPE_FOR_CPP_03(InterfaceRequest, RValue)
16 public:
17 InterfaceRequest() {}
18
19 InterfaceRequest(RValue other) {
20 handle_ = other.object->handle_.Pass();
21 }
22 InterfaceRequest& operator=(RValue other) {
23 handle_ = other.object->handle_.Pass();
24 return *this;
25 }
26
27 // Returns true if the request has yet to be completed.
28 bool is_pending() const { return handle_.is_valid(); }
29
30 void Bind(ScopedMessagePipeHandle handle) {
31 handle_ = handle.Pass();
32 }
33
34 ScopedMessagePipeHandle PassMessagePipe() {
35 return handle_.Pass();
36 }
37
38 private:
39 ScopedMessagePipeHandle handle_;
40 };
41
42 template <typename Interface>
43 InterfaceRequest<Interface> MakeRequest(ScopedMessagePipeHandle handle) {
44 InterfaceRequest<Interface> request;
45 request.Bind(handle.Pass());
46 return request.Pass();
47 }
48
49 // Used to construct a request that synchronously binds an InterfacePtr<..>,
50 // making it immediately usable upon return. The resulting request object may
51 // then be later bound to an InterfaceImpl<..> via BindToRequest.
52 //
53 // Given the following interface:
54 //
55 // interface Foo {
56 // CreateBar(Bar& bar);
57 // }
58 //
59 // The caller of CreateBar would have code similar to the following:
60 //
61 // InterfacePtr<Foo> foo = ...;
62 // InterfacePtr<Bar> bar;
63 // foo->CreateBar(Get(&bar));
64 //
65 // Upon return from CreateBar, |bar| is ready to have methods called on it.
66 //
67 template <typename Interface>
68 InterfaceRequest<Interface> Get(InterfacePtr<Interface>* ptr) {
69 MessagePipe pipe;
70 ptr->Bind(pipe.handle0.Pass());
71 return MakeRequest<Interface>(pipe.handle1.Pass());
72 }
73
74 } // namespace mojo
75
76 #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/lib/connector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698