| 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 #include <cstddef> | 9 #include <cstddef> |
| 10 | 10 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 // Assigning nullptr to this class causes it to close the currently bound | 50 // Assigning nullptr to this class causes it to close the currently bound |
| 51 // message pipe (if any) and returns the pointer to the unbound state. | 51 // message pipe (if any) and returns the pointer to the unbound state. |
| 52 InterfacePtr& operator=(std::nullptr_t) { | 52 InterfacePtr& operator=(std::nullptr_t) { |
| 53 reset(); | 53 reset(); |
| 54 return *this; | 54 return *this; |
| 55 } | 55 } |
| 56 | 56 |
| 57 // Closes the bound message pipe (if any) on destruction. | 57 // Closes the bound message pipe (if any) on destruction. |
| 58 ~InterfacePtr() {} | 58 ~InterfacePtr() {} |
| 59 | 59 |
| 60 // If |info| is valid (containing a valid message pipe handle), returns an |
| 61 // InterfacePtr bound to it. Otherwise, returns an unbound InterfacePtr. The |
| 62 // specified |waiter| will be used as in the InterfacePtr::Bind() method. |
| 63 static InterfacePtr<Interface> Create( |
| 64 InterfaceHandle<Interface> info, |
| 65 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { |
| 66 InterfacePtr<Interface> ptr; |
| 67 if (info.is_valid()) |
| 68 ptr.Bind(info.Pass(), waiter); |
| 69 return ptr; |
| 70 } |
| 71 |
| 60 // Binds the InterfacePtr to a remote implementation of Interface. The | 72 // Binds the InterfacePtr to a remote implementation of Interface. The |
| 61 // |waiter| is used for receiving notifications when there is data to read | 73 // |waiter| is used for receiving notifications when there is data to read |
| 62 // from the message pipe. For most callers, the default |waiter| will be | 74 // from the message pipe. For most callers, the default |waiter| will be |
| 63 // sufficient. | 75 // sufficient. |
| 64 // | 76 // |
| 65 // Calling with an invalid |info| (containing an invalid message pipe handle) | 77 // Calling with an invalid |info| (containing an invalid message pipe handle) |
| 66 // has the same effect as reset(). In this case, the InterfacePtr is not | 78 // has the same effect as reset(). In this case, the InterfacePtr is not |
| 67 // considered as bound. | 79 // considered as bound. |
| 68 void Bind( | 80 void Bind( |
| 69 InterfaceHandle<Interface> info, | 81 InterfaceHandle<Interface> info, |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 return &internal_state_; | 177 return &internal_state_; |
| 166 } | 178 } |
| 167 | 179 |
| 168 private: | 180 private: |
| 169 typedef internal::InterfacePtrState<Interface> State; | 181 typedef internal::InterfacePtrState<Interface> State; |
| 170 mutable State internal_state_; | 182 mutable State internal_state_; |
| 171 | 183 |
| 172 MOJO_MOVE_ONLY_TYPE(InterfacePtr); | 184 MOJO_MOVE_ONLY_TYPE(InterfacePtr); |
| 173 }; | 185 }; |
| 174 | 186 |
| 175 // If |info| is valid (containing a valid message pipe handle), returns an | |
| 176 // InterfacePtr bound to it. Otherwise, returns an unbound InterfacePtr. The | |
| 177 // specified |waiter| will be used as in the InterfacePtr::Bind() method. | |
| 178 template <typename Interface> | |
| 179 InterfacePtr<Interface> MakeProxy( | |
| 180 InterfaceHandle<Interface> info, | |
| 181 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { | |
| 182 InterfacePtr<Interface> ptr; | |
| 183 if (info.is_valid()) | |
| 184 ptr.Bind(info.Pass(), waiter); | |
| 185 return ptr; | |
| 186 } | |
| 187 | |
| 188 } // namespace mojo | 187 } // namespace mojo |
| 189 | 188 |
| 190 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ | 189 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ |
| OLD | NEW |