signal.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 (*signal_callback_t)(void*, calldata_t*);
  31. EXPORT signal_handler_t *signal_handler_create(void);
  32. EXPORT void signal_handler_destroy(signal_handler_t *handler);
  33. EXPORT bool signal_handler_add(signal_handler_t *handler,
  34. const char *signal_decl);
  35. static inline bool signal_handler_add_array(signal_handler_t *handler,
  36. const char **signal_decls)
  37. {
  38. bool success = true;
  39. if (!signal_decls)
  40. return false;
  41. while (*signal_decls)
  42. if (!signal_handler_add(handler, *(signal_decls++)))
  43. success = false;
  44. return success;
  45. }
  46. EXPORT void signal_handler_connect(signal_handler_t *handler,
  47. const char *signal, signal_callback_t callback, void *data);
  48. EXPORT void signal_handler_disconnect(signal_handler_t *handler,
  49. const char *signal, signal_callback_t callback, void *data);
  50. EXPORT void signal_handler_signal(signal_handler_t *handler, const char *signal,
  51. calldata_t *params);
  52. #ifdef __cplusplus
  53. }
  54. #endif