OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 | |
6 part of core; | |
7 | |
8 | |
9 class MojoResult { | |
10 static const int kOk = 0; | |
11 static const int kCancelled = -1; | |
12 static const int kUnknown = -2; | |
13 static const int kInvalidArgument = -3; | |
14 static const int kDeadlineExceeded = -4; | |
15 static const int kNotFound = -5; | |
16 static const int kAlreadyExists = -6; | |
17 static const int kPermissionDenied = -7; | |
18 static const int kResourceExhausted = -8; | |
19 static const int kFailedPrecondition = -9; | |
20 static const int kAborted = -10; | |
21 static const int kOutOfRange = -11; | |
22 static const int kUnimplemented = -12; | |
23 static const int kInternal = -13; | |
24 static const int kUnavailable = -14; | |
25 static const int kDataLoss = -15; | |
26 static const int kBusy = -16; | |
27 static const int kShouldWait = -17; | |
28 | |
29 static const OK = const MojoResult._(kOk); | |
30 static const CANCELLED = const MojoResult._(kCancelled); | |
31 static const UNKNOWN = const MojoResult._(kUnknown); | |
32 static const INVALID_ARGUMENT = const MojoResult._(kInvalidArgument); | |
33 static const DEADLINE_EXCEEDED = const MojoResult._(kDeadlineExceeded); | |
34 static const NOT_FOUND = const MojoResult._(kNotFound); | |
35 static const ALREADY_EXISTS = const MojoResult._(kAlreadyExists); | |
36 static const PERMISSION_DENIED = const MojoResult._(kPermissionDenied); | |
37 static const RESOURCE_EXHAUSTED = const MojoResult._(kResourceExhausted); | |
38 static const FAILED_PRECONDITION = const MojoResult._(kFailedPrecondition); | |
39 static const ABORTED = const MojoResult._(kAborted); | |
40 static const OUT_OF_RANGE = const MojoResult._(kOutOfRange); | |
41 static const UNIMPLEMENTED = const MojoResult._(kUnimplemented); | |
42 static const INTERNAL = const MojoResult._(kInternal); | |
43 static const UNAVAILABLE = const MojoResult._(kUnavailable); | |
44 static const DATA_LOSS = const MojoResult._(kDataLoss); | |
45 static const BUSY = const MojoResult._(kBusy); | |
46 static const SHOULD_WAIT = const MojoResult._(kShouldWait); | |
47 | |
48 final int value; | |
49 | |
50 const MojoResult._(this.value); | |
51 | |
52 factory MojoResult(int value) { | |
53 switch (value) { | |
54 case kOk: return OK; | |
55 case kCancelled: return CANCELLED; | |
56 case kUnknown: return UNKNOWN; | |
57 case kInvalidArgument: return INVALID_ARGUMENT; | |
58 case kDeadlineExceeded: return DEADLINE_EXCEEDED; | |
59 case kNotFound: return NOT_FOUND; | |
60 case kAlreadyExists: return ALREADY_EXISTS; | |
61 case kPermissionDenied: return PERMISSION_DENIED; | |
62 case kResourceExhausted: return RESOURCE_EXHAUSTED; | |
63 case kFailedPrecondition: return FAILED_PRECONDITION; | |
64 case kAborted: return ABORTED; | |
65 case kOutOfRange: return OUT_OF_RANGE; | |
66 case kUnimplemented: return UNIMPLEMENTED; | |
67 case kInternal: return INTERNAL; | |
68 case kUnavailable: return UNAVAILABLE; | |
69 case kDataLoss: return DATA_LOSS; | |
70 case kBusy: return BUSY; | |
71 case kShouldWait: return SHOULD_WAIT; | |
72 default: | |
73 throw 'Invalid Mojo result'; | |
74 } | |
75 } | |
76 | |
77 bool get isOk => (this == OK); | |
78 bool get isCancelled => (this == CANCELLED); | |
79 bool get isUnknown => (this == UNKNOWN); | |
80 bool get isInvalidArgument => (this == INVALID_ARGUMENT); | |
81 bool get isDeadlineExceeded => (this == DEADLINE_EXCEEDED); | |
82 bool get isNotFound => (this == NOT_FOUND); | |
83 bool get isAlreadExists => (this == ALREADY_EXISTS); | |
84 bool get isPermissionDenied => (this == PERMISSION_DENIED); | |
85 bool get isResourceExhausted => (this == RESOURCE_EXHAUSTED); | |
86 bool get isFailedPrecondition => (this == FAILED_PRECONDITION); | |
87 bool get isAborted => (this == ABORTED); | |
88 bool get isOutOfRange => (this == OUT_OF_RANGE); | |
89 bool get isUnimplemented => (this == UNIMPLEMENTED); | |
90 bool get isInternal => (this == INTERNAL); | |
91 bool get isUnavailable => (this == UNAVAILABLE); | |
92 bool get isDataLoss => (this == DATA_LOSS); | |
93 bool get isBusy => (this == BUSY); | |
94 bool get isShouldWait => (this == SHOULD_WAIT); | |
95 | |
96 String toString() { | |
97 switch (value) { | |
98 case kOk: return "OK"; | |
99 case kCancelled: return "CANCELLED"; | |
100 case kUnknown: return "UNKNOWN"; | |
101 case kInvalidArgument: return "INVALID_ARGUMENT"; | |
102 case kDeadlineExceeded: return "DEADLINE_EXCEEDED"; | |
103 case kNotFound: return "NOT_FOUND"; | |
104 case kAlreadyExists: return "ALREADY_EXISTS"; | |
105 case kPermissionDenied: return "PERMISSION_DENIED"; | |
106 case kResourceExhausted: return "RESOURCE_EXHAUSTED"; | |
107 case kFailedPrecondition: return "FAILED_PRECONDITION"; | |
108 case kAborted: return "ABORTED"; | |
109 case kOutOfRange: return "OUT_OF_RANGE"; | |
110 case kUnimplemented: return "UNIMPLEMENTED"; | |
111 case kInternal: return "INTERNAL"; | |
112 case kUnavailable: return "UNAVAILABLE"; | |
113 case kDataLoss: return "DATA_LOSS"; | |
114 case kBusy: return "BUSY"; | |
115 case kShouldWait: return "SHOULD_WAIT"; | |
116 default: return "<invalid result>"; | |
117 } | |
118 } | |
119 } | |
120 | |
121 | |
122 class MojoHandleSignals { | |
123 static const int kNone = 0; | |
124 static const int kReadable = 1 << 0; | |
125 static const int kWritable = 1 << 1; | |
126 static const int kPeerClosed = 1 << 2; | |
127 static const int kReadWrite = kReadable | kWritable; | |
128 static const int kAll = kReadable | kWritable | kPeerClosed; | |
129 | |
130 // TODO(zra): Does PEER_CLOSED | anything else make sense? | |
131 static const NONE = const MojoHandleSignals._(kNone); | |
132 static const READABLE = const MojoHandleSignals._(kReadable); | |
133 static const WRITABLE = const MojoHandleSignals._(kWritable); | |
134 static const PEER_CLOSED = const MojoHandleSignals._(kPeerClosed); | |
135 static const READWRITE = const MojoHandleSignals._(kReadWrite); | |
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 } | |
181 } | |
182 | |
183 | |
184 class MojoHandleSignalsState { | |
185 MojoHandleSignalsState(this.satisfied_signals, | |
186 this.satisfiable_signals); | |
187 final int satisfied_signals; | |
188 final int satisfiable_signals; | |
189 } | |
190 | |
191 | |
192 class MojoWaitResult { | |
193 MojoWaitResult(this.result, this.state); | |
194 final MojoResult result; | |
195 MojoHandleSignalsState state; | |
196 } | |
197 | |
198 | |
199 class MojoWaitManyResult { | |
200 MojoWaitManyResult(this.result, this.index, this.states); | |
201 final MojoResult result; | |
202 final int index; | |
203 List<MojoHandleSignalsState> states; | |
204 | |
205 bool get isIndexValid => (this.index != null); | |
206 bool get areSignalStatesValid => (this.states != null); | |
207 } | |
OLD | NEW |