@@ -29,17 +29,6 @@ import (
29
29
"github.com/arduino/go-paths-helper"
30
30
)
31
31
32
- // To work correctly a Pluggable Discovery must respect the state machine specified on the documentation:
33
- // https://arduino.github.io/arduino-cli/latest/pluggable-discovery-specification/#state-machine
34
- // States a PluggableDiscovery can be in
35
- const (
36
- Alive int = iota
37
- Idling
38
- Running
39
- Syncing
40
- Dead
41
- )
42
-
43
32
// Client is a tool that detects communication ports to interact
44
33
// with the boards.
45
34
type Client struct {
@@ -54,7 +43,6 @@ type Client struct {
54
43
// All the following fields are guarded by statusMutex
55
44
statusMutex sync.Mutex
56
45
incomingMessagesError error
57
- state int
58
46
eventChan chan <- * Event
59
47
}
60
48
@@ -108,7 +96,6 @@ func NewClient(id string, args ...string) *Client {
108
96
return & Client {
109
97
id : id ,
110
98
processArgs : args ,
111
- state : Dead ,
112
99
userAgent : "pluggable-discovery-protocol-handler" ,
113
100
logger : & nullClientLogger {},
114
101
}
@@ -137,7 +124,6 @@ func (disc *Client) jsonDecodeLoop(in io.Reader, outChan chan<- *discoveryMessag
137
124
decoder := json .NewDecoder (in )
138
125
closeAndReportError := func (err error ) {
139
126
disc .statusMutex .Lock ()
140
- disc .state = Dead
141
127
disc .incomingMessagesError = err
142
128
disc .statusMutex .Unlock ()
143
129
close (outChan )
@@ -149,7 +135,6 @@ func (disc *Client) jsonDecodeLoop(in io.Reader, outChan chan<- *discoveryMessag
149
135
if err := decoder .Decode (& msg ); errors .Is (err , io .EOF ) {
150
136
// This is fine, we exit gracefully
151
137
disc .statusMutex .Lock ()
152
- disc .state = Dead
153
138
disc .incomingMessagesError = err
154
139
disc .statusMutex .Unlock ()
155
140
close (outChan )
@@ -185,13 +170,6 @@ func (disc *Client) jsonDecodeLoop(in io.Reader, outChan chan<- *discoveryMessag
185
170
}
186
171
}
187
172
188
- // State returns the current state of this PluggableDiscovery
189
- func (disc * Client ) State () int {
190
- disc .statusMutex .Lock ()
191
- defer disc .statusMutex .Unlock ()
192
- return disc .state
193
- }
194
-
195
173
func (disc * Client ) waitMessage (timeout time.Duration ) (* discoveryMessage , error ) {
196
174
select {
197
175
case msg := <- disc .incomingMessagesChan :
@@ -246,7 +224,6 @@ func (disc *Client) runProcess() error {
246
224
disc .statusMutex .Lock ()
247
225
defer disc .statusMutex .Unlock ()
248
226
disc .process = proc
249
- disc .state = Alive
250
227
disc .logger .Infof ("started discovery %s process" , disc .id )
251
228
return nil
252
229
}
@@ -264,7 +241,6 @@ func (disc *Client) killProcess() error {
264
241
disc .statusMutex .Lock ()
265
242
defer disc .statusMutex .Unlock ()
266
243
disc .stopSync ()
267
- disc .state = Dead
268
244
disc .logger .Infof ("killed discovery %s process" , disc .id )
269
245
return nil
270
246
}
@@ -307,7 +283,6 @@ func (disc *Client) Run() (err error) {
307
283
}
308
284
disc .statusMutex .Lock ()
309
285
defer disc .statusMutex .Unlock ()
310
- disc .state = Idling
311
286
return nil
312
287
}
313
288
@@ -328,7 +303,6 @@ func (disc *Client) Start() error {
328
303
}
329
304
disc .statusMutex .Lock ()
330
305
defer disc .statusMutex .Unlock ()
331
- disc .state = Running
332
306
return nil
333
307
}
334
308
@@ -351,7 +325,6 @@ func (disc *Client) Stop() error {
351
325
disc .statusMutex .Lock ()
352
326
defer disc .statusMutex .Unlock ()
353
327
disc .stopSync ()
354
- disc .state = Idling
355
328
return nil
356
329
}
357
330
@@ -415,7 +388,6 @@ func (disc *Client) StartSync(size int) (<-chan *Event, error) {
415
388
return nil , fmt .Errorf ("communication out of sync, expected 'OK', received '%s'" , msg .Message )
416
389
}
417
390
418
- disc .state = Syncing
419
391
// In case there is already an existing event channel in use we close it before creating a new one.
420
392
disc .stopSync ()
421
393
c := make (chan * Event , size )
0 commit comments