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