| 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_INFO_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_INFO_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_INFO_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_INFO_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "mojo/public/cpp/bindings/lib/scoped_interface_endpoint_handle.h" | 12 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" |
| 13 | 13 |
| 14 namespace mojo { | 14 namespace mojo { |
| 15 | 15 |
| 16 namespace internal { | |
| 17 class AssociatedInterfacePtrInfoHelper; | |
| 18 } | |
| 19 | |
| 20 // AssociatedInterfacePtrInfo stores necessary information to construct an | 16 // AssociatedInterfacePtrInfo stores necessary information to construct an |
| 21 // associated interface pointer. It is similar to InterfacePtrInfo except that | 17 // associated interface pointer. It is similar to InterfacePtrInfo except that |
| 22 // it doesn't own a message pipe handle. | 18 // it doesn't own a message pipe handle. |
| 23 template <typename Interface> | 19 template <typename Interface> |
| 24 class AssociatedInterfacePtrInfo { | 20 class AssociatedInterfacePtrInfo { |
| 25 DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND(AssociatedInterfacePtrInfo); | 21 DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND(AssociatedInterfacePtrInfo); |
| 26 | 22 |
| 27 public: | 23 public: |
| 28 AssociatedInterfacePtrInfo() : version_(0u) {} | 24 AssociatedInterfacePtrInfo() : version_(0u) {} |
| 29 | 25 |
| 30 AssociatedInterfacePtrInfo(AssociatedInterfacePtrInfo&& other) | 26 AssociatedInterfacePtrInfo(AssociatedInterfacePtrInfo&& other) |
| 31 : handle_(std::move(other.handle_)), version_(other.version_) { | 27 : handle_(std::move(other.handle_)), version_(other.version_) { |
| 32 other.version_ = 0u; | 28 other.version_ = 0u; |
| 33 } | 29 } |
| 34 | 30 |
| 31 AssociatedInterfacePtrInfo(ScopedInterfaceEndpointHandle handle, |
| 32 uint32_t version) |
| 33 : handle_(std::move(handle)), version_(version) {} |
| 34 |
| 35 ~AssociatedInterfacePtrInfo() {} | 35 ~AssociatedInterfacePtrInfo() {} |
| 36 | 36 |
| 37 AssociatedInterfacePtrInfo& operator=(AssociatedInterfacePtrInfo&& other) { | 37 AssociatedInterfacePtrInfo& operator=(AssociatedInterfacePtrInfo&& other) { |
| 38 if (this != &other) { | 38 if (this != &other) { |
| 39 handle_ = std::move(other.handle_); | 39 handle_ = std::move(other.handle_); |
| 40 version_ = other.version_; | 40 version_ = other.version_; |
| 41 other.version_ = 0u; | 41 other.version_ = 0u; |
| 42 } | 42 } |
| 43 | 43 |
| 44 return *this; | 44 return *this; |
| 45 } | 45 } |
| 46 | 46 |
| 47 bool is_valid() const { return handle_.is_valid(); } | 47 bool is_valid() const { return handle_.is_valid(); } |
| 48 | 48 |
| 49 ScopedInterfaceEndpointHandle PassHandle() { |
| 50 return std::move(handle_); |
| 51 } |
| 52 const ScopedInterfaceEndpointHandle& handle() const { return handle_; } |
| 53 void set_handle(ScopedInterfaceEndpointHandle handle) { |
| 54 handle_ = std::move(handle); |
| 55 } |
| 56 |
| 49 uint32_t version() const { return version_; } | 57 uint32_t version() const { return version_; } |
| 50 void set_version(uint32_t version) { version_ = version; } | 58 void set_version(uint32_t version) { version_ = version; } |
| 51 | 59 |
| 52 private: | 60 private: |
| 53 friend class internal::AssociatedInterfacePtrInfoHelper; | 61 ScopedInterfaceEndpointHandle handle_; |
| 54 | |
| 55 internal::ScopedInterfaceEndpointHandle handle_; | |
| 56 uint32_t version_; | 62 uint32_t version_; |
| 57 }; | 63 }; |
| 58 | 64 |
| 59 namespace internal { | |
| 60 | |
| 61 // With this helper, AssociatedInterfacePtrInfo doesn't have to expose any | |
| 62 // operations related to ScopedInterfaceEndpointHandle, which is an internal | |
| 63 // class. | |
| 64 class AssociatedInterfacePtrInfoHelper { | |
| 65 public: | |
| 66 template <typename Interface> | |
| 67 static ScopedInterfaceEndpointHandle PassHandle( | |
| 68 AssociatedInterfacePtrInfo<Interface>* info) { | |
| 69 return std::move(info->handle_); | |
| 70 } | |
| 71 | |
| 72 template <typename Interface> | |
| 73 static const ScopedInterfaceEndpointHandle& GetHandle( | |
| 74 AssociatedInterfacePtrInfo<Interface>* info) { | |
| 75 return info->handle_; | |
| 76 } | |
| 77 | |
| 78 template <typename Interface> | |
| 79 static void SetHandle(AssociatedInterfacePtrInfo<Interface>* info, | |
| 80 ScopedInterfaceEndpointHandle handle) { | |
| 81 info->handle_ = std::move(handle); | |
| 82 } | |
| 83 }; | |
| 84 | |
| 85 } // namespace internal | |
| 86 } // namespace mojo | 65 } // namespace mojo |
| 87 | 66 |
| 88 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_INFO_H_ | 67 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_INFO_H_ |
| OLD | NEW |