Explicitly add python-numpy dependency to install-build-deps.
[chromium-blink-merge.git] / mojo / public / cpp / bindings / interface_request.h
blob0a6dc2c151682f3382a84259ffd69a2ded01a045
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.
5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_REQUEST_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_REQUEST_H_
8 #include "mojo/public/cpp/bindings/interface_ptr.h"
10 namespace mojo {
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() {}
19 InterfaceRequest(RValue other) { handle_ = other.object->handle_.Pass(); }
20 InterfaceRequest& operator=(RValue other) {
21 handle_ = other.object->handle_.Pass();
22 return *this;
25 // Returns true if the request has yet to be completed.
26 bool is_pending() const { return handle_.is_valid(); }
28 void Bind(ScopedMessagePipeHandle handle) { handle_ = handle.Pass(); }
30 ScopedMessagePipeHandle PassMessagePipe() { return handle_.Pass(); }
32 private:
33 ScopedMessagePipeHandle handle_;
36 template <typename Interface>
37 InterfaceRequest<Interface> MakeRequest(ScopedMessagePipeHandle handle) {
38 InterfaceRequest<Interface> request;
39 request.Bind(handle.Pass());
40 return request.Pass();
43 // Used to construct a request that synchronously binds an InterfacePtr<..>,
44 // making it immediately usable upon return. The resulting request object may
45 // then be later bound to an InterfaceImpl<..> via BindToRequest.
47 // Given the following interface:
49 // interface Foo {
50 // CreateBar(Bar& bar);
51 // }
53 // The caller of CreateBar would have code similar to the following:
55 // InterfacePtr<Foo> foo = ...;
56 // InterfacePtr<Bar> bar;
57 // foo->CreateBar(GetProxy(&bar));
59 // Upon return from CreateBar, |bar| is ready to have methods called on it.
61 template <typename Interface>
62 InterfaceRequest<Interface> GetProxy(InterfacePtr<Interface>* ptr) {
63 MessagePipe pipe;
64 ptr->Bind(pipe.handle0.Pass());
65 return MakeRequest<Interface>(pipe.handle1.Pass());
68 } // namespace mojo
70 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_REQUEST_H_