cache_handler.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* Portions of this file are subject to the following copyright(s). See
  2. * the Net-SNMP's COPYING file for more details and other copyrights
  3. * that may apply:
  4. */
  5. /*
  6. * Portions of this file are copyrighted by:
  7. * Copyright (C) 2007 Apple, Inc. All rights reserved.
  8. * Use is subject to license terms specified in the COPYING file
  9. * distributed with the Net-SNMP package.
  10. */
  11. #ifndef NETSNMP_CACHE_HANDLER_H
  12. #define NETSNMP_CACHE_HANDLER_H
  13. /*
  14. * This caching helper provides a generalised (SNMP-manageable) caching
  15. * mechanism. Individual SNMP table and scalar/scalar group MIB
  16. * implementations can use data caching in a consistent manner, without
  17. * needing to handle the generic caching details themselves.
  18. */
  19. #include <net-snmp/library/tools.h>
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. #define CACHE_NAME "cache_info"
  24. typedef struct netsnmp_cache_s netsnmp_cache;
  25. typedef int (NetsnmpCacheLoad)(netsnmp_cache *, void*);
  26. typedef void (NetsnmpCacheFree)(netsnmp_cache *, void*);
  27. struct netsnmp_cache_s {
  28. /** Number of handlers whose myvoid member points at this structure. */
  29. int refcnt;
  30. /*
  31. * For operation of the data caches
  32. */
  33. int flags;
  34. int enabled;
  35. int valid;
  36. char expired;
  37. int timeout; /* Length of time the cache is valid (in s) */
  38. marker_t timestampM; /* When the cache was last loaded */
  39. u_long timer_id; /* periodic timer id */
  40. NetsnmpCacheLoad *load_cache;
  41. NetsnmpCacheFree *free_cache;
  42. /*
  43. * void pointer for the user that created the cache.
  44. * You never know when it might not come in useful ....
  45. */
  46. void *magic;
  47. /*
  48. * hint from the cache helper. contains the standard
  49. * handler arguments.
  50. */
  51. netsnmp_handler_args *cache_hint;
  52. /*
  53. * For SNMP-management of the data caches
  54. */
  55. netsnmp_cache *next, *prev;
  56. oid *rootoid;
  57. int rootoid_len;
  58. };
  59. void netsnmp_cache_reqinfo_insert(netsnmp_cache* cache,
  60. netsnmp_agent_request_info * reqinfo,
  61. const char *name);
  62. netsnmp_cache *
  63. netsnmp_cache_reqinfo_extract(netsnmp_agent_request_info * reqinfo,
  64. const char *name);
  65. netsnmp_cache* netsnmp_extract_cache_info(netsnmp_agent_request_info *);
  66. int netsnmp_cache_check_and_reload(netsnmp_cache * cache);
  67. int netsnmp_cache_check_expired(netsnmp_cache *cache);
  68. int netsnmp_cache_is_valid( netsnmp_agent_request_info *,
  69. const char *name);
  70. /** for backwards compat */
  71. int netsnmp_is_cache_valid( netsnmp_agent_request_info *);
  72. netsnmp_mib_handler *netsnmp_get_cache_handler(int, NetsnmpCacheLoad *,
  73. NetsnmpCacheFree *,
  74. const oid*, int);
  75. int netsnmp_register_cache_handler(netsnmp_handler_registration *reginfo,
  76. int, NetsnmpCacheLoad *,
  77. NetsnmpCacheFree *);
  78. Netsnmp_Node_Handler netsnmp_cache_helper_handler;
  79. netsnmp_cache *
  80. netsnmp_cache_create(int timeout, NetsnmpCacheLoad * load_hook,
  81. NetsnmpCacheFree * free_hook,
  82. const oid * rootoid, int rootoid_len);
  83. int netsnmp_cache_remove(netsnmp_cache *cache);
  84. int netsnmp_cache_free(netsnmp_cache *cache);
  85. netsnmp_mib_handler *
  86. netsnmp_cache_handler_get(netsnmp_cache* cache);
  87. void netsnmp_cache_handler_owns_cache(netsnmp_mib_handler *handler);
  88. netsnmp_cache * netsnmp_cache_find_by_oid(const oid * rootoid,
  89. int rootoid_len);
  90. unsigned int netsnmp_cache_timer_start(netsnmp_cache *cache);
  91. void netsnmp_cache_timer_stop(netsnmp_cache *cache);
  92. /*
  93. * Flags affecting cache handler operation
  94. */
  95. #define NETSNMP_CACHE_DONT_INVALIDATE_ON_SET 0x0001
  96. #define NETSNMP_CACHE_DONT_FREE_BEFORE_LOAD 0x0002
  97. #define NETSNMP_CACHE_DONT_FREE_EXPIRED 0x0004
  98. #define NETSNMP_CACHE_DONT_AUTO_RELEASE 0x0008
  99. #define NETSNMP_CACHE_PRELOAD 0x0010
  100. #define NETSNMP_CACHE_AUTO_RELOAD 0x0020
  101. #define NETSNMP_CACHE_RESET_TIMER_ON_USE 0x0040
  102. #define NETSNMP_CACHE_HINT_HANDLER_ARGS 0x1000
  103. #ifdef __cplusplus
  104. }
  105. #endif
  106. #endif /* NETSNMP_CACHE_HANDLER_H */