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 3 // found in the LICENSE file. 4 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_INFO_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_INFO_H_ 7 8 #include <stdint.h> 9 #include <utility> 10 11 #include "base/macros.h" 12 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" 13 14 namespace mojo { 15 16 // AssociatedInterfacePtrInfo stores necessary information to construct an 17 // associated interface pointer. It is similar to InterfacePtrInfo except that 18 // it doesn't own a message pipe handle. 19 template <typename Interface> 20 class AssociatedInterfacePtrInfo { 21 public: AssociatedInterfacePtrInfo()22 AssociatedInterfacePtrInfo() : version_(0u) {} 23 AssociatedInterfacePtrInfo(AssociatedInterfacePtrInfo && other)24 AssociatedInterfacePtrInfo(AssociatedInterfacePtrInfo&& other) 25 : handle_(std::move(other.handle_)), version_(other.version_) { 26 other.version_ = 0u; 27 } 28 AssociatedInterfacePtrInfo(ScopedInterfaceEndpointHandle handle,uint32_t version)29 AssociatedInterfacePtrInfo(ScopedInterfaceEndpointHandle handle, 30 uint32_t version) 31 : handle_(std::move(handle)), version_(version) {} 32 ~AssociatedInterfacePtrInfo()33 ~AssociatedInterfacePtrInfo() {} 34 35 AssociatedInterfacePtrInfo& operator=(AssociatedInterfacePtrInfo&& other) { 36 if (this != &other) { 37 handle_ = std::move(other.handle_); 38 version_ = other.version_; 39 other.version_ = 0u; 40 } 41 42 return *this; 43 } 44 is_valid()45 bool is_valid() const { return handle_.is_valid(); } 46 PassHandle()47 ScopedInterfaceEndpointHandle PassHandle() { 48 return std::move(handle_); 49 } handle()50 const ScopedInterfaceEndpointHandle& handle() const { return handle_; } set_handle(ScopedInterfaceEndpointHandle handle)51 void set_handle(ScopedInterfaceEndpointHandle handle) { 52 handle_ = std::move(handle); 53 } 54 version()55 uint32_t version() const { return version_; } set_version(uint32_t version)56 void set_version(uint32_t version) { version_ = version; } 57 Equals(const AssociatedInterfacePtrInfo & other)58 bool Equals(const AssociatedInterfacePtrInfo& other) const { 59 if (this == &other) 60 return true; 61 62 // Now that the two refer to different objects, they are equivalent if 63 // and only if they are both invalid. 64 return !is_valid() && !other.is_valid(); 65 } 66 67 private: 68 ScopedInterfaceEndpointHandle handle_; 69 uint32_t version_; 70 71 DISALLOW_COPY_AND_ASSIGN(AssociatedInterfacePtrInfo); 72 }; 73 74 } // namespace mojo 75 76 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_INFO_H_ 77