Hi All,
I have requirement in which i have to fill the table data when ever a
request will come, For example check the below example.... it was generated
by using mib2c.table_data.conf.
: in which "ocStbHostAVInterfaceTable_handler" is taking care of
the requests, So my requirement is
when the a request come at " i.e "(check in code ) case MODE_GET:" then
i want to update the table instated of initialize the table first (filling
the table) at (check in code "
initialize_table_ocStbHostAVInterfaceTable(void) " )
Please give the Solution as early as possible..... (adv Thank's)
/*
* Note: this file originally auto-generated by mib2c using
* : mib2c.table_data.conf 15999 2007-03-25 22:32:02Z dts12 $
*/
/** handles requests for the ocStbHostAVInterfaceTable table */ int
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#define CHRMAX1 256
#define MAX_IOD_LENGTH1 128
/** Initializes the ocStbHostAVInterfaceTable module */
void
init_ocStbHostAVInterfaceTable(void)
{
/*
* here we initialize all the tables we're planning on supporting
*/
initialize_table_ocStbHostAVInterfaceTable();
}
//# Determine the first/last column names
/** Initialize the ocStbHostAVInterfaceTable table by defining its contents
and how it's structured */
netsnmp_tdata *table_data;
void
initialize_table_ocStbHostAVInterfaceTable(void)
{
static oid ocStbHostAVInterfaceTable_oid[] =
{ 1, 3, 6, 1, 4, 1, 4491, 2, 3, 1, 1, 1, 2, 2 };
size_t ocStbHostAVInterfaceTable_oid_len =
OID_LENGTH(ocStbHostAVInterfaceTable_oid);
netsnmp_handler_registration *reg;
/*static*/ // netsnmp_tdata *table_data;
netsnmp_table_registration_info *table_info;
reg =
netsnmp_create_handler_registration("ocStbHostAVInterfaceTable",
ocStbHostAVInterfaceTable_handler,
ocStbHostAVInterfaceTable_oid,
ocStbHostAVInterfaceTable_oid_len,
HANDLER_CAN_RONLY);
table_data =
netsnmp_tdata_create_table("ocStbHostAVInterfaceTable", 0);
table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
netsnmp_table_helper_add_indexes(table_info, ASN_UNSIGNED, /* index:
ocStbHostAVInterfaceIndex */
0);
table_info->min_column = COLUMN_OCSTBHOSTAVINTERFACETYPE;
table_info->max_column = COLUMN_OCSTBHOSTAVINTERFACESTATUS;
netsnmp_tdata_register(reg, table_data, table_info);
/*
* Initialise the contents of the table here
*/
}
/*
* Typical data structure for a row entry
*/
struct ocStbHostAVInterfaceTable_entry {
/*
* Index values
*/
u_long ocStbHostAVInterfaceIndex;
/*
* Column values
*/
oid ocStbHostAVInterfaceType[MAX_IOD_LENGTH1];
size_t ocStbHostAVInterfaceType_len;
char ocStbHostAVInterfaceDesc[CHRMAX1];
size_t ocStbHostAVInterfaceDesc_len;
long ocStbHostAVInterfaceStatus;
int valid;
};
/*
* create a new row in the table
*/
netsnmp_tdata_row *
ocStbHostAVInterfaceTable_createEntry(netsnmp_tdata * table_data,
u_long ocStbHostAVInterfaceIndex)
{
struct ocStbHostAVInterfaceTable_entry *entry;
netsnmp_tdata_row *row;
entry = SNMP_MALLOC_TYPEDEF(struct ocStbHostAVInterfaceTable_entry);
if (!entry)
return NULL;
row = netsnmp_tdata_create_row();
if (!row) {
SNMP_FREE(entry);
return NULL;
}
row->data = entry;
entry->ocStbHostAVInterfaceIndex = ocStbHostAVInterfaceIndex;
netsnmp_tdata_row_add_index(row, ASN_UNSIGNED,
&(entry->ocStbHostAVInterfaceIndex),
sizeof(entry->ocStbHostAVInterfaceIndex));
netsnmp_tdata_add_row(table_data, row);
return row;
}
/*
* remove a row from the table
*/
void
ocStbHostAVInterfaceTable_removeEntry(netsnmp_tdata * table_data,
netsnmp_tdata_row * row)
{
struct ocStbHostAVInterfaceTable_entry *entry;
if (!row)
return; /* Nothing to remove */
entry = (struct ocStbHostAVInterfaceTable_entry *)
netsnmp_tdata_remove_and_delete_row(table_data, row);
if (entry)
SNMP_FREE(entry); /* XXX - release any other internal
resources */
}
int
ocStbHostAVInterfaceTable_handler(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests)
{
netsnmp_request_info *request;
netsnmp_table_request_info *table_info;
netsnmp_tdata *table_data;
netsnmp_tdata_row *table_row;
struct ocStbHostAVInterfaceTable_entry *table_entry;
int ret;
switch (reqinfo->mode) {
/*
* Read-support (also covers GetNext requests)
*/
case MODE_GET:
table_entry = (struct ocStbHostAVInterfaceTable_entry *)
netsnmp_tdata_extract_entry(request);
table_info = netsnmp_extract_table_info(request);
switch (table_info->colnum) {
case COLUMN_OCSTBHOSTAVINTERFACETYPE:
if (!table_entry) {
netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;
}
snmp_set_var_typed_value(request->requestvb, ASN_OBJECT_ID,
(u_char *) table_entry->
ocStbHostAVInterfaceType,
table_entry->
ocStbHostAVInterfaceType_len);
break;
case COLUMN_OCSTBHOSTAVINTERFACEDESC:
if (!table_entry) {
netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;
}
snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
(u_char *) table_entry->
ocStbHostAVInterfaceDesc,
table_entry->
ocStbHostAVInterfaceDesc_len);
break;
case COLUMN_OCSTBHOSTAVINTERFACESTATUS:
if (!table_entry) {
netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHINSTANCE);
continue;
}
snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
table_entry->
ocStbHostAVInterfaceStatus);
break;
default:
netsnmp_set_request_error(reqinfo, request,
SNMP_NOSUCHOBJECT);
break;
}
}
break;
}
return SNMP_ERR_NOERROR;
}
On Wed, Mar 12, 2008 at 6:39 AM, Dave Shield <[EMAIL PROTECTED]>
wrote:
> On 11/03/2008, kumar undurthi <[EMAIL PROTECTED]> wrote:
> > I have a problem in creating a table and Fill the table. i.e
> > Normally table can create in initialization() part and can be fill with
> the
> > static data.
> > But in My case.... I want to Create and Fill the table with the dynamic
> > data(values) when ever a request comes to the Agent.
>
> Probably the best approach would be to use the cache helper.
>
> You haven't said how you are generating the code,
> or which table helper you are using. But if you run
> something like
> mib2c -c mib2c.table_data.conf -S cache=1 myTable
>
> this should generate a suitable framework for your MIB module,
> including the code to load the table data when a request
> comes in. This cached data will then be used for the next
> few requests, until it's judged "too old". Whereupon the
> next request will trigger a fresh reload.
>
> The same approach can be used with the iterator helper
> (same command, but specifying 'mib2c.iterator.conf'),
> and probably also with the MfD framework.
> (though I don't know much about that one).
>
> Dave
>
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Net-snmp-users mailing list
[email protected]
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users