Skip to content

Commit

Permalink
Bunch of small fixes cherry picked out from pluggable-discovery patch…
Browse files Browse the repository at this point in the history
… in #1333 (#1351)

* Fix discovery client

* Fix client_example

* Fixed BoardWatch message loop

* Upgraded go-properties-orderedmap to v1.5.0
  • Loading branch information
cmaglie authored Jul 6, 2021
1 parent 97842a8 commit e9c87a8
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 30 deletions.
2 changes: 2 additions & 0 deletions arduino/discovery/discovery_client/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ github.com/arduino/go-paths-helper v1.6.0 h1:S7/d7DqB9XlnvF9KrgSiGmo2oWKmYW6O/DT
github.com/arduino/go-paths-helper v1.6.0/go.mod h1:V82BWgAAp4IbmlybxQdk9Bpkz8M4Qyx+RAFKaG9NuvU=
github.com/arduino/go-properties-orderedmap v1.3.0 h1:4No/vQopB36e7WUIk6H6TxiSEJPiMrVOCZylYmua39o=
github.com/arduino/go-properties-orderedmap v1.3.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk=
github.com/arduino/go-properties-orderedmap v1.5.0 h1:istmr13qQN3nneuU3lsqlMvI6jqB3u8QUfVU1tX/t/8=
github.com/arduino/go-properties-orderedmap v1.5.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk=
github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b/go.mod h1:uwGy5PpN4lqW97FiLnbcx+xx8jly5YuPMJWfVwwjJiQ=
github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b/go.mod h1:iIPnclBMYm1g32Q5kXoqng4jLhMStReIP7ZxaoUC2y8=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
Expand Down
2 changes: 1 addition & 1 deletion arduino/discovery/discovery_client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func main() {
log.Fatal("Error initializing discovery:", err)
}

