app.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/unix/app.h
  3. // Purpose: wxAppConsole implementation for Unix
  4. // Author: Lukasz Michalski
  5. // Created: 28/01/2005
  6. // Copyright: (c) Lukasz Michalski
  7. // Licence: wxWindows licence
  8. /////////////////////////////////////////////////////////////////////////////
  9. //Ensure that sigset_t is being defined
  10. #include <signal.h>
  11. class wxFDIODispatcher;
  12. class wxFDIOHandler;
  13. class wxWakeUpPipe;
  14. // wxApp subclass implementing event processing for console applications
  15. class WXDLLIMPEXP_BASE wxAppConsole : public wxAppConsoleBase
  16. {
  17. public:
  18. wxAppConsole();
  19. virtual ~wxAppConsole();
  20. // override base class initialization
  21. virtual bool Initialize(int& argc, wxChar** argv);
  22. // Unix-specific: Unix signal handling
  23. // -----------------------------------
  24. // type of the function which can be registered as signal handler: notice
  25. // that it isn't really a signal handler, i.e. it's not subject to the
  26. // usual signal handlers constraints, because it is called later from
  27. // CheckSignal() and not when the signal really occurs
  28. typedef void (*SignalHandler)(int);
  29. // Set signal handler for the given signal, SIG_DFL or SIG_IGN can be used
  30. // instead of a function pointer
  31. //
  32. // Return true if handler was installed, false on error
  33. bool SetSignalHandler(int signal, SignalHandler handler);
  34. // Check if any Unix signals arrived since the last call and execute
  35. // handlers for them
  36. void CheckSignal();
  37. // Register the signal wake up pipe with the given dispatcher.
  38. //
  39. // This is used by wxExecute(wxEXEC_NOEVENTS) implementation only.
  40. //
  41. // The pointer to the handler used for processing events on this descriptor
  42. // is returned so that it can be deleted when we no longer needed it.
  43. wxFDIOHandler* RegisterSignalWakeUpPipe(wxFDIODispatcher& dispatcher);
  44. private:
  45. // signal handler set up by SetSignalHandler() for all signals we handle,
  46. // it just adds the signal to m_signalsCaught -- the real processing is
  47. // done later, when CheckSignal() is called
  48. static void HandleSignal(int signal);
  49. // signals for which HandleSignal() had been called (reset from
  50. // CheckSignal())
  51. sigset_t m_signalsCaught;
  52. // the signal handlers
  53. WX_DECLARE_HASH_MAP(int, SignalHandler, wxIntegerHash, wxIntegerEqual, SignalHandlerHash);
  54. SignalHandlerHash m_signalHandlerHash;
  55. // pipe used for wake up signal handling: if a signal arrives while we're
  56. // blocking for input, writing to this pipe triggers a call to our CheckSignal()
  57. wxWakeUpPipe *m_signalWakeUpPipe;
  58. };