-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonitor.go
81 lines (66 loc) · 1.69 KB
/
monitor.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package udev
// #include <libudev.h>
// #include <stdlib.h>
import "C"
import (
"unsafe"
)
type Monitor struct {
ptr *C.struct_udev_monitor
}
func NewMonitor(ptr *C.struct_udev_monitor) *Monitor {
if ptr == nil {
return nil
}
return &Monitor{
ptr: ptr,
}
}
func (m *Monitor) Free() {
C.udev_monitor_unref(m.ptr)
}
func (m *Monitor) GetManager() *Manager {
return &Manager{
ptr: C.udev_monitor_get_udev(m.ptr),
}
}
func (m *Monitor) Enable() bool {
return C.udev_monitor_enable_receiving(m.ptr) >= 0
}
func (m *Monitor) SetReceiveBufferSize(size int) bool {
return C.udev_monitor_set_receive_buffer_size(m.ptr, _Ctype_int(size)) >= 0
}
func (m *Monitor) GetFileDesc() int {
return int(C.udev_monitor_get_fd(m.ptr))
}
func (m *Monitor) ReceiveDevice() *Device {
return NewDevice(C.udev_monitor_receive_device(m.ptr))
}
func (m *Monitor) AddFilterToMatchSubsystemDevType(subsystem string, devType string) bool {
var cSubsystem *C.char
if subsystem != "" {
cSubsystem := C.CString(subsystem)
defer C.free(unsafe.Pointer(cSubsystem))
} else {
cSubsystem = nil
}
var cDevType *C.char
if devType != "" {
cDevType = C.CString(devType)
defer C.free(unsafe.Pointer(cDevType))
} else {
cDevType = nil
}
return C.udev_monitor_filter_add_match_subsystem_devtype(m.ptr, cSubsystem, cDevType) >= 0
}
func (m *Monitor) AddFilterMatchTag(tag string) bool {
cTag := C.CString(tag)
defer C.free(unsafe.Pointer(cTag))
return C.udev_monitor_filter_add_match_tag(m.ptr, cTag) >= 0
}
func (m *Monitor) UpdateFilter() bool {
return C.udev_monitor_filter_update(m.ptr) >= 0
}
func (m *Monitor) RemoveFilter() bool {
return C.udev_monitor_filter_remove(m.ptr) >= 0
}