-
Notifications
You must be signed in to change notification settings - Fork 2
/
filter.go
45 lines (33 loc) · 866 Bytes
/
filter.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package usbmon
type Filter interface {
Matches(*Device) bool
}
type ActionEvent string
const (
ActionAdd ActionEvent = "add"
ActionRemove ActionEvent = "remove"
ActionAll ActionEvent = "all"
)
type ActionFilter struct {
Action ActionEvent
}
func (f *ActionFilter) Matches(dev *Device) bool {
action := ActionEvent(dev.Properties()["ACTION"])
if f.Action == ActionAll && (action == ActionAdd || action == ActionRemove) {
return true
}
return action == f.Action
}
type SerialFilter struct {
Serial string
}
func (f *SerialFilter) Matches(dev *Device) bool {
action := ActionEvent(dev.Action())
return f.Serial == dev.Serial() && (action == ActionAdd || action == ActionRemove)
}
type PartitionFilter struct {
Serial string
}
func (f *PartitionFilter) Matches(dev *Device) bool {
return dev.Properties()["DEVICETYPE"] == "partition"
}