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 |
109 |
#include <signal.h> |
#include <signal.h> |
110 |
|
|
111 |
// File descriptor for SIGUSR1 notifier. |
// File descriptor for SIGUSR1 notifier. |
112 |
static int g_fdUsr1[2]; |
static int g_fdSigusr1[2]; |
113 |
|
|
114 |
// Unix SIGUSR1 signal handler. |
// Unix SIGUSR1 signal handler. |
115 |
static void qsampler_sigusr1_handler ( int /* signo */ ) |
static void qsampler_sigusr1_handler ( int /* signo */ ) |
116 |
{ |
{ |
117 |
char c = 1; |
char c = 1; |
118 |
|
|
119 |
(::write(g_fdUsr1[0], &c, sizeof(c)) > 0); |
(::write(g_fdSigusr1[0], &c, sizeof(c)) > 0); |
120 |
|
} |
121 |
|
|
122 |
|
// File descriptor for SIGTERM notifier. |
123 |
|
static int g_fdSigterm[2]; |
124 |
|
|
125 |
|
// Unix SIGTERM signal handler. |
126 |
|
static void qsampler_sigterm_handler ( int /* signo */ ) |
127 |
|
{ |
128 |
|
char c = 1; |
129 |
|
|
130 |
|
(::write(g_fdSigterm[0], &c, sizeof(c)) > 0); |
131 |
} |
} |
132 |
|
|
133 |
#endif // HAVE_SIGNAL_H |
#endif // HAVE_SIGNAL_H |
244 |
// LADISH Level 1 suport. |
// LADISH Level 1 suport. |
245 |
|
|
246 |
// Initialize file descriptors for SIGUSR1 socket notifier. |
// Initialize file descriptors for SIGUSR1 socket notifier. |
247 |
::socketpair(AF_UNIX, SOCK_STREAM, 0, g_fdUsr1); |
::socketpair(AF_UNIX, SOCK_STREAM, 0, g_fdSigusr1); |
248 |
m_pUsr1Notifier |
m_pSigusr1Notifier |
249 |
= new QSocketNotifier(g_fdUsr1[1], QSocketNotifier::Read, this); |
= new QSocketNotifier(g_fdSigusr1[1], QSocketNotifier::Read, this); |
250 |
|
|
251 |
QObject::connect(m_pUsr1Notifier, |
QObject::connect(m_pSigusr1Notifier, |
252 |
SIGNAL(activated(int)), |
SIGNAL(activated(int)), |
253 |
SLOT(handle_sigusr1())); |
SLOT(handle_sigusr1())); |
254 |
|
|
255 |
// Install SIGUSR1 signal handler. |
// Install SIGUSR1 signal handler. |
256 |
struct sigaction usr1; |
struct sigaction sigusr1; |
257 |
usr1.sa_handler = qsampler_sigusr1_handler; |
sigusr1.sa_handler = qsampler_sigusr1_handler; |
258 |
sigemptyset(&usr1.sa_mask); |
sigemptyset(&sigusr1.sa_mask); |
259 |
usr1.sa_flags = 0; |
sigusr1.sa_flags = 0; |
260 |
usr1.sa_flags |= SA_RESTART; |
sigusr1.sa_flags |= SA_RESTART; |
261 |
::sigaction(SIGUSR1, &usr1, NULL); |
::sigaction(SIGUSR1, &sigusr1, NULL); |
262 |
|
|
263 |
|
// Initialize file descriptors for SIGTERM socket notifier. |
264 |
|
::socketpair(AF_UNIX, SOCK_STREAM, 0, g_fdSigterm); |
265 |
|
m_pSigtermNotifier |
266 |
|
= new QSocketNotifier(g_fdSigterm[1], QSocketNotifier::Read, this); |
267 |
|
|
268 |
|
QObject::connect(m_pSigtermNotifier, |
269 |
|
SIGNAL(activated(int)), |
270 |
|
SLOT(handle_sigterm())); |
271 |
|
|
272 |
|
// Install SIGTERM signal handler. |
273 |
|
struct sigaction sigterm; |
274 |
|
sigterm.sa_handler = qsampler_sigterm_handler; |
275 |
|
::sigemptyset(&sigterm.sa_mask); |
276 |
|
sigterm.sa_flags = 0; |
277 |
|
sigterm.sa_flags |= SA_RESTART; |
278 |
|
::sigaction(SIGTERM, &sigterm, NULL); |
279 |
|
::sigaction(SIGQUIT, &sigterm, NULL); |
280 |
|
|
281 |
|
// Ignore SIGHUP/SIGINT signals. |
282 |
|
::signal(SIGHUP, SIG_IGN); |
283 |
|
::signal(SIGINT, SIG_IGN); |
284 |
|
|
285 |
#else // HAVE_SIGNAL_H |
#else // HAVE_SIGNAL_H |
286 |
|
|
287 |
m_pUsr1Notifier = NULL; |
m_pSigusr1Notifier = NULL; |
288 |
|
m_pSigtermNotifier = NULL; |
289 |
|
|
290 |
#endif // !HAVE_SIGNAL_H |
#endif // !HAVE_SIGNAL_H |
291 |
|
|
464 |
#endif |
#endif |
465 |
|
|
466 |
#if defined(HAVE_SIGNAL_H) && defined(HAVE_SYS_SOCKET_H) |
#if defined(HAVE_SIGNAL_H) && defined(HAVE_SYS_SOCKET_H) |
467 |
if (m_pUsr1Notifier) |
if (m_pSigusr1Notifier) |
468 |
delete m_pUsr1Notifier; |
delete m_pSigusr1Notifier; |
469 |
|
if (m_pSigtermNotifier) |
470 |
|
delete m_pSigtermNotifier; |
471 |
#endif |
#endif |
472 |
|
|
473 |
// Finally drop any widgets around... |
// Finally drop any widgets around... |
757 |
|
|
758 |
char c; |
char c; |
759 |
|
|
760 |
if (::read(g_fdUsr1[1], &c, sizeof(c)) > 0) |
if (::read(g_fdSigusr1[1], &c, sizeof(c)) > 0) |
761 |
saveSession(false); |
saveSession(false); |
762 |
|
|
763 |
#endif |
#endif |
764 |
} |
} |
765 |
|
|
766 |
|
|
767 |
|
void MainForm::handle_sigterm (void) |
768 |
|
{ |
769 |
|
#if defined(HAVE_SIGNAL_H) && defined(HAVE_SYS_SOCKET_H) |
770 |
|
|
771 |
|
char c; |
772 |
|
|
773 |
|
if (::read(g_fdSigterm[1], &c, sizeof(c)) > 0) |
774 |
|
close(); |
775 |
|
|
776 |
|
#endif |
777 |
|
} |
778 |
|
|
779 |
|
|
780 |
void MainForm::updateViewMidiDeviceStatusMenu (void) |
void MainForm::updateViewMidiDeviceStatusMenu (void) |