Skip to content

Commit

Permalink
added Halt() to a collection of devices
Browse files Browse the repository at this point in the history
  • Loading branch information
mattetti authored and zankich committed Apr 29, 2014
1 parent 9c639af commit 8b978c4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
17 changes: 13 additions & 4 deletions device.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion master.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
10 changes: 2 additions & 8 deletions robot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 8b978c4

Please sign in to comment.