hooks.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* classes: h_files */
  2. #ifndef SCM_HOOKS_H
  3. #define SCM_HOOKS_H
  4. /* Copyright (C) 1995,1996,1999,2000,2001, 2006, 2008, 2009 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 License
  8. * as published by the Free Software Foundation; either version 3 of
  9. * the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful, but
  12. * 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
  19. * 02110-1301 USA
  20. */
  21. #include "libguile/__scm.h"
  22. /*
  23. * C level hooks
  24. */
  25. /*
  26. * The interface is designed for and- and or-type hooks which
  27. * both may want to indicate success/failure and return a result.
  28. */
  29. typedef enum scm_t_c_hook_type {
  30. SCM_C_HOOK_NORMAL,
  31. SCM_C_HOOK_OR,
  32. SCM_C_HOOK_AND
  33. } scm_t_c_hook_type;
  34. typedef void *(*scm_t_c_hook_function) (void *hook_data,
  35. void *fn_data,
  36. void *data);
  37. typedef struct scm_t_c_hook_entry {
  38. struct scm_t_c_hook_entry *next;
  39. scm_t_c_hook_function func;
  40. void *data;
  41. } scm_t_c_hook_entry;
  42. typedef struct scm_t_c_hook {
  43. scm_t_c_hook_entry *first;
  44. scm_t_c_hook_type type;
  45. void *data;
  46. } scm_t_c_hook;
  47. SCM_API void scm_c_hook_init (scm_t_c_hook *hook,
  48. void *hook_data,
  49. scm_t_c_hook_type type);
  50. SCM_API void scm_c_hook_add (scm_t_c_hook *hook,
  51. scm_t_c_hook_function func,
  52. void *fn_data,
  53. int appendp);
  54. SCM_API void scm_c_hook_remove (scm_t_c_hook *hook,
  55. scm_t_c_hook_function func,
  56. void *fn_data);
  57. SCM_API void *scm_c_hook_run (scm_t_c_hook *hook, void *data);
  58. /*
  59. * Scheme level hooks
  60. */
  61. SCM_API scm_t_bits scm_tc16_hook;
  62. #define SCM_HOOKP(x) SCM_SMOB_PREDICATE (scm_tc16_hook, x)
  63. #define SCM_HOOK_ARITY(hook) SCM_SMOB_FLAGS (hook)
  64. #define SCM_HOOK_PROCEDURES(hook) SCM_SMOB_OBJECT (hook)
  65. #define SCM_SET_HOOK_PROCEDURES(hook, procs) SCM_SET_SMOB_OBJECT ((hook), (procs))
  66. SCM_API SCM scm_make_hook (SCM n_args);
  67. SCM_API SCM scm_hook_p (SCM x);
  68. SCM_API SCM scm_hook_empty_p (SCM hook);
  69. SCM_API SCM scm_add_hook_x (SCM hook, SCM thunk, SCM appendp);
  70. SCM_API SCM scm_remove_hook_x (SCM hook, SCM thunk);
  71. SCM_API SCM scm_reset_hook_x (SCM hook);
  72. SCM_API SCM scm_run_hook (SCM hook, SCM args);
  73. SCM_API void scm_c_run_hook (SCM hook, SCM args);
  74. SCM_API void scm_c_run_hookn (SCM hook, SCM *argv, size_t nargs);
  75. SCM_API SCM scm_hook_to_list (SCM hook);
  76. SCM_INTERNAL void scm_init_hooks (void);
  77. #endif /* SCM_HOOKS_H */
  78. /*
  79. Local Variables:
  80. c-file-style: "gnu"
  81. End:
  82. */