fix upload when monitor is open

This commit is contained in:
Alberto Iannaccone 2022-05-12 15:28:13 +02:00
parent 62eaeb1c74
commit 1982609c87
3 changed files with 19 additions and 4 deletions

View File

@ -84,4 +84,7 @@ export namespace Status {
export const CONFIG_MISSING: ErrorStatus = {
message: 'Serial Config missing.',
};
export const UPLOAD_IN_PROGRESS: ErrorStatus = {
message: 'Upload in progress.',
};
}

View File

@ -12,7 +12,7 @@ export const MonitorManagerName = 'monitor-manager';
export class MonitorManager extends CoreClientAware {
// Map of monitor services that manage the running pluggable monitors.
// Each service handles the lifetime of one, and only one, monitor.
// If either the board or port managed changes a new service must
// If either the board or port managed changes, a new service must
// be started.
private monitorServices = new Map<MonitorID, MonitorService>();
@ -109,6 +109,7 @@ export class MonitorManager extends CoreClientAware {
// There's no monitor running there, bail
return;
}
monitor.setUploadInProgress(true);
return await monitor.pause();
}
@ -132,6 +133,7 @@ export class MonitorManager extends CoreClientAware {
// There's no monitor running there, bail
return Status.NOT_CONNECTED;
}
monitor.setUploadInProgress(false);
return await monitor.start();
}

View File

@ -53,6 +53,8 @@ export class MonitorService extends CoreClientAware implements Disposable {
protected readonly webSocketProvider: WebSocketProvider =
new WebSocketProviderImpl();
protected uploadInProgress = false;
constructor(
@inject(ILogger)
@named(MonitorServiceName)
@ -80,6 +82,10 @@ export class MonitorService extends CoreClientAware implements Disposable {
);
}
setUploadInProgress(status: boolean): void {
this.uploadInProgress = status;
}
getWebsocketAddressPort(): number {
return this.webSocketProvider.getAddress().port;
}
@ -113,11 +119,14 @@ export class MonitorService extends CoreClientAware implements Disposable {
return Status.CONFIG_MISSING;
}
if (this.uploadInProgress) {
return Status.UPLOAD_IN_PROGRESS;
}
this.logger.info('starting monitor');
await this.coreClientProvider.initialized;
const coreClient = await this.coreClient();
const { client, instance } = coreClient;
this.duplex = client.monitor();
this.duplex
.on('close', () => {
@ -205,7 +214,7 @@ export class MonitorService extends CoreClientAware implements Disposable {
* Pauses the currently running monitor, it still closes the gRPC connection
* with the underlying monitor process but it doesn't stop the message handlers
* currently running.
* This is mainly used to handle upload when to the board/port combination
* This is mainly used to handle upload with the board/port combination
* the monitor is listening to.
* @returns
*/
@ -223,7 +232,8 @@ export class MonitorService extends CoreClientAware implements Disposable {
this.logger.info(
`stopped monitor to ${this.port?.address} using ${this.port?.protocol}`
);
resolve();
this.duplex.on('end', resolve);
});
}