From bd8d31e23f8cab456e55a67dc20074113aa158ab Mon Sep 17 00:00:00 2001 From: Adrian Zankich Date: Wed, 2 Jul 2014 17:12:13 -0700 Subject: [PATCH] Alias Connection to AdaptorInterface and Device to DriverInterface --- connection.go | 8 +++++--- device.go | 8 +++++--- robot.go | 6 +++--- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/connection.go b/connection.go index 7215a5c0c..88544cf20 100644 --- a/connection.go +++ b/connection.go @@ -11,20 +11,22 @@ type JSONConnection struct { Adaptor string `json:"adaptor"` } +type Connection AdaptorInterface + type connections struct { - connections []AdaptorInterface + connections []Connection } func (c *connections) Len() int { return len(c.connections) } -func (c *connections) Add(a AdaptorInterface) AdaptorInterface { +func (c *connections) Add(a Connection) Connection { c.connections = append(c.connections, a) return a } -func (c *connections) Each(f func(AdaptorInterface)) { +func (c *connections) Each(f func(Connection)) { for _, connection := range c.connections { f(connection) } diff --git a/device.go b/device.go index d7a6174f4..10a444303 100644 --- a/device.go +++ b/device.go @@ -12,20 +12,22 @@ type JSONDevice struct { Commands []string `json:"commands"` } +type Device DriverInterface + type devices struct { - devices []DriverInterface + devices []Device } func (d *devices) Len() int { return len(d.devices) } -func (d *devices) Add(dev DriverInterface) DriverInterface { +func (d *devices) Add(dev Device) Device { d.devices = append(d.devices, dev) return dev } -func (d *devices) Each(f func(DriverInterface)) { +func (d *devices) Each(f func(Device)) { for _, device := range d.devices { f(device) } diff --git a/robot.go b/robot.go index 169eab700..c70a6f602 100644 --- a/robot.go +++ b/robot.go @@ -61,7 +61,7 @@ func NewRobot(name string, v ...interface{}) *Robot { v[0] = connections{} } log.Println("Initializing connections...") - for _, connection := range v[0].([]AdaptorInterface) { + for _, connection := range v[0].([]Connection) { c := r.Connections().Add(connection) log.Println("Initializing connection", c.name(), "...") } @@ -71,7 +71,7 @@ func NewRobot(name string, v ...interface{}) *Robot { v[1] = devices{} } log.Println("Initializing devices...") - for _, device := range v[1].([]DriverInterface) { + for _, device := range v[1].([]Device) { d := r.Devices().Add(device) log.Println("Initializing device", d.name(), "...") } @@ -147,7 +147,7 @@ func (r *Robot) ToJSON() *JSONRobot { jsonRobot.Commands = append(jsonRobot.Commands, command) } - r.Devices().Each(func(device DriverInterface) { + r.Devices().Each(func(device Device) { jsonDevice := device.ToJSON() jsonRobot.Connections = append(jsonRobot.Connections, jsonDevice.Connection) jsonRobot.Devices = append(jsonRobot.Devices, jsonDevice)