Skip to content

Refactoring of the pluggable discovery client #2440

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use the Stringer interface to output discovery id
  • Loading branch information
cmaglie committed Nov 28, 2023
commit fd59f657811846201306112695c1af941ca0f36d
14 changes: 7 additions & 7 deletions arduino/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (disc *PluggableDiscovery) jsonDecodeLoop(in io.Reader, outChan chan<- *dis
disc.incomingMessagesError = err
disc.statusMutex.Unlock()
close(outChan)
logrus.Errorf("stopped discovery %s decode loop: %v", disc.id, err)
logrus.Errorf("stopped discovery %s decode loop: %v", disc, err)
}

for {
Expand All @@ -191,7 +191,7 @@ func (disc *PluggableDiscovery) jsonDecodeLoop(in io.Reader, outChan chan<- *dis
closeAndReportError(err)
return
}
logrus.Infof("from discovery %s received message %s", disc.id, msg)
logrus.Infof("from discovery %s received message %s", disc, msg)
if msg.EventType == "add" {
if msg.Port == nil {
closeAndReportError(errors.New(tr("invalid 'add' message: missing port")))
Expand Down Expand Up @@ -246,7 +246,7 @@ func (disc *PluggableDiscovery) sendCommand(command string) error {
}

func (disc *PluggableDiscovery) runProcess() error {
logrus.Infof("starting discovery %s process", disc.id)
logrus.Infof("starting discovery %s process", disc)
proc, err := executils.NewProcess(nil, disc.processArgs...)
if err != nil {
return err
Expand All @@ -272,12 +272,12 @@ func (disc *PluggableDiscovery) runProcess() error {
disc.statusMutex.Lock()
defer disc.statusMutex.Unlock()
disc.process = proc
logrus.Infof("started discovery %s process", disc.id)
logrus.Infof("started discovery %s process", disc)
return nil
}

func (disc *PluggableDiscovery) killProcess() error {
logrus.Infof("killing discovery %s process", disc.id)
logrus.Infof("killing discovery %s process", disc)
if disc.process != nil {
if err := disc.process.Kill(); err != nil {
return err
Expand All @@ -289,7 +289,7 @@ func (disc *PluggableDiscovery) killProcess() error {
disc.statusMutex.Lock()
defer disc.statusMutex.Unlock()
disc.stopSync()
logrus.Infof("killed discovery %s process", disc.id)
logrus.Infof("killed discovery %s process", disc)
return nil
}

Expand Down Expand Up @@ -384,7 +384,7 @@ func (disc *PluggableDiscovery) stopSync() {
func (disc *PluggableDiscovery) Quit() {
_ = disc.sendCommand("QUIT\n")
if _, err := disc.waitMessage(time.Second * 5); err != nil {
logrus.Errorf("Quitting discovery %s: %s", disc.id, err)
logrus.Errorf("Quitting discovery %s: %s", disc, err)
}
disc.stopSync()
disc.killProcess()
Expand Down