1
1
//
2
- // This file is part of pluggable-discovery -protocol-handler.
2
+ // This file is part of pluggable-monitor -protocol-handler.
3
3
//
4
4
// Copyright 2021 ARDUINO SA (http://www.arduino.cc/)
5
5
//
15
15
// a commercial license, send an email to [email protected] .
16
16
//
17
17
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)
20
20
//
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.
22
22
// 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
24
24
// using this library.
25
25
//
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
28
28
29
29
import (
30
30
"bufio"
@@ -47,44 +47,44 @@ type Port struct {
47
47
Properties * properties.Map `json:"properties,omitempty"`
48
48
}
49
49
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 {
54
54
// Hello is called once at startup to provide the userAgent string
55
55
// and the protocolVersion negotiated with the client.
56
56
Hello (userAgent string , protocolVersion int ) error
57
57
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")
60
60
// using the eventCB function.
61
61
StartSync (eventCB EventCallback , errorCB ErrorCallback ) error
62
62
63
- // Stop stops the discovery internal subroutines. If the discovery is
63
+ // Stop stops the monitor internal subroutines. If the monitor is
64
64
// in event mode it must stop sending events through the eventCB previously
65
65
// set.
66
66
Stop () error
67
67
68
68
// 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.
70
70
Quit ()
71
71
}
72
72
73
73
// 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
75
75
// is detected.
76
76
type EventCallback func (event string , port * Port )
77
77
78
78
// 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
80
80
// error it means that no more port-events will be delivered until the client
81
81
// performs a STOP+START_SYNC cycle.
82
82
type ErrorCallback func (err string )
83
83
84
- // A Server is a pluggable discovery protocol handler,
84
+ // A Server is a pluggable monitor protocol handler,
85
85
// it must be created using the NewServer function.
86
86
type Server struct {
87
- impl Discovery
87
+ impl Monitor
88
88
outputChan chan * message
89
89
userAgent string
90
90
reqProtocolVersion int
@@ -95,10 +95,10 @@ type Server struct {
95
95
cachedErr string
96
96
}
97
97
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
100
100
// use the Run method.
101
- func NewServer (impl Discovery ) * Server {
101
+ func NewServer (impl Monitor ) * Server {
102
102
return & Server {
103
103
impl : impl ,
104
104
outputChan : make (chan * message ),
@@ -182,11 +182,11 @@ func (d *Server) hello(cmd string) {
182
182
183
183
func (d * Server ) start () {
184
184
if d .started {
185
- d .outputChan <- messageError ("start" , "Discovery already STARTed" )
185
+ d .outputChan <- messageError ("start" , "Monitor already STARTed" )
186
186
return
187
187
}
188
188
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" )
190
190
return
191
191
}
192
192
d .cachedPorts = map [string ]* Port {}
@@ -215,11 +215,11 @@ func (d *Server) errorCallback(msg string) {
215
215
216
216
func (d * Server ) list () {
217
217
if ! d .started {
218
- d .outputChan <- messageError ("list" , "Discovery not STARTed" )
218
+ d .outputChan <- messageError ("list" , "Monitor not STARTed" )
219
219
return
220
220
}
221
221
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" )
223
223
return
224
224
}
225
225
if d .cachedErr != "" {
@@ -238,11 +238,11 @@ func (d *Server) list() {
238
238
239
239
func (d * Server ) startSync () {
240
240
if d .syncStarted {
241
- d .outputChan <- messageError ("start_sync" , "Discovery already START_SYNCed" )
241
+ d .outputChan <- messageError ("start_sync" , "Monitor already START_SYNCed" )
242
242
return
243
243
}
244
244
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" )
246
246
return
247
247
}
248
248
if err := d .impl .StartSync (d .syncEvent , d .errorEvent ); err != nil {
@@ -255,7 +255,7 @@ func (d *Server) startSync() {
255
255
256
256
func (d * Server ) stop () {
257
257
if ! d .syncStarted && ! d .started {
258
- d .outputChan <- messageError ("stop" , "Discovery already STOPped" )
258
+ d .outputChan <- messageError ("stop" , "Monitor already STOPped" )
259
259
return
260
260
}
261
261
if err := d .impl .Stop (); err != nil {
0 commit comments