hooks.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* classes: h_files */
  2. #ifndef SCM_HOOKS_H
  3. #define SCM_HOOKS_H
  4. /* Copyright (C) 1995,1996,1999,2000,2001, 2006 Free Software Foundation, Inc.
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "libguile/__scm.h"
  21. /*
  22. * C level hooks
  23. */
  24. /*
  25. * The interface is designed for and- and or-type hooks which
  26. * both may want to indicate success/failure and return a result.
  27. */
  28. typedef enum scm_t_c_hook_type {
  29. SCM_C_HOOK_NORMAL,
  30. SCM_C_HOOK_OR,
  31. SCM_C_HOOK_AND
  32. } scm_t_c_hook_type;
  33. typedef void *(*scm_t_c_hook_function) (void *hook_data,
  34. void *fn_data,
  35. void *data);
  36. typedef struct scm_t_c_hook_entry {
  37. struct scm_t_c_hook_entry *next;
  38. scm_t_c_hook_function func;
  39. void *data;
  40. } scm_t_c_hook_entry;
  41. typedef struct scm_t_c_hook {
  42. scm_t_c_hook_entry *first;
  43. scm_t_c_hook_type type;
  44. void *data;
  45. } scm_t_c_hook;
  46. SCM_API void scm_c_hook_init (scm_t_c_hook *hook,
  47. void *hook_data,
  48. scm_t_c_hook_type type);
  49. SCM_API void scm_c_hook_add (scm_t_c_hook *hook,
  50. scm_t_c_hook_function func,
  51. void *fn_data,
  52. int appendp);
  53. SCM_API void scm_c_hook_remove (scm_t_c_hook *hook,
  54. scm_t_c_hook_function func,
  55. void *fn_data);
  56. SCM_API void *scm_c_hook_run (scm_t_c_hook *hook, void *data);
  57. /*
  58. * Scheme level hooks
  59. */
  60. SCM_API scm_t_bits scm_tc16_hook;
  61. #define SCM_HOOKP(x) SCM_SMOB_PREDICATE (scm_tc16_hook, x)
  62. #define SCM_HOOK_ARITY(hook) SCM_SMOB_FLAGS (hook)
  63. #define SCM_HOOK_PROCEDURES(hook) SCM_SMOB_OBJECT (hook)
  64. #define SCM_SET_HOOK_PROCEDURES(hook, procs) SCM_SET_SMOB_OBJECT ((hook), (procs))
  65. SCM_API SCM scm_make_hook (SCM n_args);
  66. SCM_API SCM scm_hook_p (SCM x);
  67. SCM_API SCM scm_hook_empty_p (SCM hook);
  68. SCM_API SCM scm_add_hook_x (SCM hook, SCM thunk, SCM appendp);
  69. SCM_API SCM scm_remove_hook_x (SCM hook, SCM thunk);
  70. SCM_API SCM scm_reset_hook_x (SCM hook);
  71. SCM_API SCM scm_run_hook (SCM hook, SCM args);
  72. SCM_API void scm_c_run_hook (SCM hook, SCM args);
  73. SCM_API SCM scm_hook_to_list (SCM hook);
  74. SCM_API void scm_init_hooks (void);
  75. #endif /* SCM_HOOKS_H */
  76. /*
  77. Local Variables:
  78. c-file-style: "gnu"
  79. End:
  80. */