~ubuntu-branches/debian/lenny/net-snmp/lenny

« back to all changes in this revision

Viewing changes to local/mib2c-conf.d/mfd-access-container-cached-defines.m2i

  • Committer: Bazaar Package Importer
  • Author(s): Steve Kowalik
  • Date: 2007-05-10 22:20:23 UTC
  • Revision ID: james.westby@ubuntu.com-20070510222023-3fr07xb9i17xvq32
Tags: upstream-5.3.1
ImportĀ upstreamĀ versionĀ 5.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
############################################################  -*- c -*-
 
1
#######################################################################
2
2
###generic include for XXX. Do not use directly.
3
3
###
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 $ */
8
8
@end@
9
9
##//####################################################################
10
10
##//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
11
11
##//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
12
12
@if $m2c_processing_type eq 'h'@
13
13
 
14
 
/*
15
 
 * TODO:180:o: Review $context cache timeout.
16
 
 * The number of seconds before the cache times out
17
 
 */
 
14
@   if $m2c_data_cache != 1@
 
15
void ${context}_container_init(netsnmp_container **container_ptr_ptr);
 
16
@   else@
 
17
    /*
 
18
     * TODO:180:o: Review ${context} cache timeout.
 
19
     * The number of seconds before the cache times out
 
20
     */
18
21
#define $context.uc_CACHE_TIMEOUT   60
19
22
 
20
23
void ${context}_container_init(netsnmp_container **container_ptr_ptr,
21
24
                             netsnmp_cache *cache);
 
25
@   end@ # data cache
 
26
void ${context}_container_shutdown(netsnmp_container *container_ptr);
 
27
 
 
28
int ${context}_container_load(netsnmp_container *container);
 
29
void ${context}_container_free(netsnmp_container *container);
 
30
 
 
31
@   if $m2c_data_cache == 1@
22
32
int ${context}_cache_load(netsnmp_container *container);
23
33
void ${context}_cache_free(netsnmp_container *container);
24
34
 
 
35
@   end@
25
36
@   if $m2c_include_examples == 1@
26
37
$example_start
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.@
33
 
 @      exit@
34
 
 @   end@
35
41
 */
36
42
#define MAX_LINE_SIZE 256
37
43
$example_end
42
48
##//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
43
49
@if $m2c_processing_type eq 'c'@
44
50
/**
45
 
 * container-cached overview
 
51
 * container overview
46
52
 *
47
53
 */
48
54
 
49
 
/***********************************************************************
50
 
 *
51
 
 * cache
52
 
 *
53
 
 ***********************************************************************/
54
55
/**
55
56
 * container initialization
56
57
 *
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.
 
65
@   end@
63
66
 *
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.
68
71
 *
 
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.
74
78
 *
 
79
@   end@
75
80
 * @remark
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.
79
84
 */
80
85
void
 
86
@   if $m2c_data_cache != 1@
 
87
${context}_container_init(netsnmp_container **container_ptr_ptr)
 
88
@   else@
81
89
${context}_container_init(netsnmp_container **container_ptr_ptr,
82
 
                        netsnmp_cache *cache)
 
90
                             netsnmp_cache *cache)
 
91
@   end@
83
92
{
84
93
    DEBUGMSGTL(("verbose:${context}:${context}_container_init","called\n"));
85
94
    
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");
88
97
        return;
89
98
    }
90
99
 
94
103
     */
95
104
    *container_ptr_ptr = NULL;
96
105
 
 
106
@if $m2c_data_cache == 1@
 
107
    if (NULL == cache) {
 
108
        snmp_log(LOG_ERR,"bad cache param to ${context}_container_init\n");
 
109
        return;
 
110
    }
 
111
 
97
112
    /*
98
113
     * TODO:345:A: Set up $context cache properties.
99
114
     *
103
118
     * cache->enabled to 0.
104
119
     */
105
120
    cache->timeout = $context.uc_CACHE_TIMEOUT; /* seconds */
 
121
@end@
106
122
} /* ${context}_container_init */
107
123
 
108
124
/**
109
 
 * load cache data
110
 
 *
111
 
 * TODO:350:M: Implement $context cache load
 
125
 * container shutdown
 
126
 *
 
127
 * @param container_ptr_ptr A pointer to the container.
 
128
 *
 
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.
 
132
 *
 
133
 *  This function is called before ${context}_container_free().
 
134
 *
 
135
 * @remark
 
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.
 
139
 */
 
140
void
 
141
${context}_container_shutdown(netsnmp_container *container_ptr)
 
142
{
 
143
    DEBUGMSGTL(("verbose:${context}:${context}_container_shutdown","called\n"));
 
144
    
 
145
    if (NULL == container_ptr) {
 
146
        snmp_log(LOG_ERR,"bad params to ${context}_container_shutdown\n");
 
147
        return;
 
148
    }
 
149
 
 
150
} /* ${context}_container_shutdown */
 
