-
-
Notifications
You must be signed in to change notification settings - Fork 435
/
Copy pathmonitor-manager-proxy-impl.ts
95 lines (87 loc) · 2.8 KB
/
monitor-manager-proxy-impl.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { inject, injectable } from '@theia/core/shared/inversify';
import {
MonitorManagerProxy,
MonitorManagerProxyClient,
Status,
} from '../common/protocol';
import { Board, Port } from '../common/protocol';
import { MonitorManager } from './monitor-manager';
import {
MonitorSettings,
PluggableMonitorSettings,
} from './monitor-settings/monitor-settings-provider';
@injectable()
export class MonitorManagerProxyImpl implements MonitorManagerProxy {
protected client: MonitorManagerProxyClient;
constructor(
@inject(MonitorManager)
protected readonly manager: MonitorManager
) {}
dispose(): void {
this.client?.disconnect();
}
/**
* Start a pluggable monitor and/or change its settings.
* If settings are defined they'll be set before starting the monitor,
* otherwise default ones will be used by the monitor.
* @param board board connected to port
* @param port port to monitor
* @param settings map of supported configuration by the monitor
*/
async startMonitor(
board: Board,
port: Port,
settings?: PluggableMonitorSettings
): Promise<void> {
if (settings) {
await this.changeMonitorSettings(board, port, settings);
}
const status = await this.manager.startMonitor(board, port);
if (status === Status.ALREADY_CONNECTED || status === Status.OK) {
// Monitor started correctly, connect it with the frontend
this.client.connect(this.manager.getWebsocketAddressPort(board, port));
}
}
/**
* Changes the settings of a running pluggable monitor, if that monitor is not
* started this function is a noop.
* @param board board connected to port
* @param port port monitored
* @param settings map of supported configuration by the monitor
*/
async changeMonitorSettings(
board: Board,
port: Port,
settings: PluggableMonitorSettings
): Promise<void> {
if (!this.manager.isStarted(board, port)) {
// Monitor is not running, no need to change settings
return;
}
return this.manager.changeMonitorSettings(board, port, settings);
}
/**
* Stops a running pluggable monitor.
* @param board board connected to port
* @param port port monitored
*/
async stopMonitor(board: Board, port: Port): Promise<void> {
return this.manager.stopMonitor(board, port);
}
/**
* Returns the current settings by the pluggable monitor connected to specified
* by board/port combination.
* @param board board connected to port
* @param port port monitored
* @returns a map of MonitorSetting
*/
getCurrentSettings(board: Board, port: Port): Promise<MonitorSettings> {
return this.manager.currentMonitorSettings(board, port);
}
setClient(client: MonitorManagerProxyClient | undefined): void {
if (!client) {
return;
}
this.client = client;
}
}