SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
main.cpp
Go to the documentation of this file.
1 // Copyright (C) 2018 Edouard Griffiths, F4EXB. //
3 // //
4 // Swagger server adapter interface //
5 // //
6 // This program is free software; you can redistribute it and/or modify //
7 // it under the terms of the GNU General Public License as published by //
8 // the Free Software Foundation as version 3 of the License, or //
9 // (at your option) any later version. //
10 // //
11 // This program is distributed in the hope that it will be useful, //
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
14 // GNU General Public License V3 for more details. //
15 // //
16 // You should have received a copy of the GNU General Public License //
17 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
19 
20 #include <QCoreApplication>
21 #include <QSysInfo>
22 #include <QTimer>
23 
24 #include <signal.h>
25 #include <unistd.h>
26 #include <vector>
27 
28 #include "loggerwithfile.h"
29 #include "mainbench.h"
30 #include "dsp/dsptypes.h"
31 
32 void handler(int sig) {
33  fprintf(stderr, "quit the application by signal(%d).\n", sig);
34  QCoreApplication::quit();
35 }
36 
37 #ifndef _WIN32
38 void catchUnixSignals(const std::vector<int>& quitSignals) {
39  sigset_t blocking_mask;
40  sigemptyset(&blocking_mask);
41 
42  for (std::vector<int>::const_iterator it = quitSignals.begin(); it != quitSignals.end(); ++it) {
43  sigaddset(&blocking_mask, *it);
44  }
45 
46  struct sigaction sa;
47  sa.sa_handler = handler;
48  sa.sa_mask = blocking_mask;
49  sa.sa_flags = 0;
50 
51  for (std::vector<int>::const_iterator it = quitSignals.begin(); it != quitSignals.end(); ++it) {
52  sigaction(*it, &sa, 0);
53  }
54 }
55 #endif
56 
57 static int runQtApplication(int argc, char* argv[], qtwebapp::LoggerWithFile *logger)
58 {
59  QCoreApplication a(argc, argv);
60 
61  QCoreApplication::setOrganizationName(COMPANY);
62  QCoreApplication::setApplicationName("SDRangelBench");
63  QCoreApplication::setApplicationVersion(SDRANGEL_VERSION);
64 
65 #ifndef _WIN32
66  int catchSignals[] = {SIGQUIT, SIGINT, SIGTERM, SIGHUP};
67  std::vector<int> vsig(catchSignals, catchSignals + sizeof(catchSignals) / sizeof(int));
68  catchUnixSignals(vsig);
69 #endif
70 
71  ParserBench parser;
72  parser.parse(a);
73 
74 #if QT_VERSION >= 0x050400
75  qInfo("%s %s Qt %s %db %s %s DSP Rx:%db Tx:%db PID %lld",
76  qPrintable(QCoreApplication::applicationName()),
77  qPrintable(QCoreApplication::applicationVersion()),
78  qPrintable(QString(QT_VERSION_STR)),
79  QT_POINTER_SIZE*8,
80  qPrintable(QSysInfo::currentCpuArchitecture()),
81  qPrintable(QSysInfo::prettyProductName()),
84  QCoreApplication::applicationPid());
85 #else
86  qInfo("%s %s Qt %s %db DSP Rx:%db Tx:%db PID %lld",
87  qPrintable(QCoreApplication::applicationName()),
88  qPrintable((QCoreApplication::>applicationVersion()),
89  qPrintable(QString(QT_VERSION_STR)),
90  QT_POINTER_SIZE*8,
93  QCoreApplication::applicationPid());
94 #endif
95 
96  MainBench m(logger, parser, &a);
97 
98  // This will cause the application to exit when the main core is finished
99  QObject::connect(&m, SIGNAL(finished()), &a, SLOT(quit()));
100  // This will run the task from the application event loop
101  QTimer::singleShot(0, &m, SLOT(run()));
102 
103  return a.exec();
104  }
105 
106  int main(int argc, char* argv[])
107  {
109  logger->installMsgHandler();
110  int res = runQtApplication(argc, argv, logger);
111  qWarning("SDRangel quit.");
112  return res;
113  }
void installMsgHandler()
Definition: logger.cpp:111
void parse(const QCoreApplication &app)
Definition: parserbench.cpp:61
#define SDR_RX_SAMP_SZ
Definition: dsptypes.h:32
void catchUnixSignals(const std::vector< int > &quitSignals)
Definition: main.cpp:38
#define SDR_TX_SAMP_SZ
Definition: dsptypes.h:38
int main(int argc, char *argv[])
Definition: main.cpp:132
void handler(int sig)
Definition: main.cpp:32