| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 | 5 |
| 6 final Map _servicePathMap = { | 6 final Map _servicePathMap = { |
| 7 'http' : { | 7 'http' : { |
| 8 'servers' : _httpServersServiceObject, | 8 'servers' : _httpServersServiceObject, |
| 9 }, | 9 }, |
| 10 'sockets' : _socketsServiceObject, | 10 'sockets' : _socketsServiceObject, |
| 11 'websockets' : _webSocketsServiceObject, | 11 'websockets' : _webSocketsServiceObject, |
| 12 'file' : { | 12 'file' : { |
| 13 'randomaccessfiles' : _randomAccessFilesServiceObject | 13 'randomaccessfiles' : _randomAccessFilesServiceObject |
| 14 }, | 14 }, |
| 15 'processes' : _processesServiceObject, | 15 'processes' : _processesServiceObject, |
| 16 }; | 16 }; |
| 17 | 17 |
| 18 String _serviceObjectHandler(List<String> paths, | 18 String _serviceObjectHandler(List<String> paths, |
| 19 List<String> keys, | 19 List<String> keys, |
| 20 List<String> values) { | 20 List<String> values) { |
| 21 assert(keys.length == values.length); | 21 assert(keys.length == values.length); |
| 22 badPath() { | |
| 23 throw "Invalid path '${paths.join("/")}'"; | |
| 24 } | |
| 25 if (paths.isEmpty) { | 22 if (paths.isEmpty) { |
| 26 return JSON.encode(_ioServiceObject()); | 23 return JSON.encode(_ioServiceObject()); |
| 27 } | 24 } |
| 28 int i = 0; | 25 int i = 0; |
| 29 var current = _servicePathMap; | 26 var current = _servicePathMap; |
| 30 do { | 27 do { |
| 31 current = current[paths[i]]; | 28 current = current[paths[i]]; |
| 32 i++; | 29 i++; |
| 33 } while (i < paths.length && current is Map); | 30 } while (i < paths.length && current is Map); |
| 34 if (current is! Function) { | 31 if (current is! Function) { |
| 35 badPath(); | 32 return JSON.encode(_makeServiceError('Unrecognized path', paths, keys, |
| 33 values)); |
| 36 } | 34 } |
| 37 var query = new Map(); | 35 var query = new Map(); |
| 38 for (int i = 0; i < keys.length; i++) { | 36 for (int i = 0; i < keys.length; i++) { |
| 39 query[keys[i]] = values[i]; | 37 query[keys[i]] = values[i]; |
| 40 } | 38 } |
| 41 return JSON.encode(current(paths.sublist(i))); | 39 return JSON.encode(current(paths.sublist(i))); |
| 42 } | 40 } |
| 43 | 41 |
| 42 Map _makeServiceError(String message, |
| 43 List<String> paths, |
| 44 List<String> keys, |
| 45 List<String> values, |
| 46 [String kind]) { |
| 47 var error = { |
| 48 'type': 'Error', |
| 49 'id': '', |
| 50 'message': message, |
| 51 'request': { |
| 52 'arguments': paths, |
| 53 'option_keys': keys, |
| 54 'option_values': values, |
| 55 } |
| 56 }; |
| 57 if (kind != null) { |
| 58 error['kind'] = kind; |
| 59 } |
| 60 return error; |
| 61 } |
| 62 |
| 44 Map _ioServiceObject() { | 63 Map _ioServiceObject() { |
| 45 return { | 64 return { |
| 46 'id': 'io', | 65 'id': 'io', |
| 47 'type': 'IO', | 66 'type': 'IO', |
| 48 'name': 'io', | 67 'name': 'io', |
| 49 'user_name': 'io', | 68 'user_name': 'io', |
| 50 }; | 69 }; |
| 51 } | 70 } |
| 52 | 71 |
| 53 Map _httpServersServiceObject(args) { | 72 Map _httpServersServiceObject(args) { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 } | 141 } |
| 123 return process._toJSON(false); | 142 return process._toJSON(false); |
| 124 } | 143 } |
| 125 return { | 144 return { |
| 126 'id': 'io/processes', | 145 'id': 'io/processes', |
| 127 'type': 'ProcessList', | 146 'type': 'ProcessList', |
| 128 'members': _ProcessImpl._processes.values | 147 'members': _ProcessImpl._processes.values |
| 129 .map((p) => p._toJSON(true)).toList(), | 148 .map((p) => p._toJSON(true)).toList(), |
| 130 }; | 149 }; |
| 131 } | 150 } |
| OLD | NEW |