| 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_PTR_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ |
| 7 | 7 |
| 8 #include <assert.h> | 8 #include <assert.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| 11 | 11 |
| 12 #include "mojo/public/cpp/bindings/error_handler.h" | 12 #include "mojo/public/cpp/bindings/error_handler.h" |
| 13 #include "mojo/public/cpp/bindings/lib/interface_ptr_internal.h" | 13 #include "mojo/public/cpp/bindings/lib/interface_ptr_internal.h" |
| 14 #include "mojo/public/cpp/environment/environment.h" |
| 14 #include "mojo/public/cpp/system/macros.h" | 15 #include "mojo/public/cpp/system/macros.h" |
| 15 | 16 |
| 16 namespace mojo { | 17 namespace mojo { |
| 17 class ErrorHandler; | 18 class ErrorHandler; |
| 18 | 19 |
| 19 // InterfacePtr represents a proxy to a remote instance of an interface. | 20 // InterfacePtr represents a proxy to a remote instance of an interface. |
| 20 template <typename Interface> | 21 template <typename Interface> |
| 21 class InterfacePtr { | 22 class InterfacePtr { |
| 22 MOJO_MOVE_ONLY_TYPE_FOR_CPP_03(InterfacePtr, RValue) | 23 MOJO_MOVE_ONLY_TYPE_FOR_CPP_03(InterfacePtr, RValue) |
| 23 public: | 24 public: |
| (...skipping 24 matching lines...) Expand all Loading... |
| 48 // This method configures the InterfacePtr<..> to be a proxy to a remote | 49 // This method configures the InterfacePtr<..> to be a proxy to a remote |
| 49 // object on the other end of the given pipe. | 50 // object on the other end of the given pipe. |
| 50 // | 51 // |
| 51 // The proxy is bound to the current thread, which means its methods may | 52 // The proxy is bound to the current thread, which means its methods may |
| 52 // only be called on the current thread. | 53 // only be called on the current thread. |
| 53 // | 54 // |
| 54 // To move a bound InterfacePtr<..> to another thread, call | 55 // To move a bound InterfacePtr<..> to another thread, call |
| 55 // ResetAndReturnMessagePipe. Then create a new InterfacePtr<..> on another | 56 // ResetAndReturnMessagePipe. Then create a new InterfacePtr<..> on another |
| 56 // thread, and bind the new InterfacePtr<..> to the message pipe on that | 57 // thread, and bind the new InterfacePtr<..> to the message pipe on that |
| 57 // thread. | 58 // thread. |
| 58 void Bind(ScopedMessagePipeHandle handle, | 59 void Bind( |
| 59 const MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter()) { | 60 ScopedMessagePipeHandle handle, |
| 61 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { |
| 60 reset(); | 62 reset(); |
| 61 internal_state_.ConfigureProxy(handle.Pass(), waiter); | 63 internal_state_.ConfigureProxy(handle.Pass(), waiter); |
| 62 } | 64 } |
| 63 | 65 |
| 64 // The client interface may only be set after this InterfacePtr<..> is bound. | 66 // The client interface may only be set after this InterfacePtr<..> is bound. |
| 65 void set_client(typename Interface::Client* client) { | 67 void set_client(typename Interface::Client* client) { |
| 66 internal_state_.set_client(client); | 68 internal_state_.set_client(client); |
| 67 } | 69 } |
| 68 | 70 |
| 69 // This method may be called to query if the underlying pipe has encountered | 71 // This method may be called to query if the underlying pipe has encountered |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 }; | 105 }; |
| 104 | 106 |
| 105 // Takes a handle to the proxy end-point of a pipe. On the other end is | 107 // Takes a handle to the proxy end-point of a pipe. On the other end is |
| 106 // presumed to be an interface implementation of type |Interface|. Returns a | 108 // presumed to be an interface implementation of type |Interface|. Returns a |
| 107 // generated proxy to that interface, which may be used on the current thread. | 109 // generated proxy to that interface, which may be used on the current thread. |
| 108 // It is valid to call set_client on the returned InterfacePtr<..> to set an | 110 // It is valid to call set_client on the returned InterfacePtr<..> to set an |
| 109 // instance of Interface::Client. | 111 // instance of Interface::Client. |
| 110 template <typename Interface> | 112 template <typename Interface> |
| 111 InterfacePtr<Interface> MakeProxy( | 113 InterfacePtr<Interface> MakeProxy( |
| 112 ScopedMessagePipeHandle handle, | 114 ScopedMessagePipeHandle handle, |
| 113 const MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter()) { | 115 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { |
| 114 InterfacePtr<Interface> ptr; | 116 InterfacePtr<Interface> ptr; |
| 115 if (handle.is_valid()) | 117 if (handle.is_valid()) |
| 116 ptr.Bind(handle.Pass(), waiter); | 118 ptr.Bind(handle.Pass(), waiter); |
| 117 return ptr.Pass(); | 119 return ptr.Pass(); |
| 118 } | 120 } |
| 119 | 121 |
| 120 } // namespace mojo | 122 } // namespace mojo |
| 121 | 123 |
| 122 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ | 124 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ |
| OLD | NEW |