1
############################################################ -*- c -*-
1
#######################################################################
2
2
###generic include for XXX. Do not use directly.
4
### $Id: mfd-access-container-cached-defines.m2i,v 1.16.2.1 2005/01/06 14:51:52 rstory Exp $
4
### $Id: mfd-access-container-cached-defines.m2i,v 1.21 2005/11/29 19:28:56 rstory Exp $
5
5
########################################################################
6
6
@if $m2c_mark_boundary == 1@
7
/** START code generated by $RCSfile: mfd-access-container-cached-defines.m2i,v $ $Revision: 1.16.2.1 $ */
7
/** START code generated by $RCSfile: mfd-access-container-cached-defines.m2i,v $ $Revision: 1.21 $ */
9
9
##//####################################################################
10
10
##//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
11
11
##//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
12
12
@if $m2c_processing_type eq 'h'@
15
* TODO:180:o: Review $context cache timeout.
16
* The number of seconds before the cache times out
14
@ if $m2c_data_cache != 1@
15
void ${context}_container_init(netsnmp_container **container_ptr_ptr);
18
* TODO:180:o: Review ${context} cache timeout.
19
* The number of seconds before the cache times out
18
21
#define $context.uc_CACHE_TIMEOUT 60
20
23
void ${context}_container_init(netsnmp_container **container_ptr_ptr,
21
24
netsnmp_cache *cache);
26
void ${context}_container_shutdown(netsnmp_container *container_ptr);
28
int ${context}_container_load(netsnmp_container *container);
29
void ${context}_container_free(netsnmp_container *container);
31
@ if $m2c_data_cache == 1@
22
32
int ${context}_cache_load(netsnmp_container *container);
23
33
void ${context}_cache_free(netsnmp_container *container);
25
36
@ if $m2c_include_examples == 1@
27
38
/* *********************************************************************
28
39
* Since we have no idea how you really access your data, we'll go with
29
40
* a worst case example: a flat text file.
30
@ if $m2c_data_transient != 2@
31
@ print Example code is for fully transient data. Either turn off@
32
@ print m2c_include_examples or set m2c_data_transient to 2.@
36
42
#define MAX_LINE_SIZE 256
42
48
##//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
43
49
@if $m2c_processing_type eq 'c'@
45
* container-cached overview
49
/***********************************************************************
53
***********************************************************************/
55
56
* container initialization
58
59
* create a custom container, use this parameter to return it
59
60
* to the MFD helper. If set to NULL, the MFD helper will
60
61
* allocate a container for you.
62
@ if $m2c_data_cache == 1@
61
63
* @param cache A pointer to a cache structure. You can set the timeout
62
64
* and other cache flags using this pointer.
64
67
* This function is called at startup to allow you to customize certain
65
68
* aspects of the access method. For the most part, it is for advanced
66
69
* users. The default code should suffice for most cases. If no custom
67
70
* container is allocated, the MFD code will create one for your.
72
@ if $m2c_data_cache == 1@
69
73
* This is also the place to set up cache behavior. The default, to
70
74
* simply set the cache timeout, will work well with the default
71
75
* container. If you are using a custom container, you may want to
72
76
* look at the cache helper documentation to see if there are any
73
77
* flags you want to set.
76
81
* This would also be a good place to do any initialization needed
77
82
* for you data source. For example, opening a connection to another
78
83
* process that will supply the data, opening a database, etc.
86
@ if $m2c_data_cache != 1@
87
${context}_container_init(netsnmp_container **container_ptr_ptr)
81
89
${context}_container_init(netsnmp_container **container_ptr_ptr,
84
93
DEBUGMSGTL(("verbose:${context}:${context}_container_init","called\n"));
86
if((NULL == cache) || (NULL == container_ptr_ptr)) {
87
snmp_log(LOG_ERR,"bad params to ${context}_container_init\n");
95
if (NULL == container_ptr_ptr) {
96
snmp_log(LOG_ERR,"bad container param to ${context}_container_init\n");
103
118
* cache->enabled to 0.
105
120
cache->timeout = $context.uc_CACHE_TIMEOUT; /* seconds */
106
122
} /* ${context}_container_init */
111
* TODO:350:M: Implement $context cache load
127
* @param container_ptr_ptr A pointer to the container.
129
* This function is called at shutdown to allow you to customize certain
130
* aspects of the access method. For the most part, it is for advanced
131
* users. The default code should suffice for most cases.
133
* This function is called before ${context}_container_free().
136
* This would also be a good place to do any cleanup needed
137
* for you data source. For example, closing a connection to another
138
* process that supplied the data, closing a database, etc.
141
${context}_container_shutdown(netsnmp_container *container_ptr)
143
DEBUGMSGTL(("verbose:${context}:${context}_container_shutdown","called\n"));
145
if (NULL == container_ptr) {
146
snmp_log(LOG_ERR,"bad params to ${context}_container_shutdown\n");
150
} /* ${context}_container_shutdown */
155
* TODO:350:M: Implement $context data load
156
@ if $m2c_data_cache == 1@
157
* This function will also be called by the cache helper to load
158
* the container again (after the container free function has been
159
* called to free the previous contents).
113
162
* @param container container to which items should be inserted
116
165
* @retval MFD_RESOURCE_UNAVAILABLE : Can't access data source
117
166
* @retval MFD_ERROR : other error.
119
* This function is called to cache the index(es) (and data, optionally)
168
* This function is called to load the index(es) (and data, optionally)
120
169
* for the every row in the data set.
123
* While loading the cache, the only important thing is the indexes.
172
* While loading the data, the only important thing is the indexes.
124
173
* If access to your data is cheap/fast (e.g. you have a pointer to a
125
174
* structure in memory), it would make sense to update the data here.
126
175
* If, however, the accessing the data invovles more work (e.g. parsing
139
${context}_cache_load(netsnmp_container *container)
188
${context}_container_load(netsnmp_container *container)
141
190
${context}_rowreq_ctx *rowreq_ctx;
142
191
size_t count = 0;
143
@if $m2c_include_examples == 1@
146
* this example code is based on a data source that is a
147
* text file to be read and parsed.
150
char line[MAX_LINE_SIZE];
152
194
* temporary storage for index values
165
207
@ end@ # needlength
166
208
@ include node-storage.m2i@
167
209
@ end@ // foreach
211
@if $m2c_include_examples == 1@
214
* this example code is based on a data source that is a
215
* text file to be read and parsed.
218
char line[MAX_LINE_SIZE];
168
219
@end@ // examples
170
DEBUGMSGTL(("verbose:${context}:${context}_cache_load","called\n"));
221
DEBUGMSGTL(("verbose:${context}:${context}_container_load","called\n"));
172
223
@if $m2c_include_examples == 1@
302
DEBUGMSGT(("verbose:${context}:${context}_cache_load",
353
DEBUGMSGT(("verbose:${context}:${context}_container_load",
303
354
"inserted %d records\n", count));
305
356
return MFD_SUCCESS;
306
} /* ${context}_cache_load */
357
} /* ${context}_container_load */
311
362
* @param container container with all current items
328
${context}_cache_free(netsnmp_container *container)
379
${context}_container_free(netsnmp_container *container)
330
DEBUGMSGTL(("verbose:${context}:${context}_cache_free","called\n"));
381
DEBUGMSGTL(("verbose:${context}:${context}_container_free","called\n"));
333
* TODO:380:M: Free $context cache.
384
* TODO:380:M: Free $context container data.
335
} /* ${context}_cache_free */
386
} /* ${context}_container_free */
337
388
@end@ // m2c_processing_type eq 'c'
338
389
########################################################################
340
391
##//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
341
392
##//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
342
393
@if $m2c_processing_type eq 'i'@
394
@ if $m2c_data_cache == 1@
395
static void _container_free(netsnmp_container *container);
362
return ${context}_cache_load((netsnmp_container*)cache->magic);
416
return ${context}_container_load((netsnmp_container*)cache->magic);
363
417
} /* _cache_load */
369
_cache_item_free(${context}_rowreq_ctx *rowreq_ctx, void *context)
371
DEBUGMSGTL(("internal:${context}:_cache_item_free","called\n"));
373
if(NULL == rowreq_ctx)
376
${context}_release_rowreq_ctx(rowreq_ctx);
377
} /* _cache_item_free */
383
423
_cache_free(netsnmp_cache *cache, void *magic)
385
425
netsnmp_container *container;
394
434
container = (netsnmp_container*)cache->magic;
436
_container_free(container);
444
_container_item_free(${context}_rowreq_ctx *rowreq_ctx, void *context)
446
DEBUGMSGTL(("internal:${context}:_container_item_free","called\n"));
448
if(NULL == rowreq_ctx)
451
${context}_release_rowreq_ctx(rowreq_ctx);
452
} /* _container_item_free */
458
_container_free(netsnmp_container *container)
460
DEBUGMSGTL(("internal:${context}:_container_free","called\n"));
462
if (NULL == container) {
463
snmp_log(LOG_ERR, "invalid container in ${context}_container_free\n");
399
${context}_cache_free(container);
470
${context}_container_free(container);
402
473
* free all items. inefficient, but easy.
404
475
CONTAINER_CLEAR(container,
405
(netsnmp_container_obj_func *)_cache_item_free,
476
(netsnmp_container_obj_func *)_container_item_free,
478
} /* _container_free */
411
* initialize the iterator container with functions or wrappers
482
* initialize the container with functions or wrappers
414
485
_${context}_container_init(${context}_interface_ctx *if_ctx)
416
487
DEBUGMSGTL(("internal:${context}:_${context}_container_init","called\n"));
489
@ if $m2c_data_cache == 1@
423
495
netsnmp_cache_find_by_oid(PARTNER_oid, OID_LENGTH(PARTNER_oid));
428
497
if_ctx->cache = netsnmp_cache_create(30, /* timeout in seconds */
429
498
_cache_load, _cache_free,
439
508
if_ctx->cache->flags = NETSNMP_CACHE_DONT_INVALIDATE_ON_SET;
441
510
${context}_container_init(&if_ctx->container, if_ctx->cache);
515
${context}_container_init(&if_ctx->container);
442
517
if(NULL == if_ctx->container)
443
518
if_ctx->container = netsnmp_container_find("${context}:table_container");
444
519
if(NULL == if_ctx->container) {
446
521
"${context}_container_init\n");
449
if_ctx->cache->magic = (void*)if_ctx->container;
525
@ if $m2c_data_cache == 1@
526
if (NULL != if_ctx->cache)
527
if_ctx->cache->magic = (void*)if_ctx->container;
450
529
} /* _${context}_container_init */
533
* shutdown the container with functions or wrappers
536
_${context}_container_shutdown(${context}_interface_ctx *if_ctx)
538
DEBUGMSGTL(("internal:${context}:_${context}_container_shutdown","called\n"));
540
${context}_container_shutdown(if_ctx->container);
542
_container_free(if_ctx->container);
544
} /* _${context}_container_shutdown */
452
546
@end@ // m2c_processing_type eq 'i'
453
547
########################################################################
454
548
##//####################################################################
456
550
##//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
457
551
@if $m2c_processing_type eq 'r'@
459
container-cached summary
554
------------------------
555
The container data access code is for cases when you want to
556
store your data in the agent/sub-agent.
558
... to be continued...
561
@ if $m2c_data_cache == 1@
460
563
------------------------
461
564
The container-cached data access code is for cases when you want to
462
565
cache your data in the agent/sub-agent.
464
567
... to be continued...
467
########################################################################
470
TODO : update index for the raw data
471
FUNC : ${context}_indexes_set
472
WHERE: ${context}_data_access.c
474
This is a convenience function for setting the index context from
475
the native C data. Where necessary, value mapping should be done.
477
@if $mfd_readme_verbose == 1@
478
This function should update the table index values (found in
479
tbl_idx) for the given raw data.
483
571
@end@ // m2c_processing_type eq 'r'
484
572
########################################################################
485
573
##//####################################################################
486
574
@if $m2c_mark_boundary == 1@
487
/** END code generated by $RCSfile: mfd-access-container-cached-defines.m2i,v $ $Revision: 1.16.2.1 $ */
575
/** END code generated by $RCSfile: mfd-access-container-cached-defines.m2i,v $ $Revision: 1.21 $ */