Added ostinato cmdline option -s to suppress starting local drone

This commit is contained in:
Srivats P 2016-10-13 18:50:33 +05:30
parent 6a426a7a7e
commit 708aed9135
6 changed files with 143 additions and 18 deletions

View File

@ -21,6 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "../common/ostprotolib.h"
#include "../common/protocolmanager.h"
#include "../common/protocolwidgetfactory.h"
#include "params.h"
#include "preferences.h"
#include "settings.h"
@ -37,6 +38,7 @@ extern const char* revision;
extern ProtocolManager *OstProtocolManager;
extern ProtocolWidgetFactory *OstProtocolWidgetFactory;
Params appParams;
QSettings *appSettings;
QMainWindow *mainWindow;
@ -50,6 +52,8 @@ int main(int argc, char* argv[])
app.setProperty("version", version);
app.setProperty("revision", revision);
appParams.parseCommandLine(argc, argv);
OstProtocolManager = new ProtocolManager();
OstProtocolWidgetFactory = new ProtocolWidgetFactory();

View File

@ -23,6 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "dbgthread.h"
#endif
#include "params.h"
#include "portgrouplist.h"
#include "portstatswindow.h"
#include "portswindow.h"
@ -50,23 +51,28 @@ PortGroupList *pgl;
MainWindow::MainWindow(QWidget *parent)
: QMainWindow (parent)
{
QString serverApp = QCoreApplication::applicationDirPath();
Updater *updater = new Updater();
if (appParams.optLocalDrone()) {
QString serverApp = QCoreApplication::applicationDirPath();
#ifdef Q_OS_MAC
// applicationDirPath() does not return bundle, but executable inside bundle
// applicationDirPath() does not return bundle,
// but executable inside bundle
serverApp.replace("Ostinato.app", "drone.app");
#endif
#ifdef Q_OS_WIN32
serverApp.append("/drone.exe");
#else
serverApp.append("/drone");
#endif
qDebug("staring local server - %s", qPrintable(serverApp));
localServer_ = new QProcess(this);
localServer_->setProcessChannelMode(QProcess::ForwardedChannels);
localServer_->start(serverApp, QStringList());
}
else
localServer_ = NULL;
pgl = new PortGroupList;
@ -124,12 +130,14 @@ MainWindow::MainWindow(QWidget *parent)
MainWindow::~MainWindow()
{
if (localServer_) {
#ifdef Q_OS_WIN32
//! \todo - find a way to terminate cleanly
localServer_->kill();
#else
localServer_->terminate();
#endif
}
delete pgl;
@ -137,9 +145,11 @@ MainWindow::~MainWindow()
appSettings->setValue(kApplicationWindowLayout, layout);
appSettings->setValue(kApplicationWindowGeometryKey, geometry());
if (localServer_) {
localServer_->waitForFinished();
delete localServer_;
}
}
void MainWindow::on_actionOpenSession_triggered()
{

View File

@ -86,6 +86,7 @@ SOURCES += \
mainwindow.cpp \
ndpstatusmodel.cpp \
packetmodel.cpp \
params.cpp \
port.cpp \
portconfigdialog.cpp \
portgroup.cpp \

65
client/params.cpp Normal file
View File

@ -0,0 +1,65 @@
/*
Copyright (C) 2016 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>
Params::Params()
{
localDrone_ = true;
}
int Params::parseCommandLine(int argc, char* argv[])
{
int c, n = 0;
opterr = 0;
while ((c = getopt (argc, argv, "s")) != -1) {
switch (c)
{
case 's':
localDrone_ = false;
break;
default:
qDebug("ignoring unrecognized option (%c)", c);
}
n++;
}
for (int i = optind; i < argc; i++, n++)
args_ << argv[i];
return n;
}
bool Params::optLocalDrone()
{
return localDrone_;
}
int Params::argumentCount()
{
return args_.size();
}
QString Params::argument(int index)
{
return index < args_.size() ? args_.at(index) : QString();
}

43
client/params.h Normal file
View File

@ -0,0 +1,43 @@
/*
Copyright (C) 2016 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 optLocalDrone();
int argumentCount();
QString argument(int index);
private:
bool localDrone_;
QStringList args_;
};
extern Params appParams;
#endif

View File

@ -19,6 +19,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "portgrouplist.h"
#include "params.h"
// TODO(LOW): Remove
#include <modeltest.h>
@ -29,8 +31,6 @@ PortGroupList::PortGroupList()
mDeviceGroupModel(this),
mDeviceModel(this)
{
PortGroup *pg;
#ifdef QT_NO_DEBUG
streamModelTester_ = NULL;
portModelTester_ = NULL;
@ -46,9 +46,11 @@ PortGroupList::PortGroupList()
#endif
// Add the "Local" Port Group
pg = new PortGroup;
if (appParams.optLocalDrone()) {
PortGroup *pg = new PortGroup;
addPortGroup(*pg);
}
}
PortGroupList::~PortGroupList()
{