-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlistener.go
30 lines (24 loc) · 917 Bytes
/
listener.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Copyright 2018 Dan Jacques. All rights reserved.
// Use of this source code is governed under the MIT License
// that can be found in the LICENSE file.
package proxy
import (
"github.com/danjacques/gopushpixels/device"
"github.com/danjacques/gopushpixels/protocol"
)
// Listener defines a packet listener. A Listener can register with a Manager
// to receive proxy-targeted packets as they arrive.
type Listener interface {
ReceivePacket(d device.D, pkt *protocol.Packet, forwarded bool)
}
// ListenerFunc is a function that conforms to a Listener interface.
type funcListener struct {
fn func(device.D, *protocol.Packet, bool)
}
// ListenerFunc returns a Listener bound to a function.
func ListenerFunc(fn func(device.D, *protocol.Packet, bool)) Listener {
return &funcListener{fn}
}
func (fl *funcListener) ReceivePacket(d device.D, pkt *protocol.Packet, forwarded bool) {
fl.fn(d, pkt, forwarded)
}