Adding standard UNIX/POSIX signals listener. GNSS-SDR now can be safely stopped using CTL+C

This commit is contained in:
Javier Arribas 2023-09-30 14:48:04 +02:00
parent a39144105c
commit b971b61eed
2 changed files with 47 additions and 0 deletions

View File

@ -78,9 +78,49 @@ namespace wht = std;
extern Concurrent_Map<Gps_Acq_Assist> global_gps_acq_assist_map;
extern Concurrent_Queue<Gps_Acq_Assist> global_gps_acq_assist_queue;
ControlThread* ControlThread::me=nullptr;
/**
* \brief Callback function for handling signals.
* \param sig identifier of signal
*/
void ControlThread::handle_signal(int sig)
{
if (sig == SIGINT)
{
std::cout << "Stopping GNSS-SDR via SIGINT...\n";
ControlThread::me->control_queue_->push(pmt::make_any(command_event_make(200, 0)));
ControlThread::me->stop_ = true;
/* Reset signal handling to default behavior */
signal(SIGINT, SIG_DFL);
}
else if (sig == SIGHUP)
{
std::cout << "Debug: received SIGHUP signal\n";
//std::cout << "Debug: reloading daemon config file ...\n";
//todo
}
else if (sig == SIGCHLD)
{
std::cout << "Debug: received SIGCHLD signal\n";
//todo
}
}
ControlThread::ControlThread()
{
ControlThread::me=this;
/* the class will handle two signals */
signal(SIGINT, ControlThread::handle_signal);
signal(SIGHUP, ControlThread::handle_signal);
if (FLAGS_c == "-")
{
configuration_ = std::make_shared<FileConfiguration>(FLAGS_config_file);

View File

@ -37,6 +37,7 @@
#include <typeinfo> // for std::type_info, typeid
#include <utility> // for pair
#include <vector> // for vector
#include <csignal>
#ifdef ENABLE_FPGA
#include <boost/thread.hpp> // for boost::thread
@ -54,6 +55,7 @@ class ConfigurationInterface;
class GNSSFlowgraph;
class Gnss_Satellite;
/*!
* \brief This class represents the main thread of the application, so the name is ControlThread.
* This is the GNSS Receiver Control Plane: it connects the flowgraph, starts running it,
@ -63,6 +65,8 @@ class Gnss_Satellite;
class ControlThread
{
public:
static ControlThread* me;
/*!
* \brief Default constructor
*/
@ -122,6 +126,9 @@ public:
}
private:
static void handle_signal(int sig);
void init();
void apply_action(unsigned int what);