if err := disc.Hello(); err != nil {
if err := disc.Run(); err != nil {
log.Fatal("Error starting discovery:", err)
}
if err := disc.Start(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion client_example/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ replace github.com/arduino/arduino-cli => ../

require (
github.com/arduino/arduino-cli v0.0.0-20200109150215-ffa84fdaab21
google.golang.org/grpc v1.27.0
google.golang.org/grpc v1.37.0
)
71 changes: 53 additions & 18 deletions client_example/go.sum

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion client_example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -709,9 +709,16 @@ func callBoardListWatch(client rpc.ArduinoCoreServiceClient, instance *rpc.Insta
go func() {
for {
res, err := watchClient.Recv()
if err != nil {
if err == io.EOF {
log.Print("closing board watch connection")
return
} else if err != nil {
log.Fatalf("Board list watch error: %s\n", err)
}
if res.EventType == "error" {
log.Printf("res: %s\n", res.Error)
continue
}

log.Printf("event: %s, address: %s\n", res.EventType, res.Port.Address)
if res.EventType == "add" {
Expand Down
44 changes: 36 additions & 8 deletions commands/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package daemon

import (
"context"
"fmt"
"io"

"github.com/arduino/arduino-cli/arduino/utils"
Expand All @@ -28,6 +29,7 @@ import (
"github.com/arduino/arduino-cli/commands/sketch"
"github.com/arduino/arduino-cli/commands/upload"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/sirupsen/logrus"
)

// ArduinoCoreServerImpl FIXMEDOC
Expand Down Expand Up @@ -73,14 +75,37 @@ func (s *ArduinoCoreServerImpl) BoardListWatch(stream rpc.ArduinoCoreService_Boa
return err
}

interrupt := make(chan bool)
if msg.Instance == nil {
err = fmt.Errorf("no instance specified")
stream.Send(&rpc.BoardListWatchResponse{
EventType: "error",
Error: err.Error(),
})
return err
}

interrupt := make(chan bool, 1)
go func() {
msg, err := stream.Recv()
if err != nil {
interrupt <- true
}
if msg != nil {
interrupt <- msg.Interrupt
defer close(interrupt)
for {
msg, err := stream.Recv()
// Handle client closing the stream and eventual errors
if err == io.EOF {
logrus.Info("boards watcher stream closed")
interrupt <- true
return
} else if err != nil {
logrus.Infof("interrupting boards watcher: %v", err)
interrupt <- true
return
}

// Message received, does the client want to interrupt?
if msg != nil && msg.Interrupt {
logrus.Info("boards watcher interrupted by client")
interrupt <- msg.Interrupt
return
}
}
}()

Expand All @@ -90,7 +115,10 @@ func (s *ArduinoCoreServerImpl) BoardListWatch(stream rpc.ArduinoCoreService_Boa
}

for event := range eventsChan {
stream.Send(event)
err = stream.Send(event)
if err != nil {
logrus.Infof("sending board watch message: %v", err)
}
}

return nil
Expand Down
2 changes: 2 additions & 0 deletions docsgen/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ github.com/arduino/go-paths-helper v1.6.0 h1:S7/d7DqB9XlnvF9KrgSiGmo2oWKmYW6O/DT
github.com/arduino/go-paths-helper v1.6.0/go.mod h1:V82BWgAAp4IbmlybxQdk9Bpkz8M4Qyx+RAFKaG9NuvU=
github.com/arduino/go-properties-orderedmap v1.3.0 h1:4No/vQopB36e7WUIk6H6TxiSEJPiMrVOCZylYmua39o=
github.com/arduino/go-properties-orderedmap v1.3.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk=
github.com/arduino/go-properties-orderedmap v1.5.0 h1:istmr13qQN3nneuU3lsqlMvI6jqB3u8QUfVU1tX/t/8=
github.com/arduino/go-properties-orderedmap v1.5.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk=
github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b h1:9hDi4F2st6dbLC3y4i02zFT5quS4X6iioWifGlVwfy4=
github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b/go.mod h1:uwGy5PpN4lqW97FiLnbcx+xx8jly5YuPMJWfVwwjJiQ=
github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b h1:3PjgYG5gVPA7cipp7vIR2lF96KkEJIFBJ+ANnuv6J20=
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.14
require (
github.com/arduino/board-discovery v0.0.0-20180823133458-1ba29327fb0c
github.com/arduino/go-paths-helper v1.6.0
github.com/arduino/go-properties-orderedmap v1.3.0
github.com/arduino/go-properties-orderedmap v1.5.0
github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b
github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b
github.com/cmaglie/go.rice v1.0.3 // This one must be kept until https://github.com/GeertJohan/go.rice/pull/159 is merged
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ github.com/arduino/go-paths-helper v1.6.0 h1:S7/d7DqB9XlnvF9KrgSiGmo2oWKmYW6O/DT
github.com/arduino/go-paths-helper v1.6.0/go.mod h1:V82BWgAAp4IbmlybxQdk9Bpkz8M4Qyx+RAFKaG9NuvU=
github.com/arduino/go-properties-orderedmap v1.3.0 h1:4No/vQopB36e7WUIk6H6TxiSEJPiMrVOCZylYmua39o=
github.com/arduino/go-properties-orderedmap v1.3.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk=
github.com/arduino/go-properties-orderedmap v1.5.0 h1:istmr13qQN3nneuU3lsqlMvI6jqB3u8QUfVU1tX/t/8=
github.com/arduino/go-properties-orderedmap v1.5.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk=
github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b h1:9hDi4F2st6dbLC3y4i02zFT5quS4X6iioWifGlVwfy4=
github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b/go.mod h1:uwGy5PpN4lqW97FiLnbcx+xx8jly5YuPMJWfVwwjJiQ=
github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b h1:3PjgYG5gVPA7cipp7vIR2lF96KkEJIFBJ+ANnuv6J20=
Expand Down

0 comments on commit e9c87a8

Please sign in to comment.