diff --git a/base/client.go b/base/client.go new file mode 100644 index 0000000000000000000000000000000000000000..f6e239f267baf6b53b729e0675c1b8257ac739a1 --- /dev/null +++ b/base/client.go @@ -0,0 +1,12 @@ +package base + +import "github.com/zgwit/dtu-admin/packet" + +type Client interface { + CLose() error + Send(msg *packet.Packet) error + Write(b []byte) error + Handle(msg *packet.Packet) +} + + diff --git a/dbus/client.go b/dbus/client.go index 8b004ee122899fd401f3a5142dfdc1864ce6856c..857f59e8a3a71040ca9eb14ffabd61551c48bfbc 100644 --- a/dbus/client.go +++ b/dbus/client.go @@ -1,19 +1,13 @@ package dbus import ( + "github.com/zgwit/dtu-admin/base" "github.com/zgwit/dtu-admin/packet" "log" "net" "time" ) -type Client interface { - CLose() error - Send(msg *packet.Packet) error - Write(b []byte) error - handle(msg *packet.Packet) -} - type baseClient struct { conn net.Conn } @@ -47,7 +41,7 @@ func (p *baseClient) Write(b []byte) error { return nil } -func NewClient() Client { +func NewClient() base.Client { //根据类型 return nil } \ No newline at end of file diff --git a/dbus/peer.go b/dbus/peer.go index 7847d3a669ba2a9aabb381a250b0bd91731c2a78..c228f62531b9d62b99e28a653dc9b101c36e49bc 100644 --- a/dbus/peer.go +++ b/dbus/peer.go @@ -1,6 +1,7 @@ package dbus import ( + "github.com/zgwit/dtu-admin/dtu" "github.com/zgwit/dtu-admin/packet" "log" ) @@ -9,10 +10,10 @@ import ( type Peer struct { baseClient - //link *dtu.Link + link *dtu.Link } -func (p *Peer) handle(msg *packet.Packet) { +func (p *Peer) Handle(msg *packet.Packet) { switch msg.Type { case packet.TypeConnect: p.handleConnect(msg) diff --git a/dbus/plugin.go b/dbus/plugin.go index 0ee504b7b02b5df4a2b5d2c3dcf4b484408250c8..a39451d9b7b529396c6bf159255af4bcda802c19 100644 --- a/dbus/plugin.go +++ b/dbus/plugin.go @@ -9,7 +9,7 @@ type Plugin struct { baseClient } -func (p *Plugin) handle(msg *packet.Packet) { +func (p *Plugin) Handle(msg *packet.Packet) { switch msg.Type { case packet.TypeConnect: p.handleConnect(msg) diff --git a/dbus/server.go b/dbus/server.go index e623c2d58f6707dbf72c5da5b7d189b628e2c7e2..c782ce14d78b747f95d5a24ce5e1650ec909cab8 100644 --- a/dbus/server.go +++ b/dbus/server.go @@ -64,7 +64,7 @@ func (s *Server) receive(conn net.Conn) { } packs := parser.Parse(buf[:n]) for _, pack := range packs { - c.handle(pack) + c.Handle(pack) } } diff --git a/dtu/link.go b/dtu/link.go index d887a91d17e46744f921e8bb784e01ea020318bd..69a294eb3b155411d94b5aedebdab2c307134ca4 100644 --- a/dtu/link.go +++ b/dtu/link.go @@ -4,7 +4,6 @@ import ( "errors" "github.com/zgwit/dtu-admin/base" "github.com/zgwit/dtu-admin/db" - "github.com/zgwit/dtu-admin/dbus" "github.com/zgwit/dtu-admin/model" "github.com/zgwit/dtu-admin/packet" "log" @@ -25,9 +24,9 @@ type Link struct { cache [][]byte //透传链接 - peer dbus.Client + peer base.Client - plugin dbus.Client + plugin base.Client //监视器连接, monitor *Monitor