From e0c59f23cc5adf3bc12b493b3471df708a488864 Mon Sep 17 00:00:00 2001 From: Godopu Date: Fri, 10 Dec 2021 19:26:13 +0900 Subject: [PATCH] commit 2021-12-10]19:26:11 --- cli.go | 8 ++++---- examples/main.go | 10 ++++++---- manager.go | 12 ++++++++++-- model.go | 3 +-- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/cli.go b/cli.go index 10f474f..fb1d423 100644 --- a/cli.go +++ b/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 } diff --git a/examples/main.go b/examples/main.go index ad80cf4..6855e0e 100644 --- a/examples/main.go +++ b/examples/main.go @@ -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() diff --git a/manager.go b/manager.go index 0fc35af..0fa71a4 100644 --- a/manager.go +++ b/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 diff --git a/model.go b/model.go index 95d9461..ebbac2f 100644 --- a/model.go +++ b/model.go @@ -5,13 +5,12 @@ import "io" type _device struct { UUID string IfaceName string + Sname string Iface io.ReadWriter states map[string]interface{} propsToSync []string } - - type RecvEvent struct { Params map[string]interface{} }