[Libguestfs] [libnbd] More thoughts on callbacks and more

Richard W.M. Jones rjones at redhat.com
Mon Jul 22 13:52:22 UTC 2019


On Mon, Jul 22, 2019 at 08:13:12AM -0500, Eric Blake wrote:
> On 7/22/19 6:50 AM, Richard W.M. Jones wrote:
> > On Mon, Jul 22, 2019 at 10:08:25AM +0100, Richard W.M. Jones wrote:
> >> On Sat, Jul 20, 2019 at 07:38:45AM +0100, Richard W.M. Jones wrote:
> >>> More thoughts on callbacks, etc. following on from:
> >>> https://www.redhat.com/archives/libguestfs/2019-July/thread.html#00184
> >>>
> >>> Closure lifetimes
> >>> -----------------
> > 
> > Here's a possibly better idea which still changes the API a bit but
> > not as invasively.
> > 
> > We overload the callback so that it can either be a callback function
> > or a "free function".  They are distinguished by an extra flag
> > argument passed to the callback:
> > 
> >   extern int nbd_set_debug_callback (
> >         struct nbd_handle *h,
> >         int (*debug_fn) (int valid_flag,   // <-- note
> >                          void *user_data,
> > 	                 const char *context, const char *msg),
> >         void *user_data);
> 
> Would the 'valid_flag' be presented to non-C bindings, or is it only
> needed for C code?

C only.  It's not needed for languages which have garbage collection.
For non-C languages without GC, well I guess we can decide on a
case-by-case basis.


> At any rate, the idea makes sense as a lighter-weight
> way for libnbd to always inform the callback about the last invocation.

I've almost got a working implementation.  Will post it for review as
soon as I can.

[..]

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://people.redhat.com/~rjones/virt-top




More information about the Libguestfs mailing list