| 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 <stdint.h> | 8 #include <stdint.h> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/callback.h" | |
| 12 #include "base/logging.h" | 11 #include "base/logging.h" |
| 13 #include "base/macros.h" | 12 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 15 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "mojo/public/cpp/bindings/associated_group.h" | 16 #include "mojo/public/cpp/bindings/associated_group.h" |
| 18 #include "mojo/public/cpp/bindings/associated_interface_ptr_info.h" | 17 #include "mojo/public/cpp/bindings/associated_interface_ptr_info.h" |
| 19 #include "mojo/public/cpp/bindings/associated_interface_request.h" | 18 #include "mojo/public/cpp/bindings/associated_interface_request.h" |
| 19 #include "mojo/public/cpp/bindings/callback.h" |
| 20 #include "mojo/public/cpp/bindings/lib/associated_interface_ptr_state.h" | 20 #include "mojo/public/cpp/bindings/lib/associated_interface_ptr_state.h" |
| 21 | 21 |
| 22 namespace mojo { | 22 namespace mojo { |
| 23 | 23 |
| 24 // Represents the client side of an associated interface. It is similar to | 24 // Represents the client side of an associated interface. It is similar to |
| 25 // InterfacePtr, except that it doesn't own a message pipe handle. | 25 // InterfacePtr, except that it doesn't own a message pipe handle. |
| 26 template <typename Interface> | 26 template <typename Interface> |
| 27 class AssociatedInterfacePtr { | 27 class AssociatedInterfacePtr { |
| 28 public: | 28 public: |
| 29 // Constructs an unbound AssociatedInterfacePtr. | 29 // Constructs an unbound AssociatedInterfacePtr. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 | 85 |
| 86 // Returns the version number of the interface that the remote side supports. | 86 // Returns the version number of the interface that the remote side supports. |
| 87 uint32_t version() const { return internal_state_.version(); } | 87 uint32_t version() const { return internal_state_.version(); } |
| 88 | 88 |
| 89 // Returns the internal interface ID of this associated interface. | 89 // Returns the internal interface ID of this associated interface. |
| 90 uint32_t interface_id() const { return internal_state_.interface_id(); } | 90 uint32_t interface_id() const { return internal_state_.interface_id(); } |
| 91 | 91 |
| 92 // Queries the max version that the remote side supports. On completion, the | 92 // Queries the max version that the remote side supports. On completion, the |
| 93 // result will be returned as the input of |callback|. The version number of | 93 // result will be returned as the input of |callback|. The version number of |
| 94 // this object will also be updated. | 94 // this object will also be updated. |
| 95 void QueryVersion(const base::Callback<void(uint32_t)>& callback) { | 95 void QueryVersion(const Callback<void(uint32_t)>& callback) { |
| 96 internal_state_.QueryVersion(callback); | 96 internal_state_.QueryVersion(callback); |
| 97 } | 97 } |
| 98 | 98 |
| 99 // If the remote side doesn't support the specified version, it will close the | 99 // If the remote side doesn't support the specified version, it will close the |
| 100 // associated interface asynchronously. This does nothing if it's already | 100 // associated interface asynchronously. This does nothing if it's already |
| 101 // known that the remote side supports the specified version, i.e., if | 101 // known that the remote side supports the specified version, i.e., if |
| 102 // |version <= this->version()|. | 102 // |version <= this->version()|. |
| 103 // | 103 // |
| 104 // After calling RequireVersion() with a version not supported by the remote | 104 // After calling RequireVersion() with a version not supported by the remote |
| 105 // side, all subsequent calls to interface methods will be ignored. | 105 // side, all subsequent calls to interface methods will be ignored. |
| 106 void RequireVersion(uint32_t version) { | 106 void RequireVersion(uint32_t version) { |
| 107 internal_state_.RequireVersion(version); | 107 internal_state_.RequireVersion(version); |
| 108 } | 108 } |
| 109 | 109 |
| 110 // Closes the associated interface (if any) and returns the pointer to the | 110 // Closes the associated interface (if any) and returns the pointer to the |
| 111 // unbound state. | 111 // unbound state. |
| 112 void reset() { | 112 void reset() { |
| 113 State doomed; | 113 State doomed; |
| 114 internal_state_.Swap(&doomed); | 114 internal_state_.Swap(&doomed); |
| 115 } | 115 } |
| 116 | 116 |
| 117 // Indicates whether an error has been encountered. If true, method calls made | 117 // Indicates whether an error has been encountered. If true, method calls made |
| 118 // on this interface will be dropped (and may already have been dropped). | 118 // on this interface will be dropped (and may already have been dropped). |
| 119 bool encountered_error() const { return internal_state_.encountered_error(); } | 119 bool encountered_error() const { return internal_state_.encountered_error(); } |
| 120 | 120 |
| 121 // Registers a handler to receive error notifications. | 121 // Registers a handler to receive error notifications. |
| 122 // | 122 // |
| 123 // This method may only be called after the AssociatedInterfacePtr has been | 123 // This method may only be called after the AssociatedInterfacePtr has been |
| 124 // bound. | 124 // bound. |
| 125 void set_connection_error_handler(const base::Closure& error_handler) { | 125 void set_connection_error_handler(const Closure& error_handler) { |
| 126 internal_state_.set_connection_error_handler(error_handler); | 126 internal_state_.set_connection_error_handler(error_handler); |
| 127 } | 127 } |
| 128 | 128 |
| 129 // Unbinds and returns the associated interface pointer information which | 129 // Unbinds and returns the associated interface pointer information which |
| 130 // could be used to setup an AssociatedInterfacePtr again. This method may be | 130 // could be used to setup an AssociatedInterfacePtr again. This method may be |
| 131 // used to move the proxy to a different thread. | 131 // used to move the proxy to a different thread. |
| 132 // | 132 // |
| 133 // It is an error to call PassInterface() while there are pending responses. | 133 // It is an error to call PassInterface() while there are pending responses. |
| 134 // TODO: fix this restriction, it's not always obvious when there is a | 134 // TODO: fix this restriction, it's not always obvious when there is a |
| 135 // pending response. | 135 // pending response. |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 group->CreateAssociatedInterface(AssociatedGroup::WILL_PASS_REQUEST, | 199 group->CreateAssociatedInterface(AssociatedGroup::WILL_PASS_REQUEST, |
| 200 &ptr_info, &request); | 200 &ptr_info, &request); |
| 201 | 201 |
| 202 ptr->Bind(std::move(ptr_info), std::move(runner)); | 202 ptr->Bind(std::move(ptr_info), std::move(runner)); |
| 203 return request; | 203 return request; |
| 204 } | 204 } |
| 205 | 205 |
| 206 } // namespace mojo | 206 } // namespace mojo |
| 207 | 207 |
| 208 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_H_ | 208 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_H_ |
| OLD | NEW |