Skip to content

Commit c818cef

Browse files
umbynoscmaglie
authored andcommitted
add configure() implementation
1 parent a1c2335 commit c818cef

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

dummy-monitor/main.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,22 @@ func (d *dummyMonitor) Hello(userAgent string, protocol int) error {
6969
return nil
7070
}
7171

72-
//TODO implement
7372
func (d *dummyMonitor) Describe() (*monitor.PortDescriptor, error) {
7473
return settings, nil
7574
}
7675

77-
//TODO implement
7876
func (d *dummyMonitor) Configure(parameterName string, value string) error {
79-
return nil
77+
if settings.ConfigurationParameter[parameterName] == nil {
78+
return fmt.Errorf("could not find parameter named %s", parameterName)
79+
}
80+
values := settings.ConfigurationParameter[parameterName].Values
81+
for _, i := range values {
82+
if i == value {
83+
settings.ConfigurationParameter[parameterName].Selected = value
84+
return nil
85+
}
86+
}
87+
return fmt.Errorf("invalid value for parameter %s: %s", parameterName, value)
8088
}
8189

8290
//TODO implement

monitor.go

+20-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,26 @@ func (d *Server) describe() {
186186
}
187187

188188
func (d *Server) configure(cmd string) {
189-
189+
if !d.initialized {
190+
d.outputChan <- messageError("configure", "Monitor not STARTed")
191+
return
192+
}
193+
re := regexp.MustCompile(`^(\w+) (\w+)$`)
194+
matches := re.FindStringSubmatch(cmd)
195+
if len(matches) != 3 {
196+
d.outputChan <- messageError("configure", "Invalid CONFIGURE command")
197+
return
198+
}
199+
parameterName := matches[1]
200+
value := matches[2]
201+
if err := d.impl.Configure(parameterName, value); err != nil {
202+
d.outputChan <- messageError("configure", err.Error())
203+
return
204+
}
205+
d.outputChan <- &message{
206+
EventType: "configure",
207+
Message: "OK",
208+
}
190209
}
191210

192211
func (d *Server) open(cmd string) {

0 commit comments

Comments
 (0)