OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 dart._vmservice; | 5 library dart._vmservice; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 import 'dart:convert'; | 9 import 'dart:convert'; |
10 import 'dart:isolate'; | 10 import 'dart:isolate'; |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 return encodeRpcError(message, kStreamNotSubscribed); | 288 return encodeRpcError(message, kStreamNotSubscribed); |
289 } | 289 } |
290 client.streams.remove(streamId); | 290 client.streams.remove(streamId); |
291 if (!_isAnyClientSubscribed(streamId)) { | 291 if (!_isAnyClientSubscribed(streamId)) { |
292 _vmCancelStream(streamId); | 292 _vmCancelStream(streamId); |
293 } | 293 } |
294 | 294 |
295 return encodeSuccess(message); | 295 return encodeSuccess(message); |
296 } | 296 } |
297 | 297 |
| 298 Future<String> _spawnUri(Message message) async { |
| 299 var token = message.params['token']; |
| 300 if (token == null) { |
| 301 return encodeMissingParamError(message, 'token'); |
| 302 } |
| 303 if (token is! String) { |
| 304 return encodeInvalidParamError(message, 'token'); |
| 305 } |
| 306 var uri = message.params['uri']; |
| 307 if (uri == null) { |
| 308 return encodeMissingParamError(message, 'uri'); |
| 309 } |
| 310 if (uri is! String) { |
| 311 return encodeInvalidParamError(message, 'uri'); |
| 312 } |
| 313 var args = message.params['args']; |
| 314 if (args != null && |
| 315 args is! List<String>) { |
| 316 return encodeInvalidParamError(message, 'args'); |
| 317 } |
| 318 var msg = message.params['message']; |
| 319 |
| 320 Isolate.spawnUri(Uri.parse(uri), args, msg).then((isolate) { |
| 321 _spawnUriNotify(isolate.controlPort, token); |
| 322 }).catchError((e) { |
| 323 _spawnUriNotify(e.toString(), token); |
| 324 }); |
| 325 |
| 326 return encodeSuccess(message); |
| 327 } |
| 328 |
298 // TODO(johnmccutchan): Turn this into a command line tool that uses the | 329 // TODO(johnmccutchan): Turn this into a command line tool that uses the |
299 // service library. | 330 // service library. |
300 Future<String> _getCrashDump(Message message) async { | 331 Future<String> _getCrashDump(Message message) async { |
301 var client = message.client; | 332 var client = message.client; |
302 final perIsolateRequests = [ | 333 final perIsolateRequests = [ |
303 // ?isolateId=<isolate id> will be appended to each of these requests. | 334 // ?isolateId=<isolate id> will be appended to each of these requests. |
304 // Isolate information. | 335 // Isolate information. |
305 Uri.parse('getIsolate'), | 336 Uri.parse('getIsolate'), |
306 // State of heap. | 337 // State of heap. |
307 Uri.parse('_getAllocationProfile'), | 338 Uri.parse('_getAllocationProfile'), |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 // TODO(turnidge): Update to json rpc. BEFORE SUBMIT. | 391 // TODO(turnidge): Update to json rpc. BEFORE SUBMIT. |
361 if (message.method == '_getCrashDump') { | 392 if (message.method == '_getCrashDump') { |
362 return _getCrashDump(message); | 393 return _getCrashDump(message); |
363 } | 394 } |
364 if (message.method == 'streamListen') { | 395 if (message.method == 'streamListen') { |
365 return _streamListen(message); | 396 return _streamListen(message); |
366 } | 397 } |
367 if (message.method == 'streamCancel') { | 398 if (message.method == 'streamCancel') { |
368 return _streamCancel(message); | 399 return _streamCancel(message); |
369 } | 400 } |
| 401 if (message.method == '_spawnUri') { |
| 402 return _spawnUri(message); |
| 403 } |
370 if (_devfs.shouldHandleMessage(message)) { | 404 if (_devfs.shouldHandleMessage(message)) { |
371 return _devfs.handleMessage(message); | 405 return _devfs.handleMessage(message); |
372 } | 406 } |
373 if (message.params['isolateId'] != null) { | 407 if (message.params['isolateId'] != null) { |
374 return runningIsolates.route(message); | 408 return runningIsolates.route(message); |
375 } | 409 } |
376 return message.sendToVM(); | 410 return message.sendToVM(); |
377 } | 411 } |
378 } | 412 } |
379 | 413 |
(...skipping 17 matching lines...) Expand all Loading... |
397 external void onServerAddressChange(String address); | 431 external void onServerAddressChange(String address); |
398 | 432 |
399 /// Subscribe to a service stream. | 433 /// Subscribe to a service stream. |
400 external bool _vmListenStream(String streamId); | 434 external bool _vmListenStream(String streamId); |
401 | 435 |
402 /// Cancel a subscription to a service stream. | 436 /// Cancel a subscription to a service stream. |
403 external void _vmCancelStream(String streamId); | 437 external void _vmCancelStream(String streamId); |
404 | 438 |
405 /// Get the bytes to the tar archive. | 439 /// Get the bytes to the tar archive. |
406 external Uint8List _requestAssets(); | 440 external Uint8List _requestAssets(); |
| 441 |
| 442 /// Notify the vm service that an isolate has been spawned via rpc. |
| 443 external void _spawnUriNotify(obj, String token); |
OLD | NEW |