MAK Data Logger API Documentation for DIS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
loggerApp Example

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.

The Qt Toolkit is required to build the logger application.


The main application:

/*******************************************************************************
** Copyright (c) 1992-2024 MAK Technologies, Inc
** All rights reserved.
*******************************************************************************/
#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 {
// QApplication override to allow drag and drop behavior.
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)
{
// TODO Qt5 PORT. Previous code would not return the return value of func. Analyze.
return func((MSG*)msg,result);
}
return false;
}
};
#endif
DtLgrQApplication(int& argc ,char** argv = 0) : QApplication(argc,argv)
{
//Set Font.
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)
{
}
// Notify_Level and newline are unused in this situation
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
{
// Need to construct QApplication before a QPixmap
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();
}
// All config files are now named lgrConfig{protocol}.xml and are found in the bin dir
#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
app.initialize(argc,argv, configFile);
if(splash)
{
DtInfo.detachPrinter(splashPrinter);
delete splashPrinter;
splash->hide();
delete splash;
}
app.run();
{
DtLgrPrinter::verbose("Deleting qApp Loader.");
if(aQpp) delete aQpp;
}
}
catch(DtException& ex)
{
DtString msg = ex.what();
DtString indent = ">";
DtString message;
const DtException* lastExcetion = &ex;
while(lastExcetion)
{
DtString nlIndent("\n");
nlIndent += indent;
message += indent + lastExcetion->what()
+ nlIndent + DtString("Thrown at: ") + lastExcetion->where()
+ nlIndent + DtString("\n");
indent = DtString("--") + indent;
lastExcetion = lastExcetion->lastException();
}
DtLgrPrinter::critical(DtString("Uncaught DtException\n" + message));
}
catch(std::exception& stdex)
{
DtLgrPrinter::critical(DtString("Uncaught std::exception\n") + stdex.what());
}
catch(...)
{
DtLgrPrinter::critical(DtString("Uncaught unknown exception\n"));
}
printf("\n");
fflush(stdout);
}
}
#ifdef _WIN32
int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int)
#else
int main( int __argc, char** __argv )
#endif
{
// Used for error handling
DtLogFileInfo::instance().setAppName("MAK Data Logger");
DtLogFileInfo::instance().setProtocol(DT_PROTOCOL_SHORT_NAME);
DtLogFileInfo::instance().setSvnRev(SVN_REV);
DtLogFileInfo::instance().setVersion(LOGGER_VERSION_STRING);
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);
{
MAKLogger::DtLgrPrinter::verbose("Finished Execution.");
}
return 0;
}

Document ID: Generated on Fri May 31 15:45:35 EDT 2024 from SVN revision 266500
Copyright © 2024 MAK Technologies. All Rights Reserved (www.mak.com)