| 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import 'package:json_rpc_2/json_rpc_2.dart' as rpc; | 7 import 'package:json_rpc_2/json_rpc_2.dart' as rpc; |
| 8 | 8 |
| 9 /// A class that exposes the service protocol's event streams. | 9 /// A class that exposes the service protocol's event streams. |
| 10 /// | 10 /// |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 StreamController<Map> _gcController; | 34 StreamController<Map> _gcController; |
| 35 | 35 |
| 36 /// Data written to standard output. | 36 /// Data written to standard output. |
| 37 Stream<Map> get stdout => _stdoutController.stream; | 37 Stream<Map> get stdout => _stdoutController.stream; |
| 38 StreamController<Map> _stdoutController; | 38 StreamController<Map> _stdoutController; |
| 39 | 39 |
| 40 /// Data written to standard error. | 40 /// Data written to standard error. |
| 41 Stream<Map> get stderr => _stderrController.stream; | 41 Stream<Map> get stderr => _stderrController.stream; |
| 42 StreamController<Map> _stderrController; | 42 StreamController<Map> _stderrController; |
| 43 | 43 |
| 44 /// Custom events posted via `postEvent` from the `dart:developer` package. |
| 45 Stream<Map> get extension => _extensionController.stream; |
| 46 StreamController<Map> _extensionController; |
| 47 |
| 44 /// A subscription to [debug]. | 48 /// A subscription to [debug]. |
| 45 /// | 49 /// |
| 46 /// This subscription fires no events, but it exists as long as there's also a | 50 /// This subscription fires no events, but it exists as long as there's also a |
| 47 /// subscription to [stdout] or [stderr] to work around sdk#24350. | 51 /// subscription to [stdout] or [stderr] to work around sdk#24350. |
| 48 StreamSubscription _debugSubscription; | 52 StreamSubscription _debugSubscription; |
| 49 | 53 |
| 50 StreamManager(this._peer) { | 54 StreamManager(this._peer) { |
| 51 _isolateController = _controller("Isolate"); | 55 _isolateController = _controller("Isolate"); |
| 52 _vmController = _controller("VM"); | 56 _vmController = _controller("VM"); |
| 53 _debugController = _controller("Debug"); | 57 _debugController = _controller("Debug"); |
| 54 _gcController = _controller("GC"); | 58 _gcController = _controller("GC"); |
| 55 _stdoutController = _controller("Stdout"); | 59 _stdoutController = _controller("Stdout"); |
| 56 _stderrController = _controller("Stderr"); | 60 _stderrController = _controller("Stderr"); |
| 61 _extensionController = _controller("Extension"); |
| 57 | 62 |
| 58 _peer.registerMethod("streamNotify", (params) { | 63 _peer.registerMethod("streamNotify", (params) { |
| 59 switch (params["streamId"].asString) { | 64 switch (params["streamId"].asString) { |
| 60 case "VM": | 65 case "VM": |
| 61 _vmController.add(params["event"].asMap); | 66 _vmController.add(params["event"].asMap); |
| 62 break; | 67 break; |
| 63 case "Isolate": | 68 case "Isolate": |
| 64 _isolateController.add(params["event"].asMap); | 69 _isolateController.add(params["event"].asMap); |
| 65 break; | 70 break; |
| 66 case "Debug": | 71 case "Debug": |
| 67 _debugController.add(params["event"].asMap); | 72 _debugController.add(params["event"].asMap); |
| 68 break; | 73 break; |
| 69 case "GC": | 74 case "GC": |
| 70 _gcController.add(params["event"].asMap); | 75 _gcController.add(params["event"].asMap); |
| 71 break; | 76 break; |
| 72 case "Stdout": | 77 case "Stdout": |
| 73 _stdoutController.add(params["event"].asMap); | 78 _stdoutController.add(params["event"].asMap); |
| 74 break; | 79 break; |
| 75 case "Stderr": | 80 case "Stderr": |
| 76 _stderrController.add(params["event"].asMap); | 81 _stderrController.add(params["event"].asMap); |
| 77 break; | 82 break; |
| 83 case "Extension": |
| 84 _extensionController.add(params["event"].asMap); |
| 85 break; |
| 78 } | 86 } |
| 79 }); | 87 }); |
| 80 | 88 |
| 81 _peer.done.then((_) { | 89 _peer.done.then((_) { |
| 82 _vmController.close(); | 90 _vmController.close(); |
| 83 _isolateController.close(); | 91 _isolateController.close(); |
| 84 _debugController.close(); | 92 _debugController.close(); |
| 85 _gcController.close(); | 93 _gcController.close(); |
| 86 _stderrController.close(); | 94 _stderrController.close(); |
| 87 _stdoutController.close(); | 95 _stdoutController.close(); |
| 96 _extensionController.close(); |
| 88 }, onError: (_) {}); | 97 }, onError: (_) {}); |
| 89 } | 98 } |
| 90 | 99 |
| 91 /// Returns a broadcast [StreamController] for the stream with [streamID]. | 100 /// Returns a broadcast [StreamController] for the stream with [streamID]. |
| 92 /// | 101 /// |
| 93 /// This controller subscribes to the stream when it has a listener and | 102 /// This controller subscribes to the stream when it has a listener and |
| 94 /// unsubscribes once it has no listeners. | 103 /// unsubscribes once it has no listeners. |
| 95 StreamController<Map> _controller(String streamID) { | 104 StreamController<Map> _controller(String streamID) { |
| 96 var controller; | 105 var controller; |
| 97 controller = new StreamController.broadcast(sync: true, onListen: () { | 106 controller = new StreamController.broadcast(sync: true, onListen: () { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 120 _peer.sendRequest("streamCancel", { | 129 _peer.sendRequest("streamCancel", { |
| 121 "streamId": streamID | 130 "streamId": streamID |
| 122 }).catchError((_) { | 131 }).catchError((_) { |
| 123 // Do nothing if canceling the stream failed, since no one's listening | 132 // Do nothing if canceling the stream failed, since no one's listening |
| 124 // to it anyway. | 133 // to it anyway. |
| 125 }); | 134 }); |
| 126 }); | 135 }); |
| 127 return controller; | 136 return controller; |
| 128 } | 137 } |
| 129 } | 138 } |
| OLD | NEW |