Skip to content

Commit

Permalink
Add Halt function to DriverInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
zankich committed Mar 31, 2014
1 parent 16c650a commit 0418ca2
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions device.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type device struct {

type Device interface {
Start() bool
Halt() bool
}

func NewDevice(driver DriverInterface, r *Robot) *device {
Expand All @@ -31,6 +32,11 @@ func (d *device) Start() bool {
return d.Driver.Start()
}

func (d *device) Halt() bool {
log.Println("Device " + d.Name + " halted")
return d.Driver.Halt()
}

func (d *device) Commands() interface{} {
return FieldByNamePtr(d.Driver, "Commands").Interface()
}
1 change: 1 addition & 0 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ type Driver struct {

type DriverInterface interface {
Start() bool
Halt() bool
}
1 change: 1 addition & 0 deletions master.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func (m *Master) Start() {

for _ = range c {
for r := range m.Robots {
m.Robots[r].haltDevices()
m.Robots[r].finalizeConnections()
}
break
Expand Down
6 changes: 6 additions & 0 deletions robot.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ 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()
Expand Down
1 change: 1 addition & 0 deletions test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type testDriver struct {
}

func (me *testDriver) Start() bool { return true }
func (me *testDriver) Halt() bool { return true }

type testAdaptor struct {
Adaptor
Expand Down

0 comments on commit 0418ca2

Please sign in to comment.