cache.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * netlink/cache.h Caching Module
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation version 2.1
  7. * of the License.
  8. *
  9. * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
  10. */
  11. #ifndef NETLINK_CACHE_H_
  12. #define NETLINK_CACHE_H_
  13. #include <netlink/netlink.h>
  14. #include <netlink/msg.h>
  15. #include <netlink/utils.h>
  16. #include <netlink/object.h>
  17. #include <netlink/cache-api.h>
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. struct nl_cache;
  22. typedef void (*change_func_t)(struct nl_cache *, struct nl_object *, int);
  23. /* Access Functions */
  24. extern int nl_cache_nitems(struct nl_cache *);
  25. extern int nl_cache_nitems_filter(struct nl_cache *,
  26. struct nl_object *);
  27. extern struct nl_cache_ops * nl_cache_get_ops(struct nl_cache *);
  28. extern struct nl_object * nl_cache_get_first(struct nl_cache *);
  29. extern struct nl_object * nl_cache_get_last(struct nl_cache *);
  30. extern struct nl_object * nl_cache_get_next(struct nl_object *);
  31. extern struct nl_object * nl_cache_get_prev(struct nl_object *);
  32. extern struct nl_cache * nl_cache_alloc(struct nl_cache_ops *);
  33. extern int nl_cache_alloc_and_fill(struct nl_cache_ops *,
  34. struct nl_sock *,
  35. struct nl_cache **);
  36. extern int nl_cache_alloc_name(const char *,
  37. struct nl_cache **);
  38. extern struct nl_cache * nl_cache_subset(struct nl_cache *,
  39. struct nl_object *);
  40. extern void nl_cache_clear(struct nl_cache *);
  41. extern void nl_cache_free(struct nl_cache *);
  42. /* Cache modification */
  43. extern int nl_cache_add(struct nl_cache *,
  44. struct nl_object *);
  45. extern int nl_cache_parse_and_add(struct nl_cache *,
  46. struct nl_msg *);
  47. extern void nl_cache_remove(struct nl_object *);
  48. extern int nl_cache_refill(struct nl_sock *,
  49. struct nl_cache *);
  50. extern int nl_cache_pickup(struct nl_sock *,
  51. struct nl_cache *);
  52. extern int nl_cache_resync(struct nl_sock *,
  53. struct nl_cache *,
  54. change_func_t);
  55. extern int nl_cache_include(struct nl_cache *,
  56. struct nl_object *,
  57. change_func_t);
  58. /* General */
  59. extern int nl_cache_is_empty(struct nl_cache *);
  60. extern void nl_cache_mark_all(struct nl_cache *);
  61. /* Dumping */
  62. extern void nl_cache_dump(struct nl_cache *,
  63. struct nl_dump_params *);
  64. extern void nl_cache_dump_filter(struct nl_cache *,
  65. struct nl_dump_params *,
  66. struct nl_object *);
  67. /* Iterators */
  68. #ifdef disabled
  69. extern void nl_cache_foreach(struct nl_cache *,
  70. void (*cb)(struct nl_object *,
  71. void *),
  72. void *arg);
  73. extern void nl_cache_foreach_filter(struct nl_cache *,
  74. struct nl_object *,
  75. void (*cb)(struct
  76. nl_object *,
  77. void *),
  78. void *arg);
  79. #endif
  80. /* --- cache management --- */
  81. /* Cache type management */
  82. extern struct nl_cache_ops * nl_cache_ops_lookup(const char *);
  83. extern struct nl_cache_ops * nl_cache_ops_associate(int, int);
  84. extern struct nl_msgtype * nl_msgtype_lookup(struct nl_cache_ops *, int);
  85. extern void nl_cache_ops_foreach(void (*cb)(struct nl_cache_ops *, void *), void *);
  86. extern int nl_cache_mngt_register(struct nl_cache_ops *);
  87. extern int nl_cache_mngt_unregister(struct nl_cache_ops *);
  88. /* Global cache provisioning/requiring */
  89. extern void nl_cache_mngt_provide(struct nl_cache *);
  90. extern void nl_cache_mngt_unprovide(struct nl_cache *);
  91. extern struct nl_cache * nl_cache_mngt_require(const char *);
  92. struct nl_cache_mngr;
  93. #define NL_AUTO_PROVIDE 1
  94. extern int nl_cache_mngr_alloc(struct nl_sock *,
  95. int, int,
  96. struct nl_cache_mngr **);
  97. extern int nl_cache_mngr_add(struct nl_cache_mngr *,
  98. const char *,
  99. change_func_t,
  100. struct nl_cache **);
  101. extern int nl_cache_mngr_get_fd(struct nl_cache_mngr *);
  102. extern int nl_cache_mngr_poll(struct nl_cache_mngr *,
  103. int);
  104. extern int nl_cache_mngr_data_ready(struct nl_cache_mngr *);
  105. extern void nl_cache_mngr_free(struct nl_cache_mngr *);
  106. #ifdef __cplusplus
  107. }
  108. #endif
  109. #endif