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//
1515// a commercial license, send an email to license@arduino.cc.
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
2929import (
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.
7676type 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.
8282type 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.
8686type 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
183183func (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
216216func (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
239239func (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
256256func (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 {
0 commit comments