@@ -55,32 +55,13 @@ type Monitor interface {
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 monitor in event mode. When the
59
- // function returns the monitor must send port events ("add" or "remove")
60
- // using the eventCB function.
61
- StartSync (eventCB EventCallback , errorCB ErrorCallback ) error
62
-
63
- // Stop stops the monitor internal subroutines. If the monitor is
64
- // in event mode it must stop sending events through the eventCB previously
65
- // set.
66
- Stop () error
58
+ Describe () (* PortDescriptor , error )
67
59
68
60
// Quit is called just before the server terminates. This function can be
69
61
// used by the monitor as a last chance gracefully close resources.
70
62
Quit ()
71
63
}
72
64
73
- // EventCallback is a callback function to call to transmit port
74
- // metadata when the monitor is in "sync" mode and a new event
75
- // is detected.
76
- type EventCallback func (event string , port * Port )
77
-
78
- // ErrorCallback is a callback function to signal unrecoverable errors to the
79
- // client while the monitor is in event mode. Once the monitor signal an
80
- // error it means that no more port-events will be delivered until the client
81
- // performs a STOP+START_SYNC cycle.
82
- type ErrorCallback func (err string )
83
-
84
65
// A Server is a pluggable monitor protocol handler,
85
66
// it must be created using the NewServer function.
86
67
type Server struct {
@@ -89,10 +70,6 @@ type Server struct {
89
70
userAgent string
90
71
reqProtocolVersion int
91
72
initialized bool
92
- started bool
93
- syncStarted bool
94
- cachedPorts map [string ]* Port
95
- cachedErr string
96
73
}
97
74
98
75
// NewServer creates a new monitor server backed by the
@@ -132,14 +109,6 @@ func (d *Server) Run(in io.Reader, out io.Writer) error {
132
109
switch cmd {
133
110
case "HELLO" :
134
111
d .hello (fullCmd [6 :])
135
- case "START" :
136
- d .start ()
137
- case "LIST" :
138
- d .list ()
139
- case "START_SYNC" :
140
- d .startSync ()
141
- case "STOP" :
142
- d .stop ()
143
112
case "QUIT" :
144
113
d .impl .Quit ()
145
114
d .outputChan <- messageOk ("quit" )
@@ -180,102 +149,6 @@ func (d *Server) hello(cmd string) {
180
149
d .initialized = true
181
150
}
182
151
183
- func (d * Server ) start () {
184
- if d .started {
185
- d .outputChan <- messageError ("start" , "Monitor already STARTed" )
186
- return
187
- }
188
- if d .syncStarted {
189
- d .outputChan <- messageError ("start" , "Monitor already START_SYNCed, cannot START" )
190
- return
191
- }
192
- d .cachedPorts = map [string ]* Port {}
193
- d .cachedErr = ""
194
- if err := d .impl .StartSync (d .eventCallback , d .errorCallback ); err != nil {
195
- d .outputChan <- messageError ("start" , "Cannot START: " + err .Error ())
196
- return
197
- }
198
- d .started = true
199
- d .outputChan <- messageOk ("start" )
200
- }
201
-
202
- func (d * Server ) eventCallback (event string , port * Port ) {
203
- id := port .Address + "|" + port .Protocol
204
- if event == "add" {
205
- d .cachedPorts [id ] = port
206
- }
207
- if event == "remove" {
208
- delete (d .cachedPorts , id )
209
- }
210
- }
211
-
212
- func (d * Server ) errorCallback (msg string ) {
213
- d .cachedErr = msg
214
- }
215
-
216
- func (d * Server ) list () {
217
- if ! d .started {
218
- d .outputChan <- messageError ("list" , "Monitor not STARTed" )
219
- return
220
- }
221
- if d .syncStarted {
222
- d .outputChan <- messageError ("list" , "monitor already START_SYNCed, LIST not allowed" )
223
- return
224
- }
225
- if d .cachedErr != "" {
226
- d .outputChan <- messageError ("list" , d .cachedErr )
227
- return
228
- }
229
- ports := []* Port {}
230
- for _ , port := range d .cachedPorts {
231
- ports = append (ports , port )
232
- }
233
- d .outputChan <- & message {
234
- EventType : "list" ,
235
- Ports : & ports ,
236
- }
237
- }
238
-
239
- func (d * Server ) startSync () {
240
- if d .syncStarted {
241
- d .outputChan <- messageError ("start_sync" , "Monitor already START_SYNCed" )
242
- return
243
- }
244
- if d .started {
245
- d .outputChan <- messageError ("start_sync" , "Monitor already STARTed, cannot START_SYNC" )
246
- return
247
- }
248
- if err := d .impl .StartSync (d .syncEvent , d .errorEvent ); err != nil {
249
- d .outputChan <- messageError ("start_sync" , "Cannot START_SYNC: " + err .Error ())
250
- return
251
- }
252
- d .syncStarted = true
253
- d .outputChan <- messageOk ("start_sync" )
254
- }
255
-
256
- func (d * Server ) stop () {
257
- if ! d .syncStarted && ! d .started {
258
- d .outputChan <- messageError ("stop" , "Monitor already STOPped" )
259
- return
260
- }
261
- if err := d .impl .Stop (); err != nil {
262
- d .outputChan <- messageError ("stop" , "Cannot STOP: " + err .Error ())
263
- return
264
- }
265
- d .started = false
266
- if d .syncStarted {
267
- d .syncStarted = false
268
- }
269
- d .outputChan <- messageOk ("stop" )
270
- }
271
-
272
- func (d * Server ) syncEvent (event string , port * Port ) {
273
- d .outputChan <- & message {
274
- EventType : event ,
275
- Port : port ,
276
- }
277
- }
278
-
279
152
func (d * Server ) errorEvent (msg string ) {
280
153
d .outputChan <- messageError ("start_sync" , msg )
281
154
}
0 commit comments