#############################################################  -*- c -*-
## generic include for XXX. Do not use directly.
## $Id: mfd-top.m2c,v 1.32.2.1 2004/12/31 14:28:40 rstory Exp $
########################################################################
########################################################################
##
## mfd function params
##
@ifconf ${name}.m2d@
@   include ${name}.m2d@
@end@
########################################################################
@eval $m2c_processing_type = 'h'@
@open ${name}.h@
@eval $hack = "Id"@
/*
 * Note: this file originally auto-generated by mib2c using
 *       version $Revision: 1.32.2.1 $ of $RCSfile: mfd-top.m2c,v $
 *
 * $$hack:$
 */
@include generic-header-top.m2i@

/** @defgroup misc misc: Miscelaneous routines
 *
 * @{
 */
@if $m2c_mark_boundary == 1@
/** START header generated by $RCSfile: mfd-top.m2c,v $ $Revision: 1.32.2.1 $ */
@end@
#include <net-snmp/library/asn1.h>

/* other required module components */
    /* *INDENT-OFF*  */
config_require(${name}_interface);
config_require(${name}_data_access);
@if $m2c_create_fewer_files != 1@
config_require(${name}_data_get);
config_require(${name}_data_set);
    /* *INDENT-ON*  */

/* OID and column number definitions for $context */
#include "${name}_oids.h"

/* enum definions */
#include "${name}_enums.h"
@else@
    /* *INDENT-ON*  */

/* OID, column number and enum definions for $context */
#include "${name}_constants.h"
@end@ // m2c_create_fewer_files

/* *********************************************************************
 * function declarations
 */
void init_$name(void);

/* *********************************************************************
 * Table declarations
 */
@foreach $table table@
@    include m2c_setup_table.m2i@
@    include details-table.m2i@
/* *********************************************************************
 * When you register your mib, you get to provide a generic
 * pointer that will be passed back to you for most of the
 * functions calls.
 *
 * TODO:100:r: Review all context structures
 */
    /*
     * TODO:101:o: |-> Review $context registration context.
     */
@    if "x$m2c_context_reg" eq "x"@
@        eval $m2c_context_reg = "void *"@
@    end@
typedef $m2c_context_reg ${context}_registration_ptr;

@    include generic-data-context.m2i@

@   if $m2c_table_settable@
/* *********************************************************************
 * TODO:115:o: |-> Review $context undo context.
 * We're just going to use the same data structure for our
 * undo_context. If you want to do something more efficent,
 * define your typedef here.
 */
typedef ${context}_data ${context}_undo_data;

@    end@
@    include generic-table-indexes.m2i@

/* *********************************************************************
 * TODO:130:o: |-> Review $context Row request (rowreq) context.
 * When your functions are called, you will be passed a
 * ${context}_rowreq_ctx pointer.
 */
typedef struct ${context}_rowreq_ctx_s {

    /** this must be first for container compare to work */
    netsnmp_index        oid_idx;
##                                             /* xxx-rks: shrink index oid_tmp? */
    oid                  oid_tmp[MAX_${context}_IDX_LEN];
    
    ${context}_mib_index        tbl_idx;
    
@    if $m2c_data_allocate == 1@
@        eval $mfd_tmp = "*"@
@    else@
@        eval $mfd_tmp = " "@
@    end@
    ${context}_data            $mfd_tmp data;
@   if $m2c_table_settable@
@      if $m2c_undo_embed == 1@
@         eval $mfd_tmp = " "@
@      else@
@         eval $mfd_tmp = "*"@
@      end@ # embed
    ${context}_undo_data       $mfd_tmp undo;
    unsigned int                column_set_flags; /* flags for set columns */

@   end@ # settable

    /*
     * flags per row. Currently, the first (lower) 8 bits are reserved
     * for the user. See mfd.h for other flags.
     */
    u_int                       rowreq_flags;

    /*
     * implementor's context pointer (provided during registration)
     */
    ${context}_registration_ptr ${context}_reg;

    /*
     * TODO:131:o: |   |-> Add useful data to $context rowreq context.
     */
    
    /*
     * storage for future expansion
     */
    netsnmp_data_list             *${context}_data_list;

} ${context}_rowreq_ctx;

