1 |
// qsamplerMainForm.cpp |
// qsamplerMainForm.cpp |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2004-2018, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2004-2019, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
Copyright (C) 2007,2008,2015 Christian Schoenebeck |
Copyright (C) 2007,2008,2015 Christian Schoenebeck |
6 |
|
|
7 |
This program is free software; you can redistribute it and/or |
This program is free software; you can redistribute it and/or |
68 |
} |
} |
69 |
#endif |
#endif |
70 |
|
|
|
#ifdef HAVE_SIGNAL_H |
|
|
#include <signal.h> |
|
|
#endif |
|
|
|
|
71 |
#ifdef CONFIG_LIBGIG |
#ifdef CONFIG_LIBGIG |
72 |
#include <gig.h> |
#include <gig.h> |
73 |
#endif |
#endif |
89 |
// All winsock apps needs this. |
// All winsock apps needs this. |
90 |
#if defined(__WIN32__) || defined(_WIN32) || defined(WIN32) |
#if defined(__WIN32__) || defined(_WIN32) || defined(WIN32) |
91 |
static WSADATA _wsaData; |
static WSADATA _wsaData; |
92 |
|
#undef HAVE_SIGNAL_H |
93 |
#endif |
#endif |
94 |
|
|
95 |
|
|
100 |
|
|
101 |
#include <QSocketNotifier> |
#include <QSocketNotifier> |
102 |
|
|
103 |
|
#include <unistd.h> |
104 |
#include <sys/types.h> |
#include <sys/types.h> |
105 |
#include <sys/socket.h> |
#include <sys/socket.h> |
|
|
|
106 |
#include <signal.h> |
#include <signal.h> |
107 |
|
|
108 |
// File descriptor for SIGUSR1 notifier. |
// File descriptor for SIGUSR1 notifier. |
109 |
static int g_fdUsr1[2]; |
static int g_fdSigusr1[2] = { -1, -1 }; |
110 |
|
|
111 |
// Unix SIGUSR1 signal handler. |
// Unix SIGUSR1 signal handler. |
112 |
static void qsampler_sigusr1_handler ( int /* signo */ ) |
static void qsampler_sigusr1_handler ( int /* signo */ ) |
113 |
{ |
{ |
114 |
char c = 1; |
char c = 1; |
115 |
|
|
116 |
(::write(g_fdUsr1[0], &c, sizeof(c)) > 0); |
(::write(g_fdSigusr1[0], &c, sizeof(c)) > 0); |
117 |
|
} |
118 |
|
|
119 |
|
// File descriptor for SIGTERM notifier. |
120 |
|
static int g_fdSigterm[2] = { -1, -1 }; |
121 |
|
|
122 |
|
// Unix SIGTERM signal handler. |
123 |
|
static void qsampler_sigterm_handler ( int /* signo */ ) |
124 |
|
{ |
125 |
|
char c = 1; |
126 |
|
|
127 |
|
(::write(g_fdSigterm[0], &c, sizeof(c)) > 0); |
128 |
} |
} |
129 |
|
|
130 |
#endif // HAVE_SIGNAL_H |
#endif // HAVE_SIGNAL_H |
241 |
// LADISH Level 1 suport. |
// LADISH Level 1 suport. |
242 |
|
|
243 |
// Initialize file descriptors for SIGUSR1 socket notifier. |
// Initialize file descriptors for SIGUSR1 socket notifier. |
244 |
::socketpair(AF_UNIX, SOCK_STREAM, 0, g_fdUsr1); |
::socketpair(AF_UNIX, SOCK_STREAM, 0, g_fdSigusr1); |
245 |
m_pUsr1Notifier |
m_pSigusr1Notifier |
246 |
= new QSocketNotifier(g_fdUsr1[1], QSocketNotifier::Read, this); |
= new QSocketNotifier(g_fdSigusr1[1], QSocketNotifier::Read, this); |
247 |
|
|
248 |
QObject::connect(m_pUsr1Notifier, |
QObject::connect(m_pSigusr1Notifier, |
249 |
SIGNAL(activated(int)), |
SIGNAL(activated(int)), |
250 |
SLOT(handle_sigusr1())); |
SLOT(handle_sigusr1())); |
251 |
|
|
252 |
// Install SIGUSR1 signal handler. |
// Install SIGUSR1 signal handler. |
253 |
struct sigaction usr1; |
struct sigaction sigusr1; |
254 |
usr1.sa_handler = qsampler_sigusr1_handler; |
sigusr1.sa_handler = qsampler_sigusr1_handler; |
255 |
sigemptyset(&usr1.sa_mask); |
sigemptyset(&sigusr1.sa_mask); |
256 |
usr1.sa_flags = 0; |
sigusr1.sa_flags = 0; |
257 |
usr1.sa_flags |= SA_RESTART; |
sigusr1.sa_flags |= SA_RESTART; |
258 |
::sigaction(SIGUSR1, &usr1, NULL); |
::sigaction(SIGUSR1, &sigusr1, NULL); |
259 |
|
|
260 |
|
// Initialize file descriptors for SIGTERM socket notifier. |
261 |
|
::socketpair(AF_UNIX, SOCK_STREAM, 0, g_fdSigterm); |
262 |
|
m_pSigtermNotifier |
263 |
|
= new QSocketNotifier(g_fdSigterm[1], QSocketNotifier::Read, this); |
264 |
|
|
265 |
|
QObject::connect(m_pSigtermNotifier, |
266 |
|
SIGNAL(activated(int)), |
267 |
|
SLOT(handle_sigterm())); |
268 |
|
|
269 |
|
// Install SIGTERM signal handler. |
270 |
|
struct sigaction sigterm; |
271 |
|
sigterm.sa_handler = qsampler_sigterm_handler; |
272 |
|
::sigemptyset(&sigterm.sa_mask); |
273 |
|
sigterm.sa_flags = 0; |
274 |
|
sigterm.sa_flags |= SA_RESTART; |
275 |
|
::sigaction(SIGTERM, &sigterm, NULL); |
276 |
|
::sigaction(SIGQUIT, &sigterm, NULL); |
277 |
|
|
278 |
|
// Ignore SIGHUP/SIGINT signals. |
279 |
|
::signal(SIGHUP, SIG_IGN); |
280 |
|
::signal(SIGINT, SIG_IGN); |
281 |
|
|
282 |
#else // HAVE_SIGNAL_H |
#else // HAVE_SIGNAL_H |
283 |
|
|
284 |
m_pUsr1Notifier = NULL; |
m_pSigusr1Notifier = NULL; |
285 |
|
m_pSigtermNotifier = NULL; |
286 |
|
|
287 |
#endif // !HAVE_SIGNAL_H |
#endif // !HAVE_SIGNAL_H |
288 |
|
|
461 |
#endif |
#endif |
462 |
|
|
463 |
#if defined(HAVE_SIGNAL_H) && defined(HAVE_SYS_SOCKET_H) |
#if defined(HAVE_SIGNAL_H) && defined(HAVE_SYS_SOCKET_H) |
464 |
if (m_pUsr1Notifier) |
if (m_pSigusr1Notifier) |
465 |
delete m_pUsr1Notifier; |
delete m_pSigusr1Notifier; |
466 |
|
if (m_pSigtermNotifier) |
467 |
|
delete m_pSigtermNotifier; |
468 |
#endif |
#endif |
469 |
|
|
470 |
// Finally drop any widgets around... |
// Finally drop any widgets around... |
754 |
|
|
755 |
char c; |
char c; |
756 |
|
|
757 |
if (::read(g_fdUsr1[1], &c, sizeof(c)) > 0) |
if (::read(g_fdSigusr1[1], &c, sizeof(c)) > 0) |
758 |
saveSession(false); |
saveSession(false); |
759 |
|
|
760 |
#endif |
#endif |
761 |
} |
} |
762 |
|
|
763 |
|
|
764 |
|
void MainForm::handle_sigterm (void) |
765 |
|
{ |
766 |
|
#if defined(HAVE_SIGNAL_H) && defined(HAVE_SYS_SOCKET_H) |
767 |
|
|
768 |
|
char c; |
769 |
|
|
770 |
|
if (::read(g_fdSigterm[1], &c, sizeof(c)) > 0) |
771 |
|
close(); |
772 |
|
|
773 |
|
#endif |
774 |
|
} |
775 |
|
|
776 |
|
|
777 |
void MainForm::updateViewMidiDeviceStatusMenu (void) |
void MainForm::updateViewMidiDeviceStatusMenu (void) |