Further work on storage API and autogenerating bindings.
[virt-top.git] / libvirt / generator.pl
index 2c5ff1e..b389a1b 100755 (executable)
@@ -62,6 +62,8 @@ my @functions = (
     { name => "virDomainReboot", sig => "dom, 0 : unit" },
     { name => "virDomainUndefine", sig => "dom : unit" },
     { name => "virDomainCreate", sig => "dom : unit" },
+    { name => "virDomainGetAutostart", sig => "dom : bool" },
+    { name => "virDomainSetAutostart", sig => "dom, bool : unit" },
 
     { name => "virNetworkLookupByName", sig => "conn, string : net" },
     { name => "virNetworkLookupByUUIDString", sig => "conn, string : net" },
@@ -70,6 +72,8 @@ my @functions = (
     { name => "virNetworkGetBridgeName", sig => "net : string" },
     { name => "virNetworkUndefine", sig => "net : unit" },
     { name => "virNetworkCreate", sig => "net : unit" },
+    { name => "virNetworkGetAutostart", sig => "net : bool" },
+    { name => "virNetworkSetAutostart", sig => "net, bool : unit" },
 
     { name => "virStoragePoolLookupByName",
       sig => "conn, string : pool", weak => 1 },
@@ -80,28 +84,32 @@ my @functions = (
     { name => "virStoragePoolGetXMLDesc",
       sig => "pool, 0 : string", weak => 1 },
     { name => "virStoragePoolUndefine",
-      sig => "pool : string", weak => 1 },
+      sig => "pool : unit", weak => 1 },
     { name => "virStoragePoolCreate",
-      sig => "pool : string", weak => 1 },
+      sig => "pool : unit", weak => 1 },
     { name => "virStoragePoolShutdown",
-      sig => "pool : string", weak => 1 },
+      sig => "pool : unit", weak => 1 },
     { name => "virStoragePoolRefresh",
-      sig => "pool, 0 : string", weak => 1 },
-
-    { name => "virStorageVolLookupByName",
-      sig => "conn, string : vol", weak => 1 },
+      sig => "pool, 0U : unit", weak => 1 },
+    { name => "virStoragePoolGetAutostart",
+      sig => "pool : bool", weak => 1 },
+    { name => "virStoragePoolSetAutostart",
+      sig => "pool, bool : unit", weak => 1 },
+
+#    { name => "virStorageVolLookupByName", XXX see libvir-list posting
+#      sig => "pool, string : vol", weak => 1 },
     { name => "virStorageVolLookupByKey",
       sig => "conn, string : vol", weak => 1 },
     { name => "virStorageVolLookupByPath",
       sig => "conn, string : vol", weak => 1 },
     { name => "virStorageVolGetXMLDesc",
-      sig => "pool, 0 : string", weak => 1 },
+      sig => "vol, 0 : string", weak => 1 },
     { name => "virStorageVolGetPath",
-      sig => "pool : string", weak => 1 },
+      sig => "vol : string", weak => 1 },
     { name => "virStorageVolGetKey",
-      sig => "pool : static string", weak => 1 },
+      sig => "vol : static string", weak => 1 },
     { name => "virStorageVolGetName",
-      sig => "pool : static string", weak => 1 },
+      sig => "vol : static string", weak => 1 },
 
     );
 
