Re: how to Initialise the contents of the table?
"蔷<Qiang Hu>" <[email protected]>
| Newsgroups | gmane.network.net-snmp.user |
|---|---|
| Message-ID | <[email protected]> |
i saw this routine and i'm pulzzled about "table_entry = (struct
tbModuleTable_entry *)netsnmp_extract_iterator_context(request);" it seems
that table_entry get relevant datas from this
netsnmp_extract_iterator_context;and how can i initial contents of table in
iterator.i can't understand the iterator operation mechanism. i saw an
exitent mib handler code of net-snmp which initials in this way
as following:
iinfo->make_data_context = netSnmpHostsTable_context_convert_function;
iinfo->free_data_context = netSnmpHostsTable_data_free;
iinfo->free_loop_context_at_end = netSnmpHostsTable_loop_free;
is there any examples mibs for how to modify the generater code by
mib2c.iterate.conf?
that's my generated code for my mib(not modified),can you tell me how to
set the datas of table?
/*
* Note: this file originally auto-generated by mib2c using
* : mib2c.iterate.conf,v 5.17 2005/05/09 08:13:45 dts12 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 "tb.h"
/** Initializes the tb module */
void
init_tb(void)
{
/*
* here we initialize all the tables we're planning on supporting
*/
initialize_table_tbModuleTable();
initialize_table_tbHwVersionTable();
}
/** Initialize the tbModuleTable table by defining its contents and how it's
structured */
void
initialize_table_tbModuleTable(void)
{
static oid tbModuleTable_oid[] =
{ 1, 3, 6, 1, 4, 1, 21776, 1, 1 };
size_t tbModuleTable_oid_len = OID_LENGTH(tbModuleTable_oid);
netsnmp_handler_registration *reg;
netsnmp_iterator_info *iinfo;
netsnmp_table_registration_info *table_info;
reg =
netsnmp_create_handler_registration("tbModuleTable",
tbModuleTable_handler,
tbModuleTable_oid,
tbModuleTable_oid_len,
HANDLER_CAN_RWRITE);
table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
netsnmp_table_helper_add_indexes(table_info, ASN_INTEGER, /* index:
tbModuleIndex */
0);
table_info->min_column = XXX;
table_info->max_column = YYY;
iinfo = SNMP_MALLOC_TYPEDEF(netsnmp_iterator_info);
iinfo->get_first_data_point = tbModuleTable_get_first_data_point;
iinfo->get_next_data_point = tbModuleTable_get_next_data_point;
iinfo->table_reginfo = table_info;
netsnmp_register_table_iterator(reg, iinfo);
/*
* Initialise the contents of the table here
*/
}
/*
* Typical data structure for a row entry
*/
struct tbModuleTable_entry {
/*
* Index values
*/
long tbModuleIndex;
/*
* Column values
*/
long tbModuleIndex;
u_long tbModuleID;
char tbModuleDescription;
char old_tbModuleDescription;
/*
* Illustrate using a simple linked list
*/
int valid;
struct tbModuleTable_entry *next;
};
struct tbModuleTable_entry *tbModuleTable_head;
/*
* create a new row in the (unsorted) table
*/
struct tbModuleTable_entry *
tbModuleTable_createEntry(long tbModuleIndex,)
{
struct tbModuleTable_entry *entry;
entry = SNMP_MALLOC_TYPEDEF(struct tbModuleTable_entry);
if (!entry)
return NULL;
entry->tbModuleIndex = tbModuleIndex;
entry->next = tbModuleTable_head;
tbModuleTable_head = entry;
return entry;
}
/*
* remove a row from the table
*/
void
tbModuleTable_removeEntry(struct tbModuleTable_entry *entry)
{
struct tbModuleTable_entry *ptr, *prev;
if (!entry)
return; /* Nothing to remove */
for (ptr = tbModuleTable_head, prev = NULL;
ptr != NULL; prev = ptr, ptr = ptr->next) {
if (ptr == entry)
break;
}
if (!ptr)
return; /* Can't find it */
if (prev == NULL)
tbModuleTable_head = ptr->next;
else
prev->next = ptr->next;
SNMP_FREE(entry); /* XXX - release any other internal
resources */
}
/*
* Example iterator hook routines - using 'get_next' to do most of the work
*/
netsnmp_variable_list *
tbModuleTable_get_first_data_point(void **my_loop_context,
void **my_data_context,
netsnmp_variable_list * put_index_data,
netsnmp_iterator_info *mydata)
{
*my_loop_context = tbModuleTable_head;
return tbModuleTable_get_next_data_point(my_loop_context,
my_data_context,
put_index_data, mydata);
}
netsnmp_variable_list *
tbModuleTable_get_next_data_point(void **my_loop_context,
void **my_data_context,
netsnmp_variable_list * put_index_data,
netsnmp_iterator_info *mydata)
{
struct tbModuleTable_entry *entry =
(struct tbModuleTable_entry *) *my_loop_context;
netsnmp_variable_list *idx = put_index_data;
if (entry) {
snmp_set_var_value(idx, entry->tbModuleIndex,
sizeof(entry->tbModuleIndex));
idx = idx->next_variable;
*my_data_context = (void *) entry;
*my_loop_context = (void *) entry->next;
} else {
return NULL;
}
}
/** handles requests for the tbModuleTable table */
int
tbModuleTable_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;
struct tbModuleTable_entry *table_entry;
switch (reqinfo->mode) {
/*
* Read-support (also covers GetNext requests)
*/
case MODE_GET:
for (request = requests; request; request = request->next) {
table_entry = (struct tbModuleTable_entry *)
netsnmp_extract_iterator_context(request);
table_info = netsnmp_extract_table_info(request);
switch (table_info->colnum) {
case COLUMN_TBMODULEINDEX:
snmp_set_var_typed_value(request->requestvb, ASN_INTEGER,
table_entry->tbModuleIndex,
sizeof(table_entry->
tbModuleIndex));
break;
case COLUMN_TBMODULEID:
snmp_set_var_typed_value(request->requestvb, ASN_UNSIGNED,
table_entry->tbModuleID,
sizeof(table_entry->tbModuleID));
break;
case COLUMN_TBMODULEDESCRIPTION:
snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
table_entry->tbModuleDescription,
sizeof(table_entry->
tbModuleDescription));
break;
}
}
break;
/*
* Write-support
*/
case MODE_SET_RESERVE1:
for (request = requests; request; request = request->next) {
table_entry = (struct tbModuleTable_entry *)
netsnmp_extract_iterator_context(request);
table_info = netsnmp_extract_table_info(request);
switch (table_info->colnum) {
case COLUMN_TBMODULEDESCRIPTION:
if (request->requestvb->type != ASN_OCTET_STR) {
netsnmp_set_request_error(reqinfo, request,
SNMP_ERR_WRONGTYPE);
return SNMP_ERR_NOERROR;
}
/*
* Also may need to check size/value
*/
break;
default:
netsnmp_set_request_error(reqinfo, request,
SNMP_ERR_NOTWRITABLE);
return SNMP_ERR_NOERROR;
}
}
break;
case MODE_SET_RESERVE2:
break;
case MODE_SET_FREE:
break;
case MODE_SET_ACTION:
for (request = requests; request; request = request->next) {
table_entry = (struct tbModuleTable_entry *)
netsnmp_extract_iterator_context(request);
table_info = netsnmp_extract_table_info(request);
switch (table_info->colnum) {
case COLUMN_TBMODULEDESCRIPTION:
/*
* Need to save old 'table_entry->tbModuleDescription'
value.
* May need to use 'memcpy'
*/
table_entry->old_tbModuleDescription =
table_entry->tbModuleDescription;
table_entry->tbModuleDescription =
request->requestvb->val.YYY;
break;
}
}
break;
case MODE_SET_UNDO:
for (request = requests; request; request = request->next) {
table_entry = (struct tbModuleTable_entry *)
netsnmp_extract_iterator_context(request);
table_info = netsnmp_extract_table_info(request);
switch (table_info->colnum) {
case COLUMN_TBMODULEDESCRIPTION:
/*
* Need to restore old 'table_entry->tbModuleDescription'
value.
* May need to use 'memcpy'
*/
table_entry->tbModuleDescription =
table_entry->old_tbModuleDescription;
break;
}
}
break;
case MODE_SET_COMMIT:
break;
}
return SNMP_ERR_NOERROR;
}
thanks in advance !
On 8/10/06, Dave Shield <[email protected]> wrote:
>
> On 10/08/06, qiang<Qiang Hu> <[email protected]> wrote:
> > I generated mib2c files by mib2c.conf also with iterator option.and now
> i
> > wanted to know how to Initialise the contents of the table
>
> If you look at the generated code, you should see a routine
> 'tbModuleTable_createEntry()'. Call this with the relevant values for
> each row you wish to create.
>
> The only unexpected thing is you'll need to explicitly set the 'valid'
> flag for each row.
> Something like:
>
> struct tbModuleTable_entry *entry;
>
> entry = tbModuleTable_createEntry(1, 256, "eenie");
> entry->valid = 1;
> entry = tbModuleTable_createEntry(3, 128, "meenie");
> entry->valid = 1;
> entry = tbModuleTable_createEntry(4, 64, "mynie");
> entry->valid = 1;
> entry = tbModuleTable_createEntry(2, 32, "mo");
> entry->valid = 1;
>
>
> Dave
>
--
qiang
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
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