Skip to content

Instantly share code, notes, and snippets.

@Innov-Plus
Created November 6, 2020 15:40
Show Gist options
  • Select an option

  • Save Innov-Plus/ef629a8f67f2d84658156d61534c2306 to your computer and use it in GitHub Desktop.

Select an option

Save Innov-Plus/ef629a8f67f2d84658156d61534c2306 to your computer and use it in GitHub Desktop.
/*!
* \file main.cpp
* \date 01.05.2019
* \author Innov-Plus
*
* \brief Qt ToucangoLaboratorySystem main source file
*
*/
#include <net/if.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
//#include "crypter.h"
#include "easylogging++.h"
#include "files.h"
#include "frameitem.h"
#include "key.h"
#include "mainview.h"
#include "osrng.h"
#include "rsa.h"
#include "version.h"
#include <QApplication>
#include <QCoreApplication>
#include <QDateTime>
#include <QMessageBox>
#include <QtGui>
#include <QtNetwork/QNetworkInterface>
INITIALIZE_EASYLOGGINGPP
using namespace CryptoPP;
std::vector<std::string> getAllMacAddress() {
std::vector<std::string> macAddresses;
foreach (QNetworkInterface interface, QNetworkInterface::allInterfaces()) {
if (interface.type() == QNetworkInterface::Ethernet) {
macAddresses.push_back(interface.hardwareAddress().toStdString());
}
}
return macAddresses;
}
void myCrashHandler(int sig) {
LOG(ERROR) << "Woops! Crashed!";
// FOLLOWING LINE IS OPTIONAL
el::Helpers::logCrashReason(sig, true);
// FOLLOWING LINE IS ABSOLUTELY NEEDED AT THE END IN ORDER TO ABORT
// APPLICATION
el::Helpers::crashAbort(sig);
}
static void reconfigureLoggersForTest(std::string logFile) {
el::Configurations c;
c.setGlobally(el::ConfigurationType::Format, "%datetime %msg");
c.setGlobally(el::ConfigurationType::Filename, logFile);
c.setGlobally(el::ConfigurationType::MaxLogFileSize, "209715200"); // 200MB
c.setGlobally(el::ConfigurationType::ToFile, "true");
c.setGlobally(el::ConfigurationType::ToStandardOutput, "true");
c.setGlobally(el::ConfigurationType::PerformanceTracking, "true");
c.setGlobally(el::ConfigurationType::LogFlushThreshold, "1");
el::Loggers::setDefaultConfigurations(c, true);
el::Loggers::addFlag(el::LoggingFlag::DisableApplicationAbortOnFatalLog);
el::Loggers::addFlag(el::LoggingFlag::ImmediateFlush);
el::Loggers::addFlag(el::LoggingFlag::StrictLogFileSizeCheck);
el::Loggers::addFlag(el::LoggingFlag::DisableVModulesExtensions);
}
int main(int argc, char *argv[]) {
qmlRegisterType<FrameItem>("MyExtension", 1, 0, "FrameItem");
QApplication a(argc, argv);
// Configure logger
QString timestamp =
QDateTime::currentDateTime().toString("yyyy-MM-dd_hh-mm-ss");
reconfigureLoggersForTest((QCoreApplication::applicationDirPath() + "/logs/" +
"easylog_" + timestamp + ".log")
.toUtf8()
.constData());
el::Helpers::setCrashHandler(myCrashHandler);
LOG(INFO) << "Toucango Laboratory System";
Mainview w;
w.show();
return a.exec();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment