Hi
Thanks for your help.  I suspect I can use the 'free_data_context'
function to help me out here:

In get_first/get_next I could increment a reference counter which then
gets decremented in free_data_context.
I could therefore lock my data in get_first and when the counter reaches
0 again in free_data_context I could unlock the data.
This would ensure I always have a valid pointer to my data in the
data_handler.

Is there anything I might have missed in this solution?

Thanks
Graeme



> -----Original Message-----
> From: Robert Story [mailto:[EMAIL PROTECTED] 
> Sent: 21 September 2006 14:19
> To: Dave Shield
> Cc: [email protected]; Graeme Wilson
> Subject: Re: Table iterator - data protection
> 
> On Thu, 21 Sep 2006 09:43:24 +0100 Dave wrote:
> DS> What the handler needs is "some way" of retrieving the data for a 
> DS> particular row.
> DS> This is the role of 'my_data_context'.   The details of 
> "some way" are
> DS> up to you.
> DS> 
> DS> The most common approach is to have this variable point 
> directly to 
> DS> the full contents of the row (e.g. as an entry within a 
> linked list),
> DS> but that's not the only way to handle this.   You could 
> equally well
> DS> pass a database lookup key, or the index into some global 
> array, or 
> DS> a kernel memory address.
> 
> DS> If you're concerned about the underlying table data changing 
> DS> underneath your feet, then one possibillity might be to 
> load a copy 
> DS> of the table into the agent, and work with that copy instead.
> 
> Well, since Dave didn't remember the details either, I went 
> and poked about.
> It seems that the agent does track the data context as it 
> finds the best match. Usually it just keeps the pointer, but 
> if you are worried about that pointer vanishing, then you can 
> allocate data. Based on looking at the code, it looks like 
> you need to specify a function for the make_data_context 
> function pointer. The prototype for the function is:
> 
>     typedef void *(Netsnmp_Make_Data_Context) (void *loop_context,
>                                              struct 
> netsnmp_iterator_info_s *);
> 
> So, after each get_next_data_point, if the most recent OID 
> returned is the best match, the make_data_context will be 
> called with the same loop_context, allowing you to allocate 
> memory to store the data. The free_context callback function 
> will be used to free the allocated memory when the agent is 
> done with it.
> 


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to