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_INTERFACE_PTR_INFO_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_INFO_H_ 7 8 #include <cstddef> 9 #include <cstdint> 10 #include <utility> 11 12 #include "base/macros.h" 13 #include "mojo/public/cpp/system/message_pipe.h" 14 15 namespace mojo { 16 17 // InterfacePtrInfo stores necessary information to communicate with a remote 18 // interface implementation, which could be used to construct an InterfacePtr. 19 template <typename Interface> 20 class InterfacePtrInfo { 21 public: InterfacePtrInfo()22 InterfacePtrInfo() : version_(0u) {} InterfacePtrInfo(std::nullptr_t)23 InterfacePtrInfo(std::nullptr_t) : InterfacePtrInfo() {} 24 InterfacePtrInfo(ScopedMessagePipeHandle handle,uint32_t version)25 InterfacePtrInfo(ScopedMessagePipeHandle handle, uint32_t version) 26 : handle_(std::move(handle)), version_(version) {} 27 InterfacePtrInfo(InterfacePtrInfo && other)28 InterfacePtrInfo(InterfacePtrInfo&& other) 29 : handle_(std::move(other.handle_)), version_(other.version_) { 30 other.version_ = 0u; 31 } 32 ~InterfacePtrInfo()33 ~InterfacePtrInfo() {} 34 35 InterfacePtrInfo& operator=(InterfacePtrInfo&& 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 ScopedMessagePipeHandle PassHandle() { return std::move(handle_); } handle()48 const ScopedMessagePipeHandle& handle() const { return handle_; } set_handle(ScopedMessagePipeHandle handle)49 void set_handle(ScopedMessagePipeHandle handle) { 50 handle_ = std::move(handle); 51 } 52 version()53 uint32_t version() const { return version_; } set_version(uint32_t version)54 void set_version(uint32_t version) { version_ = version; } 55 56 // Allow InterfacePtrInfo<> to be used in boolean expressions. 57 explicit operator bool() const { return handle_.is_valid(); } 58 59 private: 60 ScopedMessagePipeHandle handle_; 61 uint32_t version_; 62 63 DISALLOW_COPY_AND_ASSIGN(InterfacePtrInfo); 64 }; 65 66 } // namespace mojo 67 68 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_INFO_H_ 69