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 dart._vmservice; | 5 part of dart._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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 _completer.complete(JSON.encode({ | 109 _completer.complete(JSON.encode({ |
110 'type': 'ServiceError', | 110 'type': 'ServiceError', |
111 'id': '', | 111 'id': '', |
112 'kind': 'InternalError', | 112 'kind': 'InternalError', |
113 'message': 'could not send message [${serial}] to isolate', | 113 'message': 'could not send message [${serial}] to isolate', |
114 })); | 114 })); |
115 } | 115 } |
116 return _completer.future; | 116 return _completer.future; |
117 } | 117 } |
118 | 118 |
| 119 // We currently support two ways of passing parameters from Dart code to C |
| 120 // code. The original way always converts the parameters to strings before |
| 121 // passing them over. Our goal is to convert all C handlers to take the |
| 122 // parameters as Dart objects but until the conversion is complete, we |
| 123 // maintain the list of supported methods below. |
| 124 bool _methodNeedsObjectParameters(String method) { |
| 125 switch (method) { |
| 126 case '_listDevFS': |
| 127 case '_listDevFSFiles': |
| 128 case '_createDevFS': |
| 129 case '_deleteDevFS': |
| 130 case '_writeDevFSFile': |
| 131 case '_writeDevFSFiles': |
| 132 case '_readDevFSFile': |
| 133 return true; |
| 134 default: |
| 135 return false; |
| 136 } |
| 137 } |
| 138 |
119 Future<String> sendToVM() { | 139 Future<String> sendToVM() { |
120 final receivePort = new RawReceivePort(); | 140 final receivePort = new RawReceivePort(); |
121 receivePort.handler = (value) { | 141 receivePort.handler = (value) { |
122 receivePort.close(); | 142 receivePort.close(); |
123 _completer.complete(value); | 143 _completer.complete(value); |
124 }; | 144 }; |
125 var keys = _makeAllString(params.keys.toList(growable:false)); | 145 if (_methodNeedsObjectParameters(method)) { |
126 var values = _makeAllString(params.values.toList(growable:false)); | 146 // We use a different method invocation path here. |
127 var request = new List(6) | 147 var keys = params.keys.toList(growable:false); |
128 ..[0] = 0 // Make room for OOB message type. | 148 var values = params.values.toList(growable:false); |
129 ..[1] = receivePort.sendPort | 149 var request = new List(6) |
130 ..[2] = serial | 150 ..[0] = 0 // Make room for OOB message type. |
131 ..[3] = method | 151 ..[1] = receivePort.sendPort |
132 ..[4] = keys | 152 ..[2] = serial |
133 ..[5] = values; | 153 ..[3] = method |
134 sendRootServiceMessage(request); | 154 ..[4] = keys |
135 return _completer.future; | 155 ..[5] = values; |
| 156 sendObjectRootServiceMessage(request); |
| 157 return _completer.future; |
| 158 } else { |
| 159 var keys = _makeAllString(params.keys.toList(growable:false)); |
| 160 var values = _makeAllString(params.values.toList(growable:false)); |
| 161 var request = new List(6) |
| 162 ..[0] = 0 // Make room for OOB message type. |
| 163 ..[1] = receivePort.sendPort |
| 164 ..[2] = serial |
| 165 ..[3] = method |
| 166 ..[4] = keys |
| 167 ..[5] = values; |
| 168 sendRootServiceMessage(request); |
| 169 return _completer.future; |
| 170 } |
136 } | 171 } |
137 | 172 |
138 void setResponse(String response) { | 173 void setResponse(String response) { |
139 _completer.complete(response); | 174 _completer.complete(response); |
140 } | 175 } |
141 | 176 |
142 void setErrorResponse(int code, String details) { | 177 void setErrorResponse(int code, String details) { |
143 _completer.complete(encodeRpcError(this, code, | 178 _completer.complete(encodeRpcError(this, code, |
144 details: '$method: $details')); | 179 details: '$method: $details')); |
145 } | 180 } |
146 } | 181 } |
147 | 182 |
148 external bool sendIsolateServiceMessage(SendPort sp, List m); | 183 external bool sendIsolateServiceMessage(SendPort sp, List m); |
149 external void sendRootServiceMessage(List m); | 184 external void sendRootServiceMessage(List m); |
| 185 external void sendObjectRootServiceMessage(List m); |
OLD | NEW |