Blame local/mib2c.access_functions.conf

Packit fcad23
## -*- c -*-
Packit fcad23
######################################################################
Packit fcad23
## Do the .h file
Packit fcad23
######################################################################
Packit fcad23
@open ${name}_access.h@
Packit fcad23
/*
Packit fcad23
 * Note: this file originally auto-generated by mib2c
Packit fcad23
 * using mib2c.access_functions.conf
Packit fcad23
 */
Packit fcad23
#ifndef $name.uc_ACCESS_H
Packit fcad23
#define $name.uc_ACCESS_H
Packit fcad23
Packit fcad23
@foreach $t table@
Packit fcad23
/** User-defined data access functions for data in table $t */
Packit fcad23
/** row level accessors */
Packit fcad23
Netsnmp_First_Data_Point  ${t}_get_first_data_point;
Packit fcad23
Netsnmp_Next_Data_Point   ${t}_get_next_data_point;
Packit fcad23
int ${t}_commit_row(void **my_data_context, int new_or_del);
Packit fcad23
void * ${t}_create_data_context(netsnmp_variable_list *index_data, int column);
Packit fcad23
Packit fcad23
/** column accessors */
Packit fcad23
  @foreach $c column@
Packit fcad23
    @if $c.access =~ /(Read|Create)/@
Packit fcad23
      $c.decl *get_$c(void *data_context, size_t *ret_len);
Packit fcad23
    @end@
Packit fcad23
    @if $c.access =~ /(Write|Create)/@
Packit fcad23
      int set_$c(void *data_context, $c.decl *val, size_t val_len);
Packit fcad23
    @end@
Packit fcad23
  @end@
Packit fcad23
@end@
Packit fcad23
Packit fcad23
#endif /* $name.uc_ACCESS_H */
Packit fcad23
######################################################################
Packit fcad23
## Do the .c file
Packit fcad23
######################################################################
Packit fcad23
@open ${name}_access.c@
Packit fcad23
Packit fcad23
/*
Packit fcad23
 * Note: this file originally auto-generated by mib2c
Packit fcad23
 * using mib2c.access_functions.conf
Packit fcad23
 */
Packit fcad23
Packit fcad23
#include <net-snmp/net-snmp-config.h>
Packit fcad23
#include <net-snmp/net-snmp-includes.h>
Packit fcad23
#include <net-snmp/agent/net-snmp-agent-includes.h>
Packit fcad23
#include "${name}_access.h"
Packit fcad23
#include "${name}_enums.h"
Packit fcad23
Packit fcad23
@foreach $t table@
Packit fcad23
Packit fcad23
/** returns the first data point within the $t table data.
Packit fcad23
Packit fcad23
    Set the my_loop_context variable to the first data point structure
Packit fcad23
    of your choice (from which you can find the next one).  This could
Packit fcad23
    be anything from the first node in a linked list, to an integer
Packit fcad23
    pointer containing the beginning of an array variable.
Packit fcad23
Packit fcad23
    Set the my_data_context variable to something to be returned to
Packit fcad23
    you later that will provide you with the data to return in a given
Packit fcad23
    row.  This could be the same pointer as what my_loop_context is
Packit fcad23
    set to, or something different.
Packit fcad23
Packit fcad23
    The put_index_data variable contains a list of snmp variable
Packit fcad23
    bindings, one for each index in your table.  Set the values of
Packit fcad23
    each appropriately according to the data matching the first row
Packit fcad23
    and return the put_index_data variable at the end of the function.
Packit fcad23
*/
Packit fcad23
netsnmp_variable_list *
Packit fcad23
${t}_get_first_data_point(void **my_loop_context, void **my_data_context,
Packit fcad23
                          netsnmp_variable_list *put_index_data,
Packit fcad23
                          netsnmp_iterator_info *mydata)
Packit fcad23
{
Packit fcad23
Packit fcad23
    netsnmp_variable_list *vptr;
Packit fcad23
Packit fcad23
    *my_loop_context = /** XXX */;
Packit fcad23
    *my_data_context = /** XXX */;
Packit fcad23
Packit fcad23
    vptr = put_index_data;
Packit fcad23
    
Packit fcad23
    @foreach $idx index@
Packit fcad23
    snmp_set_var_value(vptr, /** XXX: $idx data */, /** XXX: length of $idx data */);
Packit fcad23
    vptr = vptr->next_variable;
Packit fcad23
    @end@
Packit fcad23
Packit fcad23
    return put_index_data;
Packit fcad23
}
Packit fcad23
Packit fcad23
/** functionally the same as ${t}_get_first_data_point, but
Packit fcad23
   my_loop_context has already been set to a previous value and should
Packit fcad23
   be updated to the next in the list.  For example, if it was a
Packit fcad23
   linked list, you might want to cast it to your local data type and
Packit fcad23
   then return my_loop_context->next.  The my_data_context pointer
Packit fcad23
   should be set to something you need later and the indexes in
Packit fcad23
   put_index_data updated again. */
