I've downloaded hivex-1.2.5.tar.gz, there is no /generator directory exist in the
tarball. But the files in /ocaml, /python and /perl bindings do indicate they were
generated by generator. Looks like the generators are missing in the tarball. I do see
generators in libguestfs-1.10.2 tarball.
Michael
-----Original Message-----
From: Richard W.M. Jones [mailto:rjones@redhat.com]
Sent: Wednesday, April 27, 2011 2:10 PM
To: Michael Huang
Cc: libguestfs(a)redhat.com
Subject: Re: [Libguestfs] Hivex java binding
On Wed, Apr 27, 2011 at 05:50:42PM +0000, Michael Huang wrote:
Thanks. I'm an experienced C++ developer, but a Java beginner.
I'll
see how far I can go by following libguestfs java binding
generator. Could you please help me with where to start?
In both libguestfs and hivex we take a very aggressive approach to
boilerplate code, like bindings. The approach is that we generate it
all in a large generator program (in both cases, in the generator/
directory of the source).
Grab the latest libguestfs source tarball (not git) since it has the
generator and the generated Java bindings. It's helpful to compare
the two things.
# generator
generator/generator_java.ml
# generated files
$ grep ^java generator/files-generated.txt
java/Bindtests.java
java/Makefile.inc
java/com/redhat/et/libguestfs/Application.java
java/com/redhat/et/libguestfs/Dirent.java
java/com/redhat/et/libguestfs/GuestFS.java
java/com/redhat/et/libguestfs/INotifyEvent.java
java/com/redhat/et/libguestfs/IntBool.java
java/com/redhat/et/libguestfs/LV.java
java/com/redhat/et/libguestfs/PV.java
java/com/redhat/et/libguestfs/Partition.java
java/com/redhat/et/libguestfs/Stat.java
java/com/redhat/et/libguestfs/StatVFS.java
java/com/redhat/et/libguestfs/VG.java
java/com/redhat/et/libguestfs/Version.java
java/com/redhat/et/libguestfs/XAttr.java
java/com_redhat_et_libguestfs_GuestFS.c
The idea is to take hivex/generator/generator.ml and write an
equivalent generator for Java. Each function in the hivex API is
defined here, for example:
"value_key", (RString, [AHive; AValue "val"]),
(hivex_value_key, returning a string, taking as parameters a hive
handle and a value).
Most of the code in the generator is pretty simplistic. It just
iterates over the list of API functions, and generates the appropriate
bits of boilerplate for each parameter and the return value.
and do I have to know OCaml for this work?
It'll help, but it's not really that hard, and mostly it's just using
our custom 'pr' command to print things (like printf), and List.iter
to iterate over things.
There is a tutorial here:
http://mirror.ocamlcore.org/ocaml-tutorial.org/index.html
and this book is excellent if you need more detail:
http://www.cs.caltech.edu/courses/cs134/cs134b/book.pdf
Rich.
--
Richard Jones, Virtualization Group, Red Hat
http://people.redhat.com/~rjones
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine. Supports Linux and Windows.
http://et.redhat.com/~rjones/virt-df/