Disable logs by default in release mode
Enable logs if '-d' command-line option is given. Additional command-line options - -v : print version -h : print usage Drone only: -p <port-number> : use given port number for the RPC service
This commit is contained in:
parent
3fca24396d
commit
f24a6719fa
@ -42,6 +42,9 @@ Params appParams;
|
|||||||
QSettings *appSettings;
|
QSettings *appSettings;
|
||||||
QMainWindow *mainWindow;
|
QMainWindow *mainWindow;
|
||||||
|
|
||||||
|
void NoMsgHandler(QtMsgType type, const QMessageLogContext &context,
|
||||||
|
const QString &msg);
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
@ -54,6 +57,11 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
appParams.parseCommandLine(argc, argv);
|
appParams.parseCommandLine(argc, argv);
|
||||||
|
|
||||||
|
#ifndef QT_DEBUG // Release mode
|
||||||
|
if (appParams.optLogsDisabled())
|
||||||
|
qInstallMessageHandler(NoMsgHandler);
|
||||||
|
#endif
|
||||||
|
|
||||||
OstProtocolManager = new ProtocolManager();
|
OstProtocolManager = new ProtocolManager();
|
||||||
OstProtocolWidgetFactory = new ProtocolWidgetFactory();
|
OstProtocolWidgetFactory = new ProtocolWidgetFactory();
|
||||||
|
|
||||||
@ -87,3 +95,14 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
return exitCode;
|
return exitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NoMsgHandler(QtMsgType type, const QMessageLogContext &/*context*/,
|
||||||
|
const QString &msg)
|
||||||
|
{
|
||||||
|
if (type == QtFatalMsg) {
|
||||||
|
fprintf(stderr, qPrintable(msg));
|
||||||
|
fflush(stderr);
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -21,9 +21,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
|||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
extern char *version;
|
||||||
|
extern char *revision;
|
||||||
|
|
||||||
Params::Params()
|
Params::Params()
|
||||||
{
|
{
|
||||||
localDrone_ = true;
|
localDrone_ = true;
|
||||||
|
logsDisabled_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Params::parseCommandLine(int argc, char* argv[])
|
int Params::parseCommandLine(int argc, char* argv[])
|
||||||
@ -31,14 +35,22 @@ int Params::parseCommandLine(int argc, char* argv[])
|
|||||||
int c, n = 0;
|
int c, n = 0;
|
||||||
|
|
||||||
opterr = 0;
|
opterr = 0;
|
||||||
while ((c = getopt (argc, argv, "c")) != -1) {
|
while ((c = getopt (argc, argv, "cdhv")) != -1) {
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
case 'c':
|
case 'c':
|
||||||
localDrone_ = false;
|
localDrone_ = false;
|
||||||
break;
|
break;
|
||||||
|
case 'd':
|
||||||
|
logsDisabled_ = false;
|
||||||
|
break;
|
||||||
|
case 'v':
|
||||||
|
qDebug("Ostinato %s rev %s\n", version, revision);
|
||||||
|
exit(0);
|
||||||
|
case 'h':
|
||||||
default:
|
default:
|
||||||
qDebug("ignoring unrecognized option (%c)", c);
|
qDebug("usage: %s [-cdhv]\n", argv[0]);
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
@ -54,6 +66,11 @@ bool Params::optLocalDrone()
|
|||||||
return localDrone_;
|
return localDrone_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Params::optLogsDisabled()
|
||||||
|
{
|
||||||
|
return logsDisabled_;
|
||||||
|
}
|
||||||
|
|
||||||
int Params::argumentCount()
|
int Params::argumentCount()
|
||||||
{
|
{
|
||||||
return args_.size();
|
return args_.size();
|
||||||
|
@ -28,12 +28,14 @@ public:
|
|||||||
int parseCommandLine(int argc, char* argv[]);
|
int parseCommandLine(int argc, char* argv[]);
|
||||||
|
|
||||||
bool optLocalDrone();
|
bool optLocalDrone();
|
||||||
|
bool optLogsDisabled();
|
||||||
|
|
||||||
int argumentCount();
|
int argumentCount();
|
||||||
QString argument(int index);
|
QString argument(int index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool localDrone_;
|
bool localDrone_;
|
||||||
|
bool logsDisabled_;
|
||||||
QStringList args_;
|
QStringList args_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -32,11 +32,12 @@ protected:
|
|||||||
void run() { exec(); }
|
void run() { exec(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
RpcServer::RpcServer()
|
RpcServer::RpcServer(bool perConnLogs)
|
||||||
{
|
{
|
||||||
service = NULL;
|
service = NULL;
|
||||||
|
|
||||||
qInstallMessageHandler(RpcConnection::connIdMsgHandler);
|
if (perConnLogs)
|
||||||
|
qInstallMessageHandler(RpcConnection::connIdMsgHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
RpcServer::~RpcServer()
|
RpcServer::~RpcServer()
|
||||||
|
@ -37,7 +37,7 @@ class RpcServer : public QTcpServer
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RpcServer(); //! \todo (LOW) use 'parent' param
|
RpcServer(bool perConnLogs); //! \todo (LOW) use 'parent' param
|
||||||
virtual ~RpcServer();
|
virtual ~RpcServer();
|
||||||
|
|
||||||
bool registerService(::google::protobuf::Service *service,
|
bool registerService(::google::protobuf::Service *service,
|
||||||
|
@ -20,13 +20,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
|||||||
#include "drone.h"
|
#include "drone.h"
|
||||||
|
|
||||||
#include "myservice.h"
|
#include "myservice.h"
|
||||||
|
#include "params.h"
|
||||||
#include "rpcserver.h"
|
#include "rpcserver.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "../common/updater.h"
|
#include "../common/updater.h"
|
||||||
|
|
||||||
#include <QMetaType>
|
#include <QMetaType>
|
||||||
|
|
||||||
extern int myport;
|
extern Params appParams;
|
||||||
extern const char* version;
|
extern const char* version;
|
||||||
extern const char* revision;
|
extern const char* revision;
|
||||||
|
|
||||||
@ -35,7 +36,13 @@ Drone::Drone(QObject *parent)
|
|||||||
{
|
{
|
||||||
Updater *updater = new Updater();
|
Updater *updater = new Updater();
|
||||||
|
|
||||||
rpcServer = new RpcServer();
|
#ifdef QT_DEBUG
|
||||||
|
bool enableLogs = true;
|
||||||
|
#else
|
||||||
|
bool enableLogs = !appParams.optLogsDisabled();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
rpcServer = new RpcServer(enableLogs);
|
||||||
service = new MyService();
|
service = new MyService();
|
||||||
|
|
||||||
connect(updater, SIGNAL(newVersionAvailable(QString)),
|
connect(updater, SIGNAL(newVersionAvailable(QString)),
|
||||||
@ -66,7 +73,7 @@ bool Drone::init()
|
|||||||
address = QHostAddress::Any;
|
address = QHostAddress::Any;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rpcServer->registerService(service, address, myport ? myport : 7878))
|
if (!rpcServer->registerService(service, address, appParams.servicePortNumber()))
|
||||||
{
|
{
|
||||||
//qCritical(qPrintable(rpcServer->errorString()));
|
//qCritical(qPrintable(rpcServer->errorString()));
|
||||||
return false;
|
return false;
|
||||||
|
@ -58,6 +58,7 @@ SOURCES += \
|
|||||||
bsdport.cpp \
|
bsdport.cpp \
|
||||||
linuxhostdevice.cpp \
|
linuxhostdevice.cpp \
|
||||||
linuxport.cpp \
|
linuxport.cpp \
|
||||||
|
params.cpp \
|
||||||
winhostdevice.cpp \
|
winhostdevice.cpp \
|
||||||
winpcapport.cpp
|
winpcapport.cpp
|
||||||
SOURCES += myservice.cpp
|
SOURCES += myservice.cpp
|
||||||
|
@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
|||||||
#include "drone.h"
|
#include "drone.h"
|
||||||
|
|
||||||
#include "../common/protocolmanager.h"
|
#include "../common/protocolmanager.h"
|
||||||
|
#include "params.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
|
||||||
#include <google/protobuf/stubs/common.h>
|
#include <google/protobuf/stubs/common.h>
|
||||||
@ -37,7 +38,10 @@ extern char *revision;
|
|||||||
|
|
||||||
Drone *drone;
|
Drone *drone;
|
||||||
QSettings *appSettings;
|
QSettings *appSettings;
|
||||||
int myport;
|
Params appParams;
|
||||||
|
|
||||||
|
void NoMsgHandler(QtMsgType type, const QMessageLogContext &context,
|
||||||
|
const QString &msg);
|
||||||
|
|
||||||
void cleanup(int /*signum*/)
|
void cleanup(int /*signum*/)
|
||||||
{
|
{
|
||||||
@ -49,19 +53,19 @@ int main(int argc, char *argv[])
|
|||||||
int exitCode = 0;
|
int exitCode = 0;
|
||||||
QCoreApplication app(argc, argv);
|
QCoreApplication app(argc, argv);
|
||||||
|
|
||||||
qDebug("Version: %s", version);
|
|
||||||
qDebug("Revision: %s", revision);
|
|
||||||
|
|
||||||
// TODO: command line options
|
|
||||||
// -v (--version)
|
|
||||||
// -h (--help)
|
|
||||||
// -p (--portnum)
|
|
||||||
if (argc > 1)
|
|
||||||
myport = atoi(argv[1]);
|
|
||||||
|
|
||||||
app.setApplicationName("Drone");
|
app.setApplicationName("Drone");
|
||||||
app.setOrganizationName("Ostinato");
|
app.setOrganizationName("Ostinato");
|
||||||
|
|
||||||
|
appParams.parseCommandLine(argc, argv);
|
||||||
|
|
||||||
|
#ifdef QT_NO_DEBUG
|
||||||
|
if (appParams.optLogsDisabled())
|
||||||
|
qInstallMessageHandler(NoMsgHandler);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
qDebug("Version: %s", version);
|
||||||
|
qDebug("Revision: %s", revision);
|
||||||
|
|
||||||
/* (Portable Mode) If we have a .ini file in the same directory as the
|
/* (Portable Mode) If we have a .ini file in the same directory as the
|
||||||
executable, we use that instead of the platform specific location
|
executable, we use that instead of the platform specific location
|
||||||
and format for the settings */
|
and format for the settings */
|
||||||
@ -108,3 +112,12 @@ _exit:
|
|||||||
return exitCode;
|
return exitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NoMsgHandler(QtMsgType type, const QMessageLogContext &/*context*/,
|
||||||
|
const QString &msg)
|
||||||
|
{
|
||||||
|
if (type == QtFatalMsg) {
|
||||||
|
fprintf(stderr, qPrintable(msg));
|
||||||
|
fflush(stderr);
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
82
server/params.cpp
Normal file
82
server/params.cpp
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
Copyright (C) 2019 Srivats P.
|
||||||
|
|
||||||
|
This file is part of "Ostinato"
|
||||||
|
|
||||||
|
This 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 3 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, see <http://www.gnu.org/licenses/>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "params.h"
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
extern char *version;
|
||||||
|
extern char *revision;
|
||||||
|
|
||||||
|
Params::Params()
|
||||||
|
{
|
||||||
|
logsDisabled_ = true;
|
||||||
|
myPort_ = 7878;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Params::parseCommandLine(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
int c, n = 0;
|
||||||
|
|
||||||
|
opterr = 0;
|
||||||
|
while ((c = getopt (argc, argv, "dhp:v")) != -1) {
|
||||||
|
switch (c)
|
||||||
|
{
|
||||||
|
case 'd':
|
||||||
|
logsDisabled_ = false;
|
||||||
|
break;
|
||||||
|
case 'p':
|
||||||
|
myPort_ = atoi(optarg);
|
||||||
|
break;
|
||||||
|
case 'v':
|
||||||
|
printf("Ostinato Drone %s rev %s\n", version, revision);
|
||||||
|
exit(0);
|
||||||
|
case 'h':
|
||||||
|
default:
|
||||||
|
printf("usage: %s [-dhv] [-p <port-number>]\n", argv[0]);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = optind; i < argc; i++, n++)
|
||||||
|
args_ << argv[i];
|
||||||
|
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Params::optLogsDisabled()
|
||||||
|
{
|
||||||
|
return logsDisabled_;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Params::servicePortNumber()
|
||||||
|
{
|
||||||
|
return myPort_;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Params::argumentCount()
|
||||||
|
{
|
||||||
|
return args_.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Params::argument(int index)
|
||||||
|
{
|
||||||
|
return index < args_.size() ? args_.at(index) : QString();
|
||||||
|
}
|
45
server/params.h
Normal file
45
server/params.h
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
Copyright (C) 2019 Srivats P.
|
||||||
|
|
||||||
|
This file is part of "Ostinato"
|
||||||
|
|
||||||
|
This 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 3 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, see <http://www.gnu.org/licenses/>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _PARAMS_H
|
||||||
|
#define _PARAMS_H
|
||||||
|
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
class Params {
|
||||||
|
public:
|
||||||
|
Params();
|
||||||
|
int parseCommandLine(int argc, char* argv[]);
|
||||||
|
|
||||||
|
bool optLogsDisabled();
|
||||||
|
int servicePortNumber();
|
||||||
|
|
||||||
|
int argumentCount();
|
||||||
|
QString argument(int index);
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool logsDisabled_;
|
||||||
|
int myPort_;
|
||||||
|
QStringList args_;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern Params appParams;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user