From d37f69795396ec2354eb2d8480d64b9e5bdafacc Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Fri, 2 Oct 2009 15:42:14 +0100 Subject: inspector: Generate language bindings for OCaml. This commit adds a generic mechanism for deriving language bindings for virt-inspector, and implements one concrete binding, for OCaml. The bindings are generated from the RELAX NG schema (virt-inspector.rng) which is supposed to be a correct and always up to date description of the XML that the virt-inspector program can generate. From the RNG we generate a set of types to describe the output of virt-inspector for the language, plus an XML parser, plus some glue code to actually run an external instance of virt-inspector and parse the resulting XML. At runtime, an external 'virt-inspector --xml ' command runs and the XML is parsed into language-specific structures. This has been tested on the four example files (inspector/example?.xml) The only particular difficulty about the OCaml binding is the use of Obj.magic, which is naughty but works because of the isomorphism between the representation of tuples and records in OCaml. This seems to cause no problems in my test program. Apart from this, the OCaml binding is straightforward and could be adapted easily for any other languages that want type-safe virt-inspector bindings. It's important to keep virt-inspector.rng up to date with changes to virt-inspector's XML output format. --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) (limited to '.gitignore') diff --git a/.gitignore b/.gitignore index 634da994..508f13a7 100644 --- a/.gitignore +++ b/.gitignore @@ -90,6 +90,7 @@ images/test-grep.txt.gz initramfs initramfs.timestamp inspector/virt-inspector.1 +inspector/stamp-inspector-generator install-sh *.jar java/api @@ -136,6 +137,8 @@ ocaml/examples/lvs ocaml/examples/throbber.ml ocaml/examples/viewer ocaml/guestfs_c_actions.c +ocaml/guestfs_inspector.ml +ocaml/guestfs_inspector.mli ocaml/guestfs.ml ocaml/guestfs.mli ocaml/META @@ -143,6 +146,7 @@ ocaml/t/guestfs_005_load ocaml/t/guestfs_010_launch ocaml/t/guestfs_050_lvcreate ocaml/t/guestfs_060_readdir +ocaml/t/guestfs_500_inspect perl/bindtests.pl perl/blib perl/Guestfs.bs -- cgit