/*
 * Note: this file originally auto-generated by mib2c using
 *        : mib2c.create-dataset.conf,v 5.4 2004/02/02 19:06:53 rstory Exp $
 */

#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "abcTable.h"

/** Initialize the abcTable table by defining its contents and how it's structured */
void
initialize_table_abcTable(void)
{
    static oid abcTable_oid[] = {1,3,6,1,4,1,11456,3,3};
    size_t abcTable_oid_len = OID_LENGTH(abcTable_oid);
    netsnmp_table_data_set *table_set;
    netsnmp_table_row *row;

    /* create the table structure itself */
    table_set = netsnmp_create_table_data_set("abcTable");

    /* comment this out or delete if you don't support creation of new rows */
    table_set->allow_creation = 1;

    /***************************************************
     * Adding indexes
     */
    DEBUGMSGTL(("initialize_table_abcTable",
                "adding indexes to table abcTable\n"));
    netsnmp_table_set_add_indexes(table_set,
                           ASN_INTEGER,  /* index: abcIndex */
                           0);

    DEBUGMSGTL(("initialize_table_abcTable",
                "adding column types to table abcTable\n"));		 
    netsnmp_table_set_multi_add_default_row(table_set,
                                            COLUMN_ABCINDEX, ASN_INTEGER, 0,
                                            NULL, 0,
                                            COLUMN_ABCVALUE, ASN_OCTET_STR, 0,
                                            NULL, 0,
                                            COLUMN_ABCSIZE, ASN_INTEGER, 0,
                                            NULL, 0,
                              0);
    
    /* registering the table with the master agent */
    /* note: if you don't need a subhandler to deal with any aspects
       of the request, change abcTable_handler to "NULL" */
    netsnmp_register_table_data_set(netsnmp_create_handler_registration("abcTable", abcTable_handler,
                                                        abcTable_oid,
                                                        abcTable_oid_len,
                                                        HANDLER_CAN_RWRITE),
                            table_set, NULL);

    int index = 1;
    int defaultValue = 101;

    for(index = 1; index < 10; index ++) {

        row = netsnmp_create_table_data_row();

        netsnmp_table_row_add_index(row, ASN_INTEGER, &index , sizeof(index));

        char temp[10];
        char abcName[10] = "ABC-";
        sprintf(temp, "%d", defaultValue);
        strcat(abcName, temp);

        netsnmp_set_row_column(row, COLUMN_ABCVALUE, ASN_OCTET_STR, abcName, strlen(abcName));
        netsnmp_mark_row_column_writable(row, COLUMN_ABCVALUE, 1);

        netsnmp_set_row_column(row, COLUMN_ABCSIZE, ASN_INTEGER, (char*) &defaultValue, sizeof(defaultValue));
        netsnmp_mark_row_column_writable(row, COLUMN_ABCSIZE, 1);

        netsnmp_table_dataset_add_row(table_set, row);

        defaultValue ++;
    }

    netsnmp_register_auto_data_table(table_set, NULL);

}

/** Initializes the abcTable module */
void
init_abcTable(void)
{

  /* here we initialize all the tables we're planning on supporting */
    initialize_table_abcTable();
}

/** handles requests for the abcTable table, if anything else needs to be done */
int
abcTable_handler(
    netsnmp_mib_handler               *handler,
    netsnmp_handler_registration      *reginfo,
    netsnmp_agent_request_info        *reqinfo,
    netsnmp_request_info              *requests) {
    /* perform anything here that you need to do.  The requests have
       already been processed by the master table_dataset handler, but
       this gives you chance to act on the request in some other way
       if need be. */
    return SNMP_ERR_NOERROR;
}
