<filename>resources/site-packages/projectx/service.py<gh_stars>0
import threading
from projectx.config import ONLY_CLIENT
from projectx.logger import log
from projectx.rpc import server_thread
from projectx.monitor import projectxMonitor
from projectx.daemon import projectxd_thread
from projectx.osarch import PLATFORM

import xbmc

def run():
    # Make sure the XBMC jsonrpc server is started.
    xbmc.startServer(xbmc.SERVER_JSONRPCSERVER, True)

    # Make the monitor
    monitor = projectxMonitor()

    threads = [
        threading.Thread(target=server_thread),  # JSONRPC thread
    ]
    if not ONLY_CLIENT and PLATFORM["fork"]:
        threads.append(threading.Thread(target=projectxd_thread, args=[monitor]))  # projectxd thread

    for t in threads:
        t.daemon = True
        t.start()

    # XBMC loop
    while not monitor.abortRequested():
        xbmc.sleep(1000)

    log.info("projectx: exiting projectxd")
