Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(327)

Side by Side Diff: mojo/public/cpp/bindings/interface_handle.h

Issue 2250183003: Make the fuchsia mojo/public repo the source of truth. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/public/cpp/bindings/formatting.h ('k') | mojo/public/cpp/bindings/interface_ptr.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
10 #include "mojo/public/cpp/system/macros.h"
11 #include "mojo/public/cpp/system/message_pipe.h"
12
13 namespace mojo {
14
15 template <typename Interface>
16 class InterfacePtr;
17
18 template <typename Interface>
19 class SynchronousInterfacePtr;
20
21 // InterfaceHandle stores necessary information to communicate with a remote
22 // interface implementation, which could be used to construct an InterfacePtr.
23 template <typename Interface>
24 class InterfaceHandle {
25 public:
26 InterfaceHandle() : version_(0u) {}
27 InterfaceHandle(std::nullptr_t) : version_(0u) {}
28
29 InterfaceHandle(ScopedMessagePipeHandle handle, uint32_t version)
30 : handle_(handle.Pass()), version_(version) {}
31
32 InterfaceHandle(InterfaceHandle&& other)
33 : handle_(other.handle_.Pass()), version_(other.version_) {
34 other.version_ = 0u;
35 }
36
37 // Making this constructor templated ensures that it is not type-instantiated
38 // unless it is used, making the InterfacePtr<->InterfaceHandle codependency
39 // less fragile.
40 template <typename SameInterfaceAsAbove = Interface>
41 InterfaceHandle(InterfacePtr<SameInterfaceAsAbove>&& ptr) {
42 *this = ptr.PassInterfaceHandle();
43 }
44
45 // Making this constructor templated ensures that it is not type-instantiated
46 // unless it is used, making the SynchronousInterfacePtr<->InterfaceHandle
47 // codependency less fragile.
48 template <typename SameInterfaceAsAbove = Interface>
49 InterfaceHandle(SynchronousInterfacePtr<SameInterfaceAsAbove>&& ptr) {
50 *this = ptr.PassInterfaceHandle();
51 }
52
53 ~InterfaceHandle() {}
54
55 InterfaceHandle& operator=(InterfaceHandle&& other) {
56 if (this != &other) {
57 handle_ = other.handle_.Pass();
58 version_ = other.version_;
59 other.version_ = 0u;
60 }
61
62 return *this;
63 }
64
65 // Tests as true if we have a valid handle.
66 explicit operator bool() const { return is_valid(); }
67 bool is_valid() const { return handle_.is_valid(); }
68
69 ScopedMessagePipeHandle PassHandle() { return handle_.Pass(); }
70 const ScopedMessagePipeHandle& handle() const { return handle_; }
71 void set_handle(ScopedMessagePipeHandle handle) { handle_ = handle.Pass(); }
72
73 uint32_t version() const { return version_; }
74 void set_version(uint32_t version) { version_ = version; }
75
76 private:
77 ScopedMessagePipeHandle handle_;
78 uint32_t version_;
79
80 MOJO_MOVE_ONLY_TYPE(InterfaceHandle);
81 };
82
83 } // namespace mojo
84
85 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_INFO_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/formatting.h ('k') | mojo/public/cpp/bindings/interface_ptr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698