Chromium Code Reviews| Index: mojo/public/cpp/system/handle_signals_state.h |
| diff --git a/mojo/public/cpp/system/handle_signals_state.h b/mojo/public/cpp/system/handle_signals_state.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2ab5320e294f8393c70489e3e7a69c2fdbfeb59a |
| --- /dev/null |
| +++ b/mojo/public/cpp/system/handle_signals_state.h |
| @@ -0,0 +1,72 @@ |
| +// Copyright 2017 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_SYSTEM_HANDLE_SIGNALS_STATE_H_ |
| +#define MOJO_PUBLIC_CPP_SYSTEM_HANDLE_SIGNALS_STATE_H_ |
| + |
| +#include "mojo/public/c/system/types.h" |
| +#include "mojo/public/cpp/system/system_export.h" |
| + |
| +namespace mojo { |
| + |
| +// A convenience wrapper around the MojoHandleSignalsState struct. |
| +struct MOJO_CPP_SYSTEM_EXPORT HandleSignalsState final |
| + : public MojoHandleSignalsState { |
| + HandleSignalsState() { |
| + satisfied_signals = MOJO_HANDLE_SIGNAL_NONE; |
| + satisfiable_signals = MOJO_HANDLE_SIGNAL_NONE; |
| + } |
| + |
| + HandleSignalsState(MojoHandleSignals satisfied, |
| + MojoHandleSignals satisfiable) { |
| + satisfied_signals = satisfied; |
| + satisfiable_signals = satisfiable; |
| + } |
| + |
| + bool operator==(const HandleSignalsState& other) const { |
| + return satisfied_signals == other.satisfied_signals && |
| + satisfiable_signals == other.satisfiable_signals; |
| + } |
| + |
| + // TODO(rockot): Remove this in favor of operator==. |
| + bool equals(const HandleSignalsState& other) const { |
| + return satisfied_signals == other.satisfied_signals && |
| + satisfiable_signals == other.satisfiable_signals; |
| + } |
| + |
| + bool satisfies(MojoHandleSignals signals) const { |
| + return !!(satisfied_signals & signals); |
| + } |
| + |
| + bool can_satisfy(MojoHandleSignals signals) const { |
| + return !!(satisfiable_signals & signals); |
| + } |
| + |
| + bool readable() const { return satisfies(MOJO_HANDLE_SIGNAL_READABLE); } |
| + |
| + bool writable() const { return satisfies(MOJO_HANDLE_SIGNAL_WRITABLE); } |
| + |
| + bool peer_closed() const { return satisfies(MOJO_HANDLE_SIGNAL_PEER_CLOSED); } |
| + |
| + bool never_readable() const { |
| + return !can_satisfy(MOJO_HANDLE_SIGNAL_READABLE); |
| + } |
| + |
| + bool never_writable() const { |
| + return !can_satisfy(MOJO_HANDLE_SIGNAL_WRITABLE); |
| + } |
| + |
| + 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
|
| + return !can_satisfy(MOJO_HANDLE_SIGNAL_PEER_CLOSED); |
| + } |
| + |
| + // (Copy and assignment allowed.) |
| +}; |
| + |
| +static_assert(sizeof(HandleSignalsState) == sizeof(MojoHandleSignalsState), |
| + "HandleSignalsState should add no overhead"); |
| + |
| +} // namespace mojo |
| + |
| +#endif // MOJO_PUBLIC_CPP_SYSTEM_HANDLE_SIGNALS_STATE_H_ |