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. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 Future<String> send(SendPort sendPort) { | 53 Future<String> send(SendPort sendPort) { |
54 final receivePort = new RawReceivePort(); | 54 final receivePort = new RawReceivePort(); |
55 receivePort.handler = (value) { | 55 receivePort.handler = (value) { |
56 receivePort.close(); | 56 receivePort.close(); |
57 if (value is Exception) { | 57 if (value is Exception) { |
58 _completer.completeError(value); | 58 _completer.completeError(value); |
59 } else { | 59 } else { |
60 _completer.complete(value); | 60 _completer.complete(value); |
61 } | 61 } |
62 }; | 62 }; |
63 var keys = options.keys.toList(); | 63 var keys = options.keys.toList(growable:false); |
64 var values = options.values.toList(); | 64 var values = options.values.toList(growable:false); |
65 var request = [receivePort.sendPort, path, keys, values]; | 65 var request = new List(5) |
| 66 ..[0] = 0 // Make room for OOB message type. |
| 67 ..[1] = receivePort.sendPort |
| 68 ..[2] = path |
| 69 ..[3] = keys |
| 70 ..[4] = values; |
66 sendIsolateServiceMessage(sendPort, request); | 71 sendIsolateServiceMessage(sendPort, request); |
67 return _completer.future; | 72 return _completer.future; |
68 } | 73 } |
69 | 74 |
70 Future<String> sendToVM() { | 75 Future<String> sendToVM() { |
71 final receivePort = new RawReceivePort(); | 76 final receivePort = new RawReceivePort(); |
72 receivePort.handler = (value) { | 77 receivePort.handler = (value) { |
73 receivePort.close(); | 78 receivePort.close(); |
74 if (value is Exception) { | 79 if (value is Exception) { |
75 _completer.completeError(value); | 80 _completer.completeError(value); |
76 } else { | 81 } else { |
77 _completer.complete(value); | 82 _completer.complete(value); |
78 } | 83 } |
79 }; | 84 }; |
80 var keys = options.keys.toList(); | 85 var keys = options.keys.toList(growable:false); |
81 var values = options.values.toList(); | 86 var values = options.values.toList(growable:false); |
82 var request = [receivePort.sendPort, path, keys, values]; | 87 var request = new List(5) |
| 88 ..[0] = 0 // Make room for OOB message type. |
| 89 ..[1] = receivePort.sendPort |
| 90 ..[2] = path |
| 91 ..[3] = keys |
| 92 ..[4] = values; |
83 sendRootServiceMessage(request); | 93 sendRootServiceMessage(request); |
84 return _completer.future; | 94 return _completer.future; |
85 } | 95 } |
86 | 96 |
87 void setResponse(String response) { | 97 void setResponse(String response) { |
88 _completer.complete(response); | 98 _completer.complete(response); |
89 } | 99 } |
90 | 100 |
91 void setErrorResponse(String error) { | 101 void setErrorResponse(String error) { |
92 _completer.complete(JSON.encode({ | 102 _completer.complete(JSON.encode({ |
93 'type': 'ServiceError', | 103 'type': 'ServiceError', |
94 'id': '', | 104 'id': '', |
95 'kind': 'RequestError', | 105 'kind': 'RequestError', |
96 'message': error, | 106 'message': error, |
97 'path': path, | 107 'path': path, |
98 'options': options | 108 'options': options |
99 })); | 109 })); |
100 } | 110 } |
101 } | 111 } |
102 | 112 |
103 void sendIsolateServiceMessage(SendPort sp, List m) | 113 void sendIsolateServiceMessage(SendPort sp, List m) |
104 native "VMService_SendIsolateServiceMessage"; | 114 native "VMService_SendIsolateServiceMessage"; |
105 | 115 |
106 void sendRootServiceMessage(List m) | 116 void sendRootServiceMessage(List m) |
107 native "VMService_SendRootServiceMessage"; | 117 native "VMService_SendRootServiceMessage"; |
OLD | NEW |