| Index: sdk/lib/io/io_resource_info.dart
|
| diff --git a/sdk/lib/io/io_resource_info.dart b/sdk/lib/io/io_resource_info.dart
|
| index 31c57a2efdc55e428a8deac2e4f9343f33fbcc30..8e418cf705b4efa4f937402f3877924a18529604 100644
|
| --- a/sdk/lib/io/io_resource_info.dart
|
| +++ b/sdk/lib/io/io_resource_info.dart
|
| @@ -10,9 +10,9 @@ abstract class _IOResourceInfo {
|
| String get name;
|
| static int _count = 0;
|
|
|
| - _IOResourceInfo(this.type) : id = _IOResourceInfo.getNextID();
|
| + static final Stopwatch _sw = new Stopwatch()..start();
|
|
|
| - String toJSON();
|
| + _IOResourceInfo(this.type) : id = _IOResourceInfo.getNextID();
|
|
|
| /// Get the full set of values for a specific implementation. This is normally
|
| /// looked up based on an id from a referenceValueMap.
|
| @@ -39,8 +39,8 @@ abstract class _ReadWriteResourceInfo extends _IOResourceInfo {
|
| double lastRead;
|
| double lastWrite;
|
|
|
| - static final Stopwatch _sw = new Stopwatch()..start();
|
| - static double get timestamp => _sw.elapsedMicroseconds / 1000000.0;
|
| + static double get timestamp =>
|
| + _IOResourceInfo._sw.elapsedMicroseconds / 1000000.0;
|
|
|
| // Not all call sites use this. In some cases, e.g., a socket, a read does
|
| // not always mean that we actually read some bytes (we may do a read to see
|
| @@ -83,10 +83,6 @@ abstract class _ReadWriteResourceInfo extends _IOResourceInfo {
|
| 'last_read': lastRead,
|
| 'last_write': lastWrite
|
| };
|
| -
|
| - String toJSON() {
|
| - return JSON.encode(fullValueMap);
|
| - }
|
| }
|
|
|
| class _FileResourceInfo extends _ReadWriteResourceInfo {
|
| @@ -141,6 +137,68 @@ class _FileResourceInfo extends _ReadWriteResourceInfo {
|
| }
|
| }
|
|
|
| +class _ProcessResourceInfo extends _IOResourceInfo{
|
| + static const String TYPE = '_process';
|
| + final process;
|
| + final int startedAt;
|
| +
|
| + static Map<int, _ProcessResourceInfo> startedProcesses =
|
| + new Map<int, _ProcessResourceInfo>();
|
| +
|
| + _ProcessResourceInfo(this.process) :
|
| + startedAt = new DateTime.now().millisecondsSinceEpoch,
|
| + super(TYPE) {
|
| + ProcessStarted(this);
|
| + }
|
| +
|
| + String get name => process._path;
|
| +
|
| + void stopped() => ProcessStopped(this);
|
| +
|
| + Map<String, String> get fullValueMap =>
|
| + {
|
| + 'type': type,
|
| + 'id': id,
|
| + 'name': name,
|
| + 'pid': process.pid,
|
| + 'started_at': startedAt,
|
| + 'arguments': process._arguments,
|
| + 'working_directory':
|
| + process._workingDirectory == null ? '.' : process._workingDirectory,
|
| + };
|
| +
|
| + static ProcessStarted(_ProcessResourceInfo info) {
|
| + assert(!startedProcesses.containsKey(info.id));
|
| + startedProcesses[info.id] = info;
|
| + }
|
| +
|
| + static ProcessStopped(_ProcessResourceInfo info) {
|
| + assert(startedProcesses.containsKey(info.id));
|
| + startedProcesses.remove(info.id);
|
| + }
|
| +
|
| + static Iterable<Map<String, String>> getStartedProcessesList() =>
|
| + new List.from(startedProcesses.values.map((e) => e.referenceValueMap));
|
| +
|
| + static Future<ServiceExtensionResponse> getStartedProcesses(
|
| + String function, Map<String, String> params) {
|
| + assert(function == '__getProcesses');
|
| + var data = {'type': '_startedprocesses', 'data': getStartedProcessesList()};
|
| + var json = JSON.encode(data);
|
| + return new Future.value(new ServiceExtensionResponse.result(json));
|
| + }
|
| +
|
| + static Future<ServiceExtensionResponse> getProcessInfoMapById(
|
| + String function, Map<String, String> params) {
|
| + var id = int.parse(params['id']);
|
| + var result = startedProcesses.containsKey(id)
|
| + ? startedProcesses[id].fullValueMap
|
| + : {};
|
| + var json = JSON.encode(result);
|
| + return new Future.value(new ServiceExtensionResponse.result(json));
|
| + }
|
| +}
|
| +
|
| class _SocketResourceInfo extends _ReadWriteResourceInfo {
|
| static const String TCP_STRING = 'TCP';
|
| static const String UDP_STRING = 'UDP';
|
|
|