2013-10-22 16:45:31 -07:00
|
|
|
package gobot
|
2013-10-23 22:00:03 -07:00
|
|
|
|
2014-06-23 20:33:59 -07:00
|
|
|
import "fmt"
|
|
|
|
|
2013-10-23 22:00:03 -07:00
|
|
|
type Adaptor struct {
|
2014-06-15 17:32:00 -07:00
|
|
|
Name string
|
|
|
|
Port string
|
|
|
|
Connected bool
|
|
|
|
Params map[string]interface{}
|
2014-06-23 20:33:59 -07:00
|
|
|
Type string
|
2013-10-23 22:00:03 -07:00
|
|
|
}
|
|
|
|
|
2013-12-18 15:25:07 -08:00
|
|
|
type AdaptorInterface interface {
|
|
|
|
Finalize() bool
|
|
|
|
Connect() bool
|
2014-06-13 10:46:58 -07:00
|
|
|
port() string
|
|
|
|
name() string
|
2014-06-14 18:49:02 -07:00
|
|
|
setName(string)
|
2014-06-13 10:46:58 -07:00
|
|
|
params() map[string]interface{}
|
2014-07-02 18:08:44 -07:00
|
|
|
ToJSON() *JSONConnection
|
2014-06-13 10:46:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *Adaptor) port() string {
|
|
|
|
return a.Port
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *Adaptor) name() string {
|
|
|
|
return a.Name
|
|
|
|
}
|
|
|
|
|
2014-06-14 18:49:02 -07:00
|
|
|
func (a *Adaptor) setName(s string) {
|
|
|
|
a.Name = s
|
|
|
|
}
|
|
|
|
|
2014-06-13 10:46:58 -07:00
|
|
|
func (a *Adaptor) params() map[string]interface{} {
|
|
|
|
return a.Params
|
2013-10-23 22:00:03 -07:00
|
|
|
}
|
2014-06-23 20:33:59 -07:00
|
|
|
|
|
|
|
func (a *Adaptor) ToJSON() *JSONConnection {
|
|
|
|
return &JSONConnection{
|
|
|
|
Name: a.Name,
|
|
|
|
Port: a.Port,
|
|
|
|
Adaptor: a.Type,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewAdaptor(name, port, t string) *Adaptor {
|
|
|
|
if name == "" {
|
|
|
|
name = fmt.Sprintf("%X", Rand(int(^uint(0)>>1)))
|
|
|
|
}
|
|
|
|
return &Adaptor{
|
|
|
|
Type: t,
|
|
|
|
Name: name,
|
|
|
|
Port: port,
|
|
|
|
}
|
|
|
|
}
|