Browse Source

introduced BaseState, which defines default behaviour

master
Fr3deric 10 years ago
parent
commit
cdfb428e00
  1. 76
      fetapdtest.py

76
fetapdtest.py

@ -7,10 +7,12 @@ from tuitest import FeApPinConfiguration, FeApUserInterface @@ -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): @@ -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): @@ -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): @@ -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): @@ -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): @@ -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): @@ -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): @@ -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): @@ -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): @@ -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): @@ -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): @@ -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):

Loading…
Cancel
Save