phytron next version
with adaption of HasStates Change-Id: I167ac8031bc5f7120c30031e7cfcb7587b42b61d
This commit is contained in:
@@ -183,12 +183,13 @@ class HasStates:
|
||||
override for code to be executed after stopping
|
||||
"""
|
||||
|
||||
def start_machine(self, statefunc, fast_poll=True, **kwds):
|
||||
def start_machine(self, statefunc, fast_poll=True, restart_text='restarting', **kwds):
|
||||
"""start or restart the state machine
|
||||
|
||||
:param statefunc: the initial state to be called
|
||||
:param fast_poll: flag to indicate that polling has to switched to fast
|
||||
:param cleanup: a cleanup function
|
||||
:param restart_text: status text when machine was already running
|
||||
:param kwds: attributes to be added to the state machine on start
|
||||
|
||||
If the state machine is already running, the following happens:
|
||||
@@ -202,9 +203,10 @@ class HasStates:
|
||||
4) the state machine continues at the given statefunc
|
||||
"""
|
||||
sm = self._state_machine
|
||||
sm.status = self.get_status(statefunc, BUSY)
|
||||
if sm.statefunc:
|
||||
sm.status = sm.status[0], 'restarting'
|
||||
sm.status = sm.status[0], restart_text
|
||||
else:
|
||||
sm.status = self.get_status(statefunc, BUSY)
|
||||
sm.start(statefunc, cleanup=kwds.pop('cleanup', self.on_cleanup), **kwds)
|
||||
self.read_status()
|
||||
if fast_poll:
|
||||
@@ -212,24 +214,23 @@ class HasStates:
|
||||
self.setFastPoll(True)
|
||||
self.pollInfo.trigger(True) # trigger poller
|
||||
|
||||
def stop_machine(self, stopped_status=(IDLE, 'stopped')):
|
||||
def stopping(self, sm):
|
||||
return self.final_status(IDLE, 'stopped')
|
||||
|
||||
def stop_machine(self):
|
||||
"""stop the currently running machine
|
||||
|
||||
:param stopped_status: status to be set after stopping
|
||||
|
||||
If the state machine is not running, nothing happens.
|
||||
Else the state machine is stoppen, the predefined cleanup
|
||||
Else the state machine is stopped, the predefined cleanup
|
||||
sequence is executed and then the status is set to the value
|
||||
given in the sopped_status argument.
|
||||
given in the stopped_status argument.
|
||||
An already running cleanup sequence is not executed again.
|
||||
"""
|
||||
sm = self._state_machine
|
||||
if sm.is_active:
|
||||
sm.idle_status = stopped_status
|
||||
sm.stop()
|
||||
sm.status = self.get_status(sm.statefunc, sm.status[0])[0], 'stopping'
|
||||
self.read_status()
|
||||
self.pollInfo.trigger(True) # trigger poller
|
||||
self.start_machine(self.stopping, restart_text='stopping')
|
||||
|
||||
@Command
|
||||
def stop(self):
|
||||
|
||||
Reference in New Issue
Block a user