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

Side by Side Diff: runtime/vm/service/vmservice.dart

Issue 1347693004: getIsolate rpc now returns collected sentinel for expired isolate. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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
« no previous file with comments | « runtime/vm/service/service.md ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 library vmservice; 5 library vmservice;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 import 'dart:isolate'; 9 import 'dart:isolate';
10 import 'dart:typed_data'; 10 import 'dart:typed_data';
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 }, 44 },
45 }; 45 };
46 if (details != null) { 46 if (details != null) {
47 response['error']['data'] = { 47 response['error']['data'] = {
48 'details': details, 48 'details': details,
49 }; 49 };
50 } 50 }
51 return JSON.encode(response); 51 return JSON.encode(response);
52 } 52 }
53 53
54 String encodeResult(Message message, Map result) {
55 var response = {
56 'jsonrpc': '2.0',
57 'id' : message.serial,
58 'result' : result,
59 };
60 return JSON.encode(response);
61 }
62
63
54 class VMService extends MessageRouter { 64 class VMService extends MessageRouter {
55 static VMService _instance; 65 static VMService _instance;
56 66
57 /// Collection of currently connected clients. 67 /// Collection of currently connected clients.
58 final Set<Client> clients = new Set<Client>(); 68 final Set<Client> clients = new Set<Client>();
59 69
60 /// Collection of currently running isolates. 70 /// Collection of currently running isolates.
61 RunningIsolates runningIsolates = new RunningIsolates(); 71 RunningIsolates runningIsolates = new RunningIsolates();
62 72
63 /// A port used to receive events from the VM. 73 /// A port used to receive events from the VM.
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 var members = []; 176 var members = [];
167 var result = {}; 177 var result = {};
168 clients.forEach((client) { 178 clients.forEach((client) {
169 members.add(client.toJson()); 179 members.add(client.toJson());
170 }); 180 });
171 result['type'] = 'ClientList'; 181 result['type'] = 'ClientList';
172 result['members'] = members; 182 result['members'] = members;
173 message.setResponse(JSON.encode(result)); 183 message.setResponse(JSON.encode(result));
174 } 184 }
175 185
176 String _encodeResult(Message message, Map result) {
177 var response = {
178 'jsonrpc': '2.0',
179 'id' : message.serial,
180 'result' : result,
181 };
182 return JSON.encode(response);
183 }
184
185 bool _isAnyClientSubscribed(String streamId) { 186 bool _isAnyClientSubscribed(String streamId) {
186 for (var client in clients) { 187 for (var client in clients) {
187 if (client.streams.contains(streamId)) { 188 if (client.streams.contains(streamId)) {
188 return true; 189 return true;
189 } 190 }
190 } 191 }
191 return false; 192 return false;
192 } 193 }
193 194
194 Future<String> _streamListen(Message message) async { 195 Future<String> _streamListen(Message message) async {
195 var client = message.client; 196 var client = message.client;
196 var streamId = message.params['streamId']; 197 var streamId = message.params['streamId'];
197 198
198 if (client.streams.contains(streamId)) { 199 if (client.streams.contains(streamId)) {
199 return encodeRpcError(message, kStreamAlreadySubscribed); 200 return encodeRpcError(message, kStreamAlreadySubscribed);
200 } 201 }
201 if (!_isAnyClientSubscribed(streamId)) { 202 if (!_isAnyClientSubscribed(streamId)) {
202 if (!_vmListenStream(streamId)) { 203 if (!_vmListenStream(streamId)) {
203 return encodeRpcError( 204 return encodeRpcError(
204 message, kInvalidParams, 205 message, kInvalidParams,
205 details:"streamListen: invalid 'streamId' parameter: ${streamId}"); 206 details:"streamListen: invalid 'streamId' parameter: ${streamId}");
206 } 207 }
207 } 208 }
208 client.streams.add(streamId); 209 client.streams.add(streamId);
209 210
210 var result = { 'type' : 'Success' }; 211 var result = { 'type' : 'Success' };
211 return _encodeResult(message, result); 212 return encodeResult(message, result);
212 } 213 }
213 214
214 Future<String> _streamCancel(Message message) async { 215 Future<String> _streamCancel(Message message) async {
215 var client = message.client; 216 var client = message.client;
216 var streamId = message.params['streamId']; 217 var streamId = message.params['streamId'];
217 218
218 if (!client.streams.contains(streamId)) { 219 if (!client.streams.contains(streamId)) {
219 return encodeRpcError(message, kStreamNotSubscribed); 220 return encodeRpcError(message, kStreamNotSubscribed);
220 } 221 }
221 client.streams.remove(streamId); 222 client.streams.remove(streamId);
222 if (!_isAnyClientSubscribed(streamId)) { 223 if (!_isAnyClientSubscribed(streamId)) {
223 _vmCancelStream(streamId); 224 _vmCancelStream(streamId);
224 } 225 }
225 226
226 var result = { 'type' : 'Success' }; 227 var result = { 'type' : 'Success' };
227 return _encodeResult(message, result); 228 return encodeResult(message, result);
228 } 229 }
229 230
230 // TODO(johnmccutchan): Turn this into a command line tool that uses the 231 // TODO(johnmccutchan): Turn this into a command line tool that uses the
231 // service library. 232 // service library.
232 Future<String> _getCrashDump(Message message) async { 233 Future<String> _getCrashDump(Message message) async {
233 var client = message.client; 234 var client = message.client;
234 final perIsolateRequests = [ 235 final perIsolateRequests = [
235 // ?isolateId=<isolate id> will be appended to each of these requests. 236 // ?isolateId=<isolate id> will be appended to each of these requests.
236 // Isolate information. 237 // Isolate information.
237 Uri.parse('getIsolate'), 238 Uri.parse('getIsolate'),
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 var response = JSON.decode(await isolate.route(message)); 276 var response = JSON.decode(await isolate.route(message));
276 // Insert getObject requests into responses map. 277 // Insert getObject requests into responses map.
277 for (var object in response['result']['objects']) { 278 for (var object in response['result']['objects']) {
278 final requestUri = 279 final requestUri =
279 'getObject&isolateId=${isolate.serviceId}?objectId=${object["id"]}'; 280 'getObject&isolateId=${isolate.serviceId}?objectId=${object["id"]}';
280 responses[requestUri] = object; 281 responses[requestUri] = object;
281 } 282 }
282 } 283 }
283 284
284 // Encode the entire crash dump. 285 // Encode the entire crash dump.
285 return _encodeResult(message, responses); 286 return encodeResult(message, responses);
286 } 287 }
287 288
288 Future<String> route(Message message) { 289 Future<String> route(Message message) {
289 if (message.completed) { 290 if (message.completed) {
290 return message.response; 291 return message.response;
291 } 292 }
292 // TODO(turnidge): Update to json rpc. BEFORE SUBMIT. 293 // TODO(turnidge): Update to json rpc. BEFORE SUBMIT.
293 if ((message.path.length == 1) && (message.path[0] == 'clients')) { 294 if ((message.path.length == 1) && (message.path[0] == 'clients')) {
294 _clientCollection(message); 295 _clientCollection(message);
295 return message.response; 296 return message.response;
(...skipping 24 matching lines...) Expand all
320 service.runningIsolates.isolateStartup(port_id, sp, name); 321 service.runningIsolates.isolateStartup(port_id, sp, name);
321 } 322 }
322 323
323 void _onStart() native "VMService_OnStart"; 324 void _onStart() native "VMService_OnStart";
324 325
325 void _onExit() native "VMService_OnExit"; 326 void _onExit() native "VMService_OnExit";
326 327
327 bool _vmListenStream(String streamId) native "VMService_ListenStream"; 328 bool _vmListenStream(String streamId) native "VMService_ListenStream";
328 329
329 void _vmCancelStream(String streamId) native "VMService_CancelStream"; 330 void _vmCancelStream(String streamId) native "VMService_CancelStream";
OLDNEW
« no previous file with comments | « runtime/vm/service/service.md ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698