/**
 * @brief Header for sorted table helper
 *
 * Copyright 2010 SIXNET, LLC. All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 
 * *  Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 
 * *  Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 
 * *  The name of SIXNET, LLC or any of its subsidiaries,
 *    brand or product names may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef TABLE_SORTED_H
#define TABLE_SORTED_H

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

typedef struct snmp_sorted_info_s {
    /**
     * This function should store the index (or indices) of the first
     * row in the table into table_info->indexes, if it exists.
     *
     * (*ctx) should be set to NULL if there are no rows, or non-NULL
     * otherwise, but has no other significance.
     *
     * @return SNMPERR_SUCCESS on success, other values on failure
     */
    int (*first_row_context)(void **ctx,
                             netsnmp_table_request_info *table_info,
                             struct snmp_sorted_info_s *sinfo);

    /**
     * This function finds the index (or indices) of the next row in
     * this table, and stores them in table_info->indexes.
     * On entry table_info->indexes will contain the index (or indices)
     * of the current row.
     *
     * (*ctx) should be set to NULL if there are no more rows, or
     * non-NULL otherwise, but has no other significance.
     *
     * @return SNMPERR_SUCCESS on success, other values on failure
     */
    int (*next_row_context)(void **ctx,
                            netsnmp_table_request_info *table_info,
                            struct snmp_sorted_info_s *sinfo);

    /**
     * This can be used by subhandlers to store needed data.
     */
    void *myvoid;

    /**
     * This field must point to the registration structure for the
     * table. It should be set by the user's code before calling
     * snmp_register_table_sorted.
     */
    netsnmp_table_registration_info *table_reginfo;
} snmp_sorted_info;

#define TABLE_SORTED_NAME "table_sorted"

int
snmp_register_table_sorted(netsnmp_handler_registration *reginfo,
                           snmp_sorted_info *sinfo);

#endif /* TABLE_SORTED_H */
