BSignal.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. * @return 1 on success, 0 on failure
  37. */
  38. int BSignal_Init (void) WARN_UNUSED;
  39. /**
  40. * Starts capturing signals.
  41. * The object must be in not capturing state.
  42. * The object enters capturing state.
  43. */
  44. void BSignal_Capture (void);
  45. /**
  46. * Stops capturing signals.
  47. * The object must be in capturing state.
  48. * A signal handler must not be configured.
  49. * The object enters not capturing state.
  50. */
  51. void BSignal_Uncapture (void);
  52. /**
  53. * Configures a reactor and a handler for signals.
  54. * The object must be in capturing state.
  55. * A handler must not be already configured.
  56. *
  57. * @param reactor {@link BReactor} from which the handler will be called
  58. * @param handler callback function invoked from the reactor
  59. * @param user value passed to callback function
  60. * @return 1 on success, 0 on failure.
  61. */
  62. int BSignal_SetHandler (BReactor *reactor, BSignal_handler handler, void *user) WARN_UNUSED;
  63. /**
  64. * Deconfigures a signal reactor and handler.
  65. * A handler must be configured.
  66. */
  67. void BSignal_RemoveHandler (void);
  68. #endif