2021-04-04 21:34:46 +00:00
|
|
|
from setproctitle import setproctitle
|
2021-04-08 21:05:25 +00:00
|
|
|
from multiprocessing import current_process
|
2021-04-04 21:34:46 +00:00
|
|
|
from time import sleep
|
|
|
|
from os import _exit
|
|
|
|
|
2021-04-08 21:05:25 +00:00
|
|
|
from helpers.logging_manager import LoggingManager
|
2021-04-18 20:18:20 +00:00
|
|
|
from helpers.the_terminator import Terminator
|
2021-04-08 19:53:51 +00:00
|
|
|
|
2021-04-08 21:32:16 +00:00
|
|
|
|
2021-04-08 19:53:51 +00:00
|
|
|
class PlayerHandler:
|
2021-04-04 21:34:46 +00:00
|
|
|
logger: LoggingManager
|
|
|
|
|
2021-09-11 15:49:08 +00:00
|
|
|
def __init__(
|
|
|
|
self, channel_from_q, websocket_to_q, ui_to_q, controller_to_q, file_to_q
|
|
|
|
):
|
2021-04-04 21:34:46 +00:00
|
|
|
|
|
|
|
self.logger = LoggingManager("PlayerHandler")
|
2021-04-18 20:18:20 +00:00
|
|
|
process_title = "Player Handler"
|
2021-04-04 21:34:46 +00:00
|
|
|
setproctitle(process_title)
|
2021-04-08 21:05:25 +00:00
|
|
|
current_process().name = process_title
|
2021-04-04 21:34:46 +00:00
|
|
|
|
2021-04-18 20:18:20 +00:00
|
|
|
terminator = Terminator()
|
2021-04-04 21:34:46 +00:00
|
|
|
try:
|
2021-04-18 20:18:20 +00:00
|
|
|
while not terminator.terminate:
|
2021-09-24 20:11:39 +00:00
|
|
|
try:
|
|
|
|
# Format <CHANNEL NUM>:<SOURCE>:<COMMAND>:<EXTRAS>
|
|
|
|
q_msg = channel_from_q.get_nowait()
|
|
|
|
if not isinstance(q_msg, str):
|
|
|
|
continue
|
2022-03-11 23:55:53 +00:00
|
|
|
split = q_msg.split(":", 1)
|
2021-09-24 20:11:39 +00:00
|
|
|
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
|
2021-04-04 21:34:46 +00:00
|
|
|
|
2021-04-04 22:14:08 +00:00
|
|
|
sleep(0.02)
|
2021-04-04 21:34:46 +00:00
|
|
|
except Exception as e:
|
2021-09-11 16:18:35 +00:00
|
|
|
self.logger.log.exception(
|
|
|
|
"Received unexpected exception: {}".format(e))
|
2021-04-04 21:34:46 +00:00
|
|
|
del self.logger
|
|
|
|
_exit(0)
|