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) 2017 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 
23 #include <signal.h>
24 #include <vector>
25 
26 #include "loggerwithfile.h"
27 #include "maincore.h"
28 #include "dsp/dsptypes.h"
29 
30 void handler(int sig) {
31  fprintf(stderr, "quit the application by signal(%d).\n", sig);
32  QCoreApplication::quit();
33 }
34 
35 #ifndef _WIN32
36 void catchUnixSignals(const std::vector<int>& quitSignals) {
37  sigset_t blocking_mask;
38  sigemptyset(&blocking_mask);
39 
40  for (std::vector<int>::const_iterator it = quitSignals.begin(); it != quitSignals.end(); ++it) {
41  sigaddset(&blocking_mask, *it);
42  }
43 
44  struct sigaction sa;
45  sa.sa_handler = handler;
46  sa.sa_mask = blocking_mask;
47  sa.sa_flags = 0;
48 
49  for (std::vector<int>::const_iterator it = quitSignals.begin(); it != quitSignals.end(); ++it) {
50  sigaction(*it, &sa, 0);
51  }
52 }
53 #endif
54 
55 static int runQtApplication(int argc, char* argv[], qtwebapp::LoggerWithFile *logger)
56 {
57  QCoreApplication a(argc, argv);
58 
59  QCoreApplication::setOrganizationName("f4exb");
60  QCoreApplication::setApplicationName("SDRangelSrv");
61  QCoreApplication::setApplicationVersion(SDRANGEL_VERSION);
62 
63 #ifndef _WIN32
64  int catchSignals[] = {SIGQUIT, SIGINT, SIGTERM, SIGHUP};
65  std::vector<int> vsig(catchSignals, catchSignals + sizeof(catchSignals) / sizeof(int));
66  catchUnixSignals(vsig);
67 #endif
68 
69  MainParser parser;
70  parser.parse(a);
71 
72 #if QT_VERSION >= 0x050400
73  qInfo("%s %s Qt %s %db %s %s DSP Rx:%db Tx:%db PID %lld",
74  qPrintable(QCoreApplication::applicationName()),
75  qPrintable(QCoreApplication::applicationVersion()),
76  qPrintable(QString(QT_VERSION_STR)),
77  QT_POINTER_SIZE*8,
78  qPrintable(QSysInfo::currentCpuArchitecture()),
79  qPrintable(QSysInfo::prettyProductName()),
82  QCoreApplication::applicationPid());
83 #else
84  qInfo("%s %s Qt %s %db DSP Rx:%db Tx:%db PID %lld",
85  qPrintable(QCoreApplication::applicationName()),
86  qPrintable((QCoreApplication::>applicationVersion()),
87  qPrintable(QString(QT_VERSION_STR)),
88  QT_POINTER_SIZE*8,
91  QCoreApplication::applicationPid());
92 #endif
93 
94  MainCore m(logger, parser, &a);
95 
96  // This will cause the application to exit when the main core is finished
97  QObject::connect(&m, SIGNAL(finished()), &a, SLOT(quit()));
98 
99  return a.exec();
100  }
101 
102  int main(int argc, char* argv[])
103  {
105  logger->installMsgHandler();
106  int res = runQtApplication(argc, argv, logger);
107  qWarning("SDRangel quit.");
108  return res;
109  }
void installMsgHandler()
Definition: logger.cpp:111
#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
void parse(const QCoreApplication &app)
Definition: mainparser.cpp:53
int main(int argc, char *argv[])
Definition: main.cpp:132
void handler(int sig)
Definition: main.cpp:32