Packit fcad23
netsnmp_variable_list *
Packit fcad23
${t}_get_next_data_point(void **my_loop_context, void **my_data_context,
Packit fcad23
                         netsnmp_variable_list *put_index_data,
Packit fcad23
                         netsnmp_iterator_info *mydata)
Packit fcad23
{
Packit fcad23
Packit fcad23
    netsnmp_variable_list *vptr;
Packit fcad23
Packit fcad23
    *my_loop_context = /** XXX */;
Packit fcad23
    *my_data_context = /** XXX */;
Packit fcad23
Packit fcad23
    vptr = put_index_data;
Packit fcad23
    
Packit fcad23
    @foreach $idx index@
Packit fcad23
    snmp_set_var_value(vptr, /** XXX: $idx data */, /** XXX: length of $idx data */);
Packit fcad23
    vptr = vptr->next_variable;
Packit fcad23
    @end@
Packit fcad23
Packit fcad23
    return put_index_data;
Packit fcad23
}
Packit fcad23
Packit fcad23
/** Create a data_context for non-existent rows that SETs are performed on.
Packit fcad23
 *  return a void * pointer which will be passed to subsequent get_XXX
Packit fcad23
 *  and set_XXX functions for data retrieval and modification during
Packit fcad23
 *  this SET request.
Packit fcad23
 *
Packit fcad23
 *  The indexes are encoded (in order) into the index_data pointer,
Packit fcad23
 *  and the column object which triggered the row creation is available
Packit fcad23
 *  via the column parameter, if it would be helpful to use that information.
Packit fcad23
 */
Packit fcad23
void *
Packit fcad23
${t}_create_data_context(netsnmp_variable_list *index_data, int column) {
Packit fcad23
    return NULL; /* XXX: you likely want to return a real pointer */
Packit fcad23
}
Packit fcad23
Packit fcad23
/** If the implemented set_* functions don't operate directly on the
Packit fcad23
   real-live data (which is actually recommended), then this function
Packit fcad23
   can be used to take a given my_data_context pointer and "commit" it
Packit fcad23
   to whereever the modified data needs to be put back to.  For
Packit fcad23
   example, if this was a routing table you could publish the modified
Packit fcad23
   routes back into the kernel at this point.
Packit fcad23
Packit fcad23
   new_or_del will be set to 1 if new, or -1 if it should be deleted
Packit fcad23
   or 0 if it is just a modification of an existing row.
Packit fcad23
Packit fcad23
   If you free the data yourself, make sure to *my_data_context = NULL */
Packit fcad23
int
Packit fcad23
${t}_commit_row(void **my_data_context, int new_or_del)
Packit fcad23
{
Packit fcad23
    /** Add any necessary commit code here */
Packit fcad23
    /*  */
Packit fcad23
Packit fcad23
    /* return no errors.  And there shouldn't be any!!!  Ever!!!  You
Packit fcad23
    should have checked the values long before this. */
Packit fcad23
    return SNMP_ERR_NOERROR;
Packit fcad23
}
Packit fcad23
Packit fcad23
Packit fcad23
/* User-defined data access functions (per column) for data in table $t */
Packit fcad23
/*
Packit fcad23
 * NOTE:
Packit fcad23
 * - these get_ routines MUST return data that will not be freed (ie,
Packit fcad23
 *   use static variables or persistent data).  It will be copied, if
Packit fcad23
 *   needed, immediately after the get_ routine has been called.
Packit fcad23
 * - these SET routines must copy the incoming data and can not take
Packit fcad23
 *   ownership of the memory passed in by the val pointer.
Packit fcad23
 */
Packit fcad23
  @foreach $c column@
Packit fcad23
    @if $c.access =~ /(Read|Create)/@
Packit fcad23
/** XXX: return a data pointer to the data for the $c column and set
Packit fcad23
         ret_len to its proper size in bytes. */
Packit fcad23
      $c.decl *get_$c(void *data_context, size_t *ret_len) {
Packit fcad23
      return NULL; /** XXX: replace this with a pointer to a real value */
Packit fcad23
      }
Packit fcad23
    @end@
Packit fcad23
    @if $c.access =~ /(Write|Create)/@
Packit fcad23
/** XXX: Set the value of the $c column and return
Packit fcad23
         SNMP_ERR_NOERROR on success
Packit fcad23
         SNMP_ERR_XXX     for SNMP deterministic error codes
Packit fcad23
         SNMP_ERR_GENERR  on generic failures (a last result response). */
Packit fcad23
      int set_$c(void *data_context, $c.decl *val, size_t val_len) {
Packit fcad23
        return SNMP_ERR_NOERROR;  /** XXX: change if an error occurs */
Packit fcad23
      }
Packit fcad23
    @end@
Packit fcad23
  @end@
Packit fcad23
    
Packit fcad23
@end@
Packit fcad23