It's solved... :)
The correct procedure in my case, is to allocate data context in
get_next_data_point(...)
so, a skeleton of the _access.c
xxx_get_first_data_point()
{
my_loop_info * loopctx;
loopctx = SNMP_ALLOC_MEMORY(my_loop_info);
...
//obtain number of rows and/or any other info useful for looping
...
my_loop_context = *loopctx;
return xxx_get_next_data()
{
xxx_get_next_data_point()
{
int iter;
my_loop_info *loopctx;
my_data_info *datactx;
loopctx = *my_loop_ctx;
datactx = SNMP_ALLOC_MEMORY(my_data_info); //<--- CAUTION! function
free_data_context must be allocated in iinfo to free this
while (/*condition obtained from loopctx variables*/)
{
iter++;
datactx->A = get_A_value(iter);
datactx->B = get_B_value(iter);
}
/* no more rows */
*loopctx= NULL;
return NULL;
}
Dave, thanks for give me some pointers... literally :P
On Thu, Jul 3, 2008 at 1:27 PM, Victor Palacio <
[EMAIL PROTECTED]> wrote:
>
>
> On Thu, Jul 3, 2008 at 11:13 AM, Dave Shield <[EMAIL PROTECTED]>
> wrote:
>
>> 2008/7/3 Victor Palacio <[EMAIL PROTECTED]>:
>> >
>> > I'm trying to use table iterator from code skeleton generated with
>> > mib2c.iterate.conf.
>> >
>> > When I use snmptable on the agent, get_first_data_point function is
>> > executed every time one column is consulted, so I suppose I must load
>> > data for consulted row in data context.
>> >
>> > The problem is... How can I identify which row (index) is consulted
>>
>> You don't - that's the job of the iterator helper.
>>
>> You provide the get_{first,next}_data_point functions, which
>> walk through the table in whatever order is most convenient.
>>
>> The iterator helper will identify the row(s) which are required for
>> the current request. It then calls your handler routine, passing
>> the data structure for that row, as suppied via the 'data_context'
>> parameter of the two get_{first,next} routines.
>>
>>
>> Dave
>>
>
>
>
> --
> Thanks for your answer, Dave... but I still have problems with this.
>
> My problem is that all rows are using the last data context, so I get same
> information for all rows, although then number of rows is correct.
>
> In _get_first_data_point, I ...
>
> 1)Create Loop and Data context,
> 2)set number of rows in loop context and,
> 3)call get_next_data_point
>
> In get_next_data_point, I assume that I can use same data_context. Perhaps
> must I allocate new data context in get_next_data_point?
>
> Regards,
>
> CODE:
>
> myTable_get_next_data_point(void **my_loop_context, void **my_data_context,
> netsnmp_variable_list *put_index_data,
> netsnmp_iterator_info *mydata)
> {
>
> netsnmp_variable_list *vptr;
>
> my_loop_info *loopctx = *my_loop_context;
> my_data_info *datactx = *my_data_context;
>
> if (!loopctx){
> return NULL;
> }
>
>
> while (iter < loopctx->MAX_ROWS){
> iter++;
>
> /* OBTAIN VALUES A and B FOR ITER */
> //...
>
> datactx->index = iter;
> datactx->A = A;
> datactx->B = B;
>
> vptr = put_index_data;
> snmp_set_var_value(vptr, (u_char *) & datactx->index,
> sizeof(datactx->index));
>
> *my_loop_context = loopctx;
> *my_data_context = datactx;
>
> return put_index_data;
>
> }
>
> /* we're out of data */
> *my_loop_context = NULL;
>
> return NULL;
> }
>
> ********************
> Victor M. Palacio
> ********************
--
********************
Victor M. Palacio
********************
-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
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