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

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

Issue 2741033003: Mojo EDK: Introduce MojoQueryHandleSignalsState API (Closed)
Patch Set: rebase 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
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 bool readable() const { return satisfies(MOJO_HANDLE_SIGNAL_READABLE); }
47
48 bool writable() const { return satisfies(MOJO_HANDLE_SIGNAL_WRITABLE); }
49
50 bool peer_closed() const { return satisfies(MOJO_HANDLE_SIGNAL_PEER_CLOSED); }
51
52 bool never_readable() const {
53 return !can_satisfy(MOJO_HANDLE_SIGNAL_READABLE);
54 }
55
56 bool never_writable() const {
57 return !can_satisfy(MOJO_HANDLE_SIGNAL_WRITABLE);
58 }
59
60 bool never_peer_closed() const {
yzshen1 2017/03/14 18:20:45 nit: does it make sense to add a comment what exac
Ken Rockot(use gerrit already) 2017/03/14 19:16:19 Done
61 return !can_satisfy(MOJO_HANDLE_SIGNAL_PEER_CLOSED);
62 }
63
64 // (Copy and assignment allowed.)
65 };
66
67 static_assert(sizeof(HandleSignalsState) == sizeof(MojoHandleSignalsState),
68 "HandleSignalsState should add no overhead");
69
70 } // namespace mojo
71
72 #endif // MOJO_PUBLIC_CPP_SYSTEM_HANDLE_SIGNALS_STATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698