From 852a7699c1ccf796be3007f8189aaf0d2d73f395 Mon Sep 17 00:00:00 2001 From: Matt Aimonetti Date: Sat, 26 Apr 2014 21:52:10 -0700 Subject: [PATCH] added Halt() to a collection of devices --- device.go | 17 +++++++++++++---- master.go | 2 +- robot.go | 10 ++-------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/device.go b/device.go index 5b5d47e1..9b197369 100644 --- a/device.go +++ b/device.go @@ -5,6 +5,12 @@ import ( "reflect" ) +type Device interface { + Init() bool + Start() bool + Halt() bool +} + type device struct { Name string `json:"name"` Type string `json:"driver"` @@ -13,10 +19,13 @@ type device struct { Driver DriverInterface `json:"-"` } -type Device interface { - Init() bool - Start() bool - Halt() bool +type devices []*device + +// Halt() stop all the devices. +func (d devices) Halt() { + for _, device := range d { + device.Halt() + } } func NewDevice(driver DriverInterface, r *Robot) *device { diff --git a/master.go b/master.go index 2daa5ec3..f6a8289f 100644 --- a/master.go +++ b/master.go @@ -42,7 +42,7 @@ func (m *Master) Start() { // waiting on something coming on the channel _ = <-c for _, r := range m.Robots { - r.haltDevices() + r.GetDevices().Halt() r.finalizeConnections() } diff --git a/robot.go b/robot.go index 07d94651..fff6997e 100644 --- a/robot.go +++ b/robot.go @@ -113,20 +113,14 @@ func (r *Robot) startDevices() bool { return success } -func (r *Robot) haltDevices() { - for _, device := range r.devices { - device.Halt() - } -} - func (r *Robot) finalizeConnections() { for _, connection := range r.connections { connection.Finalize() } } -func (r *Robot) GetDevices() []*device { - return r.devices +func (r *Robot) GetDevices() devices { + return devices(r.devices) } func (r *Robot) GetDevice(name string) *device {