50 lines
1.2 KiB
C++
50 lines
1.2 KiB
C++
#include <QCoreApplication>
|
|
#include <QCommandLineParser>
|
|
#include <QCommandLineOption>
|
|
#include <csignal>
|
|
#include <atomic>
|
|
#include "spdlog/spdlog.h"
|
|
|
|
#include "http_server.h"
|
|
|
|
std::atomic<bool> quit{false};
|
|
|
|
void signalHandle(int) {
|
|
if (!quit.exchange(true)) {
|
|
QTimer::singleShot(0, []() {
|
|
HttpServer::instance().stop();
|
|
QCoreApplication::quit();
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
QCoreApplication app(argc, argv);
|
|
QCoreApplication::setApplicationName("dvr");
|
|
QCoreApplication::setApplicationVersion("1.0.0");
|
|
|
|
spdlog::flush_every(std::chrono::seconds(5));
|
|
|
|
Camera::createLogger();
|
|
Camera::keepalive();
|
|
|
|
std::signal(SIGINT, signalHandle);
|
|
std::signal(SIGTERM, signalHandle);
|
|
|
|
QCommandLineParser parser;
|
|
parser.addHelpOption();
|
|
parser.addVersionOption();
|
|
parser.addOption(QCommandLineOption(QStringList() << "i" << "host", "host", "string", "0.0.0.0"));
|
|
parser.addOption(QCommandLineOption(QStringList() << "p" << "port", "port", "number", "10001"));
|
|
parser.process(app);
|
|
|
|
QString host = parser.value("host");
|
|
int port = parser.value("port").toInt();
|
|
|
|
HttpServer::instance().start(host, port);
|
|
|
|
return app.exec();
|
|
}
|