2008/10/2 Jörg Westheide <[EMAIL PROTECTED]>: > I'm trying to implement a cache for some scalars. Therefore I'm trying > to understand how a cache handler works and interacts with the other > handlers. I'm especially interested in understanding how the data from > the cache is propagated to the other handlers > > Can someone please explain this or give me some pointers?
The basic idea of the cache helper is to separate out the loading of MIB data (typically from some underlying system) from the task of using that data to process an SNMP request. So the data is loaded by a "cache_load" routine (which is invoked by the cache helper handler), and then used in the normal end-user handler routine. The cache helper itself is only really concerned with deciding when the data should be loaded (or re-loaded). It doesn't care what this data is (a single scalar, a group of scalars, one or more tables, or some combination of these). Neither does it dictate how the data should be passed from the cache_load routine to the end-handler. One possibility is to use the 'vmagic' parameter of the cache_load routine. This is an opaque pointer, which is made available to the handler routine. Another possibility is to use the 'magic' field of the 'cache' parameter. This is also an opaque pointer, which is again made available to the handler routine. (In fact, 'vmagic' is exactly the same as 'cache->magic', so the end-handler would use the same approach in either case) This is the approach used in 'mibgroup/agent/extend.c' It works best when the data is only used by the end-handler routine, so would be suitable for implementing scalar objects (individually, or as a group). Another possibility is for the cache_load routine to use suitable APIs calls to populate the data structures used by the MIB module. The advantage of this approach is that the data is then available to the *whole* of the handler chain, including table helpers, which might need to use this information for intermediate processing. There are examples of this style in the current development trunk, in some of the recent HostRes rewrites. Another possibility is to use a private data structure, shared between the cache_load routine and the end handler. This is perhaps not the cleanest approach from a coding purist's point of view, but it's simple and it works. Fundamentally, as long as the two user-provided routines (cache_load and the final handler) agree how to communicate the data between them, then the cache helper doesn't care how this is done. Dave ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Net-snmp-users mailing list [email protected] Please see the following page to unsubscribe or change other options: https://lists.sourceforge.net/lists/listinfo/net-snmp-users
