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: return null; |
| 73 } |
| 74 } |
| 75 |
| 76 bool get isOk => (this == OK); |
| 77 bool get isCancelled => (this == CANCELLED); |
| 78 bool get isUnknown => (this == UNKNOWN); |
| 79 bool get isInvalidArgument => (this == INVALID_ARGUMENT); |
| 80 bool get isDeadlineExceeded => (this == DEADLINE_EXCEEDED); |
| 81 bool get isNotFound => (this == NOT_FOUND); |
| 82 bool get isAlreadExists => (this == ALREADY_EXISTS); |
| 83 bool get isPermissionDenied => (this == PERMISSION_DENIED); |
| 84 bool get isResourceExhausted => (this == RESOURCE_EXHAUSTED); |
| 85 bool get isFailedPrecondition => (this == FAILED_PRECONDITION); |
| 86 bool get isAborted => (this == ABORTED); |
| 87 bool get isOutOfRange => (this == OUT_OF_RANGE); |
| 88 bool get isUnimplemented => (this == UNIMPLEMENTED); |
| 89 bool get isInternal => (this == INTERNAL); |
| 90 bool get isUnavailable => (this == UNAVAILABLE); |
| 91 bool get isDataLoss => (this == DATA_LOSS); |
| 92 bool get isBusy => (this == BUSY); |
| 93 bool get isShouldWait => (this == SHOULD_WAIT); |
| 94 } |
| 95 |
| 96 |
| 97 class MojoHandleSignals { |
| 98 static const int NONE = 0; |
| 99 static const int READABLE = 1 << 0; |
| 100 static const int WRITABLE = 1 << 1; |
| 101 static const int READWRITE = READABLE | WRITABLE; |
| 102 |
| 103 static bool isReadable(int mask) => (mask & READABLE) == READABLE; |
| 104 static bool isWritable(int mask) => (mask & WRITABLE) == WRITABLE; |
| 105 static bool isReadWrite(int mask) => (mask & READWRITE) == READWRITE; |
| 106 static int toggleWrite(int mask) => |
| 107 isWritable(mask) ? (mask & ~WRITABLE) : (mask | WRITABLE); |
| 108 } |
| 109 |
| 110 |
| 111 class MojoHandleSignalsState { |
| 112 const MojoHandleSignalsState(this.satisfied_signals, |
| 113 this.satisfiable_signals); |
| 114 final int satisfied_signals; |
| 115 final int satisfiable_signals; |
| 116 } |
OLD | NEW |