]>
git.saurik.com Git - wxWidgets.git/blob - src/unix/appunix.cpp
1c89ecf7e4f54d9a887d36cfb4d6a18aad91b49c
   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" 
  27 // use unusual names for arg[cv] to avoid clashes with wxApp members with the 
  29 bool wxAppConsole::Initialize(int& argc_
, wxChar
** argv_
) 
  31     if ( !wxAppConsoleBase::Initialize(argc_
, argv_
) ) 
  34     sigemptyset(&m_signalsCaught
); 
  39 void wxAppConsole::HandleSignal(int signal
) 
  41     wxAppConsole 
* const app 
= wxTheApp
; 
  45     sigaddset(&(app
->m_signalsCaught
), signal
); 
  49 void wxAppConsole::CheckSignal() 
  51     for ( SignalHandlerHash::iterator it 
= m_signalHandlerHash
.begin(); 
  52           it 
!= m_signalHandlerHash
.end(); 
  56         if ( sigismember(&m_signalsCaught
, sig
) ) 
  58             sigdelset(&m_signalsCaught
, sig
); 
  64 // the type of the signal handlers we use is "void(*)(int)" while the real 
  65 // signal handlers are extern "C" and so have incompatible type and at least 
  66 // Sun CC warns about it, so use explicit casts to suppress these warnings as 
  67 // they should be harmless 
  70     typedef void (*SignalHandler_t
)(int); 
  73 bool wxAppConsole::SetSignalHandler(int signal
, SignalHandler handler
) 
  75     const bool install 
= (SignalHandler_t
)handler 
!= SIG_DFL 
&& 
  76                          (SignalHandler_t
)handler 
!= SIG_IGN
; 
  79     memset(&sa
, 0, sizeof(sa
)); 
  80     sa
.sa_handler 
= (SignalHandler_t
)&wxAppConsole::HandleSignal
; 
  84    sa
.sa_flags 
= SA_RESTART
; 
  86    int res 
= sigaction(signal
, &sa
, 0); 
  89         wxLogSysError(_("Failed to install signal handler")); 
  94         m_signalHandlerHash
[signal
] = handler
; 
  96         m_signalHandlerHash
.erase(signal
);