| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_ASSOCIATED_INTERFACE_PTR_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_H_ |
| 7 | 7 |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "mojo/public/cpp/bindings/associated_group.h" | 10 #include "mojo/public/cpp/bindings/associated_group.h" |
| 11 #include "mojo/public/cpp/bindings/associated_interface_ptr_info.h" | 11 #include "mojo/public/cpp/bindings/associated_interface_ptr_info.h" |
| 12 #include "mojo/public/cpp/bindings/associated_interface_request.h" | 12 #include "mojo/public/cpp/bindings/associated_interface_request.h" |
| 13 #include "mojo/public/cpp/bindings/callback.h" | 13 #include "mojo/public/cpp/bindings/callback.h" |
| 14 #include "mojo/public/cpp/bindings/lib/associated_interface_ptr_state.h" | 14 #include "mojo/public/cpp/bindings/lib/associated_interface_ptr_state.h" |
| 15 | 15 |
| 16 namespace mojo { | 16 namespace mojo { |
| 17 | 17 |
| 18 // Represents the client side of an associated interface. It is similar to | 18 // Represents the client side of an associated interface. It is similar to |
| 19 // InterfacePtr, except that it doesn't own a message pipe handle. | 19 // InterfacePtr, except that it doesn't own a message pipe handle. |
| 20 template <typename Interface> | 20 template <typename Interface> |
| 21 class AssociatedInterfacePtr { | 21 class AssociatedInterfacePtr { |
| 22 DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND(AssociatedInterfacePtr) | 22 DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND(AssociatedInterfacePtr) |
| 23 | 23 |
| 24 public: | 24 public: |
| 25 using GenericInterface = typename Interface::GenericInterface; |
| 26 |
| 25 // Constructs an unbound AssociatedInterfacePtr. | 27 // Constructs an unbound AssociatedInterfacePtr. |
| 26 AssociatedInterfacePtr() {} | 28 AssociatedInterfacePtr() {} |
| 27 AssociatedInterfacePtr(decltype(nullptr)) {} | 29 AssociatedInterfacePtr(decltype(nullptr)) {} |
| 28 | 30 |
| 29 AssociatedInterfacePtr(AssociatedInterfacePtr&& other) { | 31 AssociatedInterfacePtr(AssociatedInterfacePtr&& other) { |
| 30 internal_state_.Swap(&other.internal_state_); | 32 internal_state_.Swap(&other.internal_state_); |
| 31 } | 33 } |
| 32 | 34 |
| 33 AssociatedInterfacePtr& operator=(AssociatedInterfacePtr&& other) { | 35 AssociatedInterfacePtr& operator=(AssociatedInterfacePtr&& other) { |
| 34 reset(); | 36 reset(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 45 | 47 |
| 46 ~AssociatedInterfacePtr() {} | 48 ~AssociatedInterfacePtr() {} |
| 47 | 49 |
| 48 // Sets up this object as the client side of an associated interface. | 50 // Sets up this object as the client side of an associated interface. |
| 49 // Calling with an invalid |info| has the same effect as reset(). In this | 51 // Calling with an invalid |info| has the same effect as reset(). In this |
| 50 // case, the AssociatedInterfacePtr is not considered as bound. | 52 // case, the AssociatedInterfacePtr is not considered as bound. |
| 51 // | 53 // |
| 52 // NOTE: Please see the comments of | 54 // NOTE: Please see the comments of |
| 53 // AssociatedGroup.CreateAssociatedInterface() about when you can use this | 55 // AssociatedGroup.CreateAssociatedInterface() about when you can use this |
| 54 // object to make calls. | 56 // object to make calls. |
| 55 void Bind(AssociatedInterfacePtrInfo<Interface> info) { | 57 void Bind(AssociatedInterfacePtrInfo<GenericInterface> info) { |
| 56 reset(); | 58 reset(); |
| 57 | 59 |
| 58 bool is_local = | 60 bool is_local = |
| 59 internal::AssociatedInterfacePtrInfoHelper::GetHandle(&info).is_local(); | 61 internal::AssociatedInterfacePtrInfoHelper::GetHandle(&info).is_local(); |
| 60 | 62 |
| 61 DCHECK(is_local) << "The AssociatedInterfacePtrInfo is supposed to be used " | 63 DCHECK(is_local) << "The AssociatedInterfacePtrInfo is supposed to be used " |
| 62 "at the other side of the message pipe."; | 64 "at the other side of the message pipe."; |
| 63 | 65 |
| 64 if (info.is_valid() && is_local) | 66 if (info.is_valid() && is_local) |
| 65 internal_state_.Bind(info.Pass()); | 67 internal_state_.Bind(info.Pass()); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 internal_state_.set_connection_error_handler(error_handler); | 115 internal_state_.set_connection_error_handler(error_handler); |
| 114 } | 116 } |
| 115 | 117 |
| 116 // Unbinds and returns the associated interface pointer information which | 118 // Unbinds and returns the associated interface pointer information which |
| 117 // could be used to setup an AssociatedInterfacePtr again. This method may be | 119 // could be used to setup an AssociatedInterfacePtr again. This method may be |
| 118 // used to move the proxy to a different thread. | 120 // used to move the proxy to a different thread. |
| 119 // | 121 // |
| 120 // It is an error to call PassInterface() while there are pending responses. | 122 // It is an error to call PassInterface() while there are pending responses. |
| 121 // TODO: fix this restriction, it's not always obvious when there is a | 123 // TODO: fix this restriction, it's not always obvious when there is a |
| 122 // pending response. | 124 // pending response. |
| 123 AssociatedInterfacePtrInfo<Interface> PassInterface() { | 125 AssociatedInterfacePtrInfo<GenericInterface> PassInterface() { |
| 124 DCHECK(!internal_state_.has_pending_callbacks()); | 126 DCHECK(!internal_state_.has_pending_callbacks()); |
| 125 State state; | 127 State state; |
| 126 internal_state_.Swap(&state); | 128 internal_state_.Swap(&state); |
| 127 | 129 |
| 128 return state.PassInterface(); | 130 return state.PassInterface(); |
| 129 } | 131 } |
| 130 | 132 |
| 131 // Returns the associated group that this object belongs to. Returns null if | 133 // Returns the associated group that this object belongs to. Returns null if |
| 132 // the object is not bound. | 134 // the object is not bound. |
| 133 AssociatedGroup* associated_group() { | 135 AssociatedGroup* associated_group() { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 // Creates an associated interface. The output |ptr| should be used locally | 168 // Creates an associated interface. The output |ptr| should be used locally |
| 167 // while the returned request should be passed through the message pipe endpoint | 169 // while the returned request should be passed through the message pipe endpoint |
| 168 // referred to by |associated_group| to setup the corresponding asssociated | 170 // referred to by |associated_group| to setup the corresponding asssociated |
| 169 // interface implementation at the remote side. | 171 // interface implementation at the remote side. |
| 170 // | 172 // |
| 171 // NOTE: |ptr| should NOT be used to make calls before the request is sent. | 173 // NOTE: |ptr| should NOT be used to make calls before the request is sent. |
| 172 // Violating that will cause the message pipe to be closed. On the other hand, | 174 // Violating that will cause the message pipe to be closed. On the other hand, |
| 173 // as soon as the request is sent, |ptr| is usable. There is no need to wait | 175 // as soon as the request is sent, |ptr| is usable. There is no need to wait |
| 174 // until the request is bound to an implementation at the remote side. | 176 // until the request is bound to an implementation at the remote side. |
| 175 template <typename Interface> | 177 template <typename Interface> |
| 176 AssociatedInterfaceRequest<Interface> GetProxy( | 178 AssociatedInterfaceRequest<typename Interface::GenericInterface> GetProxy( |
| 177 AssociatedInterfacePtr<Interface>* ptr, | 179 AssociatedInterfacePtr<Interface>* ptr, |
| 178 AssociatedGroup* group) { | 180 AssociatedGroup* group) { |
| 179 AssociatedInterfaceRequest<Interface> request; | 181 AssociatedInterfaceRequest<typename Interface::GenericInterface> request; |
| 180 AssociatedInterfacePtrInfo<Interface> ptr_info; | 182 AssociatedInterfacePtrInfo<typename Interface::GenericInterface> ptr_info; |
| 181 group->CreateAssociatedInterface(AssociatedGroup::WILL_PASS_REQUEST, | 183 group->CreateAssociatedInterface(AssociatedGroup::WILL_PASS_REQUEST, |
| 182 &ptr_info, &request); | 184 &ptr_info, &request); |
| 183 | 185 |
| 184 ptr->Bind(ptr_info.Pass()); | 186 ptr->Bind(ptr_info.Pass()); |
| 185 return request.Pass(); | 187 return request.Pass(); |
| 186 } | 188 } |
| 187 | 189 |
| 188 } // namespace mojo | 190 } // namespace mojo |
| 189 | 191 |
| 190 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_H_ | 192 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_H_ |
| OLD | NEW |