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

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

Issue 1055703002: Gather trace data by waiting on handles with a fixed timeout (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 8 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_BINDING_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_
7 7
8 #include "mojo/public/c/environment/async_waiter.h" 8 #include "mojo/public/c/environment/async_waiter.h"
9 #include "mojo/public/cpp/bindings/error_handler.h" 9 #include "mojo/public/cpp/bindings/error_handler.h"
10 #include "mojo/public/cpp/bindings/interface_ptr.h" 10 #include "mojo/public/cpp/bindings/interface_ptr.h"
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 // implementation by removing the message pipe endpoint from |request| and 140 // implementation by removing the message pipe endpoint from |request| and
141 // binding it to the previously specified implementation. See class comment 141 // binding it to the previously specified implementation. See class comment
142 // for definition of |waiter|. 142 // for definition of |waiter|.
143 void Bind( 143 void Bind(
144 InterfaceRequest<Interface> request, 144 InterfaceRequest<Interface> request,
145 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { 145 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) {
146 Bind(request.PassMessagePipe(), waiter); 146 Bind(request.PassMessagePipe(), waiter);
147 } 147 }
148 148
149 // Blocks the calling thread until either a call arrives on the previously 149 // Blocks the calling thread until either a call arrives on the previously
150 // bound message pipe, or an error occurs. 150 // bound message pipe, the deadline is exceeded, or an error occurs. Returns
151 bool WaitForIncomingMethodCall() { 151 // true if a method was successfully read and dispatched.
152 bool WaitForIncomingMethodCall(
153 MojoDeadline deadline = MOJO_DEADLINE_INDEFINITE) {
152 MOJO_DCHECK(internal_router_); 154 MOJO_DCHECK(internal_router_);
153 return internal_router_->WaitForIncomingMessage(); 155 return internal_router_->WaitForIncomingMessage(deadline);
154 } 156 }
155 157
156 // Closes the message pipe that was previously bound. Put this object into a 158 // Closes the message pipe that was previously bound. Put this object into a
157 // state where it can be rebound to a new pipe. 159 // state where it can be rebound to a new pipe.
158 void Close() { 160 void Close() {
159 MOJO_DCHECK(internal_router_); 161 MOJO_DCHECK(internal_router_);
160 internal_router_->CloseMessagePipe(); 162 internal_router_->CloseMessagePipe();
161 DestroyRouter(); 163 DestroyRouter();
162 } 164 }
163 165
(...skipping 23 matching lines...) Expand all
187 } 189 }
188 190
189 // Returns the interface implementation that was previously specified. Caller 191 // Returns the interface implementation that was previously specified. Caller
190 // does not take ownership. 192 // does not take ownership.
191 Interface* impl() { return impl_; } 193 Interface* impl() { return impl_; }
192 194
193 // Indicates whether the binding has been completed (i.e., whether a message 195 // Indicates whether the binding has been completed (i.e., whether a message
194 // pipe has been bound to the implementation). 196 // pipe has been bound to the implementation).
195 bool is_bound() const { return !!internal_router_; } 197 bool is_bound() const { return !!internal_router_; }
196 198
199 // Returns the value of the handle currently bound to this Binding which can
200 // be used to make explicit Wait/WaitMany calls. Requires that the Binding be
201 // bound. Ownership of the handle is retained by the Binding, it is not
202 // transferred to the caller.
203 MessagePipeHandle handle() const {
204 MOJO_DCHECK(is_bound());
205 return internal_router_->handle();
206 }
207
197 // Exposed for testing, should not generally be used. 208 // Exposed for testing, should not generally be used.
198 internal::Router* internal_router() { return internal_router_; } 209 internal::Router* internal_router() { return internal_router_; }
199 210
200 private: 211 private:
201 void DestroyRouter() { 212 void DestroyRouter() {
202 internal_router_->set_error_handler(nullptr); 213 internal_router_->set_error_handler(nullptr);
203 delete internal_router_; 214 delete internal_router_;
204 internal_router_ = nullptr; 215 internal_router_ = nullptr;
205 } 216 }
206 217
207 internal::Router* internal_router_ = nullptr; 218 internal::Router* internal_router_ = nullptr;
208 typename Interface::Stub_ stub_; 219 typename Interface::Stub_ stub_;
209 Interface* impl_; 220 Interface* impl_;
210 ErrorHandler* error_handler_ = nullptr; 221 ErrorHandler* error_handler_ = nullptr;
211 222
212 MOJO_DISALLOW_COPY_AND_ASSIGN(Binding); 223 MOJO_DISALLOW_COPY_AND_ASSIGN(Binding);
213 }; 224 };
214 225
215 } // namespace mojo 226 } // namespace mojo
216 227
217 #endif // MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_ 228 #endif // MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698