]>
git.saurik.com Git - wxWidgets.git/blob - src/unix/appunix.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/unix/appunix.cpp
3 // Purpose: wxAppConsole with wxMainLoop implementation
4 // Author: Lukasz Michalski
7 // Copyright: (c) Lukasz Michalski
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #include "wx/wxprec.h"
22 #include "wx/evtloop.h"
28 // don't use for systems which don't define it (at least VMS and QNX)
32 // use unusual names for arg[cv] to avoid clashes with wxApp members with the
34 bool wxAppConsole::Initialize(int& argc_
, wxChar
** argv_
)
36 if ( !wxAppConsoleBase::Initialize(argc_
, argv_
) )
39 sigemptyset(&m_signalsCaught
);
44 void wxAppConsole::HandleSignal(int signal
)
46 wxAppConsole
* const app
= wxTheApp
;
50 sigaddset(&(app
->m_signalsCaught
), signal
);
54 void wxAppConsole::CheckSignal()
56 for ( SignalHandlerHash::iterator it
= m_signalHandlerHash
.begin();
57 it
!= m_signalHandlerHash
.end();
61 if ( sigismember(&m_signalsCaught
, sig
) )
63 sigdelset(&m_signalsCaught
, sig
);
69 // the type of the signal handlers we use is "void(*)(int)" while the real
70 // signal handlers are extern "C" and so have incompatible type and at least
71 // Sun CC warns about it, so use explicit casts to suppress these warnings as
72 // they should be harmless
75 typedef void (*SignalHandler_t
)(int);
78 bool wxAppConsole::SetSignalHandler(int signal
, SignalHandler handler
)
80 const bool install
= (SignalHandler_t
)handler
!= SIG_DFL
&&
81 (SignalHandler_t
)handler
!= SIG_IGN
;
84 memset(&sa
, 0, sizeof(sa
));
85 sa
.sa_handler
= (SignalHandler_t
)&wxAppConsole::HandleSignal
;
86 sa
.sa_flags
= SA_RESTART
;
87 int res
= sigaction(signal
, &sa
, 0);
90 wxLogSysError(_("Failed to install signal handler"));
95 m_signalHandlerHash
[signal
] = handler
;
97 m_signalHandlerHash
.erase(signal
);