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

Side by Side Diff: mojo/public/cpp/system/handle_signals_state.h

Issue 2741033003: Mojo EDK: Introduce MojoQueryHandleSignalsState API (Closed)
Patch Set: fix stupid bad DCHECK Created 3 years, 9 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/system/handle.h ('k') | mojo/public/cpp/system/tests/BUILD.gn » ('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 2017 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_SYSTEM_HANDLE_SIGNALS_STATE_H_
6 #define MOJO_PUBLIC_CPP_SYSTEM_HANDLE_SIGNALS_STATE_H_
7
8 #include "mojo/public/c/system/types.h"
9 #include "mojo/public/cpp/system/system_export.h"
10
11 namespace mojo {
12
13 // A convenience wrapper around the MojoHandleSignalsState struct.
14 struct MOJO_CPP_SYSTEM_EXPORT HandleSignalsState final
15 : public MojoHandleSignalsState {
16 HandleSignalsState() {
17 satisfied_signals = MOJO_HANDLE_SIGNAL_NONE;
18 satisfiable_signals = MOJO_HANDLE_SIGNAL_NONE;
19 }
20
21 HandleSignalsState(MojoHandleSignals satisfied,
22 MojoHandleSignals satisfiable) {
23 satisfied_signals = satisfied;
24 satisfiable_signals = satisfiable;
25 }
26
27 bool operator==(const HandleSignalsState& other) const {
28 return satisfied_signals == other.satisfied_signals &&
29 satisfiable_signals == other.satisfiable_signals;
30 }
31
32 // TODO(rockot): Remove this in favor of operator==.
33 bool equals(const HandleSignalsState& other) const {
34 return satisfied_signals == other.satisfied_signals &&
35 satisfiable_signals == other.satisfiable_signals;
36 }
37
38 bool satisfies(MojoHandleSignals signals) const {
39 return !!(satisfied_signals & signals);
40 }
41
42 bool can_satisfy(MojoHandleSignals signals) const {
43 return !!(satisfiable_signals & signals);
44 }
45
46 // The handle is currently readable. May apply to a message pipe handle or
47 // data pipe consumer handle.
48 bool readable() const { return satisfies(MOJO_HANDLE_SIGNAL_READABLE); }
49
50 // The handle is currently writable. May apply to a message pipe handle or
51 // data pipe producer handle.
52 bool writable() const { return satisfies(MOJO_HANDLE_SIGNAL_WRITABLE); }
53
54 // The handle's peer is closed. May apply to any message pipe or data pipe
55 // handle.
56 bool peer_closed() const { return satisfies(MOJO_HANDLE_SIGNAL_PEER_CLOSED); }
57
58 // The handle will never be |readable()| again.
59 bool never_readable() const {
60 return !can_satisfy(MOJO_HANDLE_SIGNAL_READABLE);
61 }
62
63 // The handle will never be |writable()| again.
64 bool never_writable() const {
65 return !can_satisfy(MOJO_HANDLE_SIGNAL_WRITABLE);
66 }
67
68 // The handle can never indicate |peer_closed()|. Never true for message pipe
69 // or data pipe handles (they can always signal peer closure), but always true
70 // for other types of handles (they have no peer.)
71 bool never_peer_closed() const {
72 return !can_satisfy(MOJO_HANDLE_SIGNAL_PEER_CLOSED);
73 }
74
75 // (Copy and assignment allowed.)
76 };
77
78 static_assert(sizeof(HandleSignalsState) == sizeof(MojoHandleSignalsState),
79 "HandleSignalsState should add no overhead");
80
81 } // namespace mojo
82
83 #endif // MOJO_PUBLIC_CPP_SYSTEM_HANDLE_SIGNALS_STATE_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/system/handle.h ('k') | mojo/public/cpp/system/tests/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698