aboutsummaryrefslogtreecommitdiff
path: root/mojo/public/cpp/bindings/interface_ptr_info.h
blob: 0b2d8089c4327f7bf608c152980d882dc0626a6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_INFO_H_
#define MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_INFO_H_

#include <stdint.h>
#include <utility>

#include "base/macros.h"
#include "mojo/public/cpp/system/message_pipe.h"

namespace mojo {

// InterfacePtrInfo stores necessary information to communicate with a remote
// interface implementation, which could be used to construct an InterfacePtr.
template <typename Interface>
class InterfacePtrInfo {
 public:
  InterfacePtrInfo() : version_(0u) {}

  InterfacePtrInfo(ScopedMessagePipeHandle handle, uint32_t version)
      : handle_(std::move(handle)), version_(version) {}

  InterfacePtrInfo(InterfacePtrInfo&& other)
      : handle_(std::move(other.handle_)), version_(other.version_) {
    other.version_ = 0u;
  }

  ~InterfacePtrInfo() {}

  InterfacePtrInfo& operator=(InterfacePtrInfo&& other) {
    if (this != &other) {
      handle_ = std::move(other.handle_);
      version_ = other.version_;
      other.version_ = 0u;
    }

    return *this;
  }

  bool is_valid() const { return handle_.is_valid(); }

  ScopedMessagePipeHandle PassHandle() { return std::move(handle_); }
  const ScopedMessagePipeHandle& handle() const { return handle_; }
  void set_handle(ScopedMessagePipeHandle handle) {
    handle_ = std::move(handle);
  }

  uint32_t version() const { return version_; }
  void set_version(uint32_t version) { version_ = version; }

 private:
  ScopedMessagePipeHandle handle_;
  uint32_t version_;

  DISALLOW_COPY_AND_ASSIGN(InterfacePtrInfo);
};

}  // namespace mojo

#endif  // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_INFO_H_