| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:convert'; | 6 import 'dart:convert'; |
| 7 import 'dart:isolate'; | 7 import 'dart:isolate'; |
| 8 | 8 |
| 9 import 'package:analyzer/instrumentation/instrumentation.dart'; | 9 import 'package:analyzer/instrumentation/instrumentation.dart'; |
| 10 import 'package:analyzer_plugin/channel/channel.dart'; | 10 import 'package:analyzer_plugin/channel/channel.dart'; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 _subscription.cancel(); | 114 _subscription.cancel(); |
| 115 _subscription = null; | 115 _subscription = null; |
| 116 } | 116 } |
| 117 } | 117 } |
| 118 | 118 |
| 119 @override | 119 @override |
| 120 void listen(void onRequest(Request request), | 120 void listen(void onRequest(Request request), |
| 121 {Function onError, void onDone()}) { | 121 {Function onError, void onDone()}) { |
| 122 void onData(data) { | 122 void onData(data) { |
| 123 Map<String, Object> requestMap = data; | 123 Map<String, Object> requestMap = data; |
| 124 // print('[plugin] Received request: ${JSON.encode(requestMap)}'); | |
| 125 Request request = new Request.fromJson(requestMap); | 124 Request request = new Request.fromJson(requestMap); |
| 126 if (request != null) { | 125 if (request != null) { |
| 127 onRequest(request); | 126 onRequest(request); |
| 128 } | 127 } |
| 129 } | 128 } |
| 130 | 129 |
| 131 if (_subscription != null) { | 130 if (_subscription != null) { |
| 132 throw new StateError('Only one listener is allowed per channel'); | 131 throw new StateError('Only one listener is allowed per channel'); |
| 133 } | 132 } |
| 134 _subscription = _receivePort.listen(onData, | 133 _subscription = _receivePort.listen(onData, |
| 135 onError: onError, onDone: onDone, cancelOnError: false); | 134 onError: onError, onDone: onDone, cancelOnError: false); |
| 136 } | 135 } |
| 137 | 136 |
| 138 @override | 137 @override |
| 139 void sendNotification(Notification notification) { | 138 void sendNotification(Notification notification) { |
| 140 Map<String, Object> json = notification.toJson(); | 139 Map<String, Object> json = notification.toJson(); |
| 141 // print('[plugin] Send notification: ${JSON.encode(json)}'); | |
| 142 _sendPort.send(json); | 140 _sendPort.send(json); |
| 143 } | 141 } |
| 144 | 142 |
| 145 @override | 143 @override |
| 146 void sendResponse(Response response) { | 144 void sendResponse(Response response) { |
| 147 Map<String, Object> json = response.toJson(); | 145 Map<String, Object> json = response.toJson(); |
| 148 // print('[plugin] Send response: ${JSON.encode(json)}'); | |
| 149 _sendPort.send(json); | 146 _sendPort.send(json); |
| 150 } | 147 } |
| 151 } | 148 } |
| 152 | 149 |
| 153 /** | 150 /** |
| 154 * A communication channel that allows an analysis server to send [Request]s | 151 * A communication channel that allows an analysis server to send [Request]s |
| 155 * to, and to receive both [Response]s and [Notification]s from, a plugin. | 152 * to, and to receive both [Response]s and [Notification]s from, a plugin. |
| 156 */ | 153 */ |
| 157 abstract class ServerIsolateChannel implements ServerCommunicationChannel { | 154 abstract class ServerIsolateChannel implements ServerCommunicationChannel { |
| 158 /** | 155 /** |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 String encodedRequest = JSON.encode(json); | 284 String encodedRequest = JSON.encode(json); |
| 288 instrumentationService.logPluginRequest(pluginId, encodedRequest); | 285 instrumentationService.logPluginRequest(pluginId, encodedRequest); |
| 289 _sendPort.send(json); | 286 _sendPort.send(json); |
| 290 } | 287 } |
| 291 | 288 |
| 292 /** | 289 /** |
| 293 * Spawn the isolate in which the plugin is running. | 290 * Spawn the isolate in which the plugin is running. |
| 294 */ | 291 */ |
| 295 Future<Isolate> _spawnIsolate(); | 292 Future<Isolate> _spawnIsolate(); |
| 296 } | 293 } |
| OLD | NEW |