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

Side by Side Diff: mojo/dart/packages/mojo/sdk_ext/src/handle_watcher.dart

Issue 1694413003: Cleanups in the Mojo package. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 10 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 internal; 5 part of internal;
6 6
7 /// This class contains static methods to send a stream of events to application 7 /// This class contains static methods to send a stream of events to application
8 /// isolates that register Mojo handles with it. 8 /// isolates that register Mojo handles with it.
9 class MojoHandleWatcher { 9 class MojoHandleWatcher {
10 // Control commands. 10 // Control commands.
(...skipping 16 matching lines...) Expand all
27 if (controlHandle == _kMojoHandleInvalid) { 27 if (controlHandle == _kMojoHandleInvalid) {
28 return _kMojoResultFailedPrecondition; 28 return _kMojoResultFailedPrecondition;
29 } 29 }
30 var result = _MojoHandleWatcherNatives.sendControlData( 30 var result = _MojoHandleWatcherNatives.sendControlData(
31 controlHandle, command, handleOrDeadline, port, signals); 31 controlHandle, command, handleOrDeadline, port, signals);
32 return result; 32 return result;
33 } 33 }
34 34
35 /// Stops watching and closes the given [handleToken]. 35 /// Stops watching and closes the given [handleToken].
36 /// 36 ///
37 /// Returns an integer, encoding the result as specified in the [MojoResult] 37 /// Returns an integer, encoding the result as specified in [MojoConstants].
38 /// class. In particular, a successful operation returns [MojoResult.kOk]. 38 /// In particular, a successful operation returns [MojoConstants.kOk].
39 /// 39 ///
40 /// Notifies the HandleWatcherIsolate that a handle it is 40 /// Notifies the HandleWatcherIsolate that a handle it is
41 /// watching should be removed from its set and closed. 41 /// watching should be removed from its set and closed.
42 /// 42 ///
43 /// The [handleToken] is a token that identifies the Mojo handle. 43 /// The [handleToken] is a token that identifies the Mojo handle.
44 /// 44 ///
45 /// If [wait] is true, returns a future that resolves only after the handle 45 /// If [wait] is true, returns a future that resolves only after the handle
46 // has actually been closed by the handle watcher. Otherwise, returns a 46 // has actually been closed by the handle watcher. Otherwise, returns a
47 // future that resolves immediately. 47 // future that resolves immediately.
48 static Future<int> close(int handleToken, {bool wait: false}) { 48 static Future<int> close(int handleToken, {bool wait: false}) {
49 if (!wait) { 49 if (!wait) {
50 return new Future.value(_sendControlData(_CLOSE, handleToken, null, 0)); 50 return new Future.value(_sendControlData(_CLOSE, handleToken, null, 0));
51 } 51 }
52 int result; 52 int result;
53 var completer = new Completer(); 53 var completer = new Completer();
54 var rawPort = new RawReceivePort((_) { 54 var rawPort = new RawReceivePort((_) {
55 completer.complete(result); 55 completer.complete(result);
56 }); 56 });
57 result = _sendControlData(_CLOSE, handleToken, rawPort.sendPort, 0); 57 result = _sendControlData(_CLOSE, handleToken, rawPort.sendPort, 0);
58 return completer.future.then((r) { 58 return completer.future.then((r) {
59 rawPort.close(); 59 rawPort.close();
60 return r; 60 return r;
61 }); 61 });
62 } 62 }
63 63
64 /// Starts watching for events on the given [handleToken]. 64 /// Starts watching for events on the given [handleToken].
65 /// 65 ///
66 /// Returns an integer, encoding the result as specified in the [MojoResult] 66 /// Returns an integer, encoding the result as specified in [MojoConstants].
67 /// class. In particular, a successful operation returns [MojoResult.kOk]. 67 /// In particular, a successful operation returns [MojoConstants.kOk].
68 /// 68 ///
69 /// Instructs the MojoHandleWatcher isolate to add [handleToken] to the set of 69 /// Instructs the MojoHandleWatcher isolate to add [handleToken] to the set of
70 /// handles it watches, and to notify the calling isolate only for the events 70 /// handles it watches, and to notify the calling isolate only for the events
71 /// specified by [signals] using the send port [port]. 71 /// specified by [signals] using the send port [port].
72 // TODO(floitsch): what does "MojoHandleWatcher isolate" mean? 72 // TODO(floitsch): what does "MojoHandleWatcher isolate" mean?
73 // TODO(floitsch): what is the calling isolate? 73 // TODO(floitsch): what is the calling isolate?
74 /// 74 ///
75 /// The [handleToken] is a token that identifies the Mojo handle. 75 /// The [handleToken] is a token that identifies the Mojo handle.
76 /// 76 ///
77 /// The filtering [signals] are encoded as specified in the 77 /// The filtering [signals] are encoded as specified in the
78 /// [MojoHandleSignals] class. For example, setting [signals] to 78 /// [MojoConstants] class (section "Handle Signals"). For example, setting
79 /// [MojoHandleSignals.kPeerClosedReadable] instructs the handle watcher to 79 /// [signals] to the bitwise union of [MojoConstants.kPeerClosed]
80 /// [MojoConstants.kReadable] instructs the handle watcher to
80 /// notify the caller, when the handle becomes readable (that is, has data 81 /// notify the caller, when the handle becomes readable (that is, has data
81 /// available for reading), or when it is closed. 82 /// available for reading), or when it is closed.
82 static int add(int handleToken, SendPort port, int signals) { 83 static int add(int handleToken, SendPort port, int signals) {
83 return _sendControlData(_ADD, handleToken, port, signals); 84 return _sendControlData(_ADD, handleToken, port, signals);
84 } 85 }
85 86
86 /// Stops watching the given [handleToken]. 87 /// Stops watching the given [handleToken].
87 /// 88 ///
88 /// Returns an integer, encoding the result as specified in the [MojoResult] 89 /// Returns an integer, encoding the result as specified in [MojoConstants].
89 /// class. In particular, a successful operation returns [MojoResult.kOk]. 90 /// In particular, a successful operation returns [MojoConstants.kOk].
90 /// 91 ///
91 /// Instructs the MojoHandleWatcher isolate to remove [handleToken] from the 92 /// Instructs the MojoHandleWatcher isolate to remove [handleToken] from the
92 /// set of handles it watches. This allows the application isolate 93 /// set of handles it watches. This allows the application isolate
93 /// to, for example, pause the stream of events. 94 /// to, for example, pause the stream of events.
94 /// 95 ///
95 /// The [handleToken] is a token that identifies the Mojo handle. 96 /// The [handleToken] is a token that identifies the Mojo handle.
96 static int remove(int handleToken) { 97 static int remove(int handleToken) {
97 return _sendControlData(_REMOVE, handleToken, null, 0); 98 return _sendControlData(_REMOVE, handleToken, null, 0);
98 } 99 }
99 100
100 /// Requests a notification on the given [port] at [deadline]. 101 /// Requests a notification on the given [port] at [deadline].
101 /// 102 ///
102 /// Returns an integer, encoding the result as specified in the [MojoResult] 103 /// Returns an integer, encoding the result as specified in [MojoConstants].
103 /// class. In particular, a successful operation returns [MojoResult.kOk]. 104 /// In particular, a successful operation returns [MojoConstants.kOk].
104 /// 105 ///
105 /// The [deadline] is in milliseconds, with 106 /// The [deadline] is in milliseconds, with
106 /// [MojoCoreNatives.timerMillisecondClock] as reference. 107 /// [MojoCoreNatives.timerMillisecondClock] as reference.
107 /// 108 ///
108 /// If the given [port] was already registered for a timer (in any isolate), 109 /// If the given [port] was already registered for a timer (in any isolate),
109 /// then the old value is discarded. 110 /// then the old value is discarded.
110 /// 111 ///
111 /// A negative [deadline] is used to remove a port. That is, a negative value 112 /// A negative [deadline] is used to remove a port. That is, a negative value
112 /// is ignored after any existing value for the port has been discarded. 113 /// is ignored after any existing value for the port has been discarded.
113 static int timer(Object ignored, SendPort port, int deadline) { 114 static int timer(Object ignored, SendPort port, int deadline) {
114 // The deadline will be unwrapped before sending to the handle watcher. 115 // The deadline will be unwrapped before sending to the handle watcher.
115 return _sendControlData(_TIMER, deadline, port, 0); 116 return _sendControlData(_TIMER, deadline, port, 0);
116 } 117 }
117 } 118 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698