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