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 79557b36fefe8d380372ce0f5a62cd507b6b50f0..8c30c646995627e7bead00ebca152a04ef2a87a1 100644 |
--- a/sdk/lib/io/io_resource_info.dart |
+++ b/sdk/lib/io/io_resource_info.dart |
@@ -4,10 +4,6 @@ |
part of dart.io; |
-const String TCP_STRING = 'TCP'; |
-const String UDP_STRING = 'UDP'; |
- |
- |
abstract class _IOResourceInfo { |
final String type; |
final int id; |
@@ -35,6 +31,9 @@ abstract class _IOResourceInfo { |
static int getNextID() => _count++; |
} |
+// TODO(ricow): Move stopwatch into this class and use it for both files |
Ivan Posva
2015/09/08 18:06:36
Can you please explain what you mean by moving sto
ricow1
2015/09/08 18:33:39
Correct. You can see the follow up here: https://c
|
+// and sockets (by using setters on totalRead/totalWritten). Also, consider |
+// setting readCount and writeCount in those setters. |
abstract class _ReadWriteResourceInfo extends _IOResourceInfo { |
int totalRead; |
int totalWritten; |
@@ -70,13 +69,69 @@ abstract class _ReadWriteResourceInfo extends _IOResourceInfo { |
} |
} |
+class _FileResourceInfo extends _ReadWriteResourceInfo { |
+ static const String TYPE = '_file'; |
+ |
+ final file; |
+ |
+ static Map<int, _FileResourceInfo> openFiles = |
+ new Map<int, _FileResourceInfo>(); |
+ |
+ _FileResourceInfo(this.file) : super(TYPE) { |
+ FileOpened(this); |
+ } |
+ |
+ static FileOpened(_FileResourceInfo info) { |
+ assert(!openFiles.containsKey(info.id)); |
+ openFiles[info.id] = info; |
+ } |
+ |
+ static FileClosed(_FileResourceInfo info) { |
+ assert(openFiles.containsKey(info.id)); |
+ openFiles.remove(info.id); |
+ } |
+ |
+ static Iterable<Map<String, String>> getOpenFilesList() { |
+ return new List.from(openFiles.values.map((e) => e.referenceValueMap)); |
+ } |
+ |
+ static Future<ServiceExtensionResponse> getOpenFiles(function, params) { |
+ assert(function == '__getOpenFiles'); |
+ var data = {'type': '_openfiles', 'data': getOpenFilesList()}; |
+ var json = JSON.encode(data); |
+ return new Future.value(new ServiceExtensionResponse.result(json)); |
+ } |
+ |
+ Map<String, String> getFileInfoMap() { |
+ var result = fullValueMap; |
+ return result; |
+ } |
+ |
+ static Future<ServiceExtensionResponse> getFileInfoMapByID(function, params) { |
+ assert(params.containsKey('id')); |
+ var id = int.parse(params['id']); |
+ var result = |
+ openFiles.containsKey(id) ? openFiles[id].getFileInfoMap() : {}; |
+ var json = JSON.encode(result); |
+ return new Future.value(new ServiceExtensionResponse.result(json)); |
+ } |
+ |
+ String get name { |
+ return '${file.path}'; |
+ } |
+} |
+ |
class _SocketResourceInfo extends _ReadWriteResourceInfo { |
+ static const String TCP_STRING = 'TCP'; |
+ static const String UDP_STRING = 'UDP'; |
+ static const String TYPE = '_socket'; |
+ |
final socket; |
static Map<int, _SocketResourceInfo> openSockets = |
new Map<int, _SocketResourceInfo>(); |
- _SocketResourceInfo(this.socket) : super('_socket') { |
+ _SocketResourceInfo(this.socket) : super(TYPE) { |
SocketOpened(this); |
} |