| 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 part of core; | |
| 6 | |
| 7 class _MojoHandleNatives { | |
| 8 static int register(MojoEventStream eventStream) native "MojoHandle_Register"; | |
| 9 static int close(int handle) native "MojoHandle_Close"; | |
| 10 static List wait(int handle, int signals, int deadline) | |
| 11 native "MojoHandle_Wait"; | |
| 12 static List waitMany( | |
| 13 List<int> handles, List<int> signals, int deadline) | |
| 14 native "MojoHandle_WaitMany"; | |
| 15 } | |
| 16 | |
| 17 | |
| 18 class MojoHandle { | |
| 19 static const int INVALID = 0; | |
| 20 static const int DEADLINE_INDEFINITE = -1; | |
| 21 | |
| 22 int h; | |
| 23 | |
| 24 MojoHandle(this.h); | |
| 25 | |
| 26 MojoResult close() { | |
| 27 int result = _MojoHandleNatives.close(h); | |
| 28 h = INVALID; | |
| 29 return new MojoResult(result); | |
| 30 } | |
| 31 | |
| 32 MojoWaitResult wait(int signals, int deadline) { | |
| 33 List result = _MojoHandleNatives.wait(h, signals, deadline); | |
| 34 return new MojoWaitResult(new MojoResult(result[0]), result[1]); | |
| 35 } | |
| 36 | |
| 37 bool _ready(MojoHandleSignals signal) { | |
| 38 MojoWaitResult mwr = wait(signal.value, 0); | |
| 39 switch (mwr.result) { | |
| 40 case MojoResult.OK: | |
| 41 return true; | |
| 42 case MojoResult.DEADLINE_EXCEEDED: | |
| 43 case MojoResult.CANCELLED: | |
| 44 case MojoResult.INVALID_ARGUMENT: | |
| 45 case MojoResult.FAILED_PRECONDITION: | |
| 46 return false; | |
| 47 default: | |
| 48 // Should be unreachable. | |
| 49 throw "Unexpected result $res for wait on $h"; | |
| 50 } | |
| 51 } | |
| 52 | |
| 53 bool get readyRead => _ready(MojoHandleSignals.READABLE); | |
| 54 bool get readyWrite => _ready(MojoHandleSignals.WRITABLE); | |
| 55 | |
| 56 static MojoWaitManyResult waitMany( | |
| 57 List<int> handles, List<int> signals, int deadline) { | |
| 58 List result = _MojoHandleNatives.waitMany(handles, signals, deadline); | |
| 59 return new MojoWaitManyResult( | |
| 60 new MojoResult(result[0]), result[1], result[2]); | |
| 61 } | |
| 62 | |
| 63 static MojoResult register(MojoEventStream eventStream) { | |
| 64 return new MojoResult(_MojoHandleNatives.register(eventStream)); | |
| 65 } | |
| 66 | |
| 67 bool get isValid => (h != INVALID); | |
| 68 | |
| 69 String toString() => "$h"; | |
| 70 | |
| 71 bool operator ==(MojoHandle other) { | |
| 72 return h == other.h; | |
| 73 } | |
| 74 } | |
| OLD | NEW |