Skip to content

Commit d34b12a

Browse files
umbynoscmaglie
authored andcommitted
Replace discovery with monitor
1 parent e584d29 commit d34b12a

File tree

10 files changed

+96
-63
lines changed

10 files changed

+96
-63
lines changed

.github/workflows/build-dummy-discovery.yaml renamed to .github/workflows/build-dummy-monitor.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build dummy discovery
1+
name: Build dummy monitor
22

33
on:
44
push:
@@ -26,4 +26,4 @@ jobs:
2626
go-version: "1.16"
2727

2828
- name: Build
29-
run: task build-dummy-discovery
29+
run: task build-dummy-monitor

LICENSE.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
This file includes licensing information for serial-discovery
1+
This file includes licensing information for serial-monitor
22

33
Copyright (c) 2018 ARDUINO SA (www.arduino.cc)
44

55
The software is released under the GNU General Public License, which covers the main body
6-
of the serial-discovery code. The terms of this license can be found at:
6+
of the serial-monitor code. The terms of this license can be found at:
77
https://www.gnu.org/licenses/gpl-3.0.en.html
88

99
You can be released from the requirements of the above licenses by purchasing

Taskfile.yml

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@ version: "3"
22

33
vars:
44
DIST_DIR: "dist"
5-
DUMMY_DISCOVERY_VERSION:
5+
DUMMY_MONITOR_VERSION:
66
sh: echo "$(git describe --tags --dirty --broken)"
7-
DUMMY_DISCOVERY_TIMESTAMP:
7+
DUMMY_MONITOR_TIMESTAMP:
88
sh: echo "$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
9-
DUMMY_DISCOVERY_LDFLAGS: >
10-
-X github.com/arduino/pluggable-discovery-protocol-handler/dummy-discovery/args.Tag={{.DUMMY_DISCOVERY_VERSION}}
11-
-X github.com/arduino/pluggable-discovery-protocol-handler/dummy-discovery/args.Timestamp={{.DUMMY_DISCOVERY_TIMESTAMP}}
9+
DUMMY_MONITOR_LDFLAGS: >
10+
-X github.com/arduino/pluggable-monitor-protocol-handler/dummy-monitor/args.Tag={{.DUMMY_MONITOR_VERSION}}
11+
-X github.com/arduino/pluggable-monitor-protocol-handler/dummy-monitor/args.Timestamp={{.DUMMY_MONITOR_TIMESTAMP}}
1212
DEFAULT_GO_PACKAGES:
1313
sh: echo $(go list ./... | tr '\n' ' ')
1414

1515
tasks:
16-
build-dummy-discovery:
17-
desc: Build the dummy-discovery client example
16+
build-dummy-monitor:
17+
desc: Build the dummy-monitor client example
1818
vars:
19-
EXECUTABLE: dummy-discovery{{if eq OS "windows"}}.exe{{end}}
19+
EXECUTABLE: dummy-monitor{{if eq OS "windows"}}.exe{{end}}
2020
cmds:
21-
- go build -o dist/{{.EXECUTABLE}} -v -ldflags '{{.DUMMY_DISCOVERY_LDFLAGS}}' ./dummy-discovery
21+
- go build -o dist/{{.EXECUTABLE}} -v -ldflags '{{.DUMMY_MONITOR_LDFLAGS}}' ./dummy-monitor
2222

2323
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-workflows-task/Taskfile.yml
2424
ci:validate:
File renamed without changes.

dummy-discovery/args/args.go renamed to dummy-monitor/args/args.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// This file is part of dummy-discovery.
2+
// This file is part of dummy-monitor.
33
//
44
// Copyright 2021 ARDUINO SA (http://www.arduino.cc/)
55
//
@@ -35,7 +35,7 @@ func Parse() {
3535
continue
3636
}
3737
if arg == "-v" || arg == "--version" {
38-
fmt.Printf("dummy-discovery %s (build timestamp: %s)\n", Tag, Timestamp)
38+
fmt.Printf("dummy-monitor %s (build timestamp: %s)\n", Tag, Timestamp)
3939
os.Exit(0)
4040
}
4141
fmt.Fprintf(os.Stderr, "invalid argument: %s\n", arg)

dummy-discovery/main.go renamed to dummy-monitor/main.go

