@@ -15,16 +15,6 @@ export class MonitorManager extends CoreClientAware {
15
15
// be started.
16
16
private monitorServices = new Map < MonitorID , MonitorService > ( ) ;
17
17
18
- // Used to notify a monitor service that an upload process started
19
- // to the board/port combination it manages
20
- protected readonly onUploadStartedEmitter = new Emitter < { board : Board , port : Port } > ( ) ;
21
- readonly onUploadStarted = this . onUploadStartedEmitter . event ;
22
-
23
- // Used to notify a monitor service that an upload process finished
24
- // to the board/port combination it manages
25
-
26
-
27
-
28
18
constructor (
29
19
@inject ( ILogger )
30
20
@named ( 'monitor-manager' )
@@ -55,7 +45,7 @@ export class MonitorManager extends CoreClientAware {
55
45
}
56
46
resolve ( resp )
57
47
} )
58
- } )
48
+ } ) ;
59
49
60
50
let settings : MonitorSettings = { } ;
61
51
for ( const iterator of res . getSettingsList ( ) ) {
@@ -71,9 +61,28 @@ export class MonitorManager extends CoreClientAware {
71
61
}
72
62
73
63
/**
74
- *
75
- * @param board
76
- * @param port
64
+ * Used to know if a monitor is started
65
+ * @param board board connected to port
66
+ * @param port port to monitor
67
+ * @returns true if the monitor is currently monitoring the board/port
68
+ * combination specifed, false in all other cases.
69
+ */
70
+ isStarted ( board : Board , port : Port ) : boolean {
71
+ const monitorID = this . monitorID ( board , port ) ;
72
+ const monitor = this . monitorServices . get ( monitorID ) ;
73
+ if ( monitor ) {
74
+ return monitor . isStarted ( ) ;
75
+ }
76
+ return false ;
77
+ }
78
+
79
+ /**
80
+ * Start a pluggable monitor that receives and sends messages
81
+ * to the specified board and port combination.
82
+ * @param board board connected to port
83
+ * @param port port to monitor
84
+ * @returns a Status object to know if the process has been
85
+ * started or if there have been errors.
77
86
*/
78
87
async startMonitor ( board : Board , port : Port ) : Promise < Status > {
79
88
const monitorID = this . monitorID ( board , port ) ;
@@ -82,12 +91,16 @@ export class MonitorManager extends CoreClientAware {
82
91
monitor = this . createMonitor ( board , port )
83
92
}
84
93
return await monitor . start ( ) ;
85
- // TODO: I need to return the address here right?
86
94
}
87
95
96
+ /**
97
+ * Stop a pluggable monitor connected to the specified board/port
98
+ * combination. It's a noop if monitor is not running.
99
+ * @param board board connected to port
100
+ * @param port port monitored
101
+ */
88
102
async stopMonitor ( board : Board , port : Port ) : Promise < void > {
89
103
const monitorID = this . monitorID ( board , port ) ;
90
-
91
104
const monitor = this . monitorServices . get ( monitorID ) ;
92
105
if ( ! monitor ) {
93
106
// There's no monitor to stop, bail
@@ -96,23 +109,29 @@ export class MonitorManager extends CoreClientAware {
96
109
return await monitor . stop ( ) ;
97
110
}
98
111
99
- getWebsocketAddress ( board : Board , port : Port ) : number {
112
+ /**
113
+ * Returns the port of the WebSocket used by the MonitorService
114
+ * that is handling the board/port combination
115
+ * @param board board connected to port
116
+ * @param port port to monitor
117
+ * @returns port of the MonitorService's WebSocket
118
+ */
119
+ getWebsocketAddressPort ( board : Board , port : Port ) : number {
100
120
const monitorID = this . monitorID ( board , port ) ;
101
-
102
121
const monitor = this . monitorServices . get ( monitorID ) ;
103
122
if ( ! monitor ) {
104
123
return - 1 ;
105
124
}
106
- return monitor . getWebsocketAddress ( ) ;
125
+ return monitor . getWebsocketAddressPort ( ) ;
107
126
}
108
127
109
128
/**
110
129
* Notifies the monitor service of that board/port combination
111
130
* that an upload process started on that exact board/port combination.
112
131
* This must be done so that we can stop the monitor for the time being
113
132
* until the upload process finished.
114
- * @param board
115
- * @param port
133
+ * @param board board connected to port
134
+ * @param port port to monitor
116
135
*/
117
136
async notifyUploadStarted ( board ?: Board , port ?: Port ) : Promise < void > {
118
137
if ( ! board || ! port ) {
@@ -132,9 +151,10 @@ export class MonitorManager extends CoreClientAware {
132
151
/**
133
152
* Notifies the monitor service of that board/port combination
134
153
* that an upload process started on that exact board/port combination.
135
- * @param board
136
- * @param port
137
- * @returns
154
+ * @param board board connected to port
155
+ * @param port port to monitor
156
+ * @returns a Status object to know if the process has been
157
+ * started or if there have been errors.
138
158
*/
139
159
async notifyUploadFinished ( board ?: Board , port ?: Port ) : Promise < Status > {
140
160
if ( ! board || ! port ) {
@@ -152,10 +172,11 @@ export class MonitorManager extends CoreClientAware {
152
172
}
153
173
154
174
/**
155
- *
156
- * @param board
157
- * @param port
158
- * @param settings map of monitor settings to change
175
+ * Changes the settings of a pluggable monitor even if it's running.
176
+ * If monitor is not running they're going to be used as soon as it's started.
177
+ * @param board board connected to port
178
+ * @param port port to monitor
179
+ * @param settings monitor settings to change
159
180
*/
160
181
changeMonitorSettings ( board : Board , port : Port , settings : Record < string , MonitorSetting > ) {
161
182
const monitorID = this . monitorID ( board , port ) ;
@@ -166,6 +187,13 @@ export class MonitorManager extends CoreClientAware {
166
187
}
167
188
}
168
189
190
+ /**
191
+ * Creates a MonitorService that handles the lifetime and the
192
+ * communication via WebSocket with the frontend.
193
+ * @param board board connected to specified port
194
+ * @param port port to monitor
195
+ * @returns a new instance of MonitorService ready to use.
196
+ */
169
197
private createMonitor ( board : Board , port : Port ) : MonitorService {
170
198
const monitorID = this . monitorID ( board , port ) ;
171
199
const monitor = new MonitorService (
0 commit comments