# The functions in the libvirt API that we can generate.
my @functions = (
+ { name => "virConnectClose", sig => "conn : free" },
{ name => "virConnectGetHostname", sig => "conn : string", weak => 1 },
{ name => "virConnectGetURI", sig => "conn : string", weak => 1 },
{ name => "virConnectGetType", sig => "conn : static string" },
sig => "conn, int : string array", weak => 1 },
{ name => "virConnectGetCapabilities", sig => "conn : string" },
+ { name => "virDomainFree", sig => "dom : free" },
+ { name => "virDomainDestroy", sig => "dom : free" },
{ name => "virDomainLookupByName", sig => "conn, string : dom" },
{ name => "virDomainLookupByUUIDString", sig => "conn, string : dom" },
{ name => "virDomainGetName", sig => "dom : static string" },
{ name => "virDomainGetAutostart", sig => "dom : bool" },
{ name => "virDomainSetAutostart", sig => "dom, bool : unit" },
+ { name => "virNetworkFree", sig => "net : free" },
+ { name => "virNetworkDestroy", sig => "net : free" },
{ name => "virNetworkLookupByName", sig => "conn, string : net" },
{ name => "virNetworkLookupByUUIDString", sig => "conn, string : net" },
{ name => "virNetworkGetName", sig => "net : static string" },
{ name => "virNetworkGetAutostart", sig => "net : bool" },
{ name => "virNetworkSetAutostart", sig => "net, bool : unit" },
+ { name => "virStoragePoolFree",
+ sig => "pool : free", weak => 1 },
+ { name => "virStoragePoolDestroy",
+ sig => "pool : free", weak => 1 },
{ name => "virStoragePoolLookupByName",
sig => "conn, string : pool", weak => 1 },
{ name => "virStoragePoolLookupByUUIDString",
{ name => "virStoragePoolSetAutostart",
sig => "pool, bool : unit", weak => 1 },
+ { name => "virStorageVolFree", sig => "vol : free" },
+ { name => "virStorageVolDestroy", sig => "vol : free" },
# { name => "virStorageVolLookupByName", XXX see libvir-list posting
# sig => "pool, string : vol", weak => 1 },
{ name => "virStorageVolLookupByKey",
"ocaml_libvirt_network_create_job",
"ocaml_libvirt_network_create_xml_job",
"ocaml_libvirt_storage_pool_get_info",
- "ocaml_libvirt_storage_pool_free", #?
- "ocaml_libvirt_storage_pool_destroy", #?
"ocaml_libvirt_storage_pool_define_xml",
"ocaml_libvirt_storage_pool_create_xml",
"ocaml_libvirt_storage_pool_lookup_by_uuid",
"ocaml_libvirt_storage_vol_lookup_by_name", # XXX
- "ocaml_libvirt_storage_vol_free", #?
- "ocaml_libvirt_storage_vol_destroy", #?
"ocaml_libvirt_storage_vol_create_xml",
"ocaml_libvirt_storage_vol_get_info",
"ocaml_libvirt_pool_of_volume",
} elsif ($sig =~ /^(\w+) : unit$/) {
my $c_type = short_name_to_c_type ($1);
"int $c_name ($c_type $1)"
+ } elsif ($sig =~ /^(\w+) : free$/) {
+ my $c_type = short_name_to_c_type ($1);
+ "int $c_name ($c_type $1)"
} elsif ($sig =~ /^(\w+), string : (\w+)$/) {
my $c_type = short_name_to_c_type ($1);
my $c_ret_type = short_name_to_c_type ($2);
( "$1v" )
} elsif ($sig =~ /^(\w+) : unit$/) {
( "$1v" )
+ } elsif ($sig =~ /^(\w+) : free$/) {
+ ( "$1v" )
} elsif ($sig =~ /^(\w+), string : (\w+)$/) {
( "$1v", "strv" )
} else {
{
local $_ = shift;
- if ($_ eq "dom") {
- "rv = Val_domain (r, connv);"
- } elsif ($_ eq "net") {
- "rv = Val_network (r, connv);"
- } elsif ($_ eq "pool") {
- "rv = Val_pool (r, connv);"
- } elsif ($_ eq "vol") {
- "rv = Val_volume (r, connv);"
+ if ($_ eq "dom") { "rv = Val_domain (r, connv);" }
+ elsif ($_ eq "net") { "rv = Val_network (r, connv);" }
+ elsif ($_ eq "pool") { "rv = Val_pool (r, connv);" }
+ elsif ($_ eq "vol") { "rv = Val_volume (r, connv);" }
+ else {
+ die "unknown short name $_"
+ }
+}
+
+sub gen_free_arg
+{
+ local $_ = shift;
+
+ if ($_ eq "conn") { "Connect_val (connv) = NULL;" }
+ elsif ($_ eq "dom") { "Domain_val (domv) = NULL;" }
+ elsif ($_ eq "net") { "Network_val (netv) = NULL;" }
+ elsif ($_ eq "pool") { "Pool_val (poolv) = NULL;" }
+ elsif ($_ eq "vol") { "Volume_val (volv) = NULL;" }
+ else {
+ die "unknown short name $_"
}
}
free (r);
CAMLreturn (rv);
"
+ } elsif ($sig =~ /^(\w+), 0U? : unit$/) {
+ "\
+ " . gen_unpack_args ($1) . "
+ int r;
+
+ NONBLOCKING (r = $c_name ($1, 0));
+ CHECK_ERROR (r == -1, conn, \"$c_name\");
+
+ CAMLreturn (Val_unit);
+"
} elsif ($sig =~ /^(\w+) : unit$/) {
"\
" . gen_unpack_args ($1) . "
CAMLreturn (Val_unit);
"
- } elsif ($sig =~ /^(\w+), 0U? : unit$/) {
+ } elsif ($sig =~ /^(\w+) : free$/) {
"\
" . gen_unpack_args ($1) . "
int r;
- NONBLOCKING (r = $c_name ($1, 0));
+ NONBLOCKING (r = $c_name ($1));
CHECK_ERROR (r == -1, conn, \"$c_name\");
+ /* So that we don't double-free in the finalizer: */
+ " . gen_free_arg ($1) . "
+
CAMLreturn (Val_unit);
"
} elsif ($sig =~ /^(\w+), string : (\w+)$/) {
#include "libvirt_c_oneoffs.c"
+CAMLprim value
+ocaml_libvirt_connect_close (value connv)
+{
+ CAMLparam1 (connv);
+
+ virConnectPtr conn = Connect_val (connv);
+ int r;
+
+ NONBLOCKING (r = virConnectClose (conn));
+ CHECK_ERROR (r == -1, conn, "virConnectClose");
+
+ /* So that we don't double-free in the finalizer: */
+ Connect_val (connv) = NULL;
+
+ CAMLreturn (Val_unit);
+}
+
#ifdef HAVE_WEAK_SYMBOLS
#ifdef HAVE_VIRCONNECTGETHOSTNAME
extern char *virConnectGetHostname (virConnectPtr conn) __attribute__((weak));
}
CAMLprim value
+ocaml_libvirt_domain_free (value domv)
+{
+ CAMLparam1 (domv);
+
+ virDomainPtr dom = Domain_val (domv);
+ virConnectPtr conn = Connect_domv (domv);
+ int r;
+
+ NONBLOCKING (r = virDomainFree (dom));
+ CHECK_ERROR (r == -1, conn, "virDomainFree");
+
+ /* So that we don't double-free in the finalizer: */
+ Domain_val (domv) = NULL;
+
+ CAMLreturn (Val_unit);
+}
+
+CAMLprim value
+ocaml_libvirt_domain_destroy (value domv)
+{
+ CAMLparam1 (domv);
+
+ virDomainPtr dom = Domain_val (domv);
+ virConnectPtr conn = Connect_domv (domv);
+ int r;
+
+ NONBLOCKING (r = virDomainDestroy (dom));
+ CHECK_ERROR (r == -1, conn, "virDomainDestroy");
+
+ /* So that we don't double-free in the finalizer: */
+ Domain_val (domv) = NULL;
+
+ CAMLreturn (Val_unit);
+}
+
+CAMLprim value
ocaml_libvirt_domain_lookup_by_name (value connv, value strv)
{
CAMLparam2 (connv, strv);
}
CAMLprim value
+ocaml_libvirt_network_free (value netv)
+{
+ CAMLparam1 (netv);
+
+ virNetworkPtr net = Network_val (netv);
+ virConnectPtr conn = Connect_netv (netv);
+ int r;
+
+ NONBLOCKING (r = virNetworkFree (net));
+ CHECK_ERROR (r == -1, conn, "virNetworkFree");
+
+ /* So that we don't double-free in the finalizer: */
+ Network_val (netv) = NULL;
+
+ CAMLreturn (Val_unit);
+}
+
+CAMLprim value
+ocaml_libvirt_network_destroy (value netv)
+{
+ CAMLparam1 (netv);
+
+ virNetworkPtr net = Network_val (netv);
+ virConnectPtr conn = Connect_netv (netv);
+ int r;
+
+ NONBLOCKING (r = virNetworkDestroy (net));
+ CHECK_ERROR (r == -1, conn, "virNetworkDestroy");
+
+ /* So that we don't double-free in the finalizer: */
+ Network_val (netv) = NULL;
+
+ CAMLreturn (Val_unit);
+}
+
+CAMLprim value
ocaml_libvirt_network_lookup_by_name (value connv, value strv)
{
CAMLparam2 (connv, strv);
}
#ifdef HAVE_WEAK_SYMBOLS
+#ifdef HAVE_VIRSTORAGEPOOLFREE
+extern int virStoragePoolFree (virStoragePoolPtr pool) __attribute__((weak));
+#endif
+#endif
+
+CAMLprim value
+ocaml_libvirt_storage_pool_free (value poolv)
+{
+ CAMLparam1 (poolv);
+#ifndef HAVE_VIRSTORAGEPOOLFREE
+ /* Symbol virStoragePoolFree not found at compile time. */
+ not_supported ("virStoragePoolFree");
+ /* Suppresses a compiler warning. */
+ (void) caml__frame;
+#else
+ /* Check that the symbol virStoragePoolFree
+ * is in runtime version of libvirt.
+ */
+ WEAK_SYMBOL_CHECK (virStoragePoolFree);
+
+ virStoragePoolPtr pool = Pool_val (poolv);
+ virConnectPtr conn = Connect_polv (poolv);
+ int r;
+
+ NONBLOCKING (r = virStoragePoolFree (pool));
+ CHECK_ERROR (r == -1, conn, "virStoragePoolFree");
+
+ /* So that we don't double-free in the finalizer: */
+ Pool_val (poolv) = NULL;
+
+ CAMLreturn (Val_unit);
+#endif
+}
+
+#ifdef HAVE_WEAK_SYMBOLS
+#ifdef HAVE_VIRSTORAGEPOOLDESTROY
+extern int virStoragePoolDestroy (virStoragePoolPtr pool) __attribute__((weak));
+#endif
+#endif
+
+CAMLprim value
+ocaml_libvirt_storage_pool_destroy (value poolv)
+{
+ CAMLparam1 (poolv);
+#ifndef HAVE_VIRSTORAGEPOOLDESTROY
+ /* Symbol virStoragePoolDestroy not found at compile time. */
+ not_supported ("virStoragePoolDestroy");
+ /* Suppresses a compiler warning. */
+ (void) caml__frame;
+#else
+ /* Check that the symbol virStoragePoolDestroy
+ * is in runtime version of libvirt.
+ */
+ WEAK_SYMBOL_CHECK (virStoragePoolDestroy);
+
+ virStoragePoolPtr pool = Pool_val (poolv);
+ virConnectPtr conn = Connect_polv (poolv);
+ int r;
+
+ NONBLOCKING (r = virStoragePoolDestroy (pool));
+ CHECK_ERROR (r == -1, conn, "virStoragePoolDestroy");
+
+ /* So that we don't double-free in the finalizer: */
+ Pool_val (poolv) = NULL;
+
+ CAMLreturn (Val_unit);
+#endif
+}
+
+#ifdef HAVE_WEAK_SYMBOLS
#ifdef HAVE_VIRSTORAGEPOOLLOOKUPBYNAME
extern virStoragePoolPtr virStoragePoolLookupByName (virConnectPtr conn, const char *str) __attribute__((weak));
#endif
#endif
}
+CAMLprim value
+ocaml_libvirt_storage_vol_free (value volv)
+{
+ CAMLparam1 (volv);
+
+ virStorageVolPtr vol = Volume_val (volv);
+ virConnectPtr conn = Connect_volv (volv);
+ int r;
+
+ NONBLOCKING (r = virStorageVolFree (vol));
+ CHECK_ERROR (r == -1, conn, "virStorageVolFree");
+
+ /* So that we don't double-free in the finalizer: */
+ Volume_val (volv) = NULL;
+
+ CAMLreturn (Val_unit);
+}
+
+CAMLprim value
+ocaml_libvirt_storage_vol_destroy (value volv)
+{
+ CAMLparam1 (volv);
+
+ virStorageVolPtr vol = Volume_val (volv);
+ virConnectPtr conn = Connect_volv (volv);
+ int r;
+
+ NONBLOCKING (r = virStorageVolDestroy (vol));
+ CHECK_ERROR (r == -1, conn, "virStorageVolDestroy");
+
+ /* So that we don't double-free in the finalizer: */
+ Volume_val (volv) = NULL;
+
+ CAMLreturn (Val_unit);
+}
+
#ifdef HAVE_WEAK_SYMBOLS
#ifdef HAVE_VIRSTORAGEVOLLOOKUPBYKEY
extern virStorageVolPtr virStorageVolLookupByKey (virConnectPtr conn, const char *str) __attribute__((weak));
}
CAMLprim value
-ocaml_libvirt_storage_pool_free ()
-{
- failwith ("ocaml_libvirt_storage_pool_free is unimplemented");
-}
-
-CAMLprim value
-ocaml_libvirt_storage_pool_destroy ()
-{
- failwith ("ocaml_libvirt_storage_pool_destroy is unimplemented");
-}
-
-CAMLprim value
ocaml_libvirt_storage_pool_define_xml ()
{
failwith ("ocaml_libvirt_storage_pool_define_xml is unimplemented");
}
CAMLprim value
-ocaml_libvirt_storage_vol_free ()
-{
- failwith ("ocaml_libvirt_storage_vol_free is unimplemented");
-}
-
-CAMLprim value
-ocaml_libvirt_storage_vol_destroy ()
-{
- failwith ("ocaml_libvirt_storage_vol_destroy is unimplemented");
-}
-
-CAMLprim value
ocaml_libvirt_storage_vol_create_xml ()
{
failwith ("ocaml_libvirt_storage_vol_create_xml is unimplemented");
}
CAMLprim value
-ocaml_libvirt_connect_close (value connv)
-{
- CAMLparam1 (connv);
- virConnectPtr conn = Connect_val (connv);
- int r;
-
- NONBLOCKING (r = virConnectClose (conn));
- CHECK_ERROR (r == -1, conn, "virConnectClose");
-
- /* So that we don't double-free in the finalizer: */
- Connect_val (connv) = NULL;
-
- CAMLreturn (Val_unit);
-}
-
-CAMLprim value
ocaml_libvirt_connect_get_version (value connv)
{
CAMLparam1 (connv);
}
CAMLprim value
-ocaml_libvirt_domain_destroy (value domv)
-{
- CAMLparam1 (domv);
- virDomainPtr dom = Domain_val (domv);
- virConnectPtr conn = Connect_domv (domv);
- int r;
-
- NONBLOCKING (r = virDomainDestroy (dom));
- CHECK_ERROR (r == -1, conn, "virDomainDestroy");
-
- /* So that we don't double-free in the finalizer: */
- Domain_val (domv) = NULL;
-
- CAMLreturn (Val_unit);
-}
-
-CAMLprim value
-ocaml_libvirt_domain_free (value domv)
-{
- CAMLparam1 (domv);
- virDomainPtr dom = Domain_val (domv);
- virConnectPtr conn = Connect_domv (domv);
- int r;
-
- NONBLOCKING (r = virDomainFree (dom));
- CHECK_ERROR (r == -1, conn, "virDomainFree");
-
- /* So that we don't double-free in the finalizer: */
- Domain_val (domv) = NULL;
-
- CAMLreturn (Val_unit);
-}
-
-CAMLprim value
ocaml_libvirt_domain_save (value domv, value pathv)
{
CAMLparam2 (domv, pathv);
CAMLreturn (rv);
}
-CAMLprim value
-ocaml_libvirt_network_destroy (value netv)
-{
- CAMLparam1 (netv);
- virNetworkPtr net = Network_val (netv);
- virConnectPtr conn = Connect_netv (netv);
- int r;
-
- NONBLOCKING (r = virNetworkDestroy (net));
- CHECK_ERROR (r == -1, conn, "virNetworkDestroy");
-
- /* So that we don't double-free in the finalizer: */
- Network_val (netv) = NULL;
-
- CAMLreturn (Val_unit);
-}
-
-CAMLprim value
-ocaml_libvirt_network_free (value netv)
-{
- CAMLparam1 (netv);
- virNetworkPtr net = Network_val (netv);
- virConnectPtr conn = Connect_netv (netv);
- int r;
-
- NONBLOCKING (r = virNetworkFree (net));
- CHECK_ERROR (r == -1, conn, "virNetworkFree");
-
- /* So that we don't double-free in the finalizer: */
- Network_val (netv) = NULL;
-
- CAMLreturn (Val_unit);
-}
-
/*----------------------------------------------------------------------*/
CAMLprim value