OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 part of vmservice; | 5 part of vmservice; |
6 | 6 |
7 class Message { | 7 class Message { |
8 final Completer _completer = new Completer.sync(); | 8 final Completer _completer = new Completer.sync(); |
9 bool get completed => _completer.isCompleted; | 9 bool get completed => _completer.isCompleted; |
10 /// Future of response. | 10 /// Future of response. |
11 Future<String> get response => _completer.future; | 11 Future<String> get response => _completer.future; |
12 Client client; | |
13 | 12 |
14 // Client-side identifier for this message. | 13 // Client-side identifier for this message. |
15 final serial; | 14 final serial; |
16 | 15 |
17 // In new messages. | 16 // In new messages. |
18 final String method; | 17 final String method; |
19 | 18 |
20 // In old messages. | 19 // In old messages. |
21 final List path = new List(); | 20 final List path = new List(); |
22 | 21 |
23 final Map params = new Map(); | 22 final Map params = new Map(); |
24 | 23 |
25 void _setPath(List<String> pathSegments) { | 24 void _setPath(List<String> pathSegments) { |
26 if (pathSegments == null) { | 25 if (pathSegments == null) { |
27 return; | 26 return; |
28 } | 27 } |
29 pathSegments.forEach((String segment) { | 28 pathSegments.forEach((String segment) { |
30 if (segment == null || segment == '') { | 29 if (segment == null || segment == '') { |
31 return; | 30 return; |
32 } | 31 } |
33 path.add(segment); | 32 path.add(segment); |
34 }); | 33 }); |
35 } | 34 } |
36 | 35 |
37 Message.fromJsonRpc(this.client, Map map) | 36 Message.fromJsonRpc(Map map) |
38 : serial = map['id'], method = map['method'] { | 37 : serial = map['id'], method = map['method'] { |
39 params.addAll(map['params']); | 38 params.addAll(map['params']); |
40 } | 39 } |
41 | 40 |
42 static String _methodNameFromUri(Uri uri) { | 41 static String _methodNameFromUri(Uri uri) { |
43 if (uri == null) { | 42 if (uri == null) { |
44 return ''; | 43 return ''; |
45 } | 44 } |
46 if (uri.pathSegments.length == 0) { | 45 if (uri.pathSegments.length == 0) { |
47 return ''; | 46 return ''; |
48 } | 47 } |
49 return uri.pathSegments[0]; | 48 return uri.pathSegments[0]; |
50 } | 49 } |
51 | 50 |
52 Message.fromUri(this.client, Uri uri) | 51 Message.fromUri(Uri uri) |
53 : method = _methodNameFromUri(uri) { | 52 : method = _methodNameFromUri(uri) { |
54 params.addAll(uri.queryParameters); | 53 params.addAll(uri.queryParameters); |
55 } | 54 } |
56 | 55 |
57 Message.forIsolate(this.client, Uri uri, RunningIsolate isolate) | 56 Message.forIsolate(Uri uri, RunningIsolate isolate) |
58 : method = _methodNameFromUri(uri) { | 57 : method = _methodNameFromUri(uri) { |
59 params.addAll(uri.queryParameters); | 58 params.addAll(uri.queryParameters); |
60 params['isolateId'] = isolate.serviceId; | 59 params['isolateId'] = isolate.serviceId; |
61 } | 60 } |
62 | 61 |
63 Uri toUri() { | 62 Uri toUri() { |
64 return new Uri(path: method, queryParameters: params); | 63 return new Uri(path: method, queryParameters: params); |
65 } | 64 } |
66 | 65 |
67 dynamic toJson() { | 66 dynamic toJson() { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 }; | 152 }; |
154 _completer.complete(JSON.encode(response)); | 153 _completer.complete(JSON.encode(response)); |
155 } | 154 } |
156 } | 155 } |
157 | 156 |
158 bool sendIsolateServiceMessage(SendPort sp, List m) | 157 bool sendIsolateServiceMessage(SendPort sp, List m) |
159 native "VMService_SendIsolateServiceMessage"; | 158 native "VMService_SendIsolateServiceMessage"; |
160 | 159 |
161 void sendRootServiceMessage(List m) | 160 void sendRootServiceMessage(List m) |
162 native "VMService_SendRootServiceMessage"; | 161 native "VMService_SendRootServiceMessage"; |
OLD | NEW |