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 }; | 10 }; |
11 | 11 |
12 String _serviceObjectHandler(List<String> paths, | 12 String _serviceObjectHandler(List<String> paths, |
13 List<String> keys, | 13 List<String> keys, |
14 List<String> values) { | 14 List<String> values) { |
15 assert(keys.length == values.length); | 15 assert(keys.length == values.length); |
16 badPath() { | 16 badPath() { |
17 throw "Invalid path '${paths.join("/")}'"; | 17 throw "Invalid path '${paths.join("/")}'"; |
18 } | 18 } |
19 if (paths.isEmpty) { | 19 if (paths.isEmpty) { |
20 badPath(); | 20 return JSON.encode(_ioServiceObject()); |
21 } | 21 } |
22 int i = 0; | 22 int i = 0; |
23 var current = _servicePathMap; | 23 var current = _servicePathMap; |
24 do { | 24 do { |
25 current = current[paths[i]]; | 25 current = current[paths[i]]; |
26 i++; | 26 i++; |
27 } while (i < paths.length && current is Map); | 27 } while (i < paths.length && current is Map); |
28 if (current is! Function) { | 28 if (current is! Function) { |
29 badPath(); | 29 badPath(); |
30 } | 30 } |
31 var query = new Map(); | 31 var query = new Map(); |
32 for (int i = 0; i < keys.length; i++) { | 32 for (int i = 0; i < keys.length; i++) { |
33 query[keys[i]] = values[i]; | 33 query[keys[i]] = values[i]; |
34 } | 34 } |
35 return JSON.encode(current(paths.sublist(i))); | 35 return JSON.encode(current(paths.sublist(i))); |
36 } | 36 } |
37 | 37 |
| 38 Map _ioServiceObject() { |
| 39 return { |
| 40 'id': 'io', |
| 41 'type': 'IO', |
| 42 'name': 'io', |
| 43 'user_name': 'io', |
| 44 }; |
| 45 } |
| 46 |
38 Map _httpServersServiceObject(args) { | 47 Map _httpServersServiceObject(args) { |
39 if (args.length == 1) { | 48 if (args.length == 1) { |
40 var server = _HttpServer._servers[int.parse(args.first)]; | 49 var server = _HttpServer._servers[int.parse(args.first)]; |
41 if (server == null) { | 50 if (server == null) { |
42 return {}; | 51 return {}; |
43 } | 52 } |
44 return server._toJSON(false); | 53 return server._toJSON(false); |
45 } | 54 } |
46 return { | 55 return { |
47 'id': 'io/http/servers', | 56 'id': 'io/http/servers', |
48 'type': 'HttpServerList', | 57 'type': 'HttpServerList', |
49 'members': _HttpServer._servers.values | 58 'members': _HttpServer._servers.values |
50 .map((server) => server._toJSON(true)).toList(), | 59 .map((server) => server._toJSON(true)).toList(), |
51 }; | 60 }; |
52 } | 61 } |
OLD | NEW |