|
|
|
@ -34,6 +34,9 @@ class AbstractState(object):
@@ -34,6 +34,9 @@ class AbstractState(object):
|
|
|
|
|
|
|
|
|
|
def on_call_ringing(self): |
|
|
|
|
raise IllegalEventError() |
|
|
|
|
|
|
|
|
|
def on_invalid_number(self): |
|
|
|
|
raise IllegalEventError() |
|
|
|
|
|
|
|
|
|
def on_nummernschalter_input(self, num): |
|
|
|
|
raise IllegalEventError() |
|
|
|
@ -125,6 +128,7 @@ class BusyBeepingState(AbstractState):
@@ -125,6 +128,7 @@ class BusyBeepingState(AbstractState):
|
|
|
|
|
return ForgottenState |
|
|
|
|
|
|
|
|
|
def on_gabelschalter_down(self): |
|
|
|
|
self.__on_leave() |
|
|
|
|
return IdleState |
|
|
|
|
|
|
|
|
|
class CallRunningState(AbstractState): |
|
|
|
@ -154,6 +158,10 @@ class ConnectingState(AbstractState):
@@ -154,6 +158,10 @@ class ConnectingState(AbstractState):
|
|
|
|
|
def on_call_accepted(self): |
|
|
|
|
return CallRunningState |
|
|
|
|
|
|
|
|
|
def on_invalid_number(self): |
|
|
|
|
# TODO: play sound |
|
|
|
|
return BusyBeepingState |
|
|
|
|
|
|
|
|
|
class DialingState(AbstractState): |
|
|
|
|
def __init__(self, controller): |
|
|
|
|
super(DialingState, self).__init__(controller) |
|
|
|
@ -186,6 +194,8 @@ class StateMachineController(object):
@@ -186,6 +194,8 @@ class StateMachineController(object):
|
|
|
|
|
self.__phone = phone |
|
|
|
|
self.__feap = feap |
|
|
|
|
|
|
|
|
|
self.__timeout = None |
|
|
|
|
|
|
|
|
|
self.__running = True |
|
|
|
|
self.__evqueue = queue.Queue() |
|
|
|
|
self.__evthread = threading.Thread(target=self.__event_dispatcher) |
|
|
|
@ -210,27 +220,19 @@ class StateMachineController(object):
@@ -210,27 +220,19 @@ class StateMachineController(object):
|
|
|
|
|
print('%s -> %s' % (oldstate.__name__, newstate.__name__)) |
|
|
|
|
self.__state = newstate(self) |
|
|
|
|
|
|
|
|
|
def __timeout_thread(self, timeout): |
|
|
|
|
i = 0 |
|
|
|
|
while self.__do_timeout and self.__running: |
|
|
|
|
time.sleep(0.001) |
|
|
|
|
i += 1 |
|
|
|
|
if i == timeout and self.__do_timeout: |
|
|
|
|
self.queue_event('timeout') |
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
def queue_event(self, evname, *evargs, **evkwargs): |
|
|
|
|
if not hasattr(AbstractState, 'on_%s' % (evname)): |
|
|
|
|
raise ValueError('Illegal event name: %s' % (evname)) |
|
|
|
|
self.__evqueue.put((evname, evargs, evkwargs)) |
|
|
|
|
|
|
|
|
|
def set_timeout(self, timeout): |
|
|
|
|
self.__do_timeout = True |
|
|
|
|
t = threading.Thread(target=self.__timeout_thread, args=(timeout,)) |
|
|
|
|
t.start() |
|
|
|
|
self.__timeout = threading.Timer(timeout/1000, lambda: self.queue_event('timeout')) |
|
|
|
|
self.__timeout.start() |
|
|
|
|
|
|
|
|
|
def abort_timeout(self): |
|
|
|
|
self.__do_timeout = False |
|
|
|
|
if self.__timeout: |
|
|
|
|
self.__timeout.cancel() |
|
|
|
|
self.__timeout = None |
|
|
|
|
|
|
|
|
|
def get_phone(self): |
|
|
|
|
return phone |
|
|
|
@ -243,7 +245,6 @@ class StateMachineController(object):
@@ -243,7 +245,6 @@ class StateMachineController(object):
|
|
|
|
|
self.__running = False |
|
|
|
|
self.__evqueue.put((None, None, None)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
c = None |
|
|
|
|
def gabelschalter_cb(state): |
|
|
|
|
global c |
|
|
|
@ -269,6 +270,8 @@ def phone_cb(event):
@@ -269,6 +270,8 @@ def phone_cb(event):
|
|
|
|
|
c.queue_event('call_ended') |
|
|
|
|
elif event == PhoneEvent.CallRinging: |
|
|
|
|
c.queue_event('call_ringing') |
|
|
|
|
elif event == PhoneEvent.CallInvalidNumber: |
|
|
|
|
c.queue_event('invalid_number') |
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
|
phone = PhoneInterface(None, '.linphonerc') |
|
|
|
|