]> git.saurik.com Git - wxWidgets.git/blame - src/unix/appunix.cpp
fix compilation in ANSI STL build
[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
e0954e72 18bool wxAppConsole::Initialize(int& argc, wxChar** argv)
b46b1d59 19{
e0954e72 20 if ( !wxAppConsoleBase::Initialize(argc,argv) )
b46b1d59
VZ
21 return false;
22
23 sigemptyset(&m_signalsCaught);
24
25 return true;
26}
27
e0954e72 28void wxAppConsole::HandleSignal(int signal)
b46b1d59 29{
e0954e72 30 wxAppConsole * const app = wxTheApp;
b46b1d59
VZ
31 if ( !app )
32 return;
33
34 sigaddset(&(app->m_signalsCaught), signal);
35 app->WakeUpIdle();
36}
37
e0954e72 38void wxAppConsole::CheckSignal()
b46b1d59
VZ
39{
40 for ( SignalHandlerHash::iterator it = m_signalHandlerHash.begin();
41 it != m_signalHandlerHash.end();
42 ++it )
43 {
44 int sig = it->first;
45 if ( sigismember(&m_signalsCaught, sig) )
46 {
47 sigdelset(&m_signalsCaught, sig);
48 (it->second)(sig);
49 }
50 }
51}
52
e0954e72 53bool wxAppConsole::SetSignalHandler(int signal, SignalHandler handler)
b46b1d59
VZ
54{
55 const bool install = handler != SIG_DFL && handler != SIG_IGN;
56
57 struct sigaction sa;
58 memset(&sa, 0, sizeof(sa));
e0954e72 59 sa.sa_handler = &wxAppConsole::HandleSignal;
b46b1d59
VZ
60 sa.sa_flags = SA_RESTART;
61 int res = sigaction(signal, &sa, 0);
62 if ( res != 0 )
63 {
64 wxLogSysError(_("Failed to install signal handler"));
65 return false;
66 }
67
68 if ( install )
69 m_signalHandlerHash[signal] = handler;
70 else
71 m_signalHandlerHash.erase(signal);
72
73 return true;
74}
f6342fb5 75