46 lines
1.0 KiB
C++
46 lines
1.0 KiB
C++
#include <iostream>
|
|
#include <signal.h>
|
|
#include <unistd.h>
|
|
|
|
#include <QApplication>
|
|
#include <QSocketNotifier>
|
|
|
|
#include "soundboard.hpp"
|
|
|
|
int sig_pipe[2];
|
|
|
|
void signal_handler(int sig) {
|
|
char a = 1;
|
|
write(sig_pipe[1], &a, sizeof(a));
|
|
std::cout << "[INFO] Signal received. Quitting application gracefully" << std::endl;
|
|
}
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
QApplication app(argc, argv);
|
|
|
|
pipe(sig_pipe);
|
|
auto notifier = std::make_unique<QSocketNotifier>(sig_pipe[0], QSocketNotifier::Read, &app);
|
|
QObject::connect(notifier.get(), &QSocketNotifier::activated, &app, [&](){
|
|
char a;
|
|
read(sig_pipe[0], &a, sizeof(a));
|
|
app.quit();
|
|
});
|
|
struct sigaction sa;
|
|
sa.sa_handler = signal_handler;
|
|
sigemptyset(&sa.sa_mask);
|
|
sa.sa_flags = SA_RESTART;
|
|
sigaction(SIGINT, &sa, nullptr);
|
|
sigaction(SIGTERM, &sa, nullptr);
|
|
|
|
Soundboard soundboard;
|
|
soundboard.show();
|
|
|
|
int result = app.exec();
|
|
|
|
close(sig_pipe[0]);
|
|
close(sig_pipe[1]);
|
|
|
|
return result;
|
|
}
|