Skip to content

Commit 1c64d78

Browse files
committed
Removed useless state tracking
1 parent 2b24b07 commit 1c64d78

File tree

2 files changed

+4
-30
lines changed

2 files changed

+4
-30
lines changed

client.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,6 @@ import (
2929
"github.com/arduino/go-paths-helper"
3030
)
3131

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-
4332
// Client is a tool that detects communication ports to interact
4433
// with the boards.
4534
type Client struct {
@@ -54,7 +43,6 @@ type Client struct {
5443
// All the following fields are guarded by statusMutex
5544
statusMutex sync.Mutex
5645
incomingMessagesError error
57-
state int
5846
eventChan chan<- *Event
5947
}
6048

@@ -108,7 +96,6 @@ func NewClient(id string, args ...string) *Client {
10896
return &Client{
10997
id: id,
11098
processArgs: args,
111-
state: Dead,
11299
userAgent: "pluggable-discovery-protocol-handler",
113100
logger: &nullClientLogger{},
114101
}
@@ -137,7 +124,6 @@ func (disc *Client) jsonDecodeLoop(in io.Reader, outChan chan<- *discoveryMessag
137124
decoder := json.NewDecoder(in)
138125
closeAndReportError := func(err error) {
139126
disc.statusMutex.Lock()
140-
disc.state = Dead
141127
disc.incomingMessagesError = err
142128
disc.statusMutex.Unlock()
143129
close(outChan)
@@ -149,7 +135,6 @@ func (disc *Client) jsonDecodeLoop(in io.Reader, outChan chan<- *discoveryMessag
149135
if err := decoder.Decode(&msg); errors.Is(err, io.EOF) {
150136
// This is fine, we exit gracefully
151137
disc.statusMutex.Lock()
152-
disc.state = Dead
153138
disc.incomingMessagesError = err
154139
disc.statusMutex.Unlock()
155140
close(outChan)
@@ -185,13 +170,6 @@ func (disc *Client) jsonDecodeLoop(in io.Reader, outChan chan<- *discoveryMessag
185170
}
186171
}
187172

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-
195173
func (disc *Client) waitMessage(timeout time.Duration) (*discoveryMessage, error) {
196174
select {
197175
case msg := <-disc.incomingMessagesChan:
@@ -246,7 +224,6 @@ func (disc *Client) runProcess() error {
246224
disc.statusMutex.Lock()
247225
defer disc.statusMutex.Unlock()
248226
disc.process = proc
249-
disc.state = Alive
250227
disc.logger.Infof("started discovery %s process", disc.id)
251228
return nil
252229
}
@@ -264,7 +241,6 @@ func (disc *Client) killProcess() error {
264241
disc.statusMutex.Lock()
265242
defer disc.statusMutex.Unlock()
266243
disc.stopSync()
267-
disc.state = Dead
268244
disc.logger.Infof("killed discovery %s process", disc.id)
269245
return nil
270246
}
@@ -307,7 +283,6 @@ func (disc *Client) Run() (err error) {
307283
}
308284
disc.statusMutex.Lock()
309285
defer disc.statusMutex.Unlock()
310-
disc.state = Idling
311286
return nil
312287
}
313288

@@ -328,7 +303,6 @@ func (disc *Client) Start() error {
328303
}
329304
disc.statusMutex.Lock()
330305
defer disc.statusMutex.Unlock()
331-
disc.state = Running
332306
return nil
333307
}
334308

@@ -351,7 +325,6 @@ func (disc *Client) Stop() error {
351325
disc.statusMutex.Lock()
352326
defer disc.statusMutex.Unlock()
353327
disc.stopSync()
354-
disc.state = Idling
355328
return nil
356329
}
357330

@@ -415,7 +388,6 @@ func (disc *Client) StartSync(size int) (<-chan *Event, error) {
415388
return nil, fmt.Errorf("communication out of sync, expected 'OK', received '%s'", msg.Message)
416389
}
417390

418-
disc.state = Syncing
419391
// In case there is already an existing event channel in use we close it before creating a new one.
420392
disc.stopSync()
421393
c := make(chan *Event, size)

client_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,13 @@ func TestDiscoveryStdioHandling(t *testing.T) {
6565
require.NotNil(t, msg)
6666
require.Equal(t, "ev2", msg.EventType)
6767

68-
require.Equal(t, disc.State(), Alive)
68+
// TODO:
69+
// require.Equal(t, disc.State(), Alive)
6970

7071
err = disc.outgoingCommandsPipe.(io.ReadCloser).Close()
7172
require.NoError(t, err)
7273
time.Sleep(time.Millisecond * 100)
7374

74-
require.Equal(t, disc.State(), Dead)
75+
// TODO:
76+
// require.Equal(t, disc.State(), Dead)
7577
}

0 commit comments

Comments
 (0)