| 
									
										
										
										
											2017-12-17 12:08:18 +01:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							| 
									
										
										
										
											2023-11-19 05:24:06 +01: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 12:08:18 +01: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 06:39:30 +02:00
										 |  |  | // (at your option) any later version.                                           //
 | 
					
						
							| 
									
										
										
										
											2017-12-17 12:08:18 +01: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-07 01:48:53 +01:00
										 |  |  | #include <QSysInfo>
 | 
					
						
							| 
									
										
										
										
											2017-12-17 12:08:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-30 21:29:48 +01:00
										 |  |  | #include <signal.h>
 | 
					
						
							|  |  |  | #include <vector>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-17 12:08:18 +01:00
										 |  |  | #include "loggerwithfile.h"
 | 
					
						
							| 
									
										
										
										
											2020-10-10 05:10:46 +02:00
										 |  |  | #include "mainparser.h"
 | 
					
						
							| 
									
										
										
										
											2020-10-08 22:33:08 +02:00
										 |  |  | #include "mainserver.h"
 | 
					
						
							| 
									
										
										
										
											2023-09-05 16:38:15 +01:00
										 |  |  | #include "remotetcpsinkstarter.h"
 | 
					
						
							| 
									
										
										
										
											2018-01-22 23:29:09 +01:00
										 |  |  | #include "dsp/dsptypes.h"
 | 
					
						
							| 
									
										
										
										
											2017-12-17 12:08:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-30 21:29:48 +01:00
										 |  |  | void handler(int sig) { | 
					
						
							|  |  |  |     fprintf(stderr, "quit the application by signal(%d).\n", sig); | 
					
						
							|  |  |  |     QCoreApplication::quit(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-02 16:04:43 +02:00
										 |  |  | #ifndef _WIN32
 | 
					
						
							| 
									
										
										
										
											2017-12-30 21:29:48 +01: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 16:04:43 +02:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2017-12-17 12:08:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | static int runQtApplication(int argc, char* argv[], qtwebapp::LoggerWithFile *logger) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QCoreApplication a(argc, argv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QCoreApplication::setOrganizationName("f4exb"); | 
					
						
							|  |  |  |     QCoreApplication::setApplicationName("SDRangelSrv"); | 
					
						
							| 
									
										
										
										
											2019-05-02 11:03:40 +02:00
										 |  |  |     QCoreApplication::setApplicationVersion(SDRANGEL_VERSION); | 
					
						
							| 
									
										
										
										
											2017-12-17 12:08:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-02 16:04:43 +02:00
										 |  |  | #ifndef _WIN32
 | 
					
						
							| 
									
										
										
										
											2017-12-30 21:29:48 +01:00
										 |  |  |     int catchSignals[] = {SIGQUIT, SIGINT, SIGTERM, SIGHUP}; | 
					
						
							|  |  |  |     std::vector<int> vsig(catchSignals, catchSignals + sizeof(catchSignals) / sizeof(int)); | 
					
						
							|  |  |  |     catchUnixSignals(vsig); | 
					
						
							| 
									
										
										
										
											2019-05-02 16:04:43 +02:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2017-12-30 21:29:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-17 12:08:18 +01:00
										 |  |  |     MainParser parser; | 
					
						
							|  |  |  |     parser.parse(a); | 
					
						
							| 
									
										
										
										
											2018-01-07 01:48:53 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-04 22:52:15 +01:00
										 |  |  | #if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
 | 
					
						
							| 
									
										
										
										
											2018-01-22 23:29:09 +01:00
										 |  |  |     qInfo("%s %s Qt %s %db %s %s DSP Rx:%db Tx:%db PID %lld", | 
					
						
							| 
									
										
										
										
											2019-05-02 11:03:40 +02: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-07 01:48:53 +01:00
										 |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2018-01-22 23:29:09 +01:00
										 |  |  |     qInfo("%s %s Qt %s %db DSP Rx:%db Tx:%db PID %lld", | 
					
						
							| 
									
										
										
										
											2019-05-02 11:03:40 +02:00
										 |  |  |           qPrintable(QCoreApplication::applicationName()), | 
					
						
							| 
									
										
										
										
											2023-04-28 00:17:46 +02:00
										 |  |  |           qPrintable(QCoreApplication::>applicationVersion()), | 
					
						
							| 
									
										
										
										
											2019-05-02 11:03:40 +02:00
										 |  |  |                      qPrintable(QString(QT_VERSION_STR)), | 
					
						
							|  |  |  |                      QT_POINTER_SIZE*8, | 
					
						
							|  |  |  |                      SDR_RX_SAMP_SZ, | 
					
						
							|  |  |  |                      SDR_TX_SAMP_SZ, | 
					
						
							|  |  |  |                      QCoreApplication::applicationPid()); | 
					
						
							| 
									
										
										
										
											2018-01-07 01:48:53 +01:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-05 16:38:15 +01:00
										 |  |  |     if (parser.getListDevices()) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // Disable log on console, so we can more easily see device list
 | 
					
						
							|  |  |  |         logger->setConsoleMinMessageLevel(QtFatalMsg); | 
					
						
							| 
									
										
										
										
											2024-07-10 22:59:13 +02:00
										 |  |  |         // Don't pass logger to MainServer, otherwise it can re-enable log output
 | 
					
						
							| 
									
										
										
										
											2023-09-05 16:38:15 +01: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 12:08:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-05 16:38:15 +01:00
										 |  |  |     if (parser.getRemoteTCPSink()) { | 
					
						
							|  |  |  |         RemoteTCPSinkStarter::start(parser); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-12-17 12:08:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-05 16:38:15 +01:00
										 |  |  |     return a.exec(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-12-17 12:08:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-05 16:38:15 +01: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; | 
					
						
							|  |  |  | } |