import os
import platform

if platform.system() == 'Windows':
    os.add_dll_directory(r'C:\Users\lambda\source\scarlet\ffmpeg-n7.0.1-221-g0ab20b5788-win64-gpl-shared-7.0\bin')
import logging
import multiprocessing
from BusClient import BusClient

from nodes.WebRTC import WebRTC

from nodes.Beamformer import Beamformer
from nodes.Loader import Loader
from nodes.Broker import Broker
from nodes.Device import Device
from nodes.ImageCV import ImageCV
from nodes.MainUI import MainUI
from nodes.Robot import Robot
from utils.Msg import KillMsg


def main():
    logging.basicConfig(level=logging.INFO)
    multiprocessing.set_start_method('spawn')
    multiprocessing.Pool()
    pps = []
    ps = [
        Broker(),
        WebRTC(),
        MainUI(level=logging.DEBUG),
        Device(level=logging.DEBUG),
        ImageCV(),
        Beamformer(level=logging.DEBUG),
        Loader(level=logging.DEBUG),
        Robot(),
    ]
    for p in ps:
        pps.append(multiprocessing.Process(target=p))
    for p in pps:
        p.start()

    c = BusClient(KillMsg)
    while True:
        x: KillMsg = c.recv()
        if x.name == '':
            break
    for p in pps:
        p.kill()


if __name__ == '__main__':
    main()
