net-snmp 5.7
cache_handler.h
00001 /* Portions of this file are subject to the following copyright(s).  See
00002  * the Net-SNMP's COPYING file for more details and other copyrights
00003  * that may apply:
00004  */
00005 /*
00006  * Portions of this file are copyrighted by:
00007  * Copyright (C) 2007 Apple, Inc. All rights reserved.
00008  * Use is subject to license terms specified in the COPYING file
00009  * distributed with the Net-SNMP package.
00010  */
00011 #ifndef NETSNMP_CACHE_HANDLER_H
00012 #define NETSNMP_CACHE_HANDLER_H
00013 
00014 /*
00015  * This caching helper provides a generalised (SNMP-manageable) caching
00016  * mechanism.  Individual SNMP table and scalar/scalar group MIB
00017  * implementations can use data caching in a consistent manner, without
00018  * needing to handle the generic caching details themselves.
00019  */
00020 
00021 #include <net-snmp/library/tools.h>
00022 
00023 #ifdef __cplusplus
00024 extern          "C" {
00025 #endif
00026 
00027 #define CACHE_NAME "cache_info"
00028 
00029     typedef struct netsnmp_cache_s netsnmp_cache;
00030 
00031     typedef int  (NetsnmpCacheLoad)(netsnmp_cache *, void*);
00032     typedef void (NetsnmpCacheFree)(netsnmp_cache *, void*);
00033 
00034     struct netsnmp_cache_s {
00036         int      refcnt;
00037         /*
00038          * For operation of the data caches
00039          */
00040         int      flags;
00041         int      enabled;
00042         int      valid;
00043         char     expired;
00044         int      timeout;       /* Length of time the cache is valid (in s) */
00045         marker_t timestamp;     /* When the cache was last loaded */
00046         u_long   timer_id;      /* periodic timer id */
00047 
00048         NetsnmpCacheLoad *load_cache;
00049         NetsnmpCacheFree *free_cache;
00050 
00051        /*
00052         * void pointer for the user that created the cache.
00053         * You never know when it might not come in useful ....
00054         */
00055         void             *magic;
00056 
00057        /*
00058         * hint from the cache helper. contains the standard
00059         * handler arguments.
00060         */
00061        netsnmp_handler_args          *cache_hint;
00062 
00063         /*
00064          * For SNMP-management of the data caches
00065          */
00066         netsnmp_cache *next, *prev;
00067         oid *rootoid;
00068         int  rootoid_len;
00069 
00070     };
00071 
00072 
00073     void netsnmp_cache_reqinfo_insert(netsnmp_cache* cache,
00074                                       netsnmp_agent_request_info * reqinfo,
00075                                       const char *name);
00076     netsnmp_cache  *
00077        netsnmp_cache_reqinfo_extract(netsnmp_agent_request_info * reqinfo,
00078                                      const char *name);
00079     netsnmp_cache* netsnmp_extract_cache_info(netsnmp_agent_request_info *);
00080 
00081     int            netsnmp_cache_check_and_reload(netsnmp_cache * cache);
00082     int            netsnmp_cache_check_expired(netsnmp_cache *cache);
00083     int            netsnmp_cache_is_valid(    netsnmp_agent_request_info *,
00084                                               const char *name);
00086     int            netsnmp_is_cache_valid(    netsnmp_agent_request_info *);
00087     netsnmp_mib_handler *netsnmp_get_cache_handler(int, NetsnmpCacheLoad *,
00088                                                         NetsnmpCacheFree *,
00089                                                         const oid*, int);
00090     int   netsnmp_register_cache_handler(netsnmp_handler_registration *reginfo,
00091                                          int, NetsnmpCacheLoad *,
00092                                               NetsnmpCacheFree *);
00093 
00094     Netsnmp_Node_Handler netsnmp_cache_helper_handler;
00095 
00096     netsnmp_cache *
00097     netsnmp_cache_create(int timeout, NetsnmpCacheLoad * load_hook,
00098                          NetsnmpCacheFree * free_hook,
00099                          const oid * rootoid, int rootoid_len);
00100     int netsnmp_cache_remove(netsnmp_cache *cache);
00101     int netsnmp_cache_free(netsnmp_cache *cache);
00102 
00103     netsnmp_mib_handler *
00104     netsnmp_cache_handler_get(netsnmp_cache* cache);
00105     void netsnmp_cache_handler_owns_cache(netsnmp_mib_handler *handler);
00106 
00107     netsnmp_cache * netsnmp_cache_find_by_oid(const oid * rootoid,
00108                                               int rootoid_len);
00109 
00110     unsigned int netsnmp_cache_timer_start(netsnmp_cache *cache);
00111     void netsnmp_cache_timer_stop(netsnmp_cache *cache);
00112 
00113 /*
00114  * Flags affecting cache handler operation
00115  */
00116 #define NETSNMP_CACHE_DONT_INVALIDATE_ON_SET                0x0001
00117 #define NETSNMP_CACHE_DONT_FREE_BEFORE_LOAD                 0x0002
00118 #define NETSNMP_CACHE_DONT_FREE_EXPIRED                     0x0004
00119 #define NETSNMP_CACHE_DONT_AUTO_RELEASE                     0x0008
00120 #define NETSNMP_CACHE_PRELOAD                               0x0010
00121 #define NETSNMP_CACHE_AUTO_RELOAD                           0x0020
00122 #define NETSNMP_CACHE_RESET_TIMER_ON_USE                    0x0040
00123 
00124 #define NETSNMP_CACHE_HINT_HANDLER_ARGS                     0x1000
00125 
00126 
00127 #ifdef __cplusplus
00128 }
00129 #endif
00130 #endif /* NETSNMP_CACHE_HANDLER_H */