Commit 1d4b7ec1 authored by Adam Wujek's avatar Adam Wujek 💬

userspace/snmpd: use netsnmp cache in wrsTableTemplate

make n_rows global since function table_next_entry has to know how many rows
are available.
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent ebc6a893
......@@ -123,6 +123,7 @@ time_t wrsPortStatusTable_data_fill(unsigned int *n_rows)
#define TT_DATA_ARRAY wrsPortStatusTable_array
#define TT_GROUP_NAME "wrsPortStatusTable"
#define TT_INIT_FUNC init_wrsPortStatusTable
#define TT_CACHE_TIMEOUT WRSPORTSTATUSTABLE_CACHE_TIMEOUT
#include "wrsTableTemplate.h"
/* global variable to keep number of rows, filled by cache function */
unsigned int n_rows;
static netsnmp_variable_list *
table_next_entry(void **loop_context,
......@@ -6,8 +8,6 @@ table_next_entry(void **loop_context,
netsnmp_iterator_info *data)
{
intptr_t i;
unsigned int n_rows;
TT_DATA_FILL_FUNC(&n_rows);
/* create the line ID from counter number */
i = (intptr_t)*loop_context;
if (i >= n_rows)
......@@ -99,6 +99,12 @@ table_handler(netsnmp_mib_handler *handler,
return SNMP_ERR_NOERROR;
}
static int table_cache_load(netsnmp_cache *cache, void *vmagic)
{
TT_DATA_FILL_FUNC(&n_rows);
return 0;
}
void TT_INIT_FUNC(void)
{
const oid wrsTT_oid[] = { TT_OID };
......@@ -133,4 +139,10 @@ void TT_INIT_FUNC(void)
HANDLER_CAN_RONLY);
netsnmp_register_table_iterator(reginfo, iinfo);
netsnmp_inject_handler(reginfo,
netsnmp_get_cache_handler(TT_CACHE_TIMEOUT,
table_cache_load, NULL,
wrsTT_oid,
OID_LENGTH(wrsTT_oid)));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment