1#############################################################  -*- c -*-
2## generic include for XXX. Do not use directly.
3##
4########################################################################
5@if $m2c_mark_boundary == 1@
6/** START code generated by parent-set.m2i */
7@end@
8########################################################################
9##//####################################################################
10##//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
11##//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
12@if $m2c_processing_type eq 'h'@
13
14int ${context}_undo_setup( ${context}_rowreq_ctx *rowreq_ctx);
15int ${context}_undo_cleanup( ${context}_rowreq_ctx *rowreq_ctx);
16int ${context}_undo( ${context}_rowreq_ctx *rowreq_ctx);
17int ${context}_commit( ${context}_rowreq_ctx *rowreq_ctx);
18int ${context}_undo_commit( ${context}_rowreq_ctx *rowreq_ctx);
19@   if $m2c_irreversible_commit == 1@
20int ${context}_irreversible_commit( ${context}_rowreq_ctx *rowreq_ctx);
21@   end@
22
23@end@ // m2c_processing_type eq 'h'
24########################################################################
25##//####################################################################
26##//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
27##//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
28@if $m2c_processing_type eq 'c'@
29##
30## MASTER COPY OF THIS FLOWCHART IS IN agent/helpers/baby_steps.c
31##
32    /*
33     * NOTE: if you update this chart, please update the versions in
34     *       local/mib2c-conf.d/parent-set.m2i
35     *       agent/mibgroup/helpers/baby_steps.c
36     * while you're at it.
37     */
38    /*
39     ***********************************************************************
40     * Baby Steps Flow Chart (2004.06.05)                                  *
41     *                                                                     *
42     * +--------------+    +================+    U = unconditional path    *
43     * |optional state|    ||required state||    S = path for success      *
44     * +--------------+    +================+    E = path for error        *
45     ***********************************************************************
46     *
47     *                        +--------------+
48     *                        |     pre      |
49     *                        |   request    |
50     *                        +--------------+
51     *                               | U
52@if $m2c_table_row_creation == 1@
53     * +-------------+        +==============+
54     * |    row    |f|<-------||  object    ||
55     * |  create   |1|      E ||  lookup    ||
56     * +-------------+        +==============+
57     *     E |   | S                 | S
58     *       |   +------------------>|
59     *       |                +==============+
60     *       |              E ||   check    ||
61     *       |<---------------||   values   ||
62@else@
63     *                        +==============+
64     *       +----------------||  object    ||
65     *       |              E ||  lookup    ||
66     *       |                +==============+
67     *       |                       | S
68     *       |                +==============+
69     *       |              E ||   check    ||
70     *       |<---------------||   values   ||
71@end@ # row creation
72     *       |                +==============+
73     *       |                       | S
74     *       |                +==============+
75     *       |       +<-------||   undo     ||
76     *       |       |      E ||   setup    ||
77     *       |       |        +==============+
78     *       |       |               | S
79     *       |       |        +==============+
80     *       |       |        ||    set     ||-------------------------->+
81     *       |       |        ||   value    || E                         |
82     *       |       |        +==============+                           |
83     *       |       |               | S                                 |
84     *       |       |        +--------------+                           |
85     *       |       |        |    check     |-------------------------->|
86     *       |       |        |  consistency | E                         |
87     *       |       |        +--------------+                           |
88     *       |       |               | S                                 |
89     *       |       |        +==============+         +==============+  |
90     *       |       |        ||   commit   ||-------->||     undo   ||  |
91     *       |       |        ||            || E       ||    commit  ||  |
92     *       |       |        +==============+         +==============+  |
93     *       |       |               | S                     U |<--------+
94     *       |       |        +--------------+         +==============+
95     *       |       |        | irreversible |         ||    undo    ||
96     *       |       |        |    commit    |         ||     set    ||
97     *       |       |        +--------------+         +==============+
98     *       |       |               | U                     U |
99     *       |       +-------------->|<------------------------+
100     *       |                +==============+
101     *       |                ||   undo     ||
102     *       |                ||  cleanup   ||
103     *       |                +==============+
104     *       +---------------------->| U
105@if $m2c_table_row_creation == 1@
106     *                               |
107     *                          (err && f1)------------------->+
108     *                               |                         |
109     *                        +--------------+         +--------------+
110     *                        |    post      |<--------|      row     |
111     *                        |   request    |       U |    release   |
112     *                        +--------------+         +--------------+
113@else@
114     *                        +--------------+
115     *                        |    post      |
116     *                        |   request    |
117     *                        +--------------+
118@end@ # row creation
119     *
120     */
121
122##----------------------------------------------------------------------
123/**
124 * Setup up context with information needed to undo a set request.
125 *
126 * This function will be called before the individual node undo setup
127 * functions are called. If you need to do any undo setup that is not
128 * related to a specific column, you can do it here.
129 *
130@if $m2c_undo_embed == 0@
131@   if $m2c_data_init == 1@
132 * Note that the undo context has been allocated with
133 * ${context}_allocate_data(), but may need extra
134 * initialization similar to what you may have done in
135 * ${context}_rowreq_ctx_init().
136@   end@
137@end@
138 * Note that an individual node's undo_setup function will only be called
139 * if that node is being set to a new value.
140 *
141 * If there is any setup specific to a particular column (e.g. allocating
142 * memory for a string), you should do that setup in the node's undo_setup
143 * function, so it won't be done unless it is necessary.
144 *
145 * @param rowreq_ctx
146 *        Pointer to the table context (${context}_rowreq_ctx)
147 *
148 * @retval MFD_SUCCESS : success
149 * @retval MFD_ERROR   : error. set will fail.
150 */
151int
152${context}_undo_setup( ${context}_rowreq_ctx *rowreq_ctx)
153{
154    int rc = MFD_SUCCESS;
155
156    DEBUGMSGTL(("verbose:${context}:${context}_undo_setup","called\n"));
157
158    /** we should have a non-NULL pointer */
159    netsnmp_assert( NULL != rowreq_ctx );
160
161    /*
162     * TODO:451:M: |-> Setup $context undo.
163     * set up $context undo information, in preparation for a set.
164     * Undo storage is in ${m2c_ctx_lh}*
165     */
166
167    return rc;
168} /* ${context}_undo_setup */
169
170/**
171 * Undo a set request.
172 *
173 * This function will be called before the individual node undo
174 * functions are called. If you need to do any undo that is not
175 * related to a specific column, you can do it here.
176 *
177 * Note that an individual node's undo function will only be called
178 * if that node is being set to a new value.
179 *
180 * If there is anything  specific to a particular column (e.g. releasing
181 * memory for a string), you should do that setup in the node's undo
182 * function, so it won't be done unless it is necessary.
183 *
184 * @param rowreq_ctx
185 *        Pointer to the table context (${context}_rowreq_ctx)
186 *
187 * @retval MFD_SUCCESS : success
188 * @retval MFD_ERROR   : error. set will fail.
189 */
190int
191${context}_undo( ${context}_rowreq_ctx *rowreq_ctx)
192{
193    int rc = MFD_SUCCESS;
194
195    DEBUGMSGTL(("verbose:${context}:${context}_undo","called\n"));
196
197    /** we should have a non-NULL pointer */
198    netsnmp_assert( NULL != rowreq_ctx );
199
200    /*
201     * TODO:451:M: |-> $context undo.
202     * $context undo information, in response to a failed set.
203     * Undo storage is in ${m2c_ctx_lh}*
204     */
205
206    return rc;
207} /* ${context}_undo_setup */
208
209/**
210 * Cleanup up context undo information.
211 *
212 * This function will be called after set/commit processing. If you
213 * allocated any resources in undo_setup, this is the place to release
214 * those resources.
215 *
216 * This function is called regardless of the success or failure of the set
217 * request. If you need to perform different steps for cleanup depending
218 * on success or failure, you can add a flag to the rowreq_ctx.
219 *
220 * @param rowreq_ctx
221 *        Pointer to the table context (${context}_rowreq_ctx)
222 *
223 * @retval MFD_SUCCESS : success
224 * @retval MFD_ERROR   : error
225 */
226int
227${context}_undo_cleanup( ${context}_rowreq_ctx *rowreq_ctx)
228{
229    int rc = MFD_SUCCESS;
230
231    DEBUGMSGTL(("verbose:${context}:${context}_undo_cleanup","called\n"));
232
233    /** we should have a non-NULL pointer */
234    netsnmp_assert( NULL != rowreq_ctx );
235
236    /*
237     * TODO:452:M: |-> Cleanup $context undo.
238     * Undo storage is in ${m2c_ctx_lh}*
239     */
240
241    return rc;
242} /* ${context}_undo_cleanup */
243
244##----------------------------------------------------------------------
245/**
246 * commit new values.
247 *
248 * At this point, you should have done everything you can to ensure that
249 * this commit will not fail.
250 *
251 * Should you need different behavior depending on which columns were
252 * set, rowreq_ctx->column_set_flags will indicate which writeable columns were
253 * set. The definitions for the COLUMN_*_FLAG bits can be found in
254@if $m2c_create_fewer_files != 1@
255 * ${context}_oids.h.
256@else@
257 * ${context}.h.
258@end@
259 * A new row will have the MFD_ROW_CREATED bit set in rowreq_flags.
260 *
261 * @param ${context}_rowreq_ctx
262 *        Pointer to the users context.
263 *
264 * @retval MFD_SUCCESS : success
265 * @retval MFD_ERROR   : error
266 */
267int
268${context}_commit( ${context}_rowreq_ctx *rowreq_ctx)
269{
270    int rc = MFD_SUCCESS;
271    int             save_flags;
272
273    DEBUGMSGTL(("verbose:${context}:${context}_commit","called\n"));
274
275    /** we should have a non-NULL pointer */
276    netsnmp_assert( NULL != rowreq_ctx );
277
278    /*
279     * save flags, then clear until we actually do something
280     */
281    save_flags = rowreq_ctx->column_set_flags;
282    rowreq_ctx->column_set_flags = 0;
283
284    /*
285     * commit $context data
286     * 1) check the column's flag in save_flags to see if it was set.
287     * 2) clear the flag when you handle that column
288     * 3) set the column's flag in column_set_flags if it needs undo
289     *    processing in case of a failure.
290     */
291@   foreach $node nonindex@
292@      include m2c_setup_node.m2i@
293@      if $node.settable == 0@
294@          next@
295@      end@
296    if (save_flags & COLUMN_$node.uc_FLAG) {
297       save_flags &= ~COLUMN_$node.uc_FLAG; /* clear $node */
298       /*
299        * TODO:482:o: |-> commit column $node.
300        */
301       rc = -1;
302       if(-1 == rc) {
303           snmp_log(LOG_ERR,"$context column $node commit failed\n");
304       }
305       else {
306            /*
307             * set flag, in case we need to undo $node
308             */
309            rowreq_ctx->column_set_flags |= COLUMN_$node.uc_FLAG;
310       }
311    }
312
313@   end@ # foreach $node
314    /*
315     * if we successfully commited this row, set the dirty flag.
316     */
317    if (MFD_SUCCESS == rc) {
318        rowreq_ctx->rowreq_flags |= MFD_ROW_DIRTY;
319    }
320
321    if (save_flags) {
322       snmp_log(LOG_ERR, "unhandled columns (0x%x) in commit\n", save_flags);
323       return MFD_ERROR;
324    }
325
326    return rc;
327} /* ${context}_commit */
328
329/**
330 * undo commit new values.
331 *
332 * Should you need different behavior depending on which columns were
333 * set, rowreq_ctx->column_set_flags will indicate which writeable columns were
334 * set. The definitions for the COLUMN_*_FLAG bits can be found in
335@if $m2c_create_fewer_files != 1@
336 * ${context}_oids.h.
337@else@
338 * ${context}.h.
339@end@
340 * A new row will have the MFD_ROW_CREATED bit set in rowreq_flags.
341 *
342 * @param ${context}_rowreq_ctx
343 *        Pointer to the users context.
344 *
345 * @retval MFD_SUCCESS : success
346 * @retval MFD_ERROR   : error
347 */
348int
349${context}_undo_commit( ${context}_rowreq_ctx *rowreq_ctx)
350{
351    int rc = MFD_SUCCESS;
352
353    DEBUGMSGTL(("verbose:${context}:${context}_undo_commit","called\n"));
354
355    /** we should have a non-NULL pointer */
356    netsnmp_assert( NULL != rowreq_ctx );
357
358    /*
359     * TODO:485:M: |-> Undo $context commit.
360     * check each column's flag in rowreq_ctx->column_set_flags to see
361     * if it was set during commit, then undo it.
362     *
363@   foreach $node nonindex@
364@      include m2c_setup_node.m2i@
365@      if $node.settable == 0@
366@          next@
367@      end@
368     * eg: if (rowreq_ctx->column_set_flags & COLUMN_$node.uc_FLAG) {}
369@   end@ # foreach $node
370     */
371
372
373    /*
374     * if we successfully un-commited this row, clear the dirty flag.
375     */
376    if (MFD_SUCCESS == rc) {
377        rowreq_ctx->rowreq_flags &= ~MFD_ROW_DIRTY;
378    }
379
380    return rc;
381} /* ${context}_undo_commit */
382
383@if $m2c_irreversible_commit == 1@
384##----------------------------------------------------------------------
385/**
386 * perform commit actions that are not reversible
387 *
388 * THERE IS NO ATTEMPT AT RECOVERY FOR ERRORS FROM THIS STATE!
389 *
390 * @param ${context}_rowreq_ctx
391 *        Pointer to the users context.
392 *
393 * @retval MFD_SUCCESS : success
394 * @retval MFD_ERROR   : other error
395 */
396int
397${context}_irreversible_commit( ${context}_rowreq_ctx *rowreq_ctx)
398{
399    int rc;
400
401    DEBUGMSGTL(("verbose:${context}:${context}_irreversible_commit","called\n"));
402
403    /** we should have a non-NULL pointer */
404    netsnmp_assert( NULL != rowreq_ctx );
405
406    /*
407     * TODO:495:o: Irreversible $context commit.
408     */
409##$example_start
410##$example_end
411
412    return MFD_SUCCESS;
413} /* ${context}_irreversible_commit */
414
415@end@ // irreversable commit
416##
417########################################################################
418@end@ // m2c_processing_type eq 'c'
419########################################################################
420@if $m2c_mark_boundary == 1@
421/** END code generated by parent-set.m2i */
422@end@
423