int main(int argc, char *argv[]) { MythMediaServerCommandLineParser cmdline; if (!cmdline.Parse(argc, argv)) { cmdline.PrintHelp(); return GENERIC_EXIT_INVALID_CMDLINE; } if (cmdline.toBool("showhelp")) { cmdline.PrintHelp(); return GENERIC_EXIT_OK; } if (cmdline.toBool("showversion")) { cmdline.PrintVersion(); return GENERIC_EXIT_OK; } QCoreApplication a(argc, argv); QCoreApplication::setApplicationName(MYTH_APPNAME_MYTHMEDIASERVER); int retval = cmdline.Daemonize(); if (retval != GENERIC_EXIT_OK) return retval; bool daemonize = cmdline.toBool("daemon"); QString mask("general"); if ((retval = cmdline.ConfigureLogging(mask, daemonize)) != GENERIC_EXIT_OK) return retval; CleanupGuard callCleanup(cleanup); #ifndef _WIN32 QList<int> signallist; signallist << SIGINT << SIGTERM << SIGSEGV << SIGABRT << SIGBUS << SIGFPE << SIGILL; #if ! CONFIG_DARWIN signallist << SIGRTMIN; #endif SignalHandler::Init(signallist); signal(SIGHUP, SIG_IGN); #endif gContext = new MythContext(MYTH_BINARY_VERSION); if (!gContext->Init(false)) { LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to init MythContext, exiting."); return GENERIC_EXIT_NO_MYTHCONTEXT; } if (!UpgradeTVDatabaseSchema(false)) { LOG(VB_GENERAL, LOG_ERR, "Exiting due to schema mismatch."); return GENERIC_EXIT_DB_OUTOFDATE; } cmdline.ApplySettingsOverride(); gCoreContext->SetBackend(true); // blocks the event connection if (!gCoreContext->ConnectToMasterServer()) { LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to connect to master server"); return GENERIC_EXIT_CONNECT_ERROR; } int port = gCoreContext->GetBackendServerPort(); if (gCoreContext->GetBackendServerIP().isEmpty()) { cerr << "No setting found for this machine's BackendServerIP.\n" << "Please run setup on this machine and modify the first page\n" << "of the general settings.\n"; return GENERIC_EXIT_SETUP_ERROR; } MythSocketManager *sockmanager = new MythSocketManager(); if (!sockmanager->Listen(port)) { LOG(VB_GENERAL, LOG_ERR, "Mediaserver exiting, failed to bind to listen port."); delete sockmanager; return GENERIC_EXIT_SOCKET_ERROR; } sockmanager->RegisterHandler(new BaseRequestHandler()); sockmanager->RegisterHandler(new FileServerHandler()); sockmanager->RegisterHandler(new MessageHandler()); ControlRequestHandler *controlRequestHandler = new ControlRequestHandler(); sockmanager->RegisterHandler(controlRequestHandler); controlRequestHandler->ConnectToMaster(); MythSystemEventHandler *sysEventHandler = new MythSystemEventHandler(); int exitCode = a.exec(); if (sysEventHandler) delete sysEventHandler; return exitCode ? exitCode : GENERIC_EXIT_OK; }
int main(int argc, char *argv[]) { MythMediaServerCommandLineParser cmdline; if (!cmdline.Parse(argc, argv)) { cmdline.PrintHelp(); return GENERIC_EXIT_INVALID_CMDLINE; } if (cmdline.toBool("showhelp")) { cmdline.PrintHelp(); return GENERIC_EXIT_OK; } if (cmdline.toBool("showversion")) { cmdline.PrintVersion(); return GENERIC_EXIT_OK; } QCoreApplication a(argc, argv); QCoreApplication::setApplicationName(MYTH_APPNAME_MYTHMEDIASERVER); int retval = cmdline.Daemonize(); if (retval != GENERIC_EXIT_OK) return retval; bool daemonize = cmdline.toBool("daemon"); QString mask("important general"); if ((retval = cmdline.ConfigureLogging(mask, daemonize)) != GENERIC_EXIT_OK) return retval; CleanupGuard callCleanup(cleanup); gContext = new MythContext(MYTH_BINARY_VERSION); if (!gContext->Init(false)) { VERBOSE(VB_IMPORTANT, LOC_ERR + "Failed to init MythContext, exiting."); return GENERIC_EXIT_NO_MYTHCONTEXT; } cmdline.ApplySettingsOverride(); gCoreContext->SetBackend(false); if (!gCoreContext->ConnectToMasterServer()) { VERBOSE(VB_IMPORTANT, LOC_ERR + "Failed to connect to master server"); return GENERIC_EXIT_CONNECT_ERROR; } QString myip = gCoreContext->GetSetting("BackendServerIP"); int port = gCoreContext->GetNumSetting("BackendServerPort", 6543); if (myip.isEmpty()) { cerr << "No setting found for this machine's BackendServerIP.\n" << "Please run setup on this machine and modify the first page\n" << "of the general settings.\n"; return GENERIC_EXIT_SETUP_ERROR; } MythSocketManager *sockmanager = new MythSocketManager(); if (!sockmanager->Listen(port)) { VERBOSE(VB_IMPORTANT, "Mediaserver exiting, failed to bind to listen port."); delete sockmanager; return GENERIC_EXIT_SOCKET_ERROR; } sockmanager->RegisterHandler(new BaseRequestHandler()); sockmanager->RegisterHandler(new FileServerHandler()); ControlRequestHandler *controlRequestHandler = new ControlRequestHandler(); sockmanager->RegisterHandler(controlRequestHandler); controlRequestHandler->ConnectToMaster(); MythSystemEventHandler *sysEventHandler = new MythSystemEventHandler(); int exitCode = a.exec(); if (sysEventHandler) delete sysEventHandler; return exitCode ? exitCode : GENERIC_EXIT_OK; }