X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9e9f08b5ed6715482307be13aa662051a25e9458..b46b1d59d6f69ad80dcf5955375578a6504d100a:/src/unix/appunix.cpp diff --git a/src/unix/appunix.cpp b/src/unix/appunix.cpp new file mode 100644 index 0000000000..a40991715a --- /dev/null +++ b/src/unix/appunix.cpp @@ -0,0 +1,77 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: wx/unix/appunix.cpp +// Purpose: wxAppConsole with wxMainLoop implementation +// Author: Lukasz Michalski +// Created: 28/01/2005 +// RCS-ID: $Id$ +// Copyright: (c) Lukasz Michalski +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#include "wx/app.h" +#include "wx/log.h" +#include "wx/evtloop.h" + +#include +#include + +bool wxAppConsoleUnix::Initialize(int& argc, wxChar** argv) +{ + if ( !wxAppConsole::Initialize(argc,argv) ) + return false; + + if ( !m_mainLoop->IsOk() ) + return false; + + sigemptyset(&m_signalsCaught); + + return true; +} + +void wxAppConsoleUnix::HandleSignal(int signal) +{ + wxAppConsoleUnix * const app = wxTheApp; + if ( !app ) + return; + + sigaddset(&(app->m_signalsCaught), signal); + app->WakeUpIdle(); +} + +void wxAppConsoleUnix::CheckSignal() +{ + for ( SignalHandlerHash::iterator it = m_signalHandlerHash.begin(); + it != m_signalHandlerHash.end(); + ++it ) + { + int sig = it->first; + if ( sigismember(&m_signalsCaught, sig) ) + { + sigdelset(&m_signalsCaught, sig); + (it->second)(sig); + } + } +} + +bool wxAppConsoleUnix::SetSignalHandler(int signal, SignalHandler handler) +{ + const bool install = handler != SIG_DFL && handler != SIG_IGN; + + struct sigaction sa; + memset(&sa, 0, sizeof(sa)); + sa.sa_handler = &wxAppConsoleUnix::HandleSignal; + sa.sa_flags = SA_RESTART; + int res = sigaction(signal, &sa, 0); + if ( res != 0 ) + { + wxLogSysError(_("Failed to install signal handler")); + return false; + } + + if ( install ) + m_signalHandlerHash[signal] = handler; + else + m_signalHandlerHash.erase(signal); + + return true; +}