-
Notifications
You must be signed in to change notification settings - Fork 1
/
player_handler.py
56 lines (47 loc) · 2 KB
/
player_handler.py
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
48
49
50
51
52
53
54
55
56
from setproctitle import setproctitle
from multiprocessing import current_process
from time import sleep
from os import _exit
from helpers.logging_manager import LoggingManager
from helpers.the_terminator import Terminator
class PlayerHandler:
logger: LoggingManager
def __init__(
self, channel_from_q, websocket_to_q, ui_to_q, controller_to_q, file_to_q
):
self.logger = LoggingManager("PlayerHandler")
process_title = "BAPSicle - Player Handler"
setproctitle(process_title)
current_process().name = process_title
terminator = Terminator()
try:
while not terminator.terminate:
try:
# Format <CHANNEL NUM>:<SOURCE>:<COMMAND>:<EXTRAS>
q_msg = channel_from_q.get_nowait()
if not isinstance(q_msg, str):
continue
split = q_msg.split(":", 1)
message = split[1]
source = message.split(":")[0]
command = message.split(":")[1]
# Let the file manager manage the files based on status and loading new show plan triggers.
if command == "GETPLAN" or command == "STATUS":
file_to_q.put(q_msg)
# TODO ENUM
if source in ["ALL", "WEBSOCKET"]:
websocket_to_q.put(q_msg)
if source in ["ALL", "UI"]:
if not message.split(":")[1] == "POS":
# We don't care about position update spam
ui_to_q.put(q_msg)
if source in ["ALL", "CONTROLLER"]:
controller_to_q.put(q_msg)
except Exception:
pass
sleep(0.02)
except Exception as e:
self.logger.log.exception(
"Received unexpected exception: {}".format(e))
del self.logger
_exit(0)