151
 
 
152
/**
 
153
 * load initial data
 
154
 *
 
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).
 
160
@   end@
112
161
 *
113
162
 * @param container container to which items should be inserted
114
163
 *
116
165
 * @retval MFD_RESOURCE_UNAVAILABLE : Can't access data source
117
166
 * @retval MFD_ERROR                : other error.
118
167
 *
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.
121
170
 *
122
171
 * @remark
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
136
185
 *
137
186
 */
138
187
int
139
 
${context}_cache_load(netsnmp_container *container)
 
188
${context}_container_load(netsnmp_container *container)
140
189
{
141
190
    ${context}_rowreq_ctx *rowreq_ctx;
142
191
    size_t                 count = 0;
143
 
@if $m2c_include_examples == 1@
144
 
    
145
 
    /*
146
 
     * this example code is based on a data source that is a
147
 
     * text file to be read and parsed.
148
 
     */
149
 
    FILE *filep;
150
 
    char line[MAX_LINE_SIZE];
 
192
 
151
193
    /*
152
194
     * temporary storage for index values
153
195
     */
165
207
@    end@ # needlength
166
208
@    include node-storage.m2i@
167
209
@  end@ // foreach
 
210
 
 
211
@if $m2c_include_examples == 1@
 
212
    
 
213
    /*
 
214
     * this example code is based on a data source that is a
 
215
     * text file to be read and parsed.
 
216
     */
 
217
    FILE *filep;
 
218
    char line[MAX_LINE_SIZE];
168
219
@end@ // examples
169
220
 
170
 
    DEBUGMSGTL(("verbose:${context}:${context}_cache_load","called\n"));
 
221
    DEBUGMSGTL(("verbose:${context}:${context}_container_load","called\n"));
171
222
 
172
223
@if $m2c_include_examples == 1@
173
224
$example_start
252
303
@   end@ # foreach index
253
304
               )) {
254
305
            snmp_log(LOG_ERR,"error setting index while loading "
255
 
                     "${context} cache.\n");
 
306
                     "${context} data.\n");
256
307
            ${context}_release_rowreq_ctx(rowreq_ctx);
257
308
            continue;
258
309
        }
299
350
$example_end
300
351
@end@ # example
301
352
 
302
 
    DEBUGMSGT(("verbose:${context}:${context}_cache_load",
 
353
    DEBUGMSGT(("verbose:${context}:${context}_container_load",
303
354
               "inserted %d records\n", count));
304
355
 
305
356
    return MFD_SUCCESS;
306
 
} /* ${context}_cache_load */
 
357
} /* ${context}_container_load */
307
358
 
308
359
/**
309
 
 * cache clean up
 
360
 * container clean up
310
361
 *
311
362
 * @param container container with all current items
312
363
 *
325
376
 *
326
377
 */
327
378
void
328
 
${context}_cache_free(netsnmp_container *container)
 
379
${context}_container_free(netsnmp_container *container)
329
380
{
330
 
    DEBUGMSGTL(("verbose:${context}:${context}_cache_free","called\n"));
 
381
    DEBUGMSGTL(("verbose:${context}:${context}_container_free","called\n"));
331
382
 
332
383
    /*
333
 
     * TODO:380:M: Free $context cache.
 
384
     * TODO:380:M: Free $context container data.
334
385
     */
335
 
} /* ${context}_cache_free */
 
386
} /* ${context}_container_free */
336
387
 
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);
 
396
 
343
397
/**
344
398
 * @internal
345
399
 */
359
413
    /*
360
414
     * call user code
361
415
     */
362
 
    return ${context}_cache_load((netsnmp_container*)cache->magic);
 
416
    return ${context}_container_load((netsnmp_container*)cache->magic);
363
417
} /* _cache_load */
364
418
 
365
419
/**
366
420
 * @internal
367
421
 */
368
422
static void
369
 
_cache_item_free(${context}_rowreq_ctx *rowreq_ctx, void *context)
370
 
{
371
 
    DEBUGMSGTL(("internal:${context}:_cache_item_free","called\n"));
372
 
 
373
 
    if(NULL == rowreq_ctx)
374
 
        return;
375
 
 
376
 
    ${context}_release_rowreq_ctx(rowreq_ctx);
377
 
} /* _cache_item_free */
378
 
 
379
 
/**
380
 
 * @internal
381
 
 */
382
 
static void
383
423
_cache_free(netsnmp_cache *cache, void *magic)
384
424
{
385
425
    netsnmp_container *container;
393
433
 
394
434
    container = (netsnmp_container*)cache->magic;
395
435
 
 
436
    _container_free(container);
 
437
} /* _cache_free */
 
438
 
 
439
@   end@ # cache
 
440
/**
 
441
 * @internal
 
442
 */
 
443
static void
 
