triglib.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * libdpkg - Debian packaging suite library routines
  3. * triglib.h - declarations for trigger handling
  4. *
  5. * Copyright © 2007 Canonical, Ltd.
  6. * written by Ian Jackson <ian@chiark.greenend.org.uk>
  7. *
  8. * This is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #ifndef LIBDPKG_TRIGLIB_H
  22. #define LIBDPKG_TRIGLIB_H
  23. #include <dpkg/macros.h>
  24. #include <dpkg/dpkg-db.h>
  25. DPKG_BEGIN_DECLS
  26. /**
  27. * @defgroup triglib Trigger handling
  28. * @ingroup dpkg-internal
  29. * @{
  30. */
  31. /*
  32. * Hooks for more sophisticated processing in dpkg proper.
  33. *
  34. * We do things like this so we can get most of the trigger tracking
  35. * in dpkg-query, dselect, and so on, but avoid the transitional
  36. * processing and deferred trigproc queue management other than when
  37. * we're actually doing real package management work.
  38. */
  39. const char *trig_name_is_illegal(const char *p);
  40. enum trig_options {
  41. trig_await,
  42. trig_noawait
  43. };
  44. struct trigfileint {
  45. struct pkginfo *pkg;
  46. struct pkgbin *pkgbin;
  47. struct filenamenode *fnn;
  48. enum trig_options options;
  49. struct trigfileint *samefile_next;
  50. struct {
  51. struct trigfileint *next, *prev;
  52. } inoverall;
  53. };
  54. /**
  55. * The first two hooks are normally NULL.
  56. * If non-NULL, we're dpkg proper and we might need to invent trigger
  57. * activations as the first run of a triggers-supporting dpkg.
  58. */
  59. struct trig_hooks {
  60. void (*enqueue_deferred)(struct pkginfo *pend);
  61. void (*transitional_activate)(enum modstatdb_rw cstatus);
  62. struct filenamenode *(*namenode_find)(const char *filename, bool nonew);
  63. struct trigfileint **(*namenode_interested)(struct filenamenode *fnn);
  64. /** Returns a pointer from nfmalloc. */
  65. const char *(*namenode_name)(struct filenamenode *fnn);
  66. };
  67. #define TRIGHOOKS_DEFINE_NAMENODE_ACCESSORS \
  68. static struct trigfileint **th_nn_interested(struct filenamenode *fnn) \
  69. { return &fnn->trig_interested; } \
  70. static const char *th_nn_name(struct filenamenode *fnn) \
  71. { return fnn->name; }
  72. void trig_override_hooks(const struct trig_hooks *hooks);
  73. void trig_file_activate_byname(const char *trig, struct pkginfo *aw);
  74. void trig_file_activate(struct filenamenode *trig, struct pkginfo *aw);
  75. bool trig_note_pend_core(struct pkginfo *pend, const char *trig /*not copied!*/);
  76. bool trig_note_pend(struct pkginfo *pend, const char *trig /*not copied!*/);
  77. bool trig_note_aw(struct pkginfo *pend, struct pkginfo *aw);
  78. void trig_clear_awaiters(struct pkginfo *notpend);
  79. typedef void trig_awaited_pend_foreach_func(struct pkginfo *pkg);
  80. void trig_awaited_pend_enqueue(struct pkginfo *pend);
  81. void trig_awaited_pend_foreach(trig_awaited_pend_foreach_func *func);
  82. void trig_awaited_pend_free(void);
  83. void trig_fixup_awaiters(enum modstatdb_rw cstatus);
  84. void trig_file_interests_ensure(void);
  85. void trig_file_interests_save(void);
  86. typedef void trig_parse_cicb(const char *trig, struct pkginfo *pkg,
  87. struct pkgbin *pkgbin, enum trig_options to);
  88. void trig_cicb_interest_delete(const char *trig, struct pkginfo *pkg,
  89. struct pkgbin *pkgbin, enum trig_options to);
  90. void trig_cicb_interest_add(const char *trig, struct pkginfo *pkg,
  91. struct pkgbin *pkgbin, enum trig_options to);
  92. void trig_cicb_statuschange_activate(const char *trig, struct pkginfo *pkg,
  93. struct pkgbin *pkgbin, enum trig_options to);
  94. void trig_parse_ci(const char *file, trig_parse_cicb *interest,
  95. trig_parse_cicb *activate, struct pkginfo *pkg,
  96. struct pkgbin *pkgbin);
  97. void trig_incorporate(enum modstatdb_rw cstatus);
  98. /** @} */
  99. DPKG_END_DECLS
  100. #endif /* LIBDPKG_TRIGLIB_H */