added files
[bcm963xx.git] / userapps / opensource / net-snmp / local / mib2c.scalar.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.scalar.conf,v 1.5 2002/07/18 14:18:52 dts12 Exp $
9  */
10 #ifndef $name.uc_H
11 #define $name.uc_H
12
13 /* function declarations */
14 void init_$name(void);
15 @foreach $i scalar@
16 @if $i.settable@
17 Netsnmp_Node_Handler do_${i};
18 @end@
19 @if !$i.settable@
20 Netsnmp_Node_Handler get_${i};
21 @end@
22 @end@
23
24 #endif /* $name.uc_H */
25 ######################################################################
26 ## Do the .c file
27 ######################################################################
28 @open ${name}.c@
29 /*
30  * Note: this file originally auto-generated by mib2c using
31  *        $Id: mib2c.scalar.conf,v 1.5 2002/07/18 14:18:52 dts12 Exp $
32  */
33
34 #include <net-snmp/net-snmp-config.h>
35 #include <net-snmp/net-snmp-includes.h>
36 #include <net-snmp/agent/net-snmp-agent-includes.h>
37 #include "${name}.h"
38
39 /** Initializes the $name module */
40 void
41 init_$name(void)
42 {
43   @foreach $i scalar@
44     static oid ${i}_oid[] = { $i.commaoid, 0 };
45   @end@
46
47   DEBUGMSGTL(("$name", "Initializing\n"));
48
49   @foreach $i scalar@
50     @if !$i.settable@
51     netsnmp_register_read_only_instance(netsnmp_create_handler_registration
52                                         ("$i",
53                                          get_$i,
54                                          ${i}_oid,
55                                          OID_LENGTH(${i}_oid),
56                                          HANDLER_CAN_RONLY));
57     @end@
58     @if $i.settable@
59     netsnmp_register_instance(netsnmp_create_handler_registration
60                               ("$i",
61                                do_$i,
62                                ${i}_oid,
63                                OID_LENGTH(${i}_oid),
64                                HANDLER_CAN_RWRITE));
65     @end@
66   @end@
67 }
68
69 @foreach $i scalar@
70 int
71 @if !$i.settable@
72 get_$i(netsnmp_mib_handler *handler,
73 @end@
74 @if $i.settable@
75 do_$i(netsnmp_mib_handler *handler,
76 @end@
77                           netsnmp_handler_registration *reginfo,
78                           netsnmp_agent_request_info *reqinfo,
79                           netsnmp_request_info *requests)
80 {
81     /* We are never called for a GETNEXT if it's registered as a
82        "instance", as it's "magically" handled for us.  */
83
84     /* a instance handler also only hands us one request at a time, so
85        we don't need to loop over a list of requests; we'll only get one. */
86     
87     switch(reqinfo->mode) {
88
89         case MODE_GET:
90             snmp_set_var_typed_value(requests->requestvb, $i.type, (u_char *) /* XXX: a pointer to the scalar's data */, /* XXX: the length of the data in bytes */);
91             break;
92
93         @if $i.settable@
94         /*
95          * SET REQUEST
96          *
97          * multiple states in the transaction.  See:
98          * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
99          */
100         case MODE_SET_RESERVE1:
101             if (/* XXX: check incoming data in requests->requestvb->val.XXX for failures, like an incorrect type or an illegal value or ... */) {
102                 netsnmp_set_request_error(reqinfo, requests, /* XXX: set error code depending on problem (like SNMP_ERR_WRONGTYPE or SNMP_ERR_WRONGVALUE or ... */);
103             }
104             break;
105
106         case MODE_SET_RESERVE2:
107             /* XXX malloc "undo" storage buffer */
108             if (/* XXX if malloc, or whatever, failed: */) {
109                 netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_RESOURCESUNAVAILABLE);
110             }
111             break;
112
113         case MODE_SET_FREE:
114             /* XXX: free resources allocated in RESERVE1 and/or
115                RESERVE2.  Something failed somewhere, and the states
116                below won't be called. */
117             break;
118
119         case MODE_SET_ACTION:
120             /* XXX: perform the value change here */
121             if (/* XXX: error? */) {
122                 netsnmp_set_request_error(reqinfo, requests, /* some error */);
123             }
124             break;
125
126         case MODE_SET_COMMIT:
127             /* XXX: delete temporary storage */
128             if (/* XXX: error? */) {
129                 /* try _really_really_ hard to never get to this point */
130                 netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_COMMITFAILED);
131             }
132             break;
133
134         case MODE_SET_UNDO:
135             /* XXX: UNDO and return to previous value for the object */
136             if (/* XXX: error? */) {
137                 /* try _really_really_ hard to never get to this point */
138                 netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_UNDOFAILED);
139             }
140             break;
141         @end@
142
143         default:
144             /* we should never get here, so this is a really bad error */
145             return SNMP_ERR_GENERR;
146     }
147
148     return SNMP_ERR_NOERROR;
149 }
150 @end@