2006-12-18 15:39:33 +01:00
|
|
|
/******************************************************************************\
|
2008-01-02 23:16:38 +01:00
|
|
|
* Copyright (c) 2004-2008
|
2006-12-18 15:39:33 +01:00
|
|
|
*
|
|
|
|
* Author(s):
|
|
|
|
* Volker Fischer
|
|
|
|
*
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU General Public License as published by the Free Software
|
|
|
|
* Foundation; either version 2 of the License, or (at your option) any later
|
|
|
|
* version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
\******************************************************************************/
|
|
|
|
|
|
|
|
#include <qapplication.h>
|
2007-09-09 11:50:22 +02:00
|
|
|
#include <iostream>
|
2006-12-18 15:39:33 +01:00
|
|
|
#include "global.h"
|
|
|
|
#include "llconclientdlg.h"
|
2006-01-28 12:29:22 +01:00
|
|
|
#include "llconserverdlg.h"
|
2006-12-18 15:39:33 +01:00
|
|
|
#include "settings.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* Implementation *************************************************************/
|
|
|
|
/* This pointer is only used for the post-event routine */
|
2006-01-28 12:29:22 +01:00
|
|
|
QApplication* pApp = NULL;
|
2006-12-18 15:39:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
int main ( int argc, char** argv )
|
2006-02-17 20:07:10 +01:00
|
|
|
{
|
2007-09-09 11:50:22 +02:00
|
|
|
std::string strArgument;
|
2006-02-17 20:07:10 +01:00
|
|
|
|
2007-09-09 11:50:22 +02:00
|
|
|
/* check if server or client application shall be started */
|
|
|
|
bool bIsClient = true;
|
|
|
|
bool bUseGUI = true;
|
|
|
|
bool bUseServerLogging = false;
|
|
|
|
std::string strIniFileName = "";
|
2007-05-06 14:27:41 +02:00
|
|
|
|
2008-01-15 23:54:04 +01:00
|
|
|
/* QT docu: argv()[0] is the program name, argv()[1] is the first
|
|
|
|
argument and argv()[argc()-1] is the last argument.
|
|
|
|
Start with first argument, therefore "i = 1" */
|
|
|
|
for ( int i = 1; i < argc; i++ )
|
|
|
|
{
|
|
|
|
/* Server mode flag ------------------------------------------------------- */
|
|
|
|
if ( GetFlagArgument ( argc, argv, i, "-s", "--server" ) == TRUE )
|
|
|
|
{
|
|
|
|
bIsClient = false;
|
|
|
|
|
|
|
|
cerr << "server ";
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Use GUI flag ----------------------------------------------------------- */
|
|
|
|
if ( GetFlagArgument ( argc, argv, i, "-n", "--nogui" ) == TRUE )
|
|
|
|
{
|
|
|
|
bUseGUI = false;
|
|
|
|
|
|
|
|
cerr << "nogui ";
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Use logging flag ------------------------------------------------------- */
|
|
|
|
if ( GetFlagArgument ( argc, argv, i, "-l", "--log" ) == TRUE )
|
|
|
|
{
|
|
|
|
bUseServerLogging = true;
|
|
|
|
|
|
|
|
cerr << "logging ";
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialization file ---------------------------------------------------- */
|
|
|
|
if ( GetStringArgument ( argc, argv, i, "-i", "--inifile", strArgument ) == TRUE )
|
|
|
|
{
|
|
|
|
strIniFileName = strArgument;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Help (usage) flag ------------------------------------------------------ */
|
|
|
|
if ( ( !strcmp ( argv[i], "--help" ) ) ||
|
|
|
|
( !strcmp ( argv[i], "-h" ) ) || ( !strcmp ( argv[i], "-?" ) ) )
|
|
|
|
{
|
|
|
|
const std::string strHelp = UsageArguments(argv);
|
|
|
|
cerr << strHelp;
|
|
|
|
exit ( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Unknown option --------------------------------------------------------- */
|
|
|
|
cerr << argv[0] << ": ";
|
|
|
|
cerr << "Unknown option '" << argv[i] << "' -- use '--help' for help"
|
|
|
|
<< endl;
|
|
|
|
|
|
|
|
exit ( 1 );
|
2007-09-09 11:50:22 +02:00
|
|
|
}
|
2006-02-17 20:07:10 +01:00
|
|
|
|
2008-01-15 23:54:04 +01:00
|
|
|
// Application object
|
2006-11-25 15:46:57 +01:00
|
|
|
QApplication app ( argc, argv, bUseGUI );
|
2006-12-18 15:39:33 +01:00
|
|
|
|
2008-01-20 19:07:13 +01:00
|
|
|
// init resources
|
|
|
|
extern int qInitResources();
|
|
|
|
qInitResources();
|
|
|
|
|
2006-12-18 15:39:33 +01:00
|
|
|
if ( bIsClient )
|
|
|
|
{
|
2007-09-09 11:50:22 +02:00
|
|
|
// client
|
2006-11-25 15:46:57 +01:00
|
|
|
// actual client object
|
|
|
|
CClient Client;
|
2006-01-28 12:29:22 +01:00
|
|
|
|
2006-11-25 15:46:57 +01:00
|
|
|
// load settings from init-file
|
|
|
|
CSettings Settings ( &Client );
|
2007-09-09 11:50:22 +02:00
|
|
|
Settings.Load ( strIniFileName );
|
2006-01-28 12:29:22 +01:00
|
|
|
|
2006-11-25 15:46:57 +01:00
|
|
|
// GUI object
|
2008-01-15 23:54:04 +01:00
|
|
|
CLlconClientDlg ClientDlg ( &Client, 0 );
|
2006-12-18 15:39:33 +01:00
|
|
|
|
2007-09-09 11:50:22 +02:00
|
|
|
// set main window
|
2008-01-15 23:54:04 +01:00
|
|
|
app.setActiveWindow ( &ClientDlg );
|
2007-09-09 11:50:22 +02:00
|
|
|
pApp = &app; // Needed for post-event routine
|
2006-12-18 15:39:33 +01:00
|
|
|
|
2007-09-09 11:50:22 +02:00
|
|
|
// show dialog
|
2007-05-06 14:27:41 +02:00
|
|
|
ClientDlg.show();
|
|
|
|
app.exec();
|
2006-01-28 12:29:22 +01:00
|
|
|
|
2007-09-09 11:50:22 +02:00
|
|
|
// save settings to init-file
|
|
|
|
Settings.Save ( strIniFileName );
|
2006-12-18 15:39:33 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-09-09 11:50:22 +02:00
|
|
|
// server
|
2006-11-25 15:46:57 +01:00
|
|
|
// actual server object
|
2007-05-06 14:27:41 +02:00
|
|
|
CServer Server ( bUseServerLogging );
|
2006-02-17 20:07:10 +01:00
|
|
|
|
2006-11-25 15:46:57 +01:00
|
|
|
if ( bUseGUI )
|
|
|
|
{
|
2006-12-18 15:39:33 +01:00
|
|
|
// GUI object for the server
|
2008-01-15 23:54:04 +01:00
|
|
|
CLlconServerDlg ServerDlg ( &Server, 0 );
|
2006-12-18 15:39:33 +01:00
|
|
|
|
2007-09-09 11:50:22 +02:00
|
|
|
// set main window
|
2008-01-15 23:54:04 +01:00
|
|
|
app.setActiveWindow ( &ServerDlg );
|
2007-09-09 11:50:22 +02:00
|
|
|
pApp = &app; // needed for post-event routine
|
2006-12-18 15:39:33 +01:00
|
|
|
|
2007-09-09 11:50:22 +02:00
|
|
|
// show dialog
|
2007-05-06 14:27:41 +02:00
|
|
|
ServerDlg.show();
|
|
|
|
app.exec();
|
2006-11-25 15:46:57 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// only start application without using the GUI
|
2008-01-15 23:54:04 +01:00
|
|
|
qDebug() << CAboutDlg::GetVersionAndNameStr ( false );
|
2007-05-06 14:27:41 +02:00
|
|
|
app.exec();
|
2006-11-25 15:46:57 +01:00
|
|
|
}
|
2006-12-18 15:39:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-09-09 11:50:22 +02:00
|
|
|
|
|
|
|
/******************************************************************************\
|
|
|
|
* Command Line Argument Parsing *
|
|
|
|
\******************************************************************************/
|
2008-01-15 23:54:04 +01:00
|
|
|
std::string UsageArguments ( char **argv )
|
|
|
|
{
|
|
|
|
return
|
|
|
|
"Usage: " + std::string ( argv[0] ) + " [option] [argument]\n"
|
|
|
|
"Recognized options:\n"
|
|
|
|
" -s, --server start server\n"
|
|
|
|
" -n, --nogui disable GUI (only avaiable for server)\n"
|
|
|
|
" -l, --log enable logging\n"
|
|
|
|
" -i, --inifile initialization file name (only available for client)\n"
|
|
|
|
" -h, -?, --help this help text\n"
|
|
|
|
"Example: " + std::string ( argv[0] ) + " -l -inifile myinifile.ini\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GetFlagArgument ( int, char **argv, int &i,
|
|
|
|
std::string strShortOpt, std::string strLongOpt )
|
|
|
|
{
|
|
|
|
if ( ( !strShortOpt.compare ( argv[i] ) ) || ( !strLongOpt.compare ( argv[i] ) ) )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GetStringArgument ( int argc, char **argv, int &i,
|
|
|
|
std::string strShortOpt, std::string strLongOpt,
|
|
|
|
std::string & strArg )
|
|
|
|
{
|
|
|
|
if ( ( !strShortOpt.compare ( argv[i] ) ) || ( !strLongOpt.compare ( argv[i] ) ) )
|
|
|
|
{
|
|
|
|
if ( ++i >= argc )
|
|
|
|
{
|
|
|
|
cerr << argv[0] << ": ";
|
|
|
|
cerr << "'" << strLongOpt << "' needs a string argument" << endl;
|
|
|
|
exit ( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
strArg = argv[i];
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GetNumericArgument ( int argc, char **argv, int &i,
|
|
|
|
std::string strShortOpt, std::string strLongOpt,
|
|
|
|
double rRangeStart, double rRangeStop,
|
|
|
|
double & rValue)
|
|
|
|
{
|
|
|
|
if ( ( !strShortOpt.compare ( argv[i] ) ) || ( !strLongOpt.compare ( argv[i] ) ) )
|
|
|
|
{
|
|
|
|
if ( ++i >= argc )
|
|
|
|
{
|
|
|
|
cerr << argv[0] << ": ";
|
|
|
|
cerr << "'" << strLongOpt << "' needs a numeric argument between "
|
|
|
|
<< rRangeStart << " and " << rRangeStop << endl;
|
|
|
|
exit ( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
char *p;
|
|
|
|
rValue = strtod ( argv[i], &p );
|
|
|
|
if ( *p || rValue < rRangeStart || rValue > rRangeStop )
|
|
|
|
{
|
|
|
|
cerr << argv[0] << ": ";
|
|
|
|
cerr << "'" << strLongOpt << "' needs a numeric argument between "
|
|
|
|
<< rRangeStart << " and " << rRangeStop << endl;
|
|
|
|
exit ( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2007-09-09 11:50:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************\
|
|
|
|
* Window Message System *
|
|
|
|
\******************************************************************************/
|
2006-12-18 15:39:33 +01:00
|
|
|
void PostWinMessage ( const _MESSAGE_IDENT MessID, const int iMessageParam,
|
|
|
|
const int iChanNum )
|
|
|
|
{
|
2007-09-09 11:50:22 +02:00
|
|
|
// first check if application is initialized
|
2006-12-18 15:39:33 +01:00
|
|
|
if ( pApp != NULL )
|
|
|
|
{
|
2006-11-25 15:46:57 +01:00
|
|
|
CLlconEvent* LlconEv =
|
2006-12-18 15:39:33 +01:00
|
|
|
new CLlconEvent ( MessID, iMessageParam, iChanNum );
|
|
|
|
|
2008-01-17 19:56:43 +01:00
|
|
|
|
|
|
|
// TODO QT4
|
2007-09-09 11:50:22 +02:00
|
|
|
// Qt will delete the event object when done
|
2008-01-15 23:54:04 +01:00
|
|
|
// QThread::postEvent ( pApp->mainWidget(), LlconEv );
|
2008-01-17 19:56:43 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2006-12-18 15:39:33 +01:00
|
|
|
}
|
|
|
|
}
|