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

Side by Side Diff: mojo/public/dart/src/handle.dart

Issue 834283003: Update Dart bindings to support updated MojoWait and MojoWaitMany APIs. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Fixed TODO. 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 part of core; 5 part of core;
6 6
7 class _MojoHandleNatives { 7 class _MojoHandleNatives {
8 static int register(MojoHandle handle) native "MojoHandle_Register"; 8 static int register(MojoHandle handle) native "MojoHandle_Register";
9 static int close(int handle) native "MojoHandle_Close"; 9 static int close(int handle) native "MojoHandle_Close";
10 static int wait(int handle, int signals, int deadline) 10 static List<Object> wait(int handle, int signals, int deadline)
zra 2015/01/07 15:56:28 For List<Object>, we usually just write List.
jimbe 2015/01/08 17:11:28 Done.
11 native "MojoHandle_Wait"; 11 native "MojoHandle_Wait";
12 static int waitMany( 12 static List<Object> waitMany(
13 List<int> handles, List<int> signals, int num_handles, int deadline) 13 List<int> handles, List<int> signals, int deadline)
14 native "MojoHandle_WaitMany"; 14 native "MojoHandle_WaitMany";
15 } 15 }
16 16
17 17
18 class RawMojoHandle { 18 class RawMojoHandle {
19 static const int INVALID = 0; 19 static const int INVALID = 0;
20 static const int DEADLINE_INDEFINITE = -1; 20 static const int DEADLINE_INDEFINITE = -1;
21 21
22 int h; 22 int h;
23 23
24 RawMojoHandle(this.h); 24 RawMojoHandle(this.h);
25 25
26 MojoResult close() { 26 MojoResult close() {
27 int result = _MojoHandleNatives.close(h); 27 int result = _MojoHandleNatives.close(h);
28 h = INVALID; 28 h = INVALID;
29 return new MojoResult(result); 29 return new MojoResult(result);
30 } 30 }
31 31
32 MojoResult wait(int signals, int deadline) { 32 MojoWaitResult wait(int signals, int deadline) {
33 int result = _MojoHandleNatives.wait(h, signals, deadline); 33 List<Object> result = _MojoHandleNatives.wait(h, signals, deadline);
34 return new MojoResult(result); 34 return new MojoWaitResult(new MojoResult(result[0]), result[1]);
35 } 35 }
36 36
37 bool _ready(int signal) { 37 bool _ready(int signal) {
38 MojoResult res = wait(signal, 0); 38 MojoWaitResult res = wait(signal, 0);
39 switch (res) { 39 switch (res.result) {
40 case MojoResult.OK: 40 case MojoResult.OK:
41 return true; 41 return true;
42 case MojoResult.DEADLINE_EXCEEDED: 42 case MojoResult.DEADLINE_EXCEEDED:
43 case MojoResult.CANCELLED: 43 case MojoResult.CANCELLED:
44 case MojoResult.INVALID_ARGUMENT: 44 case MojoResult.INVALID_ARGUMENT:
45 case MojoResult.FAILED_PRECONDITION: 45 case MojoResult.FAILED_PRECONDITION:
46 return false; 46 return false;
47 default: 47 default:
48 // Should be unreachable. 48 // Should be unreachable.
49 throw new Exception("Unreachable"); 49 throw new Exception("Unreachable");
50 } 50 }
51 } 51 }
52 52
53 bool readyRead() => _ready(MojoHandleSignals.READABLE); 53 bool readyRead() => _ready(MojoHandleSignals.READABLE);
54 bool readyWrite() => _ready(MojoHandleSignals.WRITABLE); 54 bool readyWrite() => _ready(MojoHandleSignals.WRITABLE);
55 55
56 static int waitMany(List<int> handles, 56 static MojoWaitManyResult waitMany(List<int> handles,
57 List<int> signals, 57 List<int> signals,
58 int deadline) { 58 int deadline) {
59 if (handles.length != signals.length) { 59 List<Object> result = _MojoHandleNatives.waitMany(
60 return MojoResult.kInvalidArgument; 60 handles, signals, deadline);
61 } 61
62 return _MojoHandleNatives.waitMany( 62 return new MojoWaitManyResult(
63 handles, signals, handles.length, deadline); 63 new MojoResult(result[0]), result[1], result[2]);
zra 2015/01/07 15:56:28 indent 4 spaces.
jimbe 2015/01/08 17:11:28 Done.
64 } 64 }
65 65
66 static MojoResult register(MojoHandle handle) { 66 static MojoResult register(MojoHandle handle) {
67 return new MojoResult(_MojoHandleNatives.register(handle)); 67 return new MojoResult(_MojoHandleNatives.register(handle));
68 } 68 }
69 69
70 bool get isValid => (h != INVALID); 70 bool get isValid => (h != INVALID);
71 71
72 String toString() => "$h"; 72 String toString() => "$h";
73 73
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 if (!res.isOk) { 213 if (!res.isOk) {
214 throw new Exception("MojoHandleWatcher add failed: $res"); 214 throw new Exception("MojoHandleWatcher add failed: $res");
215 } 215 }
216 _eventHandlerAdded = true; 216 _eventHandlerAdded = true;
217 } 217 }
218 } 218 }
219 } 219 }
220 220
221 String toString() => "$_handle"; 221 String toString() => "$_handle";
222 } 222 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698