introduced BaseState, which defines default behaviour

This commit is contained in:
Frederic 2015-05-20 00:04:40 +02:00
parent 40eef9aa66
commit cdfb428e00
1 changed files with 49 additions and 27 deletions

View File

@ -7,10 +7,12 @@ from tuitest import FeApPinConfiguration, FeApUserInterface
class IllegalEventError(Exception):
pass
"""
An abstract state, needed to define all possible events.
"""
class AbstractState(object):
def __init__(self, controller):
self._controller = controller
def on_registration_in_progress(self):
raise IllegalEventError()
@ -46,8 +48,39 @@ class AbstractState(object):
def on_timeout(self):
raise IllegalEventError()
class InitState(AbstractState):
"""
The basic state that every other state inherits from. It defines default
behaviour for some events (overriden if necessary).
"""
class BaseState(AbstractState):
def __init__(self, controller):
self._controller = controller
def on_gabelschalter_up(self):
return None
def on_gabelschalter_down(self):
return None
def on_incoming_call(self):
self._controller.get_phone().decline_call()
def on_call_ended(self):
# When an incoming call is declined, a call_ended event occurs, which
# needs to be ignored, here.
return None
def on_nummernschalter_active(self):
return None
def on_nummernschalter_input(self, num):
return None
class InitState(BaseState):
def __init__(self, controller):
super(InitState, self).__init__(controller)
self._controller.get_feap().set_schauzeichen(True)
@ -56,7 +89,7 @@ class InitState(AbstractState):
print('registration in progress')
return RegisteringState
class RegisteringState(AbstractState):
class RegisteringState(BaseState):
def __init__(self, controller):
super(RegisteringState, self).__init__(controller)
@ -65,7 +98,7 @@ class RegisteringState(AbstractState):
self._controller.get_feap().set_schauzeichen(False)
return IdleState
class IdleState(AbstractState):
class IdleState(BaseState):
def on_incoming_call(self):
print('incomfing call')
return SchelltState
@ -74,16 +107,7 @@ class IdleState(AbstractState):
print('gabel up')
return DialingState
def on_gabelschalter_down(self):
pass
def on_nummernschalter_active(self, x):
pass
def on_nummernschalter_input(self, x):
pass
class SchelltState(AbstractState):
class SchelltState(BaseState):
def __init__(self, controller):
super(SchelltState, self).__init__(controller)
self._controller.get_feap().set_wecker(True)
@ -99,7 +123,7 @@ class SchelltState(AbstractState):
self.__on_leave()
return IdleState
class AcceptingState(AbstractState):
class AcceptingState(BaseState):
def __init__(self, controller):
super(AcceptingState, self).__init__(controller)
self._controller.get_phone().accept_call()
@ -107,7 +131,7 @@ class AcceptingState(AbstractState):
def on_call_accepted(self):
return CallRunningState
class CallTerminatingState(AbstractState):
class CallTerminatingState(BaseState):
def __init__(self, controller):
super(CallTerminatingState, self).__init__(controller)
self._controller.get_phone().end_call()
@ -118,11 +142,11 @@ class CallTerminatingState(AbstractState):
def on_call_accepted(self):
return None
class ForgottenState(AbstractState):
class ForgottenState(BaseState):
def on_gabelschalter_down(self):
return IdleState
class BusyBeepingState(AbstractState):
class BusyBeepingState(BaseState):
def __init__(self, controller):
super(BusyBeepingState, self).__init__(controller)
self._controller.get_phone().play_busy_tone()
@ -137,14 +161,14 @@ class BusyBeepingState(AbstractState):
self.__on_leave()
return IdleState
class CallRunningState(AbstractState):
class CallRunningState(BaseState):
def on_gabelschalter_down(self):
return CallTerminatingState
def on_call_ended(self):
return BusyBeepingState
class WecktState(AbstractState):
class WecktState(BaseState):
def on_gabelschalter_down(self):
return CallTerminatingState
@ -154,7 +178,7 @@ class WecktState(AbstractState):
def on_call_accepted(self):
return CallRunningState
class ConnectingState(AbstractState):
class ConnectingState(BaseState):
def on_gabelschalter_down(self):
return CallTerminatingState
@ -171,7 +195,7 @@ class ConnectingState(AbstractState):
def on_call_ended(self):
return BusyBeepingState
class DialingState(AbstractState):
class DialingState(BaseState):
def __init__(self, controller):
super(DialingState, self).__init__(controller)
self._controller.get_phone().play_dial_tone()
@ -206,8 +230,6 @@ class DialingState(AbstractState):
self._controller.get_phone().call(self.__number)
return ConnectingState
def on_incoming_call(self):
self._controller.get_phone().decline_call()
class StateMachineController(object):
def __init__(self, phone, feap):