signal.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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, signal_callback_t callback, void *data);
  49. EXPORT void signal_handler_connect_ref(signal_handler_t *handler,
  50. const char *signal, signal_callback_t callback, void *data);
  51. EXPORT void signal_handler_disconnect(signal_handler_t *handler,
  52. const char *signal, signal_callback_t callback, void *data);
  53. EXPORT void signal_handler_connect_global(signal_handler_t *handler,
  54. global_signal_callback_t callback, void *data);
  55. EXPORT void signal_handler_disconnect_global(signal_handler_t *handler,
  56. global_signal_callback_t callback, void *data);
  57. EXPORT void signal_handler_remove_current(void);
  58. EXPORT void signal_handler_signal(signal_handler_t *handler, const char *signal,
  59. calldata_t *params);
  60. #ifdef __cplusplus
  61. }
  62. #endif