blob: c72147c3c9afc85b79813407e94fadf347eed0ca (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
#!/usr/bin/env python3
from dial import DialManager, DialThread
from hangup import HangUpThread
from time import sleep
from queue import Queue
from threading import Event
if __name__ == "__main__":
queue = Queue()
phone_held = Event()
phone_hung_up = Event()
processing_event = Event()
# start phone as on hook
phone_held.clear()
phone_hung_up.set()
processing_event.clear()
dial_thread = DialThread(queue, phone_held, processing_event)
dial_thread.start()
dial_manager = DialManager(phone_held, phone_hung_up)
hang_up_thread = HangUpThread(phone_held, phone_hung_up, dial_manager)
hang_up_thread.start()
print("Ready")
while True:
try:
# Wait for phone to be picked up
phone_held.wait()
# Dial a number
try:
dialed = queue.get(block=True, timeout=0.1)
except:
continue
response = dial_manager.dial(dialed)
# If we matched a sequence, play out event
if response is not None:
processing_event.set()
response.run()
except Exception as e:
print(e)
finally:
processing_event.clear()
|