OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 class ReceivePortFactory { | 5 class ReceivePortFactory { |
6 factory ReceivePort() { | 6 factory ReceivePort() { |
7 return new ReceivePortImpl(); | 7 return new ReceivePortImpl(); |
8 } | 8 } |
9 | 9 |
10 factory ReceivePort.singleShot() { | 10 factory ReceivePort.singleShot() { |
(...skipping 14 matching lines...) Expand all Loading... |
25 _portMap.remove(_id); | 25 _portMap.remove(_id); |
26 _closeInternal(_id); | 26 _closeInternal(_id); |
27 } | 27 } |
28 | 28 |
29 SendPort toSendPort() { | 29 SendPort toSendPort() { |
30 return new SendPortImpl(_id); | 30 return new SendPortImpl(_id); |
31 } | 31 } |
32 | 32 |
33 /**** Internal implementation details ****/ | 33 /**** Internal implementation details ****/ |
34 // Called from the VM to create a new ReceivePort instance. | 34 // Called from the VM to create a new ReceivePort instance. |
35 static ReceivePortImpl create_(int id) { | 35 static ReceivePortImpl _create(int id) { |
36 return new ReceivePortImpl._internal(id); | 36 return new ReceivePortImpl._internal(id); |
37 } | 37 } |
38 ReceivePortImpl._internal(int id) : _id = id { | 38 ReceivePortImpl._internal(int id) : _id = id { |
39 if (_portMap === null) { | 39 if (_portMap === null) { |
40 _portMap = new Map(); | 40 _portMap = new Map(); |
41 } | 41 } |
42 _portMap[id] = this; | 42 _portMap[id] = this; |
43 } | 43 } |
44 | 44 |
45 // Called from the VM to dispatch to the handler. | 45 // Called from the VM to dispatch to the handler. |
46 static void handleMessage_(int id, int replyId, var message) { | 46 static void _handleMessage(int id, int replyId, var message) { |
47 assert(_portMap !== null); | 47 assert(_portMap !== null); |
48 ReceivePort port = _portMap[id]; | 48 ReceivePort port = _portMap[id]; |
49 SendPort replyTo = (replyId == 0) ? null : new SendPortImpl(replyId); | 49 SendPort replyTo = (replyId == 0) ? null : new SendPortImpl(replyId); |
50 (port._onMessage)(message, replyTo); | 50 (port._onMessage)(message, replyTo); |
51 } | 51 } |
52 | 52 |
53 // Call into the VM to close the VM maintained mappings. | 53 // Call into the VM to close the VM maintained mappings. |
54 static _closeInternal(int id) native "ReceivePortImpl_closeInternal"; | 54 static _closeInternal(int id) native "ReceivePortImpl_closeInternal"; |
55 | 55 |
56 final int _id; | 56 final int _id; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 return (other is SendPortImpl) && _id == other._id; | 112 return (other is SendPortImpl) && _id == other._id; |
113 } | 113 } |
114 | 114 |
115 int hashCode() { | 115 int hashCode() { |
116 return _id; | 116 return _id; |
117 } | 117 } |
118 | 118 |
119 /*--- private implementation ---*/ | 119 /*--- private implementation ---*/ |
120 const SendPortImpl(int id) : _id = id; | 120 const SendPortImpl(int id) : _id = id; |
121 | 121 |
122 // SendPortImpl.create_ is called from the VM when a new SendPort instance is | 122 // SendPortImpl._create is called from the VM when a new SendPort instance is |
123 // needed by the VM code. | 123 // needed by the VM code. |
124 static SendPort create_(int id) { | 124 static SendPort _create(int id) { |
125 return new SendPortImpl(id); | 125 return new SendPortImpl(id); |
126 } | 126 } |
127 | 127 |
128 // Forward the implementation of sending messages to the VM. Only port ids | 128 // Forward the implementation of sending messages to the VM. Only port ids |
129 // are being handed to the VM. | 129 // are being handed to the VM. |
130 static _sendInternal(int sendId, int replyId, var message) | 130 static _sendInternal(int sendId, int replyId, var message) |
131 native "SendPortImpl_sendInternal_"; | 131 native "SendPortImpl_sendInternal_"; |
132 | 132 |
133 final int _id; | 133 final int _id; |
134 } | 134 } |
135 | 135 |
136 | 136 |
137 class IsolateNatives { | 137 class IsolateNatives { |
138 static Future<SendPort> spawn(Isolate isolate, bool isLight) { | 138 static Future<SendPort> spawn(Isolate isolate, bool isLight) { |
139 Completer<SendPort> completer = new Completer<SendPort>(); | 139 Completer<SendPort> completer = new Completer<SendPort>(); |
140 SendPort port = _start(isolate, isLight); | 140 SendPort port = _start(isolate, isLight); |
141 completer.complete(port); | 141 completer.complete(port); |
142 return completer.future; | 142 return completer.future; |
143 } | 143 } |
144 | 144 |
145 // Starts a new isolate calling the run method on a new instance of the | 145 // Starts a new isolate calling the run method on a new instance of the |
146 // remote class's type. | 146 // remote class's type. |
147 // Returns the send port which is passed to the newly created isolate. | 147 // Returns the send port which is passed to the newly created isolate. |
148 // This method is being dispatched to from the public core library code. | 148 // This method is being dispatched to from the public core library code. |
149 static SendPort _start(Isolate isolate, bool light) | 149 static SendPort _start(Isolate isolate, bool light) |
150 native "IsolateNatives_start"; | 150 native "IsolateNatives_start"; |
151 } | 151 } |
OLD | NEW |