On Sat, Aug 02, 2008 at 06:39:44PM +0200, Chris Lalancette wrote:
Tóth István wrote:
> I've found that libvirt for the most part has a very perdicitble and
> repetitive API (great design!), and as a result I've found myself
> copying the same code over and over again.
> I've decided to make generic JNI functions, that can handle multiple
> libvirt functions with function pointers.
> The generic functions are in generic.c and they are used extensively in
> the new Storage JNI implementation.
>
> I'd like to have your input on this architecture, my current plan is to
> refactor all trivial JNI functions to use these generics, unless there
> are objections.
(I haven't really read your patches, but...)
It's definitely good to get rid of a lot of the duplicated code.
However, you might want to take a look at the ruby-libvirt bindings
as a different way to do it. Basically, there are a few macros
which generate much of the "duplicated" type code, and in my
opinion, it's a little easier to read than lots of function
callbacks. The downside is that it's harder to debug with something
like gdb, but I'm not sure that is something you do with JNI
bindings anyway.
And while the OP is at it, take a look at a third approach used by
both the Python and OCaml bindings, namely using a script to generate
the bindings. In OCaml we have a big Perl script which writes out the
native bindings (in C):
http://hg.et.redhat.com/virt/applications/ocaml-libvirt--devel/?f=e8c67c0...
generates:
http://hg.et.redhat.com/virt/applications/ocaml-libvirt--devel/?f=114c1e0...
I've tried to generate C code which is readable, thus 'gdb' is useful.
The Python bindings are generated in a similar way.
I have in the past made comments about the 'irreducible complexity' of
generating libvirt bindings, so I won't repeat that :-)
Rich.
--
Richard Jones, Emerging Technologies, Red Hat
http://et.redhat.com/~rjones
virt-top is 'top' for virtual machines. Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://et.redhat.com/~rjones/virt-top