typedef struct ${context}_ref_rowreq_ctx_s {
    ${context}_rowreq_ctx *rowreq_ctx;
} ${context}_ref_rowreq_ctx;

/* *********************************************************************
 * function prototypes
 */
## {
    int ${context}_pre_request(${context}_registration_ptr user_context);
    int ${context}_post_request(${context}_registration_ptr user_context);

@   if $m2c_data_init == 1@
    int ${context}_init_rowreq_ctx(${context}_rowreq_ctx *rowreq_ctx);
    void ${context}_cleanup_rowreq_ctx(${context}_rowreq_ctx *rowreq_ctx);

@   end@
@    if "$m2c_data_context" ne "generated"@
@        if ($m2c_data_allocate == 1) || ($m2c_undo_embed == 1)@
    ${context}_data * ${context}_allocate_data(void);
    void ${context}_release_data(${context}_data *data);

@        end@
@   end@
@   if $m2c_table_settable@
@      if $m2c_table_dependencies == 1@
    int ${context}_check_dependencies(${context}_rowreq_ctx * rowreq_ctx); 
@      end@ 
    int ${context}_commit(${context}_rowreq_ctx * rowreq_ctx);
@      if $m2c_irreversible_commit == 1@
    int ${context}_irreversible_commit(${context}_rowreq_ctx * rowreq_ctx);
@      end@
@   end@ # writable

extern oid ${context}_oid[];
extern int ${context}_oid_size;

@end@ # for each

#include "${name}_interface.h"
#include "${name}_data_access.h"
@if $m2c_create_fewer_files != 1@
#include "${name}_data_get.h"
#include "${name}_data_set.h"
@else@
@   eval $mfd_processing_types = "h"@
@   include mfd-data-get.m2c@
@   include mfd-data-set.m2c@
@end@ // m2c_create_fewer_files

/*
 * DUMMY markers, ignore
 *
 * TODO:099:x: *************************************************************
 * TODO:199:x: *************************************************************
 * TODO:299:x: *************************************************************
 * TODO:399:x: *************************************************************
 * TODO:499:x: *************************************************************
 */
@if $m2c_mark_boundary == 1@
/** END header generated by $RCSfile: mfd-top.m2c,v $ $Revision: 1.32.2.1 $ */
@end@
@include generic-header-bottom.m2i@
######################################################################
## Do the .c file
######################################################################
@eval $m2c_processing_type = 'c'@
@open ${name}.c@
/*
 * Note: this file originally auto-generated by mib2c using
 *       version $Revision: 1.32.2.1 $ of $RCSfile: mfd-top.m2c,v $ 
 *
 * $$hack:$
 */
/** \mainpage MFD helper for ${name}
 *
 * \section intro Introduction
 * Introductory text.
 *
 */
@include generic-source-includes.m2i@
#include <net-snmp/agent/mib_modules.h>

@if $m2c_mark_boundary == 1@
/** START code generated by $RCSfile: mfd-top.m2c,v $ $Revision: 1.32.2.1 $ */
@end@
#include "${name}_interface.h"

@foreach $table table@
@    include m2c_setup_table.m2i@
oid ${context}_oid[] = { $context.uc_OID };
int ${context}_oid_size = OID_LENGTH(${context}_oid);

void initialize_table_$context(void);

@end@

/**
 * Initializes the $name module
 */
void
init_$name(void)
{
    DEBUGMSGTL(("verbose:$name:init_$name","called\n"));

    /*
     * TODO:300:o: Perform $name one-time module initialization.
     */
     
    /*
     * here we initialize all the tables we're planning on supporting
     */
  @foreach $table table@
    if (should_init("$context"))
        initialize_table_$context();

  @end@
} /* init_$name */

########################################################################
##
@foreach $table table@
@    include m2c_setup_table.m2i@
/**
 * Initialize the table $context 
 *    (Define its contents and how it's structured)
 */
