]> git.saurik.com Git - wxWidgets.git/blame - src/unix/appunix.cpp
fix warnings about parameters shadowing member variables
[wxWidgets.git] / src / unix / appunix.cpp
CommitLineData
b46b1d59
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/unix/appunix.cpp
3// Purpose: wxAppConsole with wxMainLoop implementation
4// Author: Lukasz Michalski
5// Created: 28/01/2005
6// RCS-ID: $Id$
7// Copyright: (c) Lukasz Michalski
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11#include "wx/app.h"
12#include "wx/log.h"
13#include "wx/evtloop.h"
14
15#include <signal.h>
16#include <unistd.h>
17
3bc8edd5
VZ
18// use unusual names for arg[cv] to avoid clashes with wxApp members with the
19// same names
20bool wxAppConsole::Initialize(int& argc_, wxChar** argv_)
b46b1d59 21{
3bc8edd5 22 if ( !wxAppConsoleBase::Initialize(argc_, argv_) )
b46b1d59
VZ
23 return false;
24
25 sigemptyset(&m_signalsCaught);
26
27 return true;
28}
29
e0954e72 30void wxAppConsole::HandleSignal(int signal)
b46b1d59 31{
e0954e72 32 wxAppConsole * const app = wxTheApp;
b46b1d59
VZ
33 if ( !app )
34 return;
35
36 sigaddset(&(app->m_signalsCaught), signal);
37 app->WakeUpIdle();
38}
39
e0954e72 40void wxAppConsole::CheckSignal()
b46b1d59
VZ
41{
42 for ( SignalHandlerHash::iterator it = m_signalHandlerHash.begin();
43 it != m_signalHandlerHash.end();
44 ++it )
45 {
46 int sig = it->first;
47 if ( sigismember(&m_signalsCaught, sig) )
48 {
49 sigdelset(&m_signalsCaught, sig);
50 (it->second)(sig);
51 }
52 }
53}
54
7d10ec93
VZ
55// the type of the signal handlers we use is "void(*)(int)" while the real
56// signal handlers are extern "C" and so have incompatible type and at least
57// Sun CC warns about it, so use explicit casts to suppress these warnings as
58// they should be harmless
59extern "C"
60{
61 typedef void (*SignalHandler_t)(int);
62}
63
e0954e72 64bool wxAppConsole::SetSignalHandler(int signal, SignalHandler handler)
b46b1d59 65{
7d10ec93
VZ
66 const bool install = (SignalHandler_t)handler != SIG_DFL &&
67 (SignalHandler_t)handler != SIG_IGN;
b46b1d59
VZ
68
69 struct sigaction sa;
70 memset(&sa, 0, sizeof(sa));
7d10ec93 71 sa.sa_handler = (SignalHandler_t)&wxAppConsole::HandleSignal;
b46b1d59
VZ
72 sa.sa_flags = SA_RESTART;
73 int res = sigaction(signal, &sa, 0);
74 if ( res != 0 )
75 {
76 wxLogSysError(_("Failed to install signal handler"));
77 return false;
78 }
79
80 if ( install )
81 m_signalHandlerHash[signal] = handler;
82 else
83 m_signalHandlerHash.erase(signal);
84
85 return true;
86}
f6342fb5 87