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 <stdint.h> 9 #include <utility> 10 11 #include "base/macros.h" 12 #include "mojo/public/cpp/system/message_pipe.h" 13 14 namespace mojo { 15 16 // InterfacePtrInfo stores necessary information to communicate with a remote 17 // interface implementation, which could be used to construct an InterfacePtr. 18 template <typename Interface> 19 class InterfacePtrInfo { 20 public: InterfacePtrInfo()21 InterfacePtrInfo() : version_(0u) {} 22 InterfacePtrInfo(ScopedMessagePipeHandle handle,uint32_t version)23 InterfacePtrInfo(ScopedMessagePipeHandle handle, uint32_t version) 24 : handle_(std::move(handle)), version_(version) {} 25 InterfacePtrInfo(InterfacePtrInfo && other)26 InterfacePtrInfo(InterfacePtrInfo&& other) 27 : handle_(std::move(other.handle_)), version_(other.version_) { 28 other.version_ = 0u; 29 } 30 ~InterfacePtrInfo()31 ~InterfacePtrInfo() {} 32 33 InterfacePtrInfo& operator=(InterfacePtrInfo&& other) { 34 if (this != &other) { 35 handle_ = std::move(other.handle_); 36 version_ = other.version_; 37 other.version_ = 0u; 38 } 39 40 return *this; 41 } 42 is_valid()43 bool is_valid() const { return handle_.is_valid(); } 44 PassHandle()45 ScopedMessagePipeHandle PassHandle() { return std::move(handle_); } handle()46 const ScopedMessagePipeHandle& handle() const { return handle_; } set_handle(ScopedMessagePipeHandle handle)47 void set_handle(ScopedMessagePipeHandle handle) { 48 handle_ = std::move(handle); 49 } 50 version()51 uint32_t version() const { return version_; } set_version(uint32_t version)52 void set_version(uint32_t version) { version_ = version; } 53 54 private: 55 ScopedMessagePipeHandle handle_; 56 uint32_t version_; 57 58 DISALLOW_COPY_AND_ASSIGN(InterfacePtrInfo); 59 }; 60 61 } // namespace mojo 62 63 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_INFO_H_ 64