X-Git-Url: https://git.pterodactylus.net/?p=fms.git;a=blobdiff_plain;f=src%2Fmain.cpp;h=be5ff2fae56ffead6241d1b873c48e680202413d;hp=c2c499fbbc205503ed42da278f585dfbc60c1ad1;hb=dec33c63afafabf83c3039e916725cac6faef9b3;hpb=9b22dd53fe62e312c1647310b7ec43aa127090af diff --git a/src/main.cpp b/src/main.cpp index c2c499f..be5ff2f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,140 +1,4 @@ -#include "../include/global.h" -#include "../include/commandthread.h" -#include "../include/threadcontroller.h" +#include "../include/fmsapp.h" +#include -#include -#include -#include -#include -#include - -#ifdef _WIN32 - #include "../include/fmsservice.h" -#else - #include "../include/fmsdaemon.h" -#endif - -#ifdef XMEM - #include -#endif - -int main(int argc, char *argv[]) -{ - - bool daemon=false; - - #ifdef XMEM - xmem_disable_print(); - #endif - - // check arguments - if(argc>1) - { - #ifndef _WIN32 - if(argv[1] && strncmp(argv[1],"-d",2)==0) - { - Daemonize(); - daemon=true; - } - #else - if(argv[1] && strncmp(argv[1],"-i",2)==0) - { - if(ServiceIsInstalled()) - { - std::cout << "FMS Service is already installed" << std::endl; - } - else - { - if(ServiceInstall()) - { - std::cout << "FMS Service Installed" << std::endl; - } - else - { - std::cout << "Error installing FMS Service" << std::endl; - } - } - return 0; - } - else if(argv[1] && strncmp(argv[1],"-u",2)==0) - { - if(ServiceIsInstalled()) - { - if(ServiceUninstall()) - { - std::cout << "FMS Service uninstalled" << std::endl; - } - else - { - std::cout << "There was a problem uninstalling the service" << std::endl; - } - } - else - { - std::cout << "FMS Service is not currently installed" << std::endl; - } - return 0; - } - else if(argv[1] && strncmp(argv[1],"-s",2)==0) - { - if(ServiceStart()) - { - } - else - { - std::cout << "FMS Service could not be started at this time" << std::endl; - } - return 0; - } - #endif - } - - signal(SIGINT,SigHandler); - signal(SIGTERM,SigHandler); - signal(SIGABRT,SigHandler); -#ifdef _WIN32 - signal(SIGBREAK,SigHandler); -#endif - - if(daemon==false) - { - std::cout << "FMS Running in console mode." << std::endl; - std::cout << "Use the administration pages, or CTRL+C to exit" << std::endl << std::endl; - std::cout << "Available command line arguments:" << std::endl; - #ifdef _WIN32 - std::cout << "-i\tinstall service" << std::endl; - std::cout << "-u\tuninstall service" << std::endl; - #else - std::cout << "-d\trun as daemon" << std::endl; - #endif - } - - MainFunction(); - - return 0; -} - -void MainFunction() -{ - srand(time(NULL)); - - SetupDB(); - SetupDefaultOptions(); - - SetupLogFile(); - - SetupNetwork(); - - LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_INFO,"FMS startup v"FMS_VERSION); - - ThreadController::Instance()->StartThreads(); - - do - { - PThread::Sleep(1000); - }while(!wantshutdown); - - LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_DEBUG,"FMS wants to shutdown"); - - Shutdown(); -} +POCO_SERVER_MAIN(FMSApp);