444
_container_item_free(${context}_rowreq_ctx *rowreq_ctx, void *context)
 
445
{
 
446
    DEBUGMSGTL(("internal:${context}:_container_item_free","called\n"));
 
447
 
 
448
    if(NULL == rowreq_ctx)
 
449
        return;
 
450
 
 
451
    ${context}_release_rowreq_ctx(rowreq_ctx);
 
452
} /* _container_item_free */
 
453
 
 
454
/**
 
455
 * @internal
 
456
 */
 
457
static void
 
458
_container_free(netsnmp_container *container)
 
459
{
 
460
    DEBUGMSGTL(("internal:${context}:_container_free","called\n"));
 
461
 
 
462
    if (NULL == container) {
 
463
        snmp_log(LOG_ERR, "invalid container in ${context}_container_free\n");
 
464
        return;
 
465
    }
 
466
 
396
467
    /*
397
468
     * call user code
398
469
     */
399
 
    ${context}_cache_free(container);
 
470
    ${context}_container_free(container);
400
471
    
401
472
    /*
402
473
     * free all items. inefficient, but easy.
403
474
     */
404
475
    CONTAINER_CLEAR(container,
405
 
                    (netsnmp_container_obj_func *)_cache_item_free,
 
476
                    (netsnmp_container_obj_func *)_container_item_free,
406
477
                    NULL);
407
 
} /* _cache_free */
 
478
} /* _container_free */
408
479
 
409
480
/**
410
481
 * @internal
411
 
 * initialize the iterator container with functions or wrappers
 
482
 * initialize the container with functions or wrappers
412
483
 */
413
484
void
414
485
_${context}_container_init(${context}_interface_ctx *if_ctx)
415
486
{
416
487
    DEBUGMSGTL(("internal:${context}:_${context}_container_init","called\n"));
417
 
    
 
488
 
 
489
@   if $m2c_data_cache == 1@
 
490
    /*
 
491
     * cache init
 
492
     */
418
493
@    if 0@
419
 
    /*
420
 
     * find cache
421
 
     */
422
494
    if_ctx->cache =
423
495
        netsnmp_cache_find_by_oid(PARTNER_oid, OID_LENGTH(PARTNER_oid));
424
496
@    else@
425
 
    /*
426
 
     * set up the cache
427
 
     */
428
497
    if_ctx->cache = netsnmp_cache_create(30, /* timeout in seconds */
429
498
                                         _cache_load, _cache_free,
430
499
                                         ${context}_oid,
439
508
    if_ctx->cache->flags = NETSNMP_CACHE_DONT_INVALIDATE_ON_SET;
440
509
 
441
510
    ${context}_container_init(&if_ctx->container, if_ctx->cache);
 
511
@   else@
 
512
    /*
 
513
     * container init
 
514
     */    
 
515
    ${context}_container_init(&if_ctx->container);
 
516
@   end@ data cache
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");
447
522
        return;
448
523
    }
449
 
    if_ctx->cache->magic = (void*)if_ctx->container;
 
524
 
 
525
@   if $m2c_data_cache == 1@
 
526
    if (NULL != if_ctx->cache)
 
527
        if_ctx->cache->magic = (void*)if_ctx->container;
 
528
@   end@
450
529
} /* _${context}_container_init */
451
530
 
 
531
/**
 
532
 * @internal
 
533
 * shutdown the container with functions or wrappers
 
534
 */
 
535
void
 
536
_${context}_container_shutdown(${context}_interface_ctx *if_ctx)
 
537
{
 
538
    DEBUGMSGTL(("internal:${context}:_${context}_container_shutdown","called\n"));
 
539
 
 
540
    ${context}_container_shutdown(if_ctx->container);
 
541
 
 
542
    _container_free(if_ctx->container);
 
543
 
 
544
} /* _${context}_container_shutdown */
 
545
 
452
546
@end@ // m2c_processing_type eq 'i'
453
547
########################################################################
454
548
##//####################################################################
456
550
##//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
457
551
@if $m2c_processing_type eq 'r'@
458
552
##
459
 
  container-cached summary
 
553
  container summary
 
554
  ------------------------
 
555
    The container data access code is for cases when you want to
 
556
    store your data in the agent/sub-agent.
 
557
 
 
558
    ... to be continued...
 
559
 
 
560
 
 
561
@   if $m2c_data_cache == 1@
 
562
  cache summary
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...
465
568
 
466
569
 
467
 
########################################################################
468
 
  Updating the Index
469
 
  ------------------
470
 
    TODO : update index for the raw data
471
 
    FUNC : ${context}_indexes_set
472
 
    WHERE: ${context}_data_access.c
473
 
 
474
 
    This is a convenience function for setting the index context from
475
 
    the native C data. Where necessary, value mapping should be done.
476
 
 
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.
480
 
 
481
 
    @end@
482
 
 
 
570
@   end@
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 $ */
488
576
@end@