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 cancel context.CancelFunc
|
||||||
var ch_discover chan notify.EventInfo
|
var ch_discover chan notify.EventInfo
|
||||||
var _managerObj *_manager
|
var _managerObj *_manager
|
||||||
var registerHandleFunc func(uuid string)
|
var registerHandleFunc func(e Event)
|
||||||
var removeHandleFunc func(uuid string)
|
var removeHandleFunc func(e Event)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
ctx, cancel = context.WithCancel(context.Background())
|
ctx, cancel = context.WithCancel(context.Background())
|
||||||
@ -35,11 +35,11 @@ func init() {
|
|||||||
removeHandleFunc = nil
|
removeHandleFunc = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddRegisterHandleFunc(h func(uuid string)) {
|
func AddRegisterHandleFunc(h func(e Event)) {
|
||||||
registerHandleFunc = h
|
registerHandleFunc = h
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddRemoveHandleFunc(h func(uuid string)) {
|
func AddRemoveHandleFunc(h func(e Event)) {
|
||||||
removeHandleFunc = h
|
removeHandleFunc = h
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,12 +15,14 @@ func main() {
|
|||||||
fmt.Println("RECV: ", e.Params())
|
fmt.Println("RECV: ", e.Params())
|
||||||
}))
|
}))
|
||||||
|
|
||||||
manager.AddRegisterHandleFunc(func(dname string) {
|
manager.AddRegisterHandleFunc(func(e manager.Event) {
|
||||||
fmt.Println(dname, " is registered!!")
|
param := e.Params()
|
||||||
|
fmt.Println(param["uuid"].(string), " is registered!! ] ", param["sname"])
|
||||||
})
|
})
|
||||||
|
|
||||||
manager.AddRemoveHandleFunc(func(dname string) {
|
manager.AddRemoveHandleFunc(func(e manager.Event) {
|
||||||
fmt.Println(dname, " is removed!!")
|
param := e.Params()
|
||||||
|
fmt.Println(param["uuid"].(string), " is removed!!")
|
||||||
})
|
})
|
||||||
go manager.Run()
|
go manager.Run()
|
||||||
defer manager.Close()
|
defer manager.Close()
|
||||||
|
12
manager.go
12
manager.go
@ -24,7 +24,11 @@ func (m *_manager) onRegistered(dev *_device) {
|
|||||||
// m.RegisterListener.Handle(&EventStruct{key: })
|
// m.RegisterListener.Handle(&EventStruct{key: })
|
||||||
// }
|
// }
|
||||||
if registerHandleFunc != nil {
|
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)
|
go recv(dev.Iface, m)
|
||||||
}
|
}
|
||||||
@ -40,7 +44,10 @@ func (m *_manager) onRemoved(port io.Reader) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if removeHandleFunc != nil {
|
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.devicesWithUUID)
|
||||||
// log.Println(m.devicesWithIface)
|
// log.Println(m.devicesWithIface)
|
||||||
@ -90,6 +97,7 @@ func (m *_manager) onAdded(iface string) {
|
|||||||
UUID: rcvMsg["uuid"].(string),
|
UUID: rcvMsg["uuid"].(string),
|
||||||
IfaceName: iface,
|
IfaceName: iface,
|
||||||
Iface: port,
|
Iface: port,
|
||||||
|
Sname: rcvMsg["sname"].(string),
|
||||||
states: map[string]interface{}{},
|
states: map[string]interface{}{},
|
||||||
}
|
}
|
||||||
m.devicesWithUUID[rcvMsg["uuid"].(string)] = newDevice
|
m.devicesWithUUID[rcvMsg["uuid"].(string)] = newDevice
|
||||||
|
3
model.go
3
model.go
@ -5,13 +5,12 @@ import "io"
|
|||||||
type _device struct {
|
type _device struct {
|
||||||
UUID string
|
UUID string
|
||||||
IfaceName string
|
IfaceName string
|
||||||
|
Sname string
|
||||||
Iface io.ReadWriter
|
Iface io.ReadWriter
|
||||||
states map[string]interface{}
|
states map[string]interface{}
|
||||||
propsToSync []string
|
propsToSync []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
type RecvEvent struct {
|
type RecvEvent struct {
|
||||||
Params map[string]interface{}
|
Params map[string]interface{}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user