commit 2021-12-10]19:26:11
This commit is contained in:
parent
2763715d2c
commit
e0c59f23cc
8
cli.go
8
cli.go
@ -13,8 +13,8 @@ var ctx context.Context
|
||||
var cancel context.CancelFunc
|
||||
var ch_discover chan notify.EventInfo
|
||||
var _managerObj *_manager
|
||||
var registerHandleFunc func(uuid string)
|
||||
var removeHandleFunc func(uuid string)
|
||||
var registerHandleFunc func(e Event)
|
||||
var removeHandleFunc func(e Event)
|
||||
|
||||
func init() {
|
||||
ctx, cancel = context.WithCancel(context.Background())
|
||||
@ -35,11 +35,11 @@ func init() {
|
||||
removeHandleFunc = nil
|
||||
}
|
||||
|
||||
func AddRegisterHandleFunc(h func(uuid string)) {
|
||||
func AddRegisterHandleFunc(h func(e Event)) {
|
||||
registerHandleFunc = h
|
||||
}
|
||||
|
||||
func AddRemoveHandleFunc(h func(uuid string)) {
|
||||
func AddRemoveHandleFunc(h func(e Event)) {
|
||||
removeHandleFunc = h
|
||||
}
|
||||
|
||||
|
@ -15,12 +15,14 @@ func main() {
|
||||
fmt.Println("RECV: ", e.Params())
|
||||
}))
|
||||
|
||||
manager.AddRegisterHandleFunc(func(dname string) {
|
||||
fmt.Println(dname, " is registered!!")
|
||||
manager.AddRegisterHandleFunc(func(e manager.Event) {
|
||||
param := e.Params()
|
||||
fmt.Println(param["uuid"].(string), " is registered!! ] ", param["sname"])
|
||||
})
|
||||
|
||||
manager.AddRemoveHandleFunc(func(dname string) {
|
||||
fmt.Println(dname, " is removed!!")
|
||||
manager.AddRemoveHandleFunc(func(e manager.Event) {
|
||||
param := e.Params()
|
||||
fmt.Println(param["uuid"].(string), " is removed!!")
|
||||
})
|
||||
go manager.Run()
|
||||
defer manager.Close()
|
||||
|
12
manager.go
12
manager.go
@ -24,7 +24,11 @@ func (m *_manager) onRegistered(dev *_device) {
|
||||
// m.RegisterListener.Handle(&EventStruct{key: })
|
||||
// }
|
||||
if registerHandleFunc != nil {
|
||||
registerHandleFunc(dev.UUID)
|
||||
param := map[string]interface{}{}
|
||||
param["uuid"] = dev.UUID
|
||||
param["sname"] = dev.Sname
|
||||
|
||||
registerHandleFunc(&EventStruct{key: dev.UUID, params: param})
|
||||
}
|
||||
go recv(dev.Iface, m)
|
||||
}
|
||||
@ -40,7 +44,10 @@ func (m *_manager) onRemoved(port io.Reader) {
|
||||
}
|
||||
|
||||
if removeHandleFunc != nil {
|
||||
removeHandleFunc(dev.UUID)
|
||||
param := map[string]interface{}{}
|
||||
param["uuid"] = dev.UUID
|
||||
|
||||
removeHandleFunc(&EventStruct{key: dev.UUID, params: param})
|
||||
}
|
||||
// log.Println(m.devicesWithUUID)
|
||||
// log.Println(m.devicesWithIface)
|
||||
@ -90,6 +97,7 @@ func (m *_manager) onAdded(iface string) {
|
||||
UUID: rcvMsg["uuid"].(string),
|
||||
IfaceName: iface,
|
||||
Iface: port,
|
||||
Sname: rcvMsg["sname"].(string),
|
||||
states: map[string]interface{}{},
|
||||
}
|
||||
m.devicesWithUUID[rcvMsg["uuid"].(string)] = newDevice
|
||||
|
Loading…
Reference in New Issue
Block a user