@@ -117,8 +125,6 @@ my @unimplemented = (
     "ocaml_libvirt_connect_create_linux_job",
     "ocaml_libvirt_network_create_job",
     "ocaml_libvirt_network_create_xml_job",
-    "ocaml_libvirt_storage_pool_set_autostart", #?
-    "ocaml_libvirt_storage_pool_get_autostart", #?
     "ocaml_libvirt_storage_pool_get_info",
     "ocaml_libvirt_storage_pool_get_uuid_string", #?
     "ocaml_libvirt_storage_pool_get_uuid", #?
@@ -127,6 +133,7 @@ my @unimplemented = (
     "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",
@@ -148,7 +155,10 @@ open F, ">$filename" or die "$filename: $!";
 # Write the prologue.
 
 print F <<'END';
-/* WARNING: THIS FILE IS AUTOMATICALLY GENERATED BY 'generator.pl'.
+/* !!! WARNING WARNING WARNING WARNING WARNING WARNING WARNING !!!
+ *
+ * THIS FILE IS AUTOMATICALLY GENERATED BY 'generator.pl'.
+ *
  * Any changes you make to this file may be overwritten.
  */
 
@@ -238,23 +248,31 @@ sub gen_c_signature
     } elsif ($sig =~ /^(\w+) : int$/) {
        my $c_type = short_name_to_c_type ($1);
        "int $c_name ($c_type $1)"
+    } elsif ($sig =~ /^(\w+) : bool$/) {
+       my $c_type = short_name_to_c_type ($1);
+       "int $c_name ($c_type $1, int *r)"
+    } elsif ($sig =~ /^(\w+), bool : unit$/) {
+       my $c_type = short_name_to_c_type ($1);
+       "int $c_name ($c_type $1, int b)"
     } elsif ($sig eq "conn, int : int array") {
        "int $c_name (virConnectPtr conn, int *ids, int maxids)"
     } elsif ($sig eq "conn, int : string array") {
        "int $c_name (virConnectPtr conn, char **const names, int maxnames)"
-    } elsif ($sig =~ /^(\w+), 0 : string$/) {
+    } elsif ($sig =~ /^(\w+), 0(U?) : string$/) {
        my $c_type = short_name_to_c_type ($1);
-       "char *$c_name ($c_type $1, int flags)"
-    } elsif ($sig =~ /^(\w+), 0 : unit$/) {
+       my $unsigned = $2 eq "U" ? "unsigned " : "";
+       "char *$c_name ($c_type $1, $unsigned int flags)"
+    } elsif ($sig =~ /^(\w+), 0(U?) : unit$/) {
        my $c_type = short_name_to_c_type ($1);
-       "int $c_name ($c_type $1, int flags)"
+       my $unsigned = $2 eq "U" ? "unsigned " : "";
+       "int $c_name ($c_type $1, $unsigned int flags)"
     } elsif ($sig =~ /^(\w+) : unit$/) {
        my $c_type = short_name_to_c_type ($1);
-       "int $c_name ($c_type $1 dom)"
+       "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);
-       "$c_ret_type $c_name ($c_type $1 dom)"
+       "$c_ret_type $c_name ($c_type $1, const char *str)"
     } else {
        die "unknown signature $sig"
     }
@@ -270,13 +288,17 @@ sub gen_arg_names
        ( "$1v" )
     } elsif ($sig =~ /^(\w+) : int$/) {
        ( "$1v" )
+    } elsif ($sig =~ /^(\w+) : bool$/) {
+       ( "$1v" )
+    } elsif ($sig =~ /^(\w+), bool : unit$/) {
+       ( "$1v", "bv" )
     } elsif ($sig eq "conn, int : int array") {
        ( "connv", "iv" )
     } elsif ($sig eq "conn, int : string array") {
        ( "connv", "iv" )
-    } elsif ($sig =~ /^(\w+), 0 : string$/) {
+    } elsif ($sig =~ /^(\w+), 0U? : string$/) {
        ( "$1v" )
-    } elsif ($sig =~ /^(\w+), 0 : unit$/) {
+    } elsif ($sig =~ /^(\w+), 0U? : unit$/) {
        ( "$1v" )
     } elsif ($sig =~ /^(\w+) : unit$/) {
        ( "$1v" )
@@ -365,6 +387,28 @@ sub gen_c_code
 
   CAMLreturn (Val_int (r));
 "
+    } elsif ($sig =~ /^(\w+) : bool$/) {
+       "\
+  " . gen_unpack_args ($1) . "
+  int r, b;
+
+  NONBLOCKING (r = $c_name ($1, &b));
+  CHECK_ERROR (r == -1, conn, \"$c_name\");
+
+  CAMLreturn (b ? Val_true : Val_false);
+"
+    } elsif ($sig =~ /^(\w+), bool : unit$/) {
+       "\
+  " . gen_unpack_args ($1) . "
+  int r, b;
+
+  b = bv == Val_true ? 1 : 0;
+
+  NONBLOCKING (r = $c_name ($1, b));
+  CHECK_ERROR (r == -1, conn, \"$c_name\");
+
+  CAMLreturn (Val_unit);
+"
     } elsif ($sig eq "conn, int : int array") {
        "\
   CAMLlocal1 (rv);
@@ -401,7 +445,7 @@ sub gen_c_code
 
   CAMLreturn (rv);
 "
-    } elsif ($sig =~ /^(\w+), 0 : string$/) {
+    } elsif ($sig =~ /^(\w+), 0U? : string$/) {
        "\
   CAMLlocal1 (rv);
   " . gen_unpack_args ($1) . "
@@ -424,7 +468,7 @@ sub gen_c_code
 
   CAMLreturn (Val_unit);
 "
-    } elsif ($sig =~ /^(\w+), 0 : unit$/) {
+    } elsif ($sig =~ /^(\w+), 0U? : unit$/) {
        "\
   " . gen_unpack_args ($1) . "
   int r;