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

Unified Diff: mojo/public/dart/src/types.dart

Issue 800523004: Dart: Simplifies the handle watcher. Various cleanups and bugfixes. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: cleanup Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: mojo/public/dart/src/types.dart
diff --git a/mojo/public/dart/src/types.dart b/mojo/public/dart/src/types.dart
index fa9e46579c2f0ce310e9e0311ae0f1f988c80f05..54c5319a8ce86a2eef7e06b0c3043d8b4a099ec1 100644
--- a/mojo/public/dart/src/types.dart
+++ b/mojo/public/dart/src/types.dart
@@ -69,7 +69,8 @@ class MojoResult {
case kDataLoss: return DATA_LOSS;
case kBusy: return BUSY;
case kShouldWait: return SHOULD_WAIT;
- default: return null;
+ default:
+ throw 'Invalid Mojo result';
}
}
@@ -119,36 +120,82 @@ class MojoResult {
class MojoHandleSignals {
- static const int NONE = 0;
- static const int READABLE = 1 << 0;
- static const int WRITABLE = 1 << 1;
- static const int PEER_CLOSED = 1 << 2;
- static const int READWRITE = READABLE | WRITABLE;
-
- static bool isNone(int mask) => mask == NONE;
- static bool isReadable(int mask) => (mask & READABLE) == READABLE;
- static bool isWritable(int mask) => (mask & WRITABLE) == WRITABLE;
- static bool isReadWrite(int mask) => (mask & READWRITE) == READWRITE;
- static int toggleWrite(int mask) =>
- isWritable(mask) ? (mask & ~WRITABLE) : (mask | WRITABLE);
- static bool isPeerClosed(int mask) => (mask & PEER_CLOSED) == PEER_CLOSED;
+ static const int kNone = 0;
+ static const int kReadable = 1 << 0;
+ static const int kWritable = 1 << 1;
+ static const int kPeerClosed = 1 << 2;
+ static const int kReadWrite = kReadable | kWritable;
+ static const int kAll = kReadable | kWritable | kPeerClosed;
+
+ // TODO(zra): Does PEER_CLOSED | anything else make sense?
+ static const NONE = const MojoHandleSignals._(kNone);
+ static const READABLE = const MojoHandleSignals._(kReadable);
+ static const WRITABLE = const MojoHandleSignals._(kWritable);
+ static const PEER_CLOSED = const MojoHandleSignals._(kPeerClosed);
+ static const READWRITE = const MojoHandleSignals._(kReadWrite);
+ static const ALL = const MojoHandleSignals._(kAll);
+
+ final int value;
+
+ const MojoHandleSignals._(this.value);
+
+ factory MojoHandleSignals(int value) {
+ switch (value) {
+ case kNone: return NONE;
+ case kReadable: return READABLE;
+ case kWritable: return WRITABLE;
+ case kPeerClosed: return PEER_CLOSED;
+ case kReadWrite: return READWRITE;
+ case kAll: return ALL;
+ default:
+ throw 'Invalid handle signal';
+ }
+ }
+
+ bool get isNone => (this == NONE);
+ bool get isReadable => (value & kReadable) == kReadable;
+ bool get isWritable => (value & kWritable) == kWritable;
+ bool get isPeerClosed => (value & kPeerClosed) == kPeerClosed;
+ bool get isReadWrite => (value & kReadWrite) == kReadWrite;
+ bool get isAll => (this == ALL);
+
+ MojoHandleSignals operator +(MojoHandleSignals other) {
+ return new MojoHandleSignals(value | other.value);
+ }
+
+ MojoHandleSignals operator -(MojoHandleSignals other) {
+ return new MojoHandleSignals(value & ~other.value);
+ }
+
+ String toString() {
+ switch (value) {
+ case kNone: return "NONE";
+ case kReadable: return "READABLE";
+ case kWritable: return "WRITABLE";
+ case kPeerClosed: return "PEER_CLOSED";
+ case kReadWrite: return "READWRITE";
+ case kAll: return "ALL";
+ default: return "<invalid signal>";
+ }
+ }
}
class MojoHandleSignalsState {
MojoHandleSignalsState(this.satisfied_signals,
this.satisfiable_signals);
-
final int satisfied_signals;
final int satisfiable_signals;
}
+
class MojoWaitResult {
MojoWaitResult(this.result, this.state);
final MojoResult result;
MojoHandleSignalsState state;
}
+
class MojoWaitManyResult {
MojoWaitManyResult(this.result, this.index, this.states);
final MojoResult result;
« no previous file with comments | « mojo/public/dart/src/message_pipe.dart ('k') | mojo/public/tools/bindings/generators/dart_templates/interface_definition.tmpl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698