BSignal.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * @file BSignal.h
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * This file is part of BadVPN.
  8. *
  9. * BadVPN is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2
  11. * as published by the Free Software Foundation.
  12. *
  13. * BadVPN is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. *
  22. * @section DESCRIPTION
  23. *
  24. * A global object for catching program termination requests.
  25. */
  26. #ifndef BADVPN_SYSTEM_BSIGNAL_H
  27. #define BADVPN_SYSTEM_BSIGNAL_H
  28. #include <misc/debug.h>
  29. #include <system/BReactor.h>
  30. typedef void (*BSignal_handler) (void *user);
  31. /**
  32. * Initializes signal handling.
  33. * The object is created in not capturing state.
  34. * {@link BLog_Init} must have been done.
  35. *
  36. * WARNING: make sure this won't interfere with other components:
  37. * - on Linux, this uses {@link BUnixSignal} to catch SIGTERM and SIGINT,
  38. * - on Windows, this sets up a handler with SetConsoleCtrlHandler.
  39. *
  40. * @param reactor {@link BReactor} from which the handler will be called
  41. * @param handler callback function invoked from the reactor
  42. * @param user value passed to callback function
  43. * @return 1 on success, 0 on failure
  44. */
  45. int BSignal_Init (BReactor *reactor, BSignal_handler handler, void *user) WARN_UNUSED;
  46. /**
  47. * Finishes signal handling.
  48. * {@link BSignal_Init} must not be called again.
  49. */
  50. void BSignal_Finish (void);
  51. #endif