The logger main application is an example that you can use to rebuild the logger application.
Building this example will create a duplicate of the logger executable with a different name (e.g. loggerAppDIS.exe versus loggerDIS.exe). Because it is the same executable as the logger, the pre-built executable is excluded from the release.
#include <vlutil/vlPrint.h>
#include <vlutil/vlProcessControl.h>
#include <vlutil/vlMiniDumper.h>
#include <QApplication>
#include <QSplashScreen>
#include <QSettings>
#include <QFont>
#include <QDir>
#include <QAbstractNativeEventFilter>
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#ifdef _DEBUG
#include <crtdbg.h>
#endif
#endif
#include "vlutil/vlLogFileInfo.h"
#include "lgrUtil/svnRev.h"
namespace MAKLogger {
class DtLgrQApplication : public QApplication
{
public:
#ifdef _WIN32
class WinEventFilter : public QAbstractNativeEventFilter
{
public:
bool nativeEventFilter(const QByteArray& eventType, void *msg, long *result)
{
Q_UNUSED(eventType)
DtLoggerApplication::WinEventFilterFunction func = DtLoggerApplication::winEventFilter();
if(func)
{
return func((MSG*)msg,result);
}
return false;
}
};
#endif
DtLgrQApplication(int& argc ,char** argv = 0) : QApplication(argc,argv)
{
QDir dir("../data/config");
#ifndef _WIN32
QSettings::setPath(QSettings::NativeFormat,QSettings::UserScope,dir.absolutePath());
#endif
QSettings settings;
QString str = settings.value("/qt/logger_font").toString();
QFont font;
if (! str.isNull() && ! str.isEmpty())
{
font.fromString(str);
QApplication::setFont(font);
}
#ifdef _WIN32
static WinEventFilter filter;
installNativeEventFilter(&filter);
#endif
}
};
class DtSplashPrinter : public DtPrinter
{
public:
DtSplashPrinter(QSplashScreen* screen) :
myScreen(screen)
{
}
virtual void write(const std::string &str, int notify_level, bool newline)
{
if(str.length() == 0) return;
std::string copy = str;
int i = 0;
while(( i = copy.find_last_of('\n')) > 0)
{
copy.erase(i);
}
myScreen->showMessage(copy.c_str());
qApp->processEvents();
}
protected:
QSplashScreen* myScreen;
};
void run(int& argc,char** argv)
{
try
{
DtLgrQApplication* aQpp = 0;
QSplashScreen* splash = 0;
DtSplashPrinter* splashPrinter = 0;
bool showSplash = true;
#ifndef _WIN32
showSplash = getenv("DISPLAY") != 0;
#endif
if(showSplash)
{
aQpp = new DtLgrQApplication(argc, argv);
QPixmap pixmap("../data/images/SplashScreen_DataLogger.jpg");
splash = new QSplashScreen( pixmap );
splashPrinter = new DtSplashPrinter(splash);
DtInfo.attachPrinter(splashPrinter);
splash->show();
}
#if DtHLA_1516_EVOLVED
DtString configFile(
"lgrConfigHLA1516e.xml");
#elif DtHLA_1516
DtString configFile(
"lgrConfigHLA1516.xml");
#elif DtHLA
DtString configFile(
"lgrConfigHLA13.xml");
#else
DtString configFile(
"lgrConfigDIS.xml");
#endif
if(splash)
{
DtInfo.detachPrinter(splashPrinter);
delete splashPrinter;
splash->hide();
delete splash;
}
{
if(aQpp) delete aQpp;
}
}
{
while(lastExcetion)
{
nlIndent += indent;
message += indent + lastExcetion->what()
+ nlIndent +
DtString(
"Thrown at: ") + lastExcetion->where()
lastExcetion = lastExcetion->lastException();
}
}
catch(std::exception& stdex)
{
}
catch(...)
{
}
printf("\n");
fflush(stdout);
}
}
#ifdef _WIN32
int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int)
#else
int main( int __argc, char** __argv )
#endif
{
DtLogFileInfo::instance().setAppName("MAK Data Logger");
DtLogFileInfo::instance().setProtocol(DT_PROTOCOL_SHORT_NAME);
DtLogFileInfo::instance().setSvnRev(SVN_REV);
DtINIT_MINIDUMPER(DtLogFileInfo::instance().getFullString().c_str());
#ifdef _WIN32
#ifdef _DEBUG
_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
#endif
#endif
MAKLogger::run(__argc, __argv);
{
}
return 0;
}