OLD | NEW |
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 <utility> | 8 #include <utility> |
9 | 9 |
| 10 #include "base/macros.h" |
10 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
11 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
12 #include "mojo/public/cpp/bindings/interface_ptr.h" | 13 #include "mojo/public/cpp/bindings/interface_ptr.h" |
13 | 14 |
14 namespace mojo { | 15 namespace mojo { |
15 | 16 |
16 // Represents a request from a remote client for an implementation of Interface | 17 // Represents a request from a remote client for an implementation of Interface |
17 // over a specified message pipe. The implementor of the interface should | 18 // over a specified message pipe. The implementor of the interface should |
18 // remove the message pipe by calling PassMessagePipe() and bind it to the | 19 // remove the message pipe by calling PassMessagePipe() and bind it to the |
19 // implementation. If this is not done, the InterfaceRequest will automatically | 20 // implementation. If this is not done, the InterfaceRequest will automatically |
20 // close the pipe on destruction. Can also represent the absence of a request | 21 // close the pipe on destruction. Can also represent the absence of a request |
21 // if the client did not provide a message pipe. | 22 // if the client did not provide a message pipe. |
22 template <typename Interface> | 23 template <typename Interface> |
23 class InterfaceRequest { | 24 class InterfaceRequest { |
24 MOVE_ONLY_TYPE_FOR_CPP_03(InterfaceRequest); | |
25 public: | 25 public: |
26 // Constructs an empty InterfaceRequest, representing that the client is not | 26 // Constructs an empty InterfaceRequest, representing that the client is not |
27 // requesting an implementation of Interface. | 27 // requesting an implementation of Interface. |
28 InterfaceRequest() {} | 28 InterfaceRequest() {} |
29 InterfaceRequest(decltype(nullptr)) {} | 29 InterfaceRequest(decltype(nullptr)) {} |
30 | 30 |
31 // Takes the message pipe from another InterfaceRequest. | 31 // Takes the message pipe from another InterfaceRequest. |
32 InterfaceRequest(InterfaceRequest&& other) { | 32 InterfaceRequest(InterfaceRequest&& other) { |
33 handle_ = std::move(other.handle_); | 33 handle_ = std::move(other.handle_); |
34 } | 34 } |
(...skipping 24 matching lines...) Expand all Loading... |
59 if (this == &other) | 59 if (this == &other) |
60 return true; | 60 return true; |
61 | 61 |
62 // Now that the two refer to different objects, they are equivalent if | 62 // Now that the two refer to different objects, they are equivalent if |
63 // and only if they are both invalid. | 63 // and only if they are both invalid. |
64 return !is_pending() && !other.is_pending(); | 64 return !is_pending() && !other.is_pending(); |
65 } | 65 } |
66 | 66 |
67 private: | 67 private: |
68 ScopedMessagePipeHandle handle_; | 68 ScopedMessagePipeHandle handle_; |
| 69 |
| 70 DISALLOW_COPY_AND_ASSIGN(InterfaceRequest); |
69 }; | 71 }; |
70 | 72 |
71 // Makes an InterfaceRequest bound to the specified message pipe. If |handle| | 73 // Makes an InterfaceRequest bound to the specified message pipe. If |handle| |
72 // is empty or invalid, the resulting InterfaceRequest will represent the | 74 // is empty or invalid, the resulting InterfaceRequest will represent the |
73 // absence of a request. | 75 // absence of a request. |
74 template <typename Interface> | 76 template <typename Interface> |
75 InterfaceRequest<Interface> MakeRequest(ScopedMessagePipeHandle handle) { | 77 InterfaceRequest<Interface> MakeRequest(ScopedMessagePipeHandle handle) { |
76 InterfaceRequest<Interface> request; | 78 InterfaceRequest<Interface> request; |
77 request.Bind(std::move(handle)); | 79 request.Bind(std::move(handle)); |
78 return std::move(request); | 80 return std::move(request); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 bool FuseInterface(InterfaceRequest<Interface> request, | 140 bool FuseInterface(InterfaceRequest<Interface> request, |
139 InterfacePtrInfo<Interface> proxy_info) { | 141 InterfacePtrInfo<Interface> proxy_info) { |
140 MojoResult result = FuseMessagePipes(request.PassMessagePipe(), | 142 MojoResult result = FuseMessagePipes(request.PassMessagePipe(), |
141 proxy_info.PassHandle()); | 143 proxy_info.PassHandle()); |
142 return result == MOJO_RESULT_OK; | 144 return result == MOJO_RESULT_OK; |
143 } | 145 } |
144 | 146 |
145 } // namespace mojo | 147 } // namespace mojo |
146 | 148 |
147 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_REQUEST_H_ | 149 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_REQUEST_H_ |
OLD | NEW |