This reverts commit 2b46ea447f.
This commit is contained in:
@@ -18,7 +18,6 @@ import '../base/io.dart';
|
||||
import '../build_info.dart';
|
||||
import '../commands/daemon.dart';
|
||||
import '../compile.dart';
|
||||
import '../daemon.dart';
|
||||
import '../device.dart';
|
||||
import '../device_port_forwarder.dart';
|
||||
import '../fuchsia/fuchsia_device.dart';
|
||||
@@ -236,10 +235,8 @@ known, it can be explicitly provided to attach via the command-line, e.g.
|
||||
|
||||
final Daemon daemon = boolArg('machine')
|
||||
? Daemon(
|
||||
DaemonConnection(
|
||||
daemonStreams: StdioDaemonStreams(globals.stdio),
|
||||
logger: globals.logger,
|
||||
),
|
||||
stdinCommandStream,
|
||||
stdoutCommandResponse,
|
||||
notifyingLogger: (globals.logger is NotifyingLogger)
|
||||
? globals.logger as NotifyingLogger
|
||||
: NotifyingLogger(verbose: globals.logger.isVerbose, parent: globals.logger),
|
||||
|
||||
@@ -18,7 +18,7 @@ import '../base/logger.dart';
|
||||
import '../base/terminal.dart';
|
||||
import '../base/utils.dart';
|
||||
import '../build_info.dart';
|
||||
import '../daemon.dart';
|
||||
import '../convert.dart';
|
||||
import '../device.dart';
|
||||
import '../device_port_forwarder.dart';
|
||||
import '../emulator.dart';
|
||||
@@ -41,13 +41,7 @@ const String protocolVersion = '0.6.1';
|
||||
/// It can be shutdown with a `daemon.shutdown` command (or by killing the
|
||||
/// process).
|
||||
class DaemonCommand extends FlutterCommand {
|
||||
DaemonCommand({ this.hidden = false }) {
|
||||
argParser.addOption(
|
||||
'listen-on-tcp-port',
|
||||
help: 'If specified, the daemon will be listening for commands on the specified port instead of stdio.',
|
||||
valueHelp: 'port',
|
||||
);
|
||||
}
|
||||
DaemonCommand({ this.hidden = false });
|
||||
|
||||
@override
|
||||
final String name = 'daemon';
|
||||
@@ -63,31 +57,9 @@ class DaemonCommand extends FlutterCommand {
|
||||
|
||||
@override
|
||||
Future<FlutterCommandResult> runCommand() async {
|
||||
if (argResults['listen-on-tcp-port'] != null) {
|
||||
int port;
|
||||
try {
|
||||
port = int.parse(stringArg('listen-on-tcp-port'));
|
||||
} on FormatException catch (error) {
|
||||
throwToolExit('Invalid port for `--listen-on-tcp-port`: $error');
|
||||
}
|
||||
|
||||
await _DaemonServer(
|
||||
port: port,
|
||||
logger: StdoutLogger(
|
||||
terminal: globals.terminal,
|
||||
stdio: globals.stdio,
|
||||
outputPreferences: globals.outputPreferences,
|
||||
),
|
||||
notifyingLogger: asLogger<NotifyingLogger>(globals.logger),
|
||||
).run();
|
||||
return FlutterCommandResult.success();
|
||||
}
|
||||
globals.printStatus('Starting device daemon...');
|
||||
final Daemon daemon = Daemon(
|
||||
DaemonConnection(
|
||||
daemonStreams: StdioDaemonStreams(globals.stdio),
|
||||
logger: globals.logger,
|
||||
),
|
||||
stdinCommandStream, stdoutCommandResponse,
|
||||
notifyingLogger: asLogger<NotifyingLogger>(globals.logger),
|
||||
);
|
||||
final int code = await daemon.onExit;
|
||||
@@ -98,57 +70,14 @@ class DaemonCommand extends FlutterCommand {
|
||||
}
|
||||
}
|
||||
|
||||
class _DaemonServer {
|
||||
_DaemonServer({
|
||||
this.port,
|
||||
this.logger,
|
||||
this.notifyingLogger,
|
||||
});
|
||||
|
||||
final int port;
|
||||
|
||||
/// Stdout logger used to print general server-related errors.
|
||||
final Logger logger;
|
||||
|
||||
// Logger that sends the message to the other end of daemon connection.
|
||||
final NotifyingLogger notifyingLogger;
|
||||
|
||||
Future<void> run() async {
|
||||
final ServerSocket serverSocket = await ServerSocket.bind(InternetAddress.loopbackIPv4, port);
|
||||
logger.printStatus('Daemon server listening on ${serverSocket.port}');
|
||||
|
||||
final StreamSubscription<Socket> subscription = serverSocket.listen(
|
||||
(Socket socket) async {
|
||||
// We have to listen to socket.done. Otherwise when the connection is
|
||||
// reset, we will receive an uncatchable exception.
|
||||
// https://github.com/dart-lang/sdk/issues/25518
|
||||
final Future<void> socketDone = socket.done.catchError((dynamic error, StackTrace stackTrace) {
|
||||
logger.printError('Socket error: $error');
|
||||
logger.printTrace('$stackTrace');
|
||||
});
|
||||
final Daemon daemon = Daemon(
|
||||
DaemonConnection(
|
||||
daemonStreams: TcpDaemonStreams(socket, logger: logger),
|
||||
logger: logger,
|
||||
),
|
||||
notifyingLogger: notifyingLogger,
|
||||
);
|
||||
await daemon.onExit;
|
||||
await socketDone;
|
||||
},
|
||||
);
|
||||
|
||||
// Wait indefinitely until the server closes.
|
||||
await subscription.asFuture<void>();
|
||||
await subscription.cancel();
|
||||
}
|
||||
}
|
||||
typedef DispatchCommand = void Function(Map<String, dynamic> command);
|
||||
|
||||
typedef CommandHandler = Future<dynamic> Function(Map<String, dynamic> args);
|
||||
|
||||
class Daemon {
|
||||
Daemon(
|
||||
this.connection, {
|
||||
Stream<Map<String, dynamic>> commandStream,
|
||||
this.sendCommand, {
|
||||
this.notifyingLogger,
|
||||
this.logToStdout = false,
|
||||
}) {
|
||||
@@ -160,10 +89,9 @@ class Daemon {
|
||||
_registerDomain(devToolsDomain = DevToolsDomain(this));
|
||||
|
||||
// Start listening.
|
||||
_commandSubscription = connection.incomingCommands.listen(
|
||||
_commandSubscription = commandStream.listen(
|
||||
_handleRequest,
|
||||
onDone: () {
|
||||
shutdown();
|
||||
if (!_onExitCompleter.isCompleted) {
|
||||
_onExitCompleter.complete(0);
|
||||
}
|
||||
@@ -171,15 +99,16 @@ class Daemon {
|
||||
);
|
||||
}
|
||||
|
||||
final DaemonConnection connection;
|
||||
|
||||
DaemonDomain daemonDomain;
|
||||
AppDomain appDomain;
|
||||
DeviceDomain deviceDomain;
|
||||
EmulatorDomain emulatorDomain;
|
||||
DevToolsDomain devToolsDomain;
|
||||
StreamSubscription<Map<String, dynamic>> _commandSubscription;
|
||||
int _outgoingRequestId = 1;
|
||||
final Map<String, Completer<dynamic>> _outgoingRequestCompleters = <String, Completer<dynamic>>{};
|
||||
|
||||
final DispatchCommand sendCommand;
|
||||
final NotifyingLogger notifyingLogger;
|
||||
final bool logToStdout;
|
||||
|
||||
@@ -205,27 +134,62 @@ class Daemon {
|
||||
|
||||
try {
|
||||
final String method = request['method'] as String;
|
||||
assert(method != null);
|
||||
if (!method.contains('.')) {
|
||||
throw 'method not understood: $method';
|
||||
}
|
||||
if (method != null) {
|
||||
if (!method.contains('.')) {
|
||||
throw 'method not understood: $method';
|
||||
}
|
||||
|
||||
final String prefix = method.substring(0, method.indexOf('.'));
|
||||
final String name = method.substring(method.indexOf('.') + 1);
|
||||
if (_domainMap[prefix] == null) {
|
||||
throw 'no domain for method: $method';
|
||||
}
|
||||
final String prefix = method.substring(0, method.indexOf('.'));
|
||||
final String name = method.substring(method.indexOf('.') + 1);
|
||||
if (_domainMap[prefix] == null) {
|
||||
throw 'no domain for method: $method';
|
||||
}
|
||||
|
||||
_domainMap[prefix].handleCommand(name, id, castStringKeyedMap(request['params']) ?? const <String, dynamic>{});
|
||||
_domainMap[prefix].handleCommand(name, id, castStringKeyedMap(request['params']) ?? const <String, dynamic>{});
|
||||
} else {
|
||||
// If there was no 'method' field then it's a response to a daemon-to-editor request.
|
||||
final Completer<dynamic> completer = _outgoingRequestCompleters[id.toString()];
|
||||
if (completer == null) {
|
||||
throw 'unexpected response with id: $id';
|
||||
}
|
||||
_outgoingRequestCompleters.remove(id.toString());
|
||||
|
||||
if (request['error'] != null) {
|
||||
completer.completeError(request['error']);
|
||||
} else {
|
||||
completer.complete(request['result']);
|
||||
}
|
||||
}
|
||||
} on Exception catch (error, trace) {
|
||||
connection.sendErrorResponse(id, _toJsonable(error), trace);
|
||||
_send(<String, dynamic>{
|
||||
'id': id,
|
||||
'error': _toJsonable(error),
|
||||
'trace': '$trace',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Future<dynamic> sendRequest(String method, [ dynamic args ]) {
|
||||
final Map<String, dynamic> map = <String, dynamic>{'method': method};
|
||||
if (args != null) {
|
||||
map['params'] = _toJsonable(args);
|
||||
}
|
||||
|
||||
final int id = _outgoingRequestId++;
|
||||
final Completer<dynamic> completer = Completer<dynamic>();
|
||||
|
||||
map['id'] = id.toString();
|
||||
_outgoingRequestCompleters[id.toString()] = completer;
|
||||
|
||||
_send(map);
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
void _send(Map<String, dynamic> map) => sendCommand(map);
|
||||
|
||||
Future<void> shutdown({ dynamic error }) async {
|
||||
await devToolsDomain?.dispose();
|
||||
await _commandSubscription?.cancel();
|
||||
await connection.dispose();
|
||||
for (final Domain domain in _domainMap.values) {
|
||||
await domain.dispose();
|
||||
}
|
||||
@@ -261,16 +225,30 @@ abstract class Domain {
|
||||
}
|
||||
throw 'command not understood: $name.$command';
|
||||
}).then<dynamic>((dynamic result) {
|
||||
daemon.connection.sendResponse(id, _toJsonable(result));
|
||||
}).catchError((Object error, StackTrace stackTrace) {
|
||||
daemon.connection.sendErrorResponse(id, _toJsonable(error), stackTrace);
|
||||
if (result == null) {
|
||||
_send(<String, dynamic>{'id': id});
|
||||
} else {
|
||||
_send(<String, dynamic>{'id': id, 'result': _toJsonable(result)});
|
||||
}
|
||||
}).catchError((dynamic error, dynamic trace) {
|
||||
_send(<String, dynamic>{
|
||||
'id': id,
|
||||
'error': _toJsonable(error),
|
||||
'trace': '$trace',
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void sendEvent(String name, [ dynamic args ]) {
|
||||
daemon.connection.sendEvent(name, _toJsonable(args));
|
||||
final Map<String, dynamic> map = <String, dynamic>{'event': name};
|
||||
if (args != null) {
|
||||
map['params'] = _toJsonable(args);
|
||||
}
|
||||
_send(map);
|
||||
}
|
||||
|
||||
void _send(Map<String, dynamic> map) => daemon._send(map);
|
||||
|
||||
String _getStringArg(Map<String, dynamic> args, String name, { bool required = false }) {
|
||||
if (required && !args.containsKey(name)) {
|
||||
throw '$name is required';
|
||||
@@ -368,7 +346,7 @@ class DaemonDomain extends Domain {
|
||||
/// --web-allow-expose-url switch. The client may return the same URL back if
|
||||
/// tunnelling is not required for a given URL.
|
||||
Future<String> exposeUrl(String url) async {
|
||||
final dynamic res = await daemon.connection.sendRequest('app.exposeUrl', <String, String>{'url': url});
|
||||
final dynamic res = await daemon.sendRequest('app.exposeUrl', <String, String>{'url': url});
|
||||
if (res is Map<String, dynamic> && res['url'] is String) {
|
||||
return res['url'] as String;
|
||||
} else {
|
||||
@@ -929,6 +907,35 @@ class DevToolsDomain extends Domain {
|
||||
}
|
||||
}
|
||||
|
||||
Stream<Map<String, dynamic>> get stdinCommandStream => globals.stdio.stdin
|
||||
.transform<String>(utf8.decoder)
|
||||
.transform<String>(const LineSplitter())
|
||||
.where((String line) => line.startsWith('[{') && line.endsWith('}]'))
|
||||
.map<Map<String, dynamic>>((String line) {
|
||||
line = line.substring(1, line.length - 1);
|
||||
return castStringKeyedMap(json.decode(line));
|
||||
});
|
||||
|
||||
void stdoutCommandResponse(Map<String, dynamic> command) {
|
||||
globals.stdio.stdoutWrite(
|
||||
'[${jsonEncodeObject(command)}]\n',
|
||||
fallback: (String message, dynamic error, StackTrace stack) {
|
||||
throwToolExit('Failed to write daemon command response to stdout: $error');
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
String jsonEncodeObject(dynamic object) {
|
||||
return json.encode(object, toEncodable: _toEncodable);
|
||||
}
|
||||
|
||||
dynamic _toEncodable(dynamic object) {
|
||||
if (object is OperationResult) {
|
||||
return _operationResultToMap(object);
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> _deviceToMap(Device device) async {
|
||||
return <String, dynamic>{
|
||||
'id': device.id,
|
||||
@@ -963,7 +970,7 @@ dynamic _toJsonable(dynamic obj) {
|
||||
return obj;
|
||||
}
|
||||
if (obj is OperationResult) {
|
||||
return _operationResultToMap(obj);
|
||||
return obj;
|
||||
}
|
||||
if (obj is ToolExit) {
|
||||
return obj.message;
|
||||
|
||||
@@ -14,7 +14,6 @@ import '../base/common.dart';
|
||||
import '../base/file_system.dart';
|
||||
import '../base/utils.dart';
|
||||
import '../build_info.dart';
|
||||
import '../daemon.dart';
|
||||
import '../device.dart';
|
||||
import '../features.dart';
|
||||
import '../globals.dart' as globals;
|
||||
@@ -557,10 +556,8 @@ class RunCommand extends RunCommandBase {
|
||||
throwToolExit('"--machine" does not support "-d all".');
|
||||
}
|
||||
final Daemon daemon = Daemon(
|
||||
DaemonConnection(
|
||||
daemonStreams: StdioDaemonStreams(globals.stdio),
|
||||
logger: globals.logger,
|
||||
),
|
||||
stdinCommandStream,
|
||||
stdoutCommandResponse,
|
||||
notifyingLogger: (globals.logger is NotifyingLogger)
|
||||
? globals.logger as NotifyingLogger
|
||||
: NotifyingLogger(verbose: globals.logger.isVerbose, parent: globals.logger),
|
||||
|
||||
@@ -1,241 +0,0 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'base/common.dart';
|
||||
import 'base/io.dart';
|
||||
import 'base/logger.dart';
|
||||
import 'base/utils.dart';
|
||||
import 'convert.dart';
|
||||
|
||||
/// Parse binary streams in the JSON RPC format understood by the daemon, and
|
||||
/// convert it into a stream of JSON RPC messages.
|
||||
Stream<Map<String, Object?>> _convertInputStream(Stream<List<int>> inputStream) {
|
||||
return utf8.decoder.bind(inputStream)
|
||||
.transform<String>(const LineSplitter())
|
||||
.where((String line) => line.startsWith('[{') && line.endsWith('}]'))
|
||||
.map<Map<String, Object?>?>((String line) {
|
||||
line = line.substring(1, line.length - 1);
|
||||
return castStringKeyedMap(json.decode(line));
|
||||
})
|
||||
.where((Map<String, Object?>? entry) => entry != null)
|
||||
.cast<Map<String, Object?>>();
|
||||
}
|
||||
|
||||
/// A stream that a [DaemonConnection] uses to communicate with each other.
|
||||
abstract class DaemonStreams {
|
||||
/// Stream that contains input to the [DaemonConnection].
|
||||
Stream<Map<String, Object?>> get inputStream;
|
||||
|
||||
/// Outputs a message through the connection.
|
||||
void send(Map<String, Object?> message);
|
||||
|
||||
/// Cleans up any resources used.
|
||||
Future<void> dispose() async { }
|
||||
}
|
||||
|
||||
/// A [DaemonStream] that uses stdin and stdout as the underlying streams.
|
||||
class StdioDaemonStreams extends DaemonStreams {
|
||||
StdioDaemonStreams(Stdio stdio) :
|
||||
_stdio = stdio,
|
||||
inputStream = _convertInputStream(stdio.stdin);
|
||||
|
||||
final Stdio _stdio;
|
||||
|
||||
@override
|
||||
final Stream<Map<String, Object?>> inputStream;
|
||||
|
||||
@override
|
||||
void send(Map<String, Object?> message) {
|
||||
_stdio.stdoutWrite(
|
||||
'[${json.encode(message)}]\n',
|
||||
fallback: (String message, Object? error, StackTrace stack) {
|
||||
throwToolExit('Failed to write daemon command response to stdout: $error');
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A [DaemonStream] that uses [Socket] as the underlying stream.
|
||||
class TcpDaemonStreams extends DaemonStreams {
|
||||
/// Creates a [DaemonStreams] with an existing [Socket].
|
||||
TcpDaemonStreams(
|
||||
Socket socket, {
|
||||
required Logger logger,
|
||||
}): _logger = logger {
|
||||
_socket = Future<Socket>.value(_initializeSocket(socket));
|
||||
}
|
||||
|
||||
/// Connects to a remote host and creates a [DaemonStreams] from the socket.
|
||||
TcpDaemonStreams.connect(
|
||||
String host,
|
||||
int port, {
|
||||
required Logger logger,
|
||||
}) : _logger = logger {
|
||||
_socket = Socket.connect(host, port).then(_initializeSocket);
|
||||
}
|
||||
|
||||
late final Future<Socket> _socket;
|
||||
final StreamController<Map<String, Object?>> _commands = StreamController<Map<String, Object?>>();
|
||||
final Logger _logger;
|
||||
|
||||
@override
|
||||
Stream<Map<String, Object?>> get inputStream => _commands.stream;
|
||||
|
||||
@override
|
||||
void send(Map<String, Object?> message) {
|
||||
_socket.then((Socket socket) {
|
||||
try {
|
||||
socket.write('[${json.encode(message)}]\n');
|
||||
} on SocketException catch (error) {
|
||||
_logger.printError('Failed to write daemon command response to socket: $error');
|
||||
// Failed to send, close the connection
|
||||
socket.close();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Socket _initializeSocket(Socket socket) {
|
||||
_commands.addStream(_convertInputStream(socket));
|
||||
return socket;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> dispose() async {
|
||||
await (await _socket).close();
|
||||
}
|
||||
}
|
||||
|
||||
/// Connection between a flutter daemon and a client.
|
||||
class DaemonConnection {
|
||||
DaemonConnection({
|
||||
required DaemonStreams daemonStreams,
|
||||
required Logger logger,
|
||||
}): _logger = logger,
|
||||
_daemonStreams = daemonStreams {
|
||||
_commandSubscription = daemonStreams.inputStream.listen(
|
||||
_handleData,
|
||||
onError: (Object error, StackTrace stackTrace) {
|
||||
// We have to listen for on error otherwise the error on the socket
|
||||
// will end up in the Zone error handler.
|
||||
// Do nothing here and let the stream close handlers handle shutting
|
||||
// down the daemon.
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
final DaemonStreams _daemonStreams;
|
||||
|
||||
final Logger _logger;
|
||||
|
||||
late final StreamSubscription<Map<String, Object?>> _commandSubscription;
|
||||
|
||||
int _outgoingRequestId = 0;
|
||||
final Map<String, Completer<Object?>> _outgoingRequestCompleters = <String, Completer<Object?>>{};
|
||||
|
||||
final StreamController<Map<String, Object?>> _events = StreamController<Map<String, Object?>>.broadcast();
|
||||
final StreamController<Map<String, Object?>> _incomingCommands = StreamController<Map<String, Object?>>();
|
||||
|
||||
/// A stream that contains all the incoming requests.
|
||||
Stream<Map<String, Object?>> get incomingCommands => _incomingCommands.stream;
|
||||
|
||||
/// Listens to the event with the event name [eventToListen].
|
||||
Stream<Object?> listenToEvent(String eventToListen) {
|
||||
return _events.stream
|
||||
.where((Map<String, Object?> event) => event['event'] == eventToListen)
|
||||
.map<Object?>((Map<String, Object?> event) => event['params']);
|
||||
}
|
||||
|
||||
/// Sends a request to the other end of the connection.
|
||||
///
|
||||
/// Returns a [Future] that resolves with the content.
|
||||
Future<Object?> sendRequest(String method, [Object? params]) async {
|
||||
final String id = '${++_outgoingRequestId}';
|
||||
final Completer<Object?> completer = Completer<Object?>();
|
||||
_outgoingRequestCompleters[id] = completer;
|
||||
final Map<String, Object?> data = <String, Object?>{
|
||||
'id': id,
|
||||
'method': method,
|
||||
if (params != null) 'params': params,
|
||||
};
|
||||
_logger.printTrace('-> Sending to daemon, id = $id, method = $method');
|
||||
_daemonStreams.send(data);
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
/// Sends a response to the other end of the connection.
|
||||
void sendResponse(Object id, [Object? result]) {
|
||||
_daemonStreams.send(<String, Object?>{
|
||||
'id': id,
|
||||
if (result != null) 'result': result,
|
||||
});
|
||||
}
|
||||
|
||||
/// Sends an error response to the other end of the connection.
|
||||
void sendErrorResponse(Object id, Object error, StackTrace trace) {
|
||||
_daemonStreams.send(<String, Object?>{
|
||||
'id': id,
|
||||
'error': error,
|
||||
'trace': '$trace',
|
||||
});
|
||||
}
|
||||
|
||||
/// Sends an event to the client.
|
||||
void sendEvent(String name, [ Object? params ]) {
|
||||
_daemonStreams.send(<String, Object?>{
|
||||
'event': name,
|
||||
if (params != null) 'params': params,
|
||||
});
|
||||
}
|
||||
|
||||
/// Handles the input from the stream.
|
||||
///
|
||||
/// There are three kinds of data: Request, Response, Event.
|
||||
///
|
||||
/// Request:
|
||||
/// {"id": <Object>. "method": <String>, "params": <optional, Object?>}
|
||||
///
|
||||
/// Response:
|
||||
/// {"id": <Object>. "result": <optional, Object?>} for a successful response.
|
||||
/// {"id": <Object>. "error": <Object>, "stackTrace": <String>} for an error response.
|
||||
///
|
||||
/// Event:
|
||||
/// {"event": <String>. "params": <optional, Object?>}
|
||||
void _handleData(Map<String, Object?> data) {
|
||||
if (data['id'] != null) {
|
||||
if (data['method'] == null) {
|
||||
// This is a response to previously sent request.
|
||||
final String id = data['id']! as String;
|
||||
if (data['error'] != null) {
|
||||
// This is an error response.
|
||||
_logger.printTrace('<- Error response received from daemon, id = $id');
|
||||
final Object error = data['error']!;
|
||||
final String stackTrace = data['stackTrace'] as String? ?? '';
|
||||
_outgoingRequestCompleters.remove(id)?.completeError(error, StackTrace.fromString(stackTrace));
|
||||
} else {
|
||||
_logger.printTrace('<- Response received from daemon, id = $id');
|
||||
final Object? result = data['result'];
|
||||
_outgoingRequestCompleters.remove(id)?.complete(result);
|
||||
}
|
||||
} else {
|
||||
_incomingCommands.add(data);
|
||||
}
|
||||
} else if (data['event'] != null) {
|
||||
// This is an event
|
||||
_logger.printTrace('<- Event received: ${data['event']}');
|
||||
_events.add(data);
|
||||
} else {
|
||||
_logger.printError('Unknown data received from daemon');
|
||||
}
|
||||
}
|
||||
|
||||
/// Cleans up any resources used in the connection.
|
||||
Future<void> dispose() async {
|
||||
await _commandSubscription.cancel();
|
||||
await _daemonStreams.dispose();
|
||||
unawaited(_events.close());
|
||||
unawaited(_incomingCommands.close());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user