void
initialize_table_$context(void)
{
    ${context}_registration_ptr user_context;
    u_long flags;

    DEBUGMSGTL(("verbose:$context:initialize_table_$context","called\n"));

    /*
     * TODO:301:o: Perform $context one-time table initialization.
     */

    /*
     * TODO:302:o: |->Initialize $context user context
     * if you'd like to pass in a pointer to some data for this
     * table, allocate or set it up here.
     */
@    if "$m2c_context_reg" eq "netsnmp_data_list *"@
    /*
     * a netsnmp_data_list is a simple way to store void pointers. A simple
     * string token is used to add, find or remove pointers.
     */
    user_context = netsnmp_create_data_list("$context", NULL, NULL);
@    else@
    user_context = NULL;
@   end@
    
    /*
     * No support for any flags yet, but in the future you would
     * set any flags here.
     */
    flags = 0;
    
    /*
     * call interface initialization code
     */
    _${context}_initialize_interface(user_context, flags);
} /* initialize_table_$context */

########################################################################
@   if $m2c_data_init == 1@
/**
 * extra context initialization
 *
 * @param rowreq_ctx    : row request context
 * @param user_init_ctx : void pointer for user (parameter to rowreq_ctx_allocate)
 *
 * @retval MFD_SUCCESS  : no errors
 * @retval MFD_ERROR    : error (context allocate will fail)
 */
int
${context}_rowreq_ctx_init(${context}_rowreq_ctx *rowreq_ctx,
                           void *user_init_ctx)
{
    DEBUGMSGTL(("verbose:$context:${context}_rowreq_ctx_init","called\n"));

    netsnmp_assert(NULL != rowreq_ctx);
    
    /*
     * TODO:210:o: |-> Perform extra $context rowreq initialization.
     */

    return MFD_SUCCESS;
} /* ${context}_rowreq_ctx_init */

/**
 * extra context cleanup
 *
 */
void ${context}_rowreq_ctx_cleanup(${context}_rowreq_ctx *rowreq_ctx)
{
    DEBUGMSGTL(("verbose:$context:${context}_rowreq_ctx_cleanup","called\n"));

    netsnmp_assert(NULL != rowreq_ctx);
    
    /*
     * TODO:211:o: |-> Perform extra $context rowreq cleanup.
     */
} /* ${context}_rowreq_ctx_cleanup */

@   end@ // data_init
########################################################################
/**
 * pre-request callback
 *
 *
 * @retval MFD_SUCCESS              : success.
 * @retval MFD_ERROR                : other error
 */
int
${context}_pre_request(${context}_registration_ptr user_context)
{
    DEBUGMSGTL(("verbose:${context}:${context}_pre_request","called\n"));

    /*
     * TODO:510:o: Perform $context pre-request actions.
     */

    return MFD_SUCCESS;
} /* ${context}_pre_request */

/**
 * post-request callback
 *
 *
 * @retval MFD_SUCCESS : success.
 * @retval MFD_ERROR   : other error (ignored)
 */
int
${context}_post_request(${context}_registration_ptr user_context)
{
    DEBUGMSGTL(("verbose:${context}:${context}_post_request","called\n"));

    /*
     * TODO:511:o: Perform $context pos-request actions.
     */

    return MFD_SUCCESS;
} /* ${context}_post_request */

@end@ // table

########################################################################
@if $m2c_create_fewer_files == 1@
@   eval $mfd_processing_types = "c"@
@   include mfd-data-get.m2c@
@   include mfd-data-set.m2c@
@else@
@   eval $mfd_processing_types = "chi"@
@   run mfd-data-get.m2c@
@   run mfd-data-set.m2c@
@end@
########################################################################
/** @{ */
@if $m2c_mark_boundary == 1@
/** END code generated by $RCSfile: mfd-top.m2c,v $ $Revision: 1.32.2.1 $ */
@end@
##
########################################################################
##
## Do support files
##
########################################################################
@run generic-table-constants.m2c@
@run mfd-interface.m2c@
@run mfd-data-access.m2c@
@run mfd-readme.m2c@
@run mfd-doxygen.m2c@
