1
0

signal.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright (c) 2013 Hugh Bailey <[email protected]>
  3. *
  4. * Permission to use, copy, modify, and distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #pragma once
  17. #include "../util/c99defs.h"
  18. #include "calldata.h"
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. /*
  23. * Signal handler
  24. *
  25. * This is used to create a signal handler which can broadcast events
  26. * to one or more callbacks connected to a signal.
  27. */
  28. struct signal_handler;
  29. typedef struct signal_handler signal_handler_t;
  30. typedef void (*global_signal_callback_t)(void *, const char *, calldata_t *);
  31. typedef void (*signal_callback_t)(void *, calldata_t *);
  32. EXPORT signal_handler_t *signal_handler_create(void);
  33. EXPORT void signal_handler_destroy(signal_handler_t *handler);
  34. EXPORT bool signal_handler_add(signal_handler_t *handler,
  35. const char *signal_decl);
  36. static inline bool signal_handler_add_array(signal_handler_t *handler,
  37. const char **signal_decls)
  38. {
  39. bool success = true;
  40. if (!signal_decls)
  41. return false;
  42. while (*signal_decls)
  43. if (!signal_handler_add(handler, *(signal_decls++)))
  44. success = false;
  45. return success;
  46. }
  47. EXPORT void signal_handler_connect(signal_handler_t *handler,
  48. const char *signal,
  49. signal_callback_t callback, void *data);
  50. EXPORT void signal_handler_connect_ref(signal_handler_t *handler,
  51. const char *signal,
  52. signal_callback_t callback, void *data);
  53. EXPORT void signal_handler_disconnect(signal_handler_t *handler,
  54. const char *signal,
  55. signal_callback_t callback, void *data);
  56. EXPORT void signal_handler_connect_global(signal_handler_t *handler,
  57. global_signal_callback_t callback,
  58. void *data);
  59. EXPORT void signal_handler_disconnect_global(signal_handler_t *handler,
  60. global_signal_callback_t callback,
  61. void *data);
  62. EXPORT void signal_handler_remove_current(void);
  63. EXPORT void signal_handler_signal(signal_handler_t *handler, const char *signal,
  64. calldata_t *params);
  65. #ifdef __cplusplus
  66. }
  67. #endif