Files
qt6-migration-pipeline/TetraIF/PrtCnv/PrtCnvMain.cpp
T
2026-07-14 12:07:36 +02:00

125 lines
2.0 KiB
C++

#include "PrtCnvApplication.hpp"
#include <NGLLogger/INGLLogger.h>
#include <nglapplication/nglcoreapplication.h>
#include <LtsCommandLineParser/LtsCommandLineParser.h>
#include <QNetworkProxy>
#ifndef WIN32
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#endif
static void daemonize()
{
#ifndef WIN32
pid_t pid, sid;
if ( getppid() == 1 )
return;
pid = fork();
if (pid < 0) {
exit(EXIT_FAILURE);
}
if (pid > 0) {
exit(EXIT_SUCCESS);
}
umask(0);
sid = setsid();
if (sid < 0) {
exit(EXIT_FAILURE);
}
if ((chdir("/")) < 0) {
exit(EXIT_FAILURE);
}
freopen( "/dev/null", "r", stdin);
freopen( "/dev/null", "w", stdout);
freopen( "/dev/null", "w", stderr);
#endif
}
class CmdLineParser : public LtsCommandLineParser::LtsCommandLineParser
{
public:
CmdLineParser()
: LtsCommandLineParser(ProvideCommandLineParameterOptions(ExerciseId|CustomConfigFile))
{
addOption( { QStringList() << QStringLiteral("d") << QStringLiteral("daemonize"),
QStringLiteral("Start in background") } );
addOption( { QStringList() << QStringLiteral("c") << QStringLiteral("cleandb"),
QStringLiteral("Start over with clean database") } );
}
bool daemonize() const
{
return isSet(QStringLiteral("d"));
}
bool cleanDb() const
{
return isSet(QStringLiteral("c"));
}
};
int main(int argc, char** argv)
{
QNetworkProxy::setApplicationProxy(QNetworkProxy());
NGLCoreApplication app(argc, argv);
CmdLineParser options;
if (!options.init())
return -1;
app.createLogger("PrtCnv", options.exerciseId());
if (options.daemonize())
daemonize();
PrtCnv::PrtCnvApplication prtCnvApp;
prtCnvApp.setCleanDb(options.cleanDb());
prtCnvApp.setExerciseId(options.exerciseId());
if (options.iniFileSet())
prtCnvApp.setConfigFile(options.iniFile());
STARTUP_LOG(app.baseLogger());
prtCnvApp.startApp();
int ret = app.exec();
prtCnvApp.shutdownApp();
SHUTDOWN_LOG(app.baseLogger());
return ret;
}