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

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

Issue 1524693002: [mojo] Add GenericInterface_ to interface class variants (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bindings-2-typemaps
Patch Set: merge Created 5 years 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
« no previous file with comments | « mojo/common/weak_binding_set.h ('k') | mojo/public/cpp/bindings/associated_group.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_ASSOCIATED_BINDING_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_BINDING_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_BINDING_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_BINDING_H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "mojo/public/cpp/bindings/associated_group.h" 10 #include "mojo/public/cpp/bindings/associated_group.h"
11 #include "mojo/public/cpp/bindings/associated_interface_request.h" 11 #include "mojo/public/cpp/bindings/associated_interface_request.h"
12 #include "mojo/public/cpp/bindings/callback.h" 12 #include "mojo/public/cpp/bindings/callback.h"
13 #include "mojo/public/cpp/bindings/lib/interface_endpoint_client.h" 13 #include "mojo/public/cpp/bindings/lib/interface_endpoint_client.h"
14 #include "mojo/public/cpp/bindings/lib/multiplex_router.h" 14 #include "mojo/public/cpp/bindings/lib/multiplex_router.h"
15 #include "mojo/public/cpp/bindings/lib/scoped_interface_endpoint_handle.h" 15 #include "mojo/public/cpp/bindings/lib/scoped_interface_endpoint_handle.h"
16 16
17 namespace mojo { 17 namespace mojo {
18 18
19 // Represents the implementation side of an associated interface. It is similar 19 // Represents the implementation side of an associated interface. It is similar
20 // to Binding, except that it doesn't own a message pipe handle. 20 // to Binding, except that it doesn't own a message pipe handle.
21 template <typename Interface> 21 template <typename Interface>
22 class AssociatedBinding { 22 class AssociatedBinding {
23 public: 23 public:
24 using GenericInterface = typename Interface::GenericInterface;
25
24 // Constructs an incomplete associated binding that will use the 26 // Constructs an incomplete associated binding that will use the
25 // implementation |impl|. It may be completed with a subsequent call to the 27 // implementation |impl|. It may be completed with a subsequent call to the
26 // |Bind| method. Does not take ownership of |impl|, which must outlive this 28 // |Bind| method. Does not take ownership of |impl|, which must outlive this
27 // object. 29 // object.
28 explicit AssociatedBinding(Interface* impl) : impl_(impl) { 30 explicit AssociatedBinding(Interface* impl) : impl_(impl) {
29 stub_.set_sink(impl_); 31 stub_.set_sink(impl_);
30 } 32 }
31 33
32 // Constructs a completed associated binding of |impl|. The output |ptr_info| 34 // Constructs a completed associated binding of |impl|. The output |ptr_info|
33 // should be passed through the message pipe endpoint referred to by 35 // should be passed through the message pipe endpoint referred to by
34 // |associated_group| to setup the corresponding asssociated interface 36 // |associated_group| to setup the corresponding asssociated interface
35 // pointer. |impl| must outlive this object. 37 // pointer. |impl| must outlive this object.
36 AssociatedBinding(Interface* impl, 38 AssociatedBinding(Interface* impl,
37 AssociatedInterfacePtrInfo<Interface>* ptr_info, 39 AssociatedInterfacePtrInfo<GenericInterface>* ptr_info,
38 AssociatedGroup* associated_group) 40 AssociatedGroup* associated_group)
39 : AssociatedBinding(impl) { 41 : AssociatedBinding(impl) {
40 Bind(ptr_info, associated_group); 42 Bind(ptr_info, associated_group);
41 } 43 }
42 44
43 // Constructs a completed associated binding of |impl|. |impl| must outlive 45 // Constructs a completed associated binding of |impl|. |impl| must outlive
44 // the binding. 46 // the binding.
45 AssociatedBinding(Interface* impl, 47 AssociatedBinding(Interface* impl,
46 AssociatedInterfaceRequest<Interface> request) 48 AssociatedInterfaceRequest<GenericInterface> request)
47 : AssociatedBinding(impl) { 49 : AssociatedBinding(impl) {
48 Bind(request.Pass()); 50 Bind(request.Pass());
49 } 51 }
50 52
51 ~AssociatedBinding() {} 53 ~AssociatedBinding() {}
52 54
53 // Creates an associated inteface and sets up this object as the 55 // Creates an associated inteface and sets up this object as the
54 // implementation side. The output |ptr_info| should be passed through the 56 // implementation side. The output |ptr_info| should be passed through the
55 // message pipe endpoint referred to by |associated_group| to setup the 57 // message pipe endpoint referred to by |associated_group| to setup the
56 // corresponding asssociated interface pointer. 58 // corresponding asssociated interface pointer.
57 void Bind(AssociatedInterfacePtrInfo<Interface>* ptr_info, 59 void Bind(AssociatedInterfacePtrInfo<GenericInterface>* ptr_info,
58 AssociatedGroup* associated_group) { 60 AssociatedGroup* associated_group) {
59 AssociatedInterfaceRequest<Interface> request; 61 AssociatedInterfaceRequest<Interface> request;
60 associated_group->CreateAssociatedInterface(AssociatedGroup::WILL_PASS_PTR, 62 associated_group->CreateAssociatedInterface(AssociatedGroup::WILL_PASS_PTR,
61 ptr_info, &request); 63 ptr_info, &request);
62 Bind(request.Pass()); 64 Bind(request.Pass());
63 } 65 }
64 66
65 // Sets up this object as the implementation side of an associated interface. 67 // Sets up this object as the implementation side of an associated interface.
66 void Bind(AssociatedInterfaceRequest<Interface> request) { 68 void Bind(AssociatedInterfaceRequest<GenericInterface> request) {
67 internal::ScopedInterfaceEndpointHandle handle = 69 internal::ScopedInterfaceEndpointHandle handle =
68 internal::AssociatedInterfaceRequestHelper::PassHandle(&request); 70 internal::AssociatedInterfaceRequestHelper::PassHandle(&request);
69 71
70 DCHECK(handle.is_local()) 72 DCHECK(handle.is_local())
71 << "The AssociatedInterfaceRequest is supposed to be used at the " 73 << "The AssociatedInterfaceRequest is supposed to be used at the "
72 << "other side of the message pipe."; 74 << "other side of the message pipe.";
73 75
74 if (!handle.is_valid() || !handle.is_local()) { 76 if (!handle.is_valid() || !handle.is_local()) {
75 endpoint_client_.reset(); 77 endpoint_client_.reset();
76 return; 78 return;
(...skipping 11 matching lines...) Expand all
88 // Closes the associated interface. Puts this object into a state where it can 90 // Closes the associated interface. Puts this object into a state where it can
89 // be rebound. 91 // be rebound.
90 void Close() { 92 void Close() {
91 DCHECK(endpoint_client_); 93 DCHECK(endpoint_client_);
92 endpoint_client_.reset(); 94 endpoint_client_.reset();
93 } 95 }
94 96
95 // Unbinds and returns the associated interface request so it can be 97 // Unbinds and returns the associated interface request so it can be
96 // used in another context, such as on another thread or with a different 98 // used in another context, such as on another thread or with a different
97 // implementation. Puts this object into a state where it can be rebound. 99 // implementation. Puts this object into a state where it can be rebound.
98 AssociatedInterfaceRequest<Interface> Unbind() { 100 AssociatedInterfaceRequest<GenericInterface> Unbind() {
99 DCHECK(endpoint_client_); 101 DCHECK(endpoint_client_);
100 102
101 AssociatedInterfaceRequest<Interface> request; 103 AssociatedInterfaceRequest<GenericInterface> request;
102 internal::AssociatedInterfaceRequestHelper::SetHandle( 104 internal::AssociatedInterfaceRequestHelper::SetHandle(
103 &request, endpoint_client_->PassHandle()); 105 &request, endpoint_client_->PassHandle());
104 106
105 endpoint_client_.reset(); 107 endpoint_client_.reset();
106 108
107 return request.Pass(); 109 return request.Pass();
108 } 110 }
109 111
110 // Sets an error handler that will be called if a connection error occurs. 112 // Sets an error handler that will be called if a connection error occurs.
111 void set_connection_error_handler(const Closure& error_handler) { 113 void set_connection_error_handler(const Closure& error_handler) {
(...skipping 18 matching lines...) Expand all
130 typename Interface::Stub_ stub_; 132 typename Interface::Stub_ stub_;
131 Interface* impl_; 133 Interface* impl_;
132 Closure connection_error_handler_; 134 Closure connection_error_handler_;
133 135
134 DISALLOW_COPY_AND_ASSIGN(AssociatedBinding); 136 DISALLOW_COPY_AND_ASSIGN(AssociatedBinding);
135 }; 137 };
136 138
137 } // namespace mojo 139 } // namespace mojo
138 140
139 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_BINDING_H_ 141 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_BINDING_H_
OLDNEW
« no previous file with comments | « mojo/common/weak_binding_set.h ('k') | mojo/public/cpp/bindings/associated_group.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698