2013-10-23 07:45:31 +08:00
|
|
|
package gobot
|
2013-10-24 13:00:03 +08:00
|
|
|
|
|
|
|
type Adaptor struct {
|
2013-11-14 12:44:54 +08:00
|
|
|
Name string
|
|
|
|
Port string
|
|
|
|
Connected bool
|
2013-12-07 06:44:48 +08:00
|
|
|
Params map[string]interface{}
|
2013-10-24 13:00:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (Adaptor) NewAdaptor(a Adaptor) Adaptor {
|
2013-11-14 12:44:54 +08:00
|
|
|
return a
|
2013-10-24 13:00:03 +08:00
|
|
|
}
|
|
|
|
|
2013-11-14 12:44:54 +08:00
|
|
|
func (a *Adaptor) Finalize() bool {
|
|
|
|
if a.IsConnected() {
|
|
|
|
a.Disconnect()
|
|
|
|
}
|
|
|
|
return true
|
2013-10-24 13:00:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *Adaptor) Connect() bool {
|
2013-11-14 12:44:54 +08:00
|
|
|
a.Connected = true
|
|
|
|
return true
|
2013-10-24 13:00:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *Adaptor) Disconnect() bool {
|
2013-11-14 12:44:54 +08:00
|
|
|
a.Connected = false
|
|
|
|
return true
|
2013-10-24 13:00:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *Adaptor) Reconnect() bool {
|
2013-11-14 12:44:54 +08:00
|
|
|
if !a.IsConnected() {
|
|
|
|
return a.Connect()
|
|
|
|
}
|
|
|
|
return true
|
2013-10-24 13:00:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *Adaptor) IsConnected() bool {
|
2013-11-14 12:44:54 +08:00
|
|
|
return a.Connected
|
2013-10-24 13:00:03 +08:00
|
|
|
}
|