Skip to content

Commit b9bc502

Browse files
umbynoscmaglie
authored andcommitted
remove useless stuff and implement callback functions to be implemented
1 parent 60e4967 commit b9bc502

File tree

2 files changed

+46
-78
lines changed

2 files changed

+46
-78
lines changed

dummy-monitor/main.go

+11-77
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@
1818
package main
1919

2020
import (
21-
"errors"
2221
"fmt"
2322
"os"
24-
"time"
2523

2624
"github.com/arduino/go-properties-orderedmap"
2725
monitor "github.com/arduino/pluggable-monitor-protocol-handler"
@@ -53,94 +51,30 @@ func (d *dummyMonitor) Hello(userAgent string, protocol int) error {
5351
return nil
5452
}
5553

56-
// Quit does nothing.
57-
// In a real implementation it can be used to tear down resources
58-
// used to monitor Ports.
59-
func (d *dummyMonitor) Quit() {}
60-
6154
//TODO implement
62-
func (d *dummyMonitor) Describe() {
63-
55+
func (d *dummyMonitor) Describe() (*monitor.PortDescriptor, error) {
56+
return nil, nil
6457
}
6558

6659
//TODO implement
67-
func (d *dummyMonitor) Configure() {
68-
60+
func (d *dummyMonitor) Configure(parameterName string, value string) error {
61+
return nil
6962
}
7063

7164
//TODO implement
72-
func (d *dummyMonitor) Open() {
73-
65+
func (d *dummyMonitor) Open(ipAddress string, boardPort string) error {
66+
return nil
7467
}
7568

7669
//TODO implement
77-
func (d *dummyMonitor) Close() {
78-
79-
}
80-
81-
//TODO remove
82-
// Stop is used to stop the goroutine started by StartSync
83-
// used to discover ports.
84-
func (d *dummyMonitor) Stop() error {
85-
if d.closeChan != nil {
86-
d.closeChan <- true
87-
close(d.closeChan)
88-
d.closeChan = nil
89-
}
70+
func (d *dummyMonitor) Close() error {
9071
return nil
9172
}
9273

93-
//TODO remove
94-
// StartSync starts the goroutine that generates fake Ports.
95-
func (d *dummyMonitor) StartSync(eventCB monitor.EventCallback, errorCB monitor.ErrorCallback) error {
96-
d.startSyncCount++
97-
if d.startSyncCount%5 == 0 {
98-
return errors.New("could not start_sync every 5 times")
99-
}
100-
101-
c := make(chan bool)
102-
d.closeChan = c
103-
104-
// Run synchronous event emitter
105-
go func() {
106-
var closeChan <-chan bool = c
107-
108-
// Output initial port state
109-
eventCB("add", createDummyPort())
110-
eventCB("add", createDummyPort())
111-
112-
// Start sending events
113-
count := 0
114-
for count < 2 {
115-
count++
116-
117-
select {
118-
case <-closeChan:
119-
return
120-
case <-time.After(2 * time.Second):
121-
}
122-
123-
port := createDummyPort()
124-
eventCB("add", port)
125-
126-
select {
127-
case <-closeChan:
128-
return
129-
case <-time.After(2 * time.Second):
130-
}
131-
132-
eventCB("remove", &monitor.Port{
133-
Address: port.Address,
134-
Protocol: port.Protocol,
135-
})
136-
}
137-
138-
errorCB("unrecoverable error, cannot send more events")
139-
<-closeChan
140-
}()
141-
142-
return nil
143-
}
74+
// Quit does nothing.
75+
// In a real implementation it can be used to tear down resources
76+
// used to monitor Ports.
77+
func (d *dummyMonitor) Quit() {}
14478

14579
var dummyCounter = 0
14680

monitor.go

+35-1
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,20 @@ type Monitor interface {
5555
// and the protocolVersion negotiated with the client.
5656
Hello(userAgent string, protocolVersion int) error
5757

58+
// Describe is called to obtain the description of the comunication port
5859
Describe() (*PortDescriptor, error)
5960

61+
// Configure allows to set the configuration parameters for the comunication port
62+
Configure(parameterName string, value string) error
63+
64+
// Open allows to open a comunication with the board using TCP/IP
65+
Open(ipAddress string, boardPort string) error
66+
67+
// Close will close the currently open port and TCP/IP connection
68+
Close() error
69+
6070
// Quit is called just before the server terminates. This function can be
61-
// used by the monitor as a last chance gracefully close resources.
71+
// used by the monitor as a last chance to gracefully close resources.
6272
Quit()
6373
}
6474

@@ -109,6 +119,14 @@ func (d *Server) Run(in io.Reader, out io.Writer) error {
109119
switch cmd {
110120
case "HELLO":
111121
d.hello(fullCmd[6:])
122+
case "DESCRIBE":
123+
d.describe()
124+
case "CONFIGURE":
125+
d.configure(fullCmd[10:])
126+
case "OPEN":
127+
d.open(fullCmd[5:])
128+
case "CLOSE":
129+
d.close()
112130
case "QUIT":
113131
d.impl.Quit()
114132
d.outputChan <- messageOk("quit")
@@ -149,6 +167,22 @@ func (d *Server) hello(cmd string) {
149167
d.initialized = true
150168
}
151169

170+
func (d *Server) describe() {
171+
172+
}
173+
174+
func (d *Server) configure(cmd string) {
175+
176+
}
177+
178+
func (d *Server) open(cmd string) {
179+
180+
}
181+
182+
func (d *Server) close() {
183+
184+
}
185+
152186
func (d *Server) errorEvent(msg string) {
153187
d.outputChan <- messageError("start_sync", msg)
154188
}

0 commit comments

Comments
 (0)