Revert "Revert "and added files""
[bcm963xx.git] / userapps / opensource / net-snmp / local / mib2c.iterate.conf
1 ## -*- c -*-
2 ######################################################################
3 ## Do the .h file
4 ######################################################################
5 @open ${name}.h@
6 /*
7  * Note: this file originally auto-generated by mib2c using
8  *        $Id: mib2c.iterate.conf,v 5.5 2002/12/16 22:50:18 hardaker Exp $
9  */
10 #ifndef $name.uc_H
11 #define $name.uc_H
12
13 /* function declarations */
14 void init_$name(void);
15 @foreach $i table@
16 void initialize_table_$i(void);
17 Netsnmp_Node_Handler ${i}_handler;
18
19 Netsnmp_First_Data_Point  ${i}_get_first_data_point;
20 Netsnmp_Next_Data_Point   ${i}_get_next_data_point;
21 @end@
22 @foreach $i table@
23
24 /* column number definitions for table $i */
25     @foreach $c column@
26        #define COLUMN_$c.uc             $c.subid
27     @end@
28 @end@
29 #endif /* $name.uc_H */
30 ######################################################################
31 ## Do the .c file
32 ######################################################################
33 @open ${name}.c@
34 /*
35  * Note: this file originally auto-generated by mib2c using
36  *        $Id: mib2c.iterate.conf,v 5.5 2002/12/16 22:50:18 hardaker Exp $
37  */
38
39 #include <net-snmp/net-snmp-config.h>
40 #include <net-snmp/net-snmp-includes.h>
41 #include <net-snmp/agent/net-snmp-agent-includes.h>
42 #include "${name}.h"
43
44 @foreach $i table@
45 /** Initialize the $i table by defining its contents and how it's structured */
46 void
47 initialize_table_$i(void)
48 {
49     static oid ${i}_oid[] = {$i.commaoid};
50     netsnmp_table_registration_info *table_info;
51     netsnmp_handler_registration *my_handler;
52     netsnmp_iterator_info *iinfo;
53
54     /* create the table structure itself */
55     table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
56     iinfo = SNMP_MALLOC_TYPEDEF(netsnmp_iterator_info);
57
58     /* if your table is read only, it's easiest to change the
59        HANDLER_CAN_RWRITE definition below to HANDLER_CAN_RONLY */
60     my_handler = netsnmp_create_handler_registration("$i",
61                                              ${i}_handler,
62                                              ${i}_oid,
63                                              OID_LENGTH(${i}_oid),
64                                              HANDLER_CAN_RWRITE);
65             
66     if (!my_handler || !table_info || !iinfo)
67         return; /* mallocs failed */
68
69     /***************************************************
70      * Setting up the table's definition
71      */
72     netsnmp_table_helper_add_indexes(table_info,
73     @foreach $idx index@
74                                   $idx.type, /* index: $idx */
75     @end@
76                              0);
77
78     @eval $minv = 0xffffffff@
79     @eval $maxv = 0@
80     @foreach $c column@
81         @if $c.access =~ /(Read|Create)/@
82           @eval $minv = min($minv, $c.subid)@
83           @eval $maxv = max($maxv, $c.subid)@
84         @end@
85     @end@
86     table_info->min_column = $minv;
87     table_info->max_column = $maxv;
88
89     /* iterator access routines */
90     iinfo->get_first_data_point = ${i}_get_first_data_point;
91     iinfo->get_next_data_point = ${i}_get_next_data_point;
92
93     iinfo->table_reginfo = table_info;
94
95     /***************************************************
96      * registering the table with the master agent
97      */
98     DEBUGMSGTL(("initialize_table_$i",
99                 "Registering table $i as a table iterator\n"));          
100     netsnmp_register_table_iterator(my_handler, iinfo);
101 }
102 @end@
103
104 /** Initializes the $name module */
105 void
106 init_$name(void)
107 {
108
109   /* here we initialize all the tables we're planning on supporting */
110   @foreach $i table@
111     initialize_table_$i();
112   @end@
113 }
114 @foreach $i table@
115
116 /** returns the first data point within the $i table data.
117
118     Set the my_loop_context variable to the first data point structure
119     of your choice (from which you can find the next one).  This could
120     be anything from the first node in a linked list, to an integer
121     pointer containing the beginning of an array variable.
122
123     Set the my_data_context variable to something to be returned to
124     you later that will provide you with the data to return in a given
125     row.  This could be the same pointer as what my_loop_context is
126     set to, or something different.
127
128     The put_index_data variable contains a list of snmp variable
129     bindings, one for each index in your table.  Set the values of
130     each appropriately according to the data matching the first row
131     and return the put_index_data variable at the end of the function.
132 */
133 netsnmp_variable_list *
134 ${i}_get_first_data_point(void **my_loop_context, void **my_data_context,
135                           netsnmp_variable_list *put_index_data,
136                           netsnmp_iterator_info *mydata)
137 {
138
139     netsnmp_variable_list *vptr;
140
141     *my_loop_context = /* XXX */;
142     *my_data_context = /* XXX */;
143
144     vptr = put_index_data;
145     
146     @foreach $idx index@
147     snmp_set_var_value(vptr, (u_char *) /* XXX: $idx data */, /* XXX: length of $idx data */);
148     vptr = vptr->next_variable;
149     @end@
150
151     return put_index_data;
152 }
153
154 /** functionally the same as ${i}_get_first_data_point, but
155    my_loop_context has already been set to a previous value and should
156    be updated to the next in the list.  For example, if it was a
157    linked list, you might want to cast it and the return
158    my_loop_context->next.  The my_data_context pointer should be set
159    to something you need later and the indexes in put_index_data
160    updated again. */
161
162 netsnmp_variable_list *
163 ${i}_get_next_data_point(void **my_loop_context, void **my_data_context,
164                          netsnmp_variable_list *put_index_data,
165                          netsnmp_iterator_info *mydata)
166 {
167
168     netsnmp_variable_list *vptr;
169
170     *my_loop_context = /* XXX */;
171     *my_data_context = /* XXX */;
172
173     vptr = put_index_data;
174     
175     @foreach $idx index@
176     snmp_set_var_value(vptr, (u_char *) /* XXX: $idx data */, /* XXX: length of $idx data */);
177     vptr = vptr->next_variable;
178     @end@
179
180     return put_index_data;
181 }
182
183 /** handles requests for the $i table, if anything else needs to be done */
184 int
185 ${i}_handler(
186     netsnmp_mib_handler               *handler,
187     netsnmp_handler_registration      *reginfo,
188     netsnmp_agent_request_info        *reqinfo,
189     netsnmp_request_info              *requests) {
190
191     netsnmp_request_info *request;
192     netsnmp_table_request_info *table_info;
193     netsnmp_variable_list *var;
194     
195     for(request = requests; request; request = request->next) {
196         var = request->requestvb;
197         if (request->processed != 0)
198             continue;
199
200         /* perform anything here that you need to do before each
201            request is processed. */
202
203         /* the following extracts the my_data_context pointer set in
204            the loop functions above.  You can then use the results to
205            help return data for the columns of the $i table in question */
206         /* XXX */ = (/* XXX */ *) netsnmp_extract_iterator_context(request);
207         if (/* XXX */ == NULL) {
208             if (reqinfo->mode == MODE_GET) {
209                 netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
210                 continue;
211             }
212             /* XXX: no row existed, if you support creation and this is a
213                set, start dealing with it here, else continue */
214         }
215
216         /* extracts the information about the table from the request */
217         table_info = netsnmp_extract_table_info(request);
218         /* table_info->colnum contains the column number requested */
219         /* table_info->indexes contains a linked list of snmp variable
220            bindings for the indexes of the table.  Values in the list
221            have been set corresponding to the indexes of the
222            request */
223         if (table_info==NULL) {
224             continue;
225         }
226
227         switch(reqinfo->mode) {
228             /* the table_iterator helper should change all GETNEXTs
229                into GETs for you automatically, so you don't have to
230                worry about the GETNEXT case.  Only GETs and SETs need
231                to be dealt with here */
232             case MODE_GET:
233                 switch(table_info->colnum) {
234                     @foreach $c column@
235                         @if $c.access =~ /(Read|Create)/@
236                     case COLUMN_$c.uc:
237                         snmp_set_var_typed_value(var, $c.type, (u_char *) /* XXX: column data */, /* XXX: column data length */);
238                         break;
239
240                         @end@
241                     @end@
242                     default:
243                         /* We shouldn't get here */
244                         snmp_log(LOG_ERR, "problem encountered in ${i}_handler: unknown column\n");
245                 }
246                 break;
247
248             case MODE_SET_RESERVE1:
249                 /* set handling... */
250
251             default:
252                 snmp_log(LOG_ERR, "problem encountered in ${i}_handler: unsupported mode\n");
253         }
254     }
255     return SNMP_ERR_NOERROR;
256 }