@@ -66,7 +66,7 @@ type Discovery interface {
66
66
// StartSync is called to put the discovery in event mode. When the
67
67
// function returns the discovery must send port events ("add" or "remove")
68
68
// using the eventCB function.
69
- StartSync (eventCB EventCallback ) error
69
+ StartSync (eventCB EventCallback , errorCB ErrorCallback ) error
70
70
71
71
// Stop stops the discovery internal subroutines. If the discovery is
72
72
// in event mode it must stop sending events through the eventCB previously
@@ -83,6 +83,12 @@ type Discovery interface {
83
83
// is detected.
84
84
type EventCallback func (event string , port * Port )
85
85
86
+ // ErrorCallback is a callback function to signal unrecoverable errors to the
87
+ // client while the discovery is in event mode. Once the discovery signal an
88
+ // error it means that no more port-events will be delivered until the client
89
+ // performs a STOP+START_SYNC cycle.
90
+ type ErrorCallback func (err string )
91
+
86
92
// A DiscoveryServer is a pluggable discovery protocol handler,
87
93
// it must be created using the NewDiscoveryServer function.
88
94
type DiscoveryServer struct {
@@ -233,7 +239,7 @@ func (d *DiscoveryServer) startSync() {
233
239
}
234
240
c := make (chan interface {}, 10 ) // buffer up to 10 events
235
241
d .syncChannel = c
236
- if err := d .impl .StartSync (d .syncEvent ); err != nil {
242
+ if err := d .impl .StartSync (d .syncEvent , d . errorEvent ); err != nil {
237
243
d .outputError ("start_sync" , "Cannot START_SYNC: " + err .Error ())
238
244
close (d .syncChannel ) // do not leak channel...
239
245
d .syncChannel = nil
@@ -278,6 +284,19 @@ func (d *DiscoveryServer) syncEvent(event string, port *Port) {
278
284
}
279
285
}
280
286
287
+ func (d * DiscoveryServer ) errorEvent (msg string ) {
288
+ type syncOutputJSON struct {
289
+ EventType string `json:"eventType"`
290
+ Error bool `json:"error"`
291
+ Message string `json:"message"`
292
+ }
293
+ d .syncChannel <- & syncOutputJSON {
294
+ EventType : "start_sync" ,
295
+ Error : true ,
296
+ Message : msg ,
297
+ }
298
+ }
299
+
281
300
type genericMessageJSON struct {
282
301
EventType string `json:"eventType"`
283
302
Message string `json:"message"`
0 commit comments