1
0
mirror of https://github.com/binary-kitchen/doorlockd synced 2024-12-22 18:34:25 +01:00
doorlockd-mirror/doorlockd/client/doorlock-client.cpp

79 lines
2.1 KiB
C++
Raw Normal View History

#include <exception>
#include <iostream>
#include <string>
2015-09-25 13:11:36 +02:00
#include <thread>
#include <boost/program_options.hpp>
2015-09-30 15:21:41 +02:00
#include <QApplication>
#include "config.h"
#include "mainwindow.h"
2015-09-25 13:11:36 +02:00
// Info about doorlock-client version
const static std::string version =
"doorlock-client-" DOORLOCK_VERSION;
const static std::string gitversion =
DOORLOCK_GIT_BRANCH "-" DOORLOCK_GIT_COMMIT_HASH;
namespace po = boost::program_options;
int main(int argc, char** argv)
{
int retval = 0;
Logger &l = Logger::get();
l((std::string)"Hello, this is " + version + " built on " + gitversion,
LogLevel::info);
try {
QApplication app(argc, argv);
std::string hostname;
unsigned short port;
po::variables_map vm;
qRegisterMetaType<Clientmessage>("Clientmessage");
app.setOrganizationName("Binary Kitchen");
app.setApplicationName("doorlock-client");
po::options_description desc("doorlockd (" + version + " built on " + gitversion + ")");
desc.add_options()
("help,h",
"print help")
("port,p",
po::value<unsigned short>(&port)->default_value(DEFAULT_PORT),
"Port")
("host,c",
po::value<std::string>(&hostname)->default_value("localhost"),
"IP or name of host running doorlockd");
po::store(po::command_line_parser(argc, argv).options(desc).run(), vm);
if (vm.count("help"))
{
std::cout << desc << std::endl;
2015-09-29 02:13:48 +02:00
exit(-1);
}
po::notify(vm);
l(LogLevel::notice, "Starting doorlock-client");
// Start main GUI
MainWindow mainWindow(hostname, port);
mainWindow.showFullScreen();
2015-09-25 13:11:36 +02:00
// This routine will never return under normal conditions
retval = app.exec();
2015-09-29 02:13:48 +02:00
mainWindow.hide();
mainWindow.close();
}
catch(const std::exception &e)
{
l(LogLevel::error, e.what());
retval = -1;
}
2015-09-29 02:13:48 +02:00
l(LogLevel::notice, "Stopping doorlock-client");
return retval;
}