OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MOJO_EDK_SYSTEM_HANDLE_H_ | 5 #ifndef MOJO_EDK_SYSTEM_HANDLE_H_ |
6 #define MOJO_EDK_SYSTEM_HANDLE_H_ | 6 #define MOJO_EDK_SYSTEM_HANDLE_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "mojo/edk/util/ref_ptr.h" | 10 #include "mojo/edk/util/ref_ptr.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 Handle(); | 25 Handle(); |
26 Handle(const Handle&); | 26 Handle(const Handle&); |
27 Handle(Handle&&); | 27 Handle(Handle&&); |
28 Handle(util::RefPtr<Dispatcher>&& dispatcher, MojoHandleRights rights); | 28 Handle(util::RefPtr<Dispatcher>&& dispatcher, MojoHandleRights rights); |
29 | 29 |
30 ~Handle(); | 30 ~Handle(); |
31 | 31 |
32 Handle& operator=(const Handle&); | 32 Handle& operator=(const Handle&); |
33 Handle& operator=(Handle&&); | 33 Handle& operator=(Handle&&); |
34 | 34 |
| 35 // Returns a new |Handle| with the same contents as this object. Useful when a |
| 36 // function takes a |Handle&&| argument and the caller wants to retain its |
| 37 // copy (rather than moving it). |
| 38 Handle Clone() const { return *this; } |
| 39 |
35 // A |Handle| tests as true if it actually has a dispatcher. | 40 // A |Handle| tests as true if it actually has a dispatcher. |
36 explicit operator bool() const { return !!dispatcher; } | 41 explicit operator bool() const { return !!dispatcher; } |
37 | 42 |
| 43 bool operator==(const Handle& rhs) const { |
| 44 return dispatcher == rhs.dispatcher && rights == rhs.rights; |
| 45 } |
| 46 |
| 47 bool operator!=(const Handle& rhs) const { return !operator==(rhs); } |
| 48 |
38 void reset() { *this = Handle(); } | 49 void reset() { *this = Handle(); } |
39 | 50 |
40 // Note: |dispatcher| is guaranteed to be null if default-constructed or | 51 // Note: |dispatcher| is guaranteed to be null if default-constructed or |
41 // moved-from, but we make no guarantees about the value of |rights| in either | 52 // moved-from, but we make no guarantees about the value of |rights| in either |
42 // case. | 53 // case. |
43 util::RefPtr<Dispatcher> dispatcher; | 54 util::RefPtr<Dispatcher> dispatcher; |
44 MojoHandleRights rights; | 55 MojoHandleRights rights; |
45 }; | 56 }; |
46 | 57 |
47 using HandleVector = std::vector<Handle>; | 58 using HandleVector = std::vector<Handle>; |
48 | 59 |
49 } // namespace system | 60 } // namespace system |
50 } // namespace mojo | 61 } // namespace mojo |
51 | 62 |
52 #endif // MOJO_EDK_SYSTEM_HANDLE_H_ | 63 #endif // MOJO_EDK_SYSTEM_HANDLE_H_ |
OLD | NEW |