Skip to content

Commit

Permalink
Alias Connection to AdaptorInterface and Device to DriverInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
zankich committed Jul 3, 2014
1 parent e10d617 commit bd8d31e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
8 changes: 5 additions & 3 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
8 changes: 5 additions & 3 deletions device.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions robot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(), "...")
}
Expand All @@ -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(), "...")
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit bd8d31e

Please sign in to comment.