| 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 <algorithm> | 8 #include <algorithm> |
| 9 | 9 |
| 10 #include "mojo/public/cpp/bindings/error_handler.h" | 10 #include "mojo/public/cpp/bindings/error_handler.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 return &internal_state_; | 102 return &internal_state_; |
| 103 } | 103 } |
| 104 | 104 |
| 105 // Allow InterfacePtr<> to be used in boolean expressions, but not | 105 // Allow InterfacePtr<> to be used in boolean expressions, but not |
| 106 // implicitly convertible to a real bool (which is dangerous). | 106 // implicitly convertible to a real bool (which is dangerous). |
| 107 private: | 107 private: |
| 108 typedef internal::InterfacePtrState<Interface> InterfacePtr::*Testable; | 108 typedef internal::InterfacePtrState<Interface> InterfacePtr::*Testable; |
| 109 | 109 |
| 110 public: | 110 public: |
| 111 operator Testable() const { | 111 operator Testable() const { |
| 112 return internal_state_.is_bound() ? &InterfacePtr::internal_state_ : NULL; | 112 return internal_state_.is_bound() ? &InterfacePtr::internal_state_ |
| 113 : nullptr; |
| 113 } | 114 } |
| 114 | 115 |
| 115 private: | 116 private: |
| 116 typedef internal::InterfacePtrState<Interface> State; | 117 typedef internal::InterfacePtrState<Interface> State; |
| 117 mutable State internal_state_; | 118 mutable State internal_state_; |
| 118 }; | 119 }; |
| 119 | 120 |
| 120 // Takes a handle to the proxy end-point of a pipe. On the other end is | 121 // Takes a handle to the proxy end-point of a pipe. On the other end is |
| 121 // presumed to be an interface implementation of type |Interface|. Returns a | 122 // presumed to be an interface implementation of type |Interface|. Returns a |
| 122 // generated proxy to that interface, which may be used on the current thread. | 123 // generated proxy to that interface, which may be used on the current thread. |
| 123 // It is valid to call set_client on the returned InterfacePtr<..> to set an | 124 // It is valid to call set_client on the returned InterfacePtr<..> to set an |
| 124 // instance of Interface::Client. | 125 // instance of Interface::Client. |
| 125 template <typename Interface> | 126 template <typename Interface> |
| 126 InterfacePtr<Interface> MakeProxy( | 127 InterfacePtr<Interface> MakeProxy( |
| 127 ScopedMessagePipeHandle handle, | 128 ScopedMessagePipeHandle handle, |
| 128 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { | 129 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { |
| 129 InterfacePtr<Interface> ptr; | 130 InterfacePtr<Interface> ptr; |
| 130 if (handle.is_valid()) | 131 if (handle.is_valid()) |
| 131 ptr.Bind(handle.Pass(), waiter); | 132 ptr.Bind(handle.Pass(), waiter); |
| 132 return ptr.Pass(); | 133 return ptr.Pass(); |
| 133 } | 134 } |
| 134 | 135 |
| 135 } // namespace mojo | 136 } // namespace mojo |
| 136 | 137 |
| 137 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ | 138 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ |
| OLD | NEW |