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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 5
6 part of core; 6 part of core;
7 7
8 8
9 class MojoResult { 9 class MojoResult {
10 static const int kOk = 0; 10 static const int kOk = 0;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 case kResourceExhausted: return RESOURCE_EXHAUSTED; 62 case kResourceExhausted: return RESOURCE_EXHAUSTED;
63 case kFailedPrecondition: return FAILED_PRECONDITION; 63 case kFailedPrecondition: return FAILED_PRECONDITION;
64 case kAborted: return ABORTED; 64 case kAborted: return ABORTED;
65 case kOutOfRange: return OUT_OF_RANGE; 65 case kOutOfRange: return OUT_OF_RANGE;
66 case kUnimplemented: return UNIMPLEMENTED; 66 case kUnimplemented: return UNIMPLEMENTED;
67 case kInternal: return INTERNAL; 67 case kInternal: return INTERNAL;
68 case kUnavailable: return UNAVAILABLE; 68 case kUnavailable: return UNAVAILABLE;
69 case kDataLoss: return DATA_LOSS; 69 case kDataLoss: return DATA_LOSS;
70 case kBusy: return BUSY; 70 case kBusy: return BUSY;
71 case kShouldWait: return SHOULD_WAIT; 71 case kShouldWait: return SHOULD_WAIT;
72 default: return null; 72 default:
73 throw 'Invalid Mojo result';
73 } 74 }
74 } 75 }
75 76
76 bool get isOk => (this == OK); 77 bool get isOk => (this == OK);
77 bool get isCancelled => (this == CANCELLED); 78 bool get isCancelled => (this == CANCELLED);
78 bool get isUnknown => (this == UNKNOWN); 79 bool get isUnknown => (this == UNKNOWN);
79 bool get isInvalidArgument => (this == INVALID_ARGUMENT); 80 bool get isInvalidArgument => (this == INVALID_ARGUMENT);
80 bool get isDeadlineExceeded => (this == DEADLINE_EXCEEDED); 81 bool get isDeadlineExceeded => (this == DEADLINE_EXCEEDED);
81 bool get isNotFound => (this == NOT_FOUND); 82 bool get isNotFound => (this == NOT_FOUND);
82 bool get isAlreadExists => (this == ALREADY_EXISTS); 83 bool get isAlreadExists => (this == ALREADY_EXISTS);
(...skipping 29 matching lines...) Expand all
112 case kDataLoss: return "DATA_LOSS"; 113 case kDataLoss: return "DATA_LOSS";
113 case kBusy: return "BUSY"; 114 case kBusy: return "BUSY";
114 case kShouldWait: return "SHOULD_WAIT"; 115 case kShouldWait: return "SHOULD_WAIT";
115 default: return "<invalid result>"; 116 default: return "<invalid result>";
116 } 117 }
117 } 118 }
118 } 119 }
119 120
120 121
121 class MojoHandleSignals { 122 class MojoHandleSignals {
122 static const int NONE = 0; 123 static const int kNone = 0;
123 static const int READABLE = 1 << 0; 124 static const int kReadable = 1 << 0;
124 static const int WRITABLE = 1 << 1; 125 static const int kWritable = 1 << 1;
125 static const int PEER_CLOSED = 1 << 2; 126 static const int kPeerClosed = 1 << 2;
126 static const int READWRITE = READABLE | WRITABLE; 127 static const int kReadWrite = kReadable | kWritable;
128 static const int kAll = kReadable | kWritable | kPeerClosed;
127 129
128 static bool isNone(int mask) => mask == NONE; 130 // TODO(zra): Does PEER_CLOSED | anything else make sense?
129 static bool isReadable(int mask) => (mask & READABLE) == READABLE; 131 static const NONE = const MojoHandleSignals._(kNone);
130 static bool isWritable(int mask) => (mask & WRITABLE) == WRITABLE; 132 static const READABLE = const MojoHandleSignals._(kReadable);
131 static bool isReadWrite(int mask) => (mask & READWRITE) == READWRITE; 133 static const WRITABLE = const MojoHandleSignals._(kWritable);
132 static int toggleWrite(int mask) => 134 static const PEER_CLOSED = const MojoHandleSignals._(kPeerClosed);
133 isWritable(mask) ? (mask & ~WRITABLE) : (mask | WRITABLE); 135 static const READWRITE = const MojoHandleSignals._(kReadWrite);
134 static bool isPeerClosed(int mask) => (mask & PEER_CLOSED) == PEER_CLOSED; 136 static const ALL = const MojoHandleSignals._(kAll);
137
138 final int value;
139
140 const MojoHandleSignals._(this.value);
141
142 factory MojoHandleSignals(int value) {
143 switch (value) {
144 case kNone: return NONE;
145 case kReadable: return READABLE;
146 case kWritable: return WRITABLE;
147 case kPeerClosed: return PEER_CLOSED;
148 case kReadWrite: return READWRITE;
149 case kAll: return ALL;
150 default:
151 throw 'Invalid handle signal';
152 }
153 }
154
155 bool get isNone => (this == NONE);
156 bool get isReadable => (value & kReadable) == kReadable;
157 bool get isWritable => (value & kWritable) == kWritable;
158 bool get isPeerClosed => (value & kPeerClosed) == kPeerClosed;
159 bool get isReadWrite => (value & kReadWrite) == kReadWrite;
160 bool get isAll => (this == ALL);
161
162 MojoHandleSignals operator +(MojoHandleSignals other) {
163 return new MojoHandleSignals(value | other.value);
164 }
165
166 MojoHandleSignals operator -(MojoHandleSignals other) {
167 return new MojoHandleSignals(value & ~other.value);
168 }
169
170 String toString() {
171 switch (value) {
172 case kNone: return "NONE";
173 case kReadable: return "READABLE";
174 case kWritable: return "WRITABLE";
175 case kPeerClosed: return "PEER_CLOSED";
176 case kReadWrite: return "READWRITE";
177 case kAll: return "ALL";
178 default: return "<invalid signal>";
179 }
180 }
135 } 181 }
136 182
137 183
138 class MojoHandleSignalsState { 184 class MojoHandleSignalsState {
139 MojoHandleSignalsState(this.satisfied_signals, 185 MojoHandleSignalsState(this.satisfied_signals,
140 this.satisfiable_signals); 186 this.satisfiable_signals);
141
142 final int satisfied_signals; 187 final int satisfied_signals;
143 final int satisfiable_signals; 188 final int satisfiable_signals;
144 } 189 }
145 190
191
146 class MojoWaitResult { 192 class MojoWaitResult {
147 MojoWaitResult(this.result, this.state); 193 MojoWaitResult(this.result, this.state);
148 final MojoResult result; 194 final MojoResult result;
149 MojoHandleSignalsState state; 195 MojoHandleSignalsState state;
150 } 196 }
151 197
198
152 class MojoWaitManyResult { 199 class MojoWaitManyResult {
153 MojoWaitManyResult(this.result, this.index, this.states); 200 MojoWaitManyResult(this.result, this.index, this.states);
154 final MojoResult result; 201 final MojoResult result;
155 final int index; 202 final int index;
156 List<MojoHandleSignalsState> states; 203 List<MojoHandleSignalsState> states;
157 204
158 bool get isIndexValid => (this.index != null); 205 bool get isIndexValid => (this.index != null);
159 bool get areSignalStatesValid => (this.states != null); 206 bool get areSignalStatesValid => (this.states != null);
160 } 207 }
OLDNEW
« 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