| 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 <cstddef> |
| 9 |
| 8 #include "mojo/public/cpp/system/message_pipe.h" | 10 #include "mojo/public/cpp/system/message_pipe.h" |
| 9 | 11 |
| 10 namespace mojo { | 12 namespace mojo { |
| 11 | 13 |
| 12 template <typename I> | 14 template <typename I> |
| 13 class InterfacePtr; | 15 class InterfacePtr; |
| 14 | 16 |
| 15 template <typename I> | 17 template <typename I> |
| 16 class InterfacePtrInfo; | 18 class InterfacePtrInfo; |
| 17 | 19 |
| 18 // Represents a request from a remote client for an implementation of Interface | 20 // Represents a request from a remote client for an implementation of Interface |
| 19 // over a specified message pipe. The implementor of the interface should | 21 // over a specified message pipe. The implementor of the interface should |
| 20 // remove the message pipe by calling PassMessagePipe() and bind it to the | 22 // remove the message pipe by calling PassMessagePipe() and bind it to the |
| 21 // implementation. If this is not done, the InterfaceRequest will automatically | 23 // implementation. If this is not done, the InterfaceRequest will automatically |
| 22 // close the pipe on destruction. Can also represent the absence of a request | 24 // close the pipe on destruction. Can also represent the absence of a request |
| 23 // if the client did not provide a message pipe. | 25 // if the client did not provide a message pipe. |
| 24 template <typename Interface> | 26 template <typename Interface> |
| 25 class InterfaceRequest { | 27 class InterfaceRequest { |
| 26 public: | 28 public: |
| 27 // Constructs an empty InterfaceRequest, representing that the client is not | 29 // Constructs an empty InterfaceRequest, representing that the client is not |
| 28 // requesting an implementation of Interface. | 30 // requesting an implementation of Interface. |
| 29 InterfaceRequest() {} | 31 InterfaceRequest() {} |
| 30 InterfaceRequest(decltype(nullptr)) {} | 32 InterfaceRequest(std::nullptr_t) {} |
| 31 | 33 |
| 32 // Takes the message pipe from another InterfaceRequest. | 34 // Takes the message pipe from another InterfaceRequest. |
| 33 InterfaceRequest(InterfaceRequest&& other) { handle_ = other.handle_.Pass(); } | 35 InterfaceRequest(InterfaceRequest&& other) { handle_ = other.handle_.Pass(); } |
| 34 InterfaceRequest& operator=(InterfaceRequest&& other) { | 36 InterfaceRequest& operator=(InterfaceRequest&& other) { |
| 35 handle_ = other.handle_.Pass(); | 37 handle_ = other.handle_.Pass(); |
| 36 return *this; | 38 return *this; |
| 37 } | 39 } |
| 38 | 40 |
| 39 // Assigning to nullptr resets the InterfaceRequest to an empty state, | 41 // Assigning to nullptr resets the InterfaceRequest to an empty state, |
| 40 // closing the message pipe currently bound to it (if any). | 42 // closing the message pipe currently bound to it (if any). |
| 41 InterfaceRequest& operator=(decltype(nullptr)) { | 43 InterfaceRequest& operator=(std::nullptr_t) { |
| 42 handle_.reset(); | 44 handle_.reset(); |
| 43 return *this; | 45 return *this; |
| 44 } | 46 } |
| 45 | 47 |
| 46 // Binds the request to a message pipe over which Interface is to be | 48 // Binds the request to a message pipe over which Interface is to be |
| 47 // requested. If the request is already bound to a message pipe, the current | 49 // requested. If the request is already bound to a message pipe, the current |
| 48 // message pipe will be closed. | 50 // message pipe will be closed. |
| 49 void Bind(ScopedMessagePipeHandle handle) { handle_ = handle.Pass(); } | 51 void Bind(ScopedMessagePipeHandle handle) { handle_ = handle.Pass(); } |
| 50 | 52 |
| 51 // Indicates whether the request currently contains a valid message pipe. | 53 // Indicates whether the request currently contains a valid message pipe. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 template <typename Interface> | 118 template <typename Interface> |
| 117 InterfaceRequest<Interface> GetProxy(InterfacePtr<Interface>* ptr) { | 119 InterfaceRequest<Interface> GetProxy(InterfacePtr<Interface>* ptr) { |
| 118 MessagePipe pipe; | 120 MessagePipe pipe; |
| 119 ptr->Bind(InterfacePtrInfo<Interface>(pipe.handle0.Pass(), 0u)); | 121 ptr->Bind(InterfacePtrInfo<Interface>(pipe.handle0.Pass(), 0u)); |
| 120 return MakeRequest<Interface>(pipe.handle1.Pass()); | 122 return MakeRequest<Interface>(pipe.handle1.Pass()); |
| 121 } | 123 } |
| 122 | 124 |
| 123 } // namespace mojo | 125 } // namespace mojo |
| 124 | 126 |
| 125 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_REQUEST_H_ | 127 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_REQUEST_H_ |
| OLD | NEW |