2017-12-17 06:08:18 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
2023-11-18 23:24:06 -05:00
|
|
|
// Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany //
|
|
|
|
// written by Christian Daniel //
|
|
|
|
// Copyright (C) 2015-2020 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
|
|
|
|
// Copyright (C) 2019 Davide Gerhard <rainbow@irh.it> //
|
|
|
|
// Copyright (C) 2023 Jon Beniston, M7RCE <jon@beniston.com> //
|
|
|
|
// Copyright (C) 2023 Daniele Forsi <iu5hkx@gmail.com> //
|
2017-12-17 06:08:18 -05:00
|
|
|
// //
|
|
|
|
// 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 as version 3 of the License, or //
|
2019-04-11 00:39:30 -04:00
|
|
|
// (at your option) any later version. //
|
2017-12-17 06:08:18 -05:00
|
|
|
// //
|
|
|
|
// 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 V3 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 <QCoreApplication>
|
2018-01-06 19:48:53 -05:00
|
|
|
#include <QSysInfo>
|
2017-12-17 06:08:18 -05:00
|
|
|
|
2017-12-30 15:29:48 -05:00
|
|
|
#include <signal.h>
|
|
|
|
#include <vector>
|
|
|
|
|
2017-12-17 06:08:18 -05:00
|
|
|
#include "loggerwithfile.h"
|
2020-10-09 23:10:46 -04:00
|
|
|
#include "mainparser.h"
|
2020-10-08 16:33:08 -04:00
|
|
|
#include "mainserver.h"
|
2023-09-05 11:38:15 -04:00
|
|
|
#include "remotetcpsinkstarter.h"
|
2018-01-22 17:29:09 -05:00
|
|
|
#include "dsp/dsptypes.h"
|
2017-12-17 06:08:18 -05:00
|
|
|
|
2017-12-30 15:29:48 -05:00
|
|
|
void handler(int sig) {
|
|
|
|
fprintf(stderr, "quit the application by signal(%d).\n", sig);
|
|
|
|
QCoreApplication::quit();
|
|
|
|
}
|
|
|
|
|
2019-05-02 10:04:43 -04:00
|
|
|
#ifndef _WIN32
|
2017-12-30 15:29:48 -05:00
|
|
|
void catchUnixSignals(const std::vector<int>& quitSignals) {
|
|
|
|
sigset_t blocking_mask;
|
|
|
|
sigemptyset(&blocking_mask);
|
|
|
|
|
|
|
|
for (std::vector<int>::const_iterator it = quitSignals.begin(); it != quitSignals.end(); ++it) {
|
|
|
|
sigaddset(&blocking_mask, *it);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct sigaction sa;
|
|
|
|
sa.sa_handler = handler;
|
|
|
|
sa.sa_mask = blocking_mask;
|
|
|
|
sa.sa_flags = 0;
|
|
|
|
|
|
|
|
for (std::vector<int>::const_iterator it = quitSignals.begin(); it != quitSignals.end(); ++it) {
|
|
|
|
sigaction(*it, &sa, 0);
|
|
|
|
}
|
|
|
|
}
|
2019-05-02 10:04:43 -04:00
|
|
|
#endif
|
2017-12-17 06:08:18 -05:00
|
|
|
|
|
|
|
static int runQtApplication(int argc, char* argv[], qtwebapp::LoggerWithFile *logger)
|
|
|
|
{
|
|
|
|
QCoreApplication a(argc, argv);
|
|
|
|
|
|
|
|
QCoreApplication::setOrganizationName("f4exb");
|
|
|
|
QCoreApplication::setApplicationName("SDRangelSrv");
|
2019-05-02 05:03:40 -04:00
|
|
|
QCoreApplication::setApplicationVersion(SDRANGEL_VERSION);
|
2017-12-17 06:08:18 -05:00
|
|
|
|
2019-05-02 10:04:43 -04:00
|
|
|
#ifndef _WIN32
|
2017-12-30 15:29:48 -05:00
|
|
|
int catchSignals[] = {SIGQUIT, SIGINT, SIGTERM, SIGHUP};
|
|
|
|
std::vector<int> vsig(catchSignals, catchSignals + sizeof(catchSignals) / sizeof(int));
|
|
|
|
catchUnixSignals(vsig);
|
2019-05-02 10:04:43 -04:00
|
|
|
#endif
|
2017-12-30 15:29:48 -05:00
|
|
|
|
2017-12-17 06:08:18 -05:00
|
|
|
MainParser parser;
|
|
|
|
parser.parse(a);
|
2018-01-06 19:48:53 -05:00
|
|
|
|
2020-11-04 16:52:15 -05:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
|
2018-01-22 17:29:09 -05:00
|
|
|
qInfo("%s %s Qt %s %db %s %s DSP Rx:%db Tx:%db PID %lld",
|
2019-05-02 05:03:40 -04:00
|
|
|
qPrintable(QCoreApplication::applicationName()),
|
|
|
|
qPrintable(QCoreApplication::applicationVersion()),
|
|
|
|
qPrintable(QString(QT_VERSION_STR)),
|
|
|
|
QT_POINTER_SIZE*8,
|
|
|
|
qPrintable(QSysInfo::currentCpuArchitecture()),
|
|
|
|
qPrintable(QSysInfo::prettyProductName()),
|
|
|
|
SDR_RX_SAMP_SZ,
|
|
|
|
SDR_TX_SAMP_SZ,
|
|
|
|
QCoreApplication::applicationPid());
|
2018-01-06 19:48:53 -05:00
|
|
|
#else
|
2018-01-22 17:29:09 -05:00
|
|
|
qInfo("%s %s Qt %s %db DSP Rx:%db Tx:%db PID %lld",
|
2019-05-02 05:03:40 -04:00
|
|
|
qPrintable(QCoreApplication::applicationName()),
|
2023-04-27 18:17:46 -04:00
|
|
|
qPrintable(QCoreApplication::>applicationVersion()),
|
2019-05-02 05:03:40 -04:00
|
|
|
qPrintable(QString(QT_VERSION_STR)),
|
|
|
|
QT_POINTER_SIZE*8,
|
|
|
|
SDR_RX_SAMP_SZ,
|
|
|
|
SDR_TX_SAMP_SZ,
|
|
|
|
QCoreApplication::applicationPid());
|
2018-01-06 19:48:53 -05:00
|
|
|
#endif
|
|
|
|
|
2023-09-05 11:38:15 -04:00
|
|
|
if (parser.getListDevices())
|
|
|
|
{
|
|
|
|
// Disable log on console, so we can more easily see device list
|
|
|
|
logger->setConsoleMinMessageLevel(QtFatalMsg);
|
2023-09-05 12:14:09 -04:00
|
|
|
// Don't pass logger to MainServer, otherwise it can reenable log output
|
2023-09-05 11:38:15 -04:00
|
|
|
logger = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
MainServer m(logger, parser, &a);
|
|
|
|
|
|
|
|
// This will cause the application to exit when the main core is finished
|
|
|
|
QObject::connect(&m, SIGNAL(finished()), &a, SLOT(quit()));
|
|
|
|
|
|
|
|
if (parser.getListDevices())
|
|
|
|
{
|
|
|
|
// List available physical devices and exit
|
|
|
|
RemoteTCPSinkStarter::listAvailableDevices();
|
|
|
|
exit (EXIT_SUCCESS);
|
|
|
|
}
|
2017-12-17 06:08:18 -05:00
|
|
|
|
2023-09-05 11:38:15 -04:00
|
|
|
if (parser.getRemoteTCPSink()) {
|
|
|
|
RemoteTCPSinkStarter::start(parser);
|
|
|
|
}
|
2017-12-17 06:08:18 -05:00
|
|
|
|
2023-09-05 11:38:15 -04:00
|
|
|
return a.exec();
|
|
|
|
}
|
2017-12-17 06:08:18 -05:00
|
|
|
|
2023-09-05 11:38:15 -04:00
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
qtwebapp::LoggerWithFile *logger = new qtwebapp::LoggerWithFile(qApp);
|
|
|
|
logger->installMsgHandler();
|
|
|
|
int res = runQtApplication(argc, argv, logger);
|
|
|
|
delete logger;
|
|
|
|
qWarning("SDRangel quit.");
|
|
|
|
return res;
|
|
|
|
}
|