+38-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// This file is part of dummy-discovery.
2+
// This file is part of dummy-monitor.
33
//
44
// Copyright 2021 ARDUINO SA (http://www.arduino.cc/)
55
//
@@ -24,23 +24,23 @@ import (
2424
"time"
2525

2626
"github.com/arduino/go-properties-orderedmap"
27-
discovery "github.com/arduino/pluggable-discovery-protocol-handler/v2"
28-
"github.com/arduino/pluggable-discovery-protocol-handler/v2/dummy-discovery/args"
27+
monitor "github.com/arduino/pluggable-monitor-protocol-handler"
28+
"github.com/arduino/pluggable-monitor-protocol-handler/dummy-monitor/args"
2929
)
3030

31-
// dummyDiscovery is an example implementation of a Discovery.
32-
// It simulates a real implementation of a Discovery by generating
31+
// dummyMonitor is an example implementation of a Monitor.
32+
// It simulates a real implementation of a Monitor by generating
3333
// connected ports deterministically, it can also be used for testing
3434
// purposes.
35-
type dummyDiscovery struct {
35+
type dummyMonitor struct {
3636
startSyncCount int
3737
closeChan chan<- bool
3838
}
3939

4040
func main() {
4141
args.Parse()
42-
dummy := &dummyDiscovery{}
43-
server := discovery.NewServer(dummy)
42+
dummy := &dummyMonitor{}
43+
server := monitor.NewServer(dummy)
4444
if err := server.Run(os.Stdin, os.Stdout); err != nil {
4545
os.Exit(1)
4646
}
@@ -49,18 +49,39 @@ func main() {
4949
// Hello does nothing.
5050
// In a real implementation it could setup background processes
5151
// or other kind of resources necessary to discover Ports.
52-
func (d *dummyDiscovery) Hello(userAgent string, protocol int) error {
52+
func (d *dummyMonitor) Hello(userAgent string, protocol int) error {
5353
return nil
5454
}
5555

5656
// Quit does nothing.
5757
// In a real implementation it can be used to tear down resources
58-
// used to discovery Ports.
59-
func (d *dummyDiscovery) Quit() {}
58+
// used to monitor Ports.
59+
func (d *dummyMonitor) Quit() {}
6060

61+
//TODO implement
62+
func (d *dummyMonitor) Describe() {
63+
64+
}
65+
66+
//TODO implement
67+
func (d *dummyMonitor) Configure() {
68+
69+
}
70+
71+
//TODO implement
72+
func (d *dummyMonitor) Open() {
73+
74+
}
75+
76+
//TODO implement
77+
func (d *dummyMonitor) Close() {
78+
79+
}
80+
81+
//TODO remove
6182
// Stop is used to stop the goroutine started by StartSync
6283
// used to discover ports.
63-
func (d *dummyDiscovery) Stop() error {
84+
func (d *dummyMonitor) Stop() error {
6485
if d.closeChan != nil {
6586
d.closeChan <- true
6687
close(d.closeChan)
@@ -69,8 +90,9 @@ func (d *dummyDiscovery) Stop() error {
6990
return nil
7091
}
7192

93+
//TODO remove
7294
// StartSync starts the goroutine that generates fake Ports.
73-
func (d *dummyDiscovery) StartSync(eventCB discovery.EventCallback, errorCB discovery.ErrorCallback) error {
95+
func (d *dummyMonitor) StartSync(eventCB monitor.EventCallback, errorCB monitor.ErrorCallback) error {
7496
d.startSyncCount++
7597
if d.startSyncCount%5 == 0 {
7698
return errors.New("could not start_sync every 5 times")
@@ -107,7 +129,7 @@ func (d *dummyDiscovery) StartSync(eventCB discovery.EventCallback, errorCB disc
107129
case <-time.After(2 * time.Second):
108130
}
109131

110-
eventCB("remove", &discovery.Port{
132+
eventCB("remove", &monitor.Port{
111133
Address: port.Address,
112134
Protocol: port.Protocol,
113135
})
@@ -123,9 +145,9 @@ func (d *dummyDiscovery) StartSync(eventCB discovery.EventCallback, errorCB disc
123145
var dummyCounter = 0
124146

125147
// createDummyPort creates a Port with fake data
126-
func createDummyPort() *discovery.Port {
148+
func createDummyPort() *monitor.Port {
127149
dummyCounter++
128-
return &discovery.Port{
150+
return &monitor.Port{
129151
Address: fmt.Sprintf("%d", dummyCounter),
130152
AddressLabel: "Dummy upload port",
131153
Protocol: "dummy",

go.sum

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
github.com/arduino/go-paths-helper v1.0.1 h1:utYXLM2RfFlc9qp/MJTIYp3t6ux/xM6mWjeEb/WLK4Q=
2+
github.com/arduino/go-paths-helper v1.0.1/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck=
3+
github.com/arduino/go-properties-orderedmap v1.4.0 h1:YEbbzPqm1gXWDM/Jaq8tlvmh09z2qeHPJTUw9/VA4Dk=
4+
github.com/arduino/go-properties-orderedmap v1.4.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk=
5+
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
6+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
7+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
8+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
9+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
10+
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
11+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=

message.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// This file is part of pluggable-discovery-protocol-handler.
2+
// This file is part of pluggable-monitor-protocol-handler.
33
//
44
// Copyright 2021 ARDUINO SA (http://www.arduino.cc/)
55
//
@@ -15,7 +15,7 @@
1515
// a commercial license, send an email to [email protected].
1616
//
1717

18-
package discovery
18+
package monitor
1919

2020
type message struct {
2121
EventType string `json:"eventType"`

discovery.go renamed to monitor.go

+29-29
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// This file is part of pluggable-discovery-protocol-handler.
2+
// This file is part of pluggable-monitor-protocol-handler.
33
//
44
// Copyright 2021 ARDUINO SA (http://www.arduino.cc/)
55
//
@@ -15,16 +15,16 @@
1515
// a commercial license, send an email to [email protected].
1616
//
1717

18-
// Package discovery is a library for handling the Arduino Pluggable-Discovery protocol
19-
// (https://github.com/arduino/tooling-rfcs/blob/main/RFCs/0002-pluggable-discovery.md#pluggable-discovery-api-via-stdinstdout)
18+
// Package monitor is a library for handling the Arduino Pluggable-Monitor protocol
19+
// (https://github.com/arduino/tooling-rfcs/blob/main/RFCs/0004-pluggable-monitor.md#pluggable-monitor-api-via-stdinstdout)
2020
//
21-
// The library implements the state machine and the parsing logic to communicate with a pluggable-discovery client.
21+
// The library implements the state machine and the parsing logic to communicate with a pluggable-monitor client.
2222
// All the commands issued by the client are conveniently translated into function calls, in particular
23-
// the Discovery interface are the only functions that must be implemented to get a fully working pluggable discovery
23+
// the Monitor interface are the only functions that must be implemented to get a fully working pluggable monitor
2424
// using this library.
2525
//
26-
// A usage example is provided in the dummy-discovery package.
27-
package discovery
26+
// A usage example is provided in the dummy-monitor package.
27+
package monitor
2828

2929
import (
3030
"bufio"
@@ -47,44 +47,44 @@ type Port struct {
4747
Properties *properties.Map `json:"properties,omitempty"`
4848
}
4949

50-
// Discovery is an interface that represents the business logic that
51-
// a pluggable discovery must implement. The communication protocol
52-
// is completely hidden and it's handled by a DiscoveryServer.
53-
type Discovery interface {
50+
// Monitor is an interface that represents the business logic that
51+
// a pluggable monitor must implement. The communication protocol
52+
// is completely hidden and it's handled by a MonitorServer.
53+
type Monitor interface {
5454
// Hello is called once at startup to provide the userAgent string
5555
// and the protocolVersion negotiated with the client.
5656
Hello(userAgent string, protocolVersion int) error
5757

58-
// StartSync is called to put the discovery in event mode. When the
59-
// function returns the discovery must send port events ("add" or "remove")
58+
// StartSync is called to put the monitor in event mode. When the
59+
// function returns the monitor must send port events ("add" or "remove")
6060
// using the eventCB function.
6161
StartSync(eventCB EventCallback, errorCB ErrorCallback) error
6262

63-
// Stop stops the discovery internal subroutines. If the discovery is
63+
// Stop stops the monitor internal subroutines. If the monitor is
6464
// in event mode it must stop sending events through the eventCB previously
6565
// set.
6666
Stop() error
6767

6868
// Quit is called just before the server terminates. This function can be
69-
// used by the discovery as a last chance gracefully close resources.
69+
// used by the monitor as a last chance gracefully close resources.
7070
Quit()
7171
}
7272

7373
// EventCallback is a callback function to call to transmit port
74-
// metadata when the discovery is in "sync" mode and a new event
74+
// metadata when the monitor is in "sync" mode and a new event
7575
// is detected.
7676
type EventCallback func(event string, port *Port)
7777

7878
// ErrorCallback is a callback function to signal unrecoverable errors to the
79-
// client while the discovery is in event mode. Once the discovery signal an
79+
// client while the monitor is in event mode. Once the monitor signal an
8080
// error it means that no more port-events will be delivered until the client
8181
// performs a STOP+START_SYNC cycle.
8282
type ErrorCallback func(err string)
8383

84-
// A Server is a pluggable discovery protocol handler,
84+
// A Server is a pluggable monitor protocol handler,
8585
// it must be created using the NewServer function.
8686
type Server struct {
87-
impl Discovery
87+
impl Monitor
8888
outputChan chan *message
8989
userAgent string
9090
reqProtocolVersion int
@@ -95,10 +95,10 @@ type Server struct {
9595
cachedErr string
9696
}
9797

98-
// NewServer creates a new discovery server backed by the
99-
// provided pluggable discovery implementation. To start the server
98+
// NewServer creates a new monitor server backed by the
99+
// provided pluggable monitor implementation. To start the server
100100
// use the Run method.
101-
func NewServer(impl Discovery) *Server {
101+
func NewServer(impl Monitor) *Server {
102102
return &Server{
103103
impl: impl,
104104
outputChan: make(chan *message),
@@ -182,11 +182,11 @@ func (d *Server) hello(cmd string) {
182182

183183
func (d *Server) start() {
184184
if d.started {
185-
d.outputChan <- messageError("start", "Discovery already STARTed")
185+
d.outputChan <- messageError("start", "Monitor already STARTed")
186186
return
187187
}
188188
if d.syncStarted {
189-
d.outputChan <- messageError("start", "Discovery already START_SYNCed, cannot START")
189+
d.outputChan <- messageError("start", "Monitor already START_SYNCed, cannot START")
190190
return
191191
}
192192
d.cachedPorts = map[string]*Port{}
@@ -215,11 +215,11 @@ func (d *Server) errorCallback(msg string) {
215215

216216
func (d *Server) list() {
217217
if !d.started {
218-
d.outputChan <- messageError("list", "Discovery not STARTed")
218+
d.outputChan <- messageError("list", "Monitor not STARTed")
219219
return
220220
}
221221
if d.syncStarted {
222-
d.outputChan <- messageError("list", "discovery already START_SYNCed, LIST not allowed")
222+
d.outputChan <- messageError("list", "monitor already START_SYNCed, LIST not allowed")
223223
return
224224
}
225225
if d.cachedErr != "" {
@@ -238,11 +238,11 @@ func (d *Server) list() {
238238

239239
func (d *Server) startSync() {
240240
if d.syncStarted {
241-
d.outputChan <- messageError("start_sync", "Discovery already START_SYNCed")
241+
d.outputChan <- messageError("start_sync", "Monitor already START_SYNCed")
242242
return
243243
}
244244
if d.started {
245-
d.outputChan <- messageError("start_sync", "Discovery already STARTed, cannot START_SYNC")
245+
d.outputChan <- messageError("start_sync", "Monitor already STARTed, cannot START_SYNC")
246246
return
247247
}
248248
if err := d.impl.StartSync(d.syncEvent, d.errorEvent); err != nil {
@@ -255,7 +255,7 @@ func (d *Server) startSync() {
255255

256256
func (d *Server) stop() {
257257
if !d.syncStarted && !d.started {
258-
d.outputChan <- messageError("stop", "Discovery already STOPped")
258+
d.outputChan <- messageError("stop", "Monitor already STOPped")
259259
return
260260
}
261261
if err := d.impl.Stop(); err != nil {

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tool.poetry]
2-
name = "pluggable-discovery-protocol-handler"
2+
name = "pluggable-monitor-protocol-handler"
33
version = "0.1.0"
44
description = ""
55
authors = ["Your Name <[email protected]>"]

0 commit comments

Comments
 (0)