-
Notifications
You must be signed in to change notification settings - Fork 9
/
DeviceManagerSignalConnect.go
80 lines (68 loc) · 2.69 KB
/
DeviceManagerSignalConnect.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
package frida_go
import (
"github.com/a97077088/frida-go/cfrida"
"reflect"
"sync"
)
type DeviceManagerAddedEventFunc func(device *Device)
type DeviceManagerChangedEventFunc func()
type DeviceManagerRemovedEventFunc func(device *Device)
type DeviceManagerSignalConnect struct {
onAddedSigs sync.Map
onChangedSigs sync.Map
onRemovedSigs sync.Map
rawDeviceManagerPtr uintptr
}
var deviceManager_onAddedCallbackTable=sync.Map{}
var deviceManager_onChangedCallbackTable=sync.Map{}
var deviceManager_onRemovedCallbackTable=sync.Map{}
func (s *DeviceManagerSignalConnect) OnAdded(on DeviceManagerAddedEventFunc) int64 {
userdata:=int64(reflect.ValueOf(on).Pointer())
deviceManager_onAddedCallbackTable.Store(userdata,on)
sigid := cfrida.G_signal_connect_data(s.rawDeviceManagerPtr, "added", deviceManager_onAddedPtr, uintptr(userdata), 0, G_CONNECT_AFTER)
s.onAddedSigs.Store(sigid,userdata)
return sigid
}
func (s *DeviceManagerSignalConnect) OnChanged(on DeviceManagerChangedEventFunc) int64 {
userdata:=int64(reflect.ValueOf(on).Pointer())
deviceManager_onChangedCallbackTable.Store(userdata,on)
sigid := cfrida.G_signal_connect_data(s.rawDeviceManagerPtr, "changed", deviceManager_onChangedPtr, uintptr(userdata), 0, G_CONNECT_AFTER)
s.onChangedSigs.Store(sigid,userdata)
return sigid
}
func (s *DeviceManagerSignalConnect) OnRemoved(on DeviceManagerRemovedEventFunc) int64 {
userdata:=int64(reflect.ValueOf(on).Pointer())
deviceManager_onRemovedCallbackTable.Store(userdata,on)
sigid := cfrida.G_signal_connect_data(s.rawDeviceManagerPtr, "removed", deviceManager_onRemovedPtr, uintptr(userdata), 0, G_CONNECT_AFTER)
s.onRemovedSigs.Store(sigid,userdata)
return sigid
}
func (s *DeviceManagerSignalConnect) free() {
if s.rawDeviceManagerPtr!=0{
//fmt.Println("DeviceManagerSignalConnect gc")
s.onAddedSigs.Range(func(key, value interface{}) bool {
cfrida.G_signal_handler_disconnect(s.rawDeviceManagerPtr, key.(int64))
deviceManager_onAddedCallbackTable.Delete(key.(int64))
return true
})
s.onChangedSigs.Range(func(key, value interface{}) bool {
cfrida.G_signal_handler_disconnect(s.rawDeviceManagerPtr, key.(int64))
deviceManager_onChangedCallbackTable.Delete(key.(int64))
return true
})
s.onRemovedSigs.Range(func(key, value interface{}) bool {
cfrida.G_signal_handler_disconnect(s.rawDeviceManagerPtr, key.(int64))
deviceManager_onRemovedCallbackTable.Delete(key.(int64))
return true
})
s.rawDeviceManagerPtr=0
}
}
func NewDeviceManagerSignalConnect(rawPtr uintptr) *DeviceManagerSignalConnect {
sig := new(DeviceManagerSignalConnect)
sig.onAddedSigs = sync.Map{}
sig.onChangedSigs = sync.Map{}
sig.onRemovedSigs = sync.Map{}
sig.rawDeviceManagerPtr = rawPtr
return sig
}