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> |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 State state; | 97 State state; |
98 internal_state_.Swap(&state); | 98 internal_state_.Swap(&state); |
99 return state.PassMessagePipe(); | 99 return state.PassMessagePipe(); |
100 } | 100 } |
101 | 101 |
102 // DO NOT USE. Exposed only for internal use and for testing. | 102 // DO NOT USE. Exposed only for internal use and for testing. |
103 internal::InterfacePtrState<Interface>* internal_state() { | 103 internal::InterfacePtrState<Interface>* internal_state() { |
104 return &internal_state_; | 104 return &internal_state_; |
105 } | 105 } |
106 | 106 |
107 // Allow InterfacePtr<> to be used in boolean expressions, but not | |
yzshen1
2014/07/18 19:17:43
One thing that may worth considering:
I just lande
Elliot Glaysher
2014/07/18 19:32:15
What do you propose replacing get() with?
yzshen1
2014/07/18 19:38:45
Maybe an IsBound() method on the internal state, w
| |
108 // implicitly convertible to a real bool (which is dangerous). | |
109 private: | |
110 typedef internal::InterfacePtrState<Interface> InterfacePtr::*Testable; | |
111 | |
112 public: | |
113 operator Testable() const { | |
114 return get() ? &InterfacePtr::internal_state_ : NULL; | |
115 } | |
116 | |
107 private: | 117 private: |
108 typedef internal::InterfacePtrState<Interface> State; | 118 typedef internal::InterfacePtrState<Interface> State; |
109 mutable State internal_state_; | 119 mutable State internal_state_; |
110 }; | 120 }; |
111 | 121 |
112 // Takes a handle to the proxy end-point of a pipe. On the other end is | 122 // Takes a handle to the proxy end-point of a pipe. On the other end is |
113 // presumed to be an interface implementation of type |Interface|. Returns a | 123 // presumed to be an interface implementation of type |Interface|. Returns a |
114 // generated proxy to that interface, which may be used on the current thread. | 124 // generated proxy to that interface, which may be used on the current thread. |
115 // It is valid to call set_client on the returned InterfacePtr<..> to set an | 125 // It is valid to call set_client on the returned InterfacePtr<..> to set an |
116 // instance of Interface::Client. | 126 // instance of Interface::Client. |
117 template <typename Interface> | 127 template <typename Interface> |
118 InterfacePtr<Interface> MakeProxy( | 128 InterfacePtr<Interface> MakeProxy( |
119 ScopedMessagePipeHandle handle, | 129 ScopedMessagePipeHandle handle, |
120 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { | 130 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { |
121 InterfacePtr<Interface> ptr; | 131 InterfacePtr<Interface> ptr; |
122 if (handle.is_valid()) | 132 if (handle.is_valid()) |
123 ptr.Bind(handle.Pass(), waiter); | 133 ptr.Bind(handle.Pass(), waiter); |
124 return ptr.Pass(); | 134 return ptr.Pass(); |
125 } | 135 } |
126 | 136 |
127 } // namespace mojo | 137 } // namespace mojo |
128 | 138 |
129 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ | 139 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ |
OLD | NEW |