3 # OCaml bindings for libvirt.
4 # (C) Copyright 2007-2008 Richard W.M. Jones, Red Hat Inc.
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2 of the License, or (at your option) any later version.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 # This generates libvirt_c.c (the core of the bindings). You don't
22 # need to run this program unless you are extending the bindings
23 # themselves (eg. because libvirt has been extended).
25 # Please read libvirt/README.
29 #----------------------------------------------------------------------
31 # The functions in the libvirt API that we can generate.
33 # The 'sig' (signature) doesn't have a meaning or any internal structure.
34 # It is interpreted by the generation functions below to indicate what
35 # "class" the function falls into, and to generate the right class of
38 # Any function added since libvirt 0.2.1 must be marked weak.
41 { name => "virConnectClose", sig => "conn : free" },
42 { name => "virConnectGetHostname", sig => "conn : string", weak => 1 },
43 { name => "virConnectGetURI", sig => "conn : string", weak => 1 },
44 { name => "virConnectGetType", sig => "conn : static string" },
45 { name => "virConnectNumOfDomains", sig => "conn : int" },
46 { name => "virConnectListDomains", sig => "conn, int : int array" },
47 { name => "virConnectNumOfDefinedDomains", sig => "conn : int" },
48 { name => "virConnectListDefinedDomains",
49 sig => "conn, int : string array" },
50 { name => "virConnectNumOfNetworks", sig => "conn : int" },
51 { name => "virConnectListNetworks", sig => "conn, int : string array" },
52 { name => "virConnectNumOfDefinedNetworks", sig => "conn : int" },
53 { name => "virConnectListDefinedNetworks",
54 sig => "conn, int : string array" },
55 { name => "virConnectNumOfStoragePools", sig => "conn : int", weak => 1 },
56 { name => "virConnectListStoragePools",
57 sig => "conn, int : string array", weak => 1 },
58 { name => "virConnectNumOfDefinedStoragePools",
59 sig => "conn : int", weak => 1 },
60 { name => "virConnectListDefinedStoragePools",
61 sig => "conn, int : string array", weak => 1 },
62 { name => "virConnectGetCapabilities", sig => "conn : string" },
64 { name => "virDomainCreateLinux", sig => "conn, string, 0U : dom" },
65 { name => "virDomainCreateLinuxJob",
66 sig => "conn, string, 0U : job", weak => 1 },
67 { name => "virDomainFree", sig => "dom : free" },
68 { name => "virDomainDestroy", sig => "dom : free" },
69 { name => "virDomainLookupByName", sig => "conn, string : dom" },
70 { name => "virDomainLookupByID", sig => "conn, int : dom" },
71 { name => "virDomainLookupByUUID", sig => "conn, uuid : dom" },
72 { name => "virDomainLookupByUUIDString", sig => "conn, string : dom" },
73 { name => "virDomainGetName", sig => "dom : static string" },
74 { name => "virDomainGetOSType", sig => "dom : string" },
75 { name => "virDomainGetXMLDesc", sig => "dom, 0 : string" },
76 { name => "virDomainGetUUID", sig => "dom : uuid" },
77 { name => "virDomainGetUUIDString", sig => "dom : uuid string" },
78 { name => "virDomainGetMaxVcpus", sig => "dom : int" },
79 { name => "virDomainSave", sig => "dom, string : unit" },
80 { name => "virDomainSaveJob",
81 sig => "dom, string : job from dom", weak => 1 },
82 { name => "virDomainRestore", sig => "conn, string : unit" },
83 { name => "virDomainRestoreJob",
84 sig => "conn, string : job", weak => 1 },
85 { name => "virDomainCoreDump", sig => "dom, string, 0 : unit" },
86 { name => "virDomainCoreDumpJob",
87 sig => "dom, string, 0 : job from dom", weak => 1 },
88 { name => "virDomainSuspend", sig => "dom : unit" },
89 { name => "virDomainResume", sig => "dom : unit" },
90 { name => "virDomainShutdown", sig => "dom : unit" },
91 { name => "virDomainReboot", sig => "dom, 0 : unit" },
92 { name => "virDomainDefineXML", sig => "conn, string : dom" },
93 { name => "virDomainUndefine", sig => "dom : unit" },
94 { name => "virDomainCreate", sig => "dom : unit" },
95 { name => "virDomainCreateJob",
96 sig => "dom, 0U : job from dom", weak => 1 },
97 { name => "virDomainAttachDevice", sig => "dom, string : unit" },
98 { name => "virDomainDetachDevice", sig => "dom, string : unit" },
99 { name => "virDomainGetAutostart", sig => "dom : bool" },
100 { name => "virDomainSetAutostart", sig => "dom, bool : unit" },
102 { name => "virNetworkFree", sig => "net : free" },
103 { name => "virNetworkDestroy", sig => "net : free" },
104 { name => "virNetworkLookupByName", sig => "conn, string : net" },
105 { name => "virNetworkLookupByUUID", sig => "conn, uuid : net" },
106 { name => "virNetworkLookupByUUIDString", sig => "conn, string : net" },
107 { name => "virNetworkGetName", sig => "net : static string" },
108 { name => "virNetworkGetXMLDesc", sig => "net, 0 : string" },
109 { name => "virNetworkGetBridgeName", sig => "net : string" },
110 { name => "virNetworkGetUUID", sig => "net : uuid" },
111 { name => "virNetworkGetUUIDString", sig => "net : uuid string" },
112 { name => "virNetworkUndefine", sig => "net : unit" },
113 { name => "virNetworkCreateXML", sig => "conn, string : net" },
114 { name => "virNetworkCreateXMLJob",
115 sig => "conn, string : job", weak => 1 },
116 { name => "virNetworkDefineXML", sig => "conn, string : net" },
117 { name => "virNetworkCreate", sig => "net : unit" },
118 { name => "virNetworkCreateJob",
119 sig => "net : job from net", weak => 1 },
120 { name => "virNetworkGetAutostart", sig => "net : bool" },
121 { name => "virNetworkSetAutostart", sig => "net, bool : unit" },
123 { name => "virStoragePoolFree", sig => "pool : free", weak => 1 },
124 { name => "virStoragePoolDestroy", sig => "pool : free", weak => 1 },
125 { name => "virStoragePoolLookupByName",
126 sig => "conn, string : pool", weak => 1 },
127 { name => "virStoragePoolLookupByUUID",
128 sig => "conn, uuid : pool", weak => 1 },
129 { name => "virStoragePoolLookupByUUIDString",
130 sig => "conn, string : pool", weak => 1 },
131 { name => "virStoragePoolGetName",
132 sig => "pool : static string", weak => 1 },
133 { name => "virStoragePoolGetXMLDesc",
134 sig => "pool, 0 : string", weak => 1 },
135 { name => "virStoragePoolGetUUID",
136 sig => "pool : uuid", weak => 1 },
137 { name => "virStoragePoolGetUUIDString",
138 sig => "pool : uuid string", weak => 1 },
139 { name => "virStoragePoolCreateXML",
140 sig => "conn, string : pool", weak => 1 },
141 { name => "virStoragePoolDefineXML",
142 sig => "conn, string : pool", weak => 1 },
143 { name => "virStoragePoolUndefine",
144 sig => "pool : unit", weak => 1 },
145 { name => "virStoragePoolCreate",
146 sig => "pool : unit", weak => 1 },
147 { name => "virStoragePoolShutdown",
148 sig => "pool : unit", weak => 1 },
149 { name => "virStoragePoolRefresh",
150 sig => "pool, 0U : unit", weak => 1 },
151 { name => "virStoragePoolGetAutostart",
152 sig => "pool : bool", weak => 1 },
153 { name => "virStoragePoolSetAutostart",
154 sig => "pool, bool : unit", weak => 1 },
156 { name => "virStorageVolFree", sig => "vol : free", weak => 1 },
157 { name => "virStorageVolDestroy", sig => "vol : free", weak => 1 },
158 # { name => "virStorageVolLookupByName", XXX see libvir-list posting
159 # sig => "pool, string : vol", weak => 1 },
160 { name => "virStorageVolLookupByKey",
161 sig => "conn, string : vol", weak => 1 },
162 { name => "virStorageVolLookupByPath",
163 sig => "conn, string : vol", weak => 1 },
164 # { name => "virStorageVolCreateXML",
165 # sig => "pool, string : vol", weak => 1 }, XXX
166 { name => "virStorageVolGetXMLDesc",
167 sig => "vol, 0 : string", weak => 1 },
168 { name => "virStorageVolGetPath",
169 sig => "vol : string", weak => 1 },
170 { name => "virStorageVolGetKey",
171 sig => "vol : static string", weak => 1 },
172 { name => "virStorageVolGetName",
173 sig => "vol : static string", weak => 1 },
174 { name => "virStoragePoolLookupByVolume",
175 sig => "vol : pool from vol", weak => 1 },
177 { name => "virJobFree",
178 sig => "job : free", weak => 1 },
179 { name => "virJobCancel",
180 sig => "job : unit", weak => 1 },
181 { name => "virJobGetNetwork",
182 sig => "job : net from job", weak => 1 },
183 { name => "virJobGetDomain",
184 sig => "job : dom from job", weak => 1 },
188 # Functions we haven't implemented anywhere yet but which are mentioned
191 # We create stubs for these, but eventually they need to either be
192 # moved ^^^ so they are auto-generated, or implementations of them
193 # written in 'libvirt_c_oneoffs.c'.
195 my @unimplemented = (
196 "ocaml_libvirt_storage_vol_lookup_by_name", # XXX see above
197 "ocaml_libvirt_storage_vol_create_xml", # XXX see above
200 #----------------------------------------------------------------------
202 # Open the output file.
204 my $filename = "libvirt_c.c";
205 open F, ">$filename" or die "$filename: $!";
207 # Write the prologue.
210 /* !!! WARNING WARNING WARNING WARNING WARNING WARNING WARNING !!!
212 * THIS FILE IS AUTOMATICALLY GENERATED BY 'generator.pl'.
214 * Any changes you make to this file may be overwritten.
217 /* OCaml bindings for libvirt.
218 * (C) Copyright 2007-2008 Richard W.M. Jones, Red Hat Inc.
219 * http://libvirt.org/
221 * This library is free software; you can redistribute it and/or
222 * modify it under the terms of the GNU Lesser General Public
223 * License as published by the Free Software Foundation; either
224 * version 2 of the License, or (at your option) any later version.
226 * This library is distributed in the hope that it will be useful,
227 * but WITHOUT ANY WARRANTY; without even the implied warranty of
228 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
229 * Lesser General Public License for more details.
231 * You should have received a copy of the GNU Lesser General Public
232 * License along with this library; if not, write to the Free Software
233 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
242 #include <libvirt/libvirt.h>
243 #include <libvirt/virterror.h>
245 #include <caml/config.h>
246 #include <caml/alloc.h>
247 #include <caml/callback.h>
248 #include <caml/custom.h>
249 #include <caml/fail.h>
250 #include <caml/memory.h>
251 #include <caml/misc.h>
252 #include <caml/mlvalues.h>
253 #include <caml/signals.h>
255 #include "libvirt_c_prologue.c"
257 #include "libvirt_c_oneoffs.c"
261 #----------------------------------------------------------------------
263 sub camel_case_to_underscores
267 $name =~ s/([A-Z][a-z]+|XML|URI|OS|UUID)/$1,/g;
268 my @subs = split (/,/, $name);
269 @subs = map { lc($_) } @subs;
273 # Helper functions dealing with signatures.
275 sub short_name_to_c_type
279 if ($_ eq "conn") { "virConnectPtr" }
280 elsif ($_ eq "dom") { "virDomainPtr" }
281 elsif ($_ eq "net") { "virNetworkPtr" }
282 elsif ($_ eq "pool") { "virStoragePoolPtr" }
283 elsif ($_ eq "vol") { "virStorageVolPtr" }
284 elsif ($_ eq "job") { "virJobPtr" }
286 die "unknown short name $_"
290 # Generate a C signature for the original function. Used when building
298 if ($sig =~ /^(\w+) : string$/) {
299 my $c_type = short_name_to_c_type ($1);
300 "char *$c_name ($c_type $1)"
301 } elsif ($sig =~ /^(\w+) : static string$/) {
302 my $c_type = short_name_to_c_type ($1);
303 "const char *$c_name ($c_type $1)"
304 } elsif ($sig =~ /^(\w+) : int$/) {
305 my $c_type = short_name_to_c_type ($1);
306 "int $c_name ($c_type $1)"
307 } elsif ($sig =~ /^(\w+) : uuid$/) {
308 my $c_type = short_name_to_c_type ($1);
309 "int $c_name ($c_type $1, unsigned char *)"
310 } elsif ($sig =~ /^(\w+) : uuid string$/) {
311 my $c_type = short_name_to_c_type ($1);
312 "int $c_name ($c_type $1, char *)"
313 } elsif ($sig =~ /^(\w+) : bool$/) {
314 my $c_type = short_name_to_c_type ($1);
315 "int $c_name ($c_type $1, int *r)"
316 } elsif ($sig =~ /^(\w+), bool : unit$/) {
317 my $c_type = short_name_to_c_type ($1);
318 "int $c_name ($c_type $1, int b)"
319 } elsif ($sig eq "conn, int : int array") {
320 "int $c_name (virConnectPtr conn, int *ids, int maxids)"
321 } elsif ($sig eq "conn, int : string array") {
322 "int $c_name (virConnectPtr conn, char **const names, int maxnames)"
323 } elsif ($sig =~ /^(\w+), 0(U?) : string$/) {
324 my $c_type = short_name_to_c_type ($1);
325 my $unsigned = $2 eq "U" ? "unsigned " : "";
326 "char *$c_name ($c_type $1, $unsigned int flags)"
327 } elsif ($sig =~ /^(\w+), 0(U?) : unit$/) {
328 my $c_type = short_name_to_c_type ($1);
329 my $unsigned = $2 eq "U" ? "unsigned " : "";
330 "int $c_name ($c_type $1, $unsigned int flags)"
331 } elsif ($sig =~ /^(\w+) : unit$/) {
332 my $c_type = short_name_to_c_type ($1);
333 "int $c_name ($c_type $1)"
334 } elsif ($sig =~ /^(\w+) : free$/) {
335 my $c_type = short_name_to_c_type ($1);
336 "int $c_name ($c_type $1)"
337 } elsif ($sig =~ /^(\w+), string : unit$/) {
338 my $c_type = short_name_to_c_type ($1);
339 "int $c_name ($c_type $1, const char *str)"
340 } elsif ($sig =~ /^(\w+), string, 0(U?) : unit$/) {
341 my $c_type = short_name_to_c_type ($1);
342 my $unsigned = $2 eq "U" ? "unsigned " : "";
343 "int $c_name ($c_type $1, const char *str, $unsigned int flags)"
344 } elsif ($sig =~ /^(\w+), string : (\w+)$/) {
345 my $c_type = short_name_to_c_type ($1);
346 my $c_ret_type = short_name_to_c_type ($2);
347 "$c_ret_type $c_name ($c_type $1, const char *str)"
348 } elsif ($sig =~ /^(\w+), string, 0(U?) : (\w+)$/) {
349 my $c_type = short_name_to_c_type ($1);
350 my $unsigned = $2 eq "U" ? "unsigned " : "";
351 my $c_ret_type = short_name_to_c_type ($3);
352 "$c_ret_type $c_name ($c_type $1, const char *str, $unsigned int flags)"
353 } elsif ($sig =~ /^(\w+), int : (\w+)$/) {
354 my $c_type = short_name_to_c_type ($1);
355 my $c_ret_type = short_name_to_c_type ($2);
356 "$c_ret_type $c_name ($c_type $1, int i)"
357 } elsif ($sig =~ /^(\w+), uuid : (\w+)$/) {
358 my $c_type = short_name_to_c_type ($1);
359 my $c_ret_type = short_name_to_c_type ($2);
360 "$c_ret_type $c_name ($c_type $1, const unsigned char *str)"
361 } elsif ($sig =~ /^(\w+), 0(U?) : (\w+)$/) {
362 my $c_type = short_name_to_c_type ($1);
363 my $unsigned = $2 eq "U" ? "unsigned " : "";
364 my $c_ret_type = short_name_to_c_type ($3);
365 "$c_ret_type $c_name ($c_type $1, $unsigned int flags)"
366 } elsif ($sig =~ /^(\w+) : (\w+)$/) {
367 my $c_type = short_name_to_c_type ($1);
368 my $c_ret_type = short_name_to_c_type ($2);
369 "$c_ret_type $c_name ($c_type $1)"
370 } elsif ($sig =~ /^(\w+), string : (\w+) from \w+$/) {
371 my $c_type = short_name_to_c_type ($1);
372 my $c_ret_type = short_name_to_c_type ($2);
373 "$c_ret_type $c_name ($c_type $1, const char *str)"
374 } elsif ($sig =~ /^(\w+), string, 0(U?) : (\w+) from \w+$/) {
375 my $c_type = short_name_to_c_type ($1);
376 my $unsigned = $2 eq "U" ? "unsigned " : "";
377 my $c_ret_type = short_name_to_c_type ($3);
378 "$c_ret_type $c_name ($c_type $1, const char *str, $unsigned int flags)"
379 } elsif ($sig =~ /^(\w+), 0(U?) : (\w+) from \w+$/) {
380 my $c_type = short_name_to_c_type ($1);
381 my $unsigned = $2 eq "U" ? "unsigned " : "";
382 my $c_ret_type = short_name_to_c_type ($3);
383 "$c_ret_type $c_name ($c_type $1, $unsigned int flags)"
384 } elsif ($sig =~ /^(\w+) : (\w+) from \w+$/) {
385 my $c_type = short_name_to_c_type ($1);
386 my $c_ret_type = short_name_to_c_type ($2);
387 "$c_ret_type $c_name ($c_type $1)"
389 die "unknown signature $sig"
393 # OCaml argument names.
399 if ($sig =~ /^(\w+) : string$/) {
401 } elsif ($sig =~ /^(\w+) : static string$/) {
403 } elsif ($sig =~ /^(\w+) : int$/) {
405 } elsif ($sig =~ /^(\w+) : uuid$/) {
407 } elsif ($sig =~ /^(\w+) : uuid string$/) {
409 } elsif ($sig =~ /^(\w+) : bool$/) {
411 } elsif ($sig =~ /^(\w+), bool : unit$/) {
413 } elsif ($sig eq "conn, int : int array") {
415 } elsif ($sig eq "conn, int : string array") {
417 } elsif ($sig =~ /^(\w+), 0U? : string$/) {
419 } elsif ($sig =~ /^(\w+), 0U? : unit$/) {
421 } elsif ($sig =~ /^(\w+) : unit$/) {
423 } elsif ($sig =~ /^(\w+) : free$/) {
425 } elsif ($sig =~ /^(\w+), string : unit$/) {
427 } elsif ($sig =~ /^(\w+), string, 0U? : unit$/) {
429 } elsif ($sig =~ /^(\w+), string : (\w+)$/) {
431 } elsif ($sig =~ /^(\w+), string, 0U? : (\w+)$/) {
433 } elsif ($sig =~ /^(\w+), int : (\w+)$/) {
435 } elsif ($sig =~ /^(\w+), uuid : (\w+)$/) {
437 } elsif ($sig =~ /^(\w+), 0U? : (\w+)$/) {
439 } elsif ($sig =~ /^(\w+) : (\w+)$/) {
441 } elsif ($sig =~ /^(\w+), string : (\w+) from \w+$/) {
443 } elsif ($sig =~ /^(\w+), string, 0U? : (\w+) from \w+$/) {
445 } elsif ($sig =~ /^(\w+), 0U? : (\w+) from \w+$/) {
447 } elsif ($sig =~ /^(\w+) : (\w+) from \w+$/) {
450 die "unknown signature $sig"
454 # Unpack the first (object) argument.
461 "virConnectPtr conn = Connect_val (connv);"
462 } elsif ($_ eq "dom") {
463 "virDomainPtr dom = Domain_val (domv);\n".
464 " virConnectPtr conn = Connect_domv (domv);"
465 } elsif ($_ eq "net") {
466 "virNetworkPtr net = Network_val (netv);\n".
467 " virConnectPtr conn = Connect_netv (netv);"
468 } elsif ($_ eq "pool") {
469 "virStoragePoolPtr pool = Pool_val (poolv);\n".
470 " virConnectPtr conn = Connect_polv (poolv);"
471 } elsif ($_ eq "vol") {
472 "virStorageVolPtr vol = Volume_val (volv);\n".
473 " virConnectPtr conn = Connect_volv (volv);"
474 } elsif ($_ eq "job") {
475 "virJobPtr job = Job_val (jobv);\n".
476 " virConnectPtr conn = Connect_jobv (jobv);"
478 die "unknown short name $_"
482 # Pack the result if it's an object.
488 if ($_ eq "dom") { "rv = Val_domain (r, connv);" }
489 elsif ($_ eq "net") { "rv = Val_network (r, connv);" }
490 elsif ($_ eq "pool") { "rv = Val_pool (r, connv);" }
491 elsif ($_ eq "vol") { "rv = Val_volume (r, connv);" }
492 elsif ($_ eq "job") { "rv = Val_job (r, connv);" }
494 die "unknown short name $_"
502 if ($_ eq "conn") { "Connect_val (connv) = NULL;" }
503 elsif ($_ eq "dom") { "Domain_val (domv) = NULL;" }
504 elsif ($_ eq "net") { "Network_val (netv) = NULL;" }
505 elsif ($_ eq "pool") { "Pool_val (poolv) = NULL;" }
506 elsif ($_ eq "vol") { "Volume_val (volv) = NULL;" }
507 elsif ($_ eq "job") { "Job_val (jobv) = NULL;" }
509 die "unknown short name $_"
513 # Generate the C body for each signature (class of function).
520 if ($sig =~ /^(\w+) : string$/) {
523 " . gen_unpack_args ($1) . "
526 NONBLOCKING (r = $c_name ($1));
527 CHECK_ERROR (!r, conn, \"$c_name\");
529 rv = caml_copy_string (r);
533 } elsif ($sig =~ /^(\w+) : static string$/) {
536 " . gen_unpack_args ($1) . "
539 NONBLOCKING (r = $c_name ($1));
540 CHECK_ERROR (!r, conn, \"$c_name\");
542 rv = caml_copy_string (r);
545 } elsif ($sig =~ /^(\w+) : int$/) {
547 " . gen_unpack_args ($1) . "
550 NONBLOCKING (r = $c_name ($1));
551 CHECK_ERROR (r == -1, conn, \"$c_name\");
553 CAMLreturn (Val_int (r));
555 } elsif ($sig =~ /^(\w+) : uuid$/) {
558 " . gen_unpack_args ($1) . "
559 unsigned char uuid[VIR_UUID_BUFLEN];
562 NONBLOCKING (r = $c_name ($1, uuid));
563 CHECK_ERROR (r == -1, conn, \"$c_name\");
565 /* UUIDs are byte arrays with a fixed length. */
566 rv = caml_alloc_string (VIR_UUID_BUFLEN);
567 memcpy (String_val (rv), uuid, VIR_UUID_BUFLEN);
570 } elsif ($sig =~ /^(\w+) : uuid string$/) {
573 " . gen_unpack_args ($1) . "
574 char uuid[VIR_UUID_STRING_BUFLEN];
577 NONBLOCKING (r = $c_name ($1, uuid));
578 CHECK_ERROR (r == -1, conn, \"$c_name\");
580 rv = caml_copy_string (uuid);
583 } elsif ($sig =~ /^(\w+) : bool$/) {
585 " . gen_unpack_args ($1) . "
588 NONBLOCKING (r = $c_name ($1, &b));
589 CHECK_ERROR (r == -1, conn, \"$c_name\");
591 CAMLreturn (b ? Val_true : Val_false);
593 } elsif ($sig =~ /^(\w+), bool : unit$/) {
595 " . gen_unpack_args ($1) . "
598 b = bv == Val_true ? 1 : 0;
600 NONBLOCKING (r = $c_name ($1, b));
601 CHECK_ERROR (r == -1, conn, \"$c_name\");
603 CAMLreturn (Val_unit);
605 } elsif ($sig eq "conn, int : int array") {
608 virConnectPtr conn = Connect_val (connv);
609 int i = Int_val (iv);
612 NONBLOCKING (r = $c_name (conn, ids, i));
613 CHECK_ERROR (r == -1, conn, \"$c_name\");
615 rv = caml_alloc (r, 0);
616 for (i = 0; i < r; ++i)
617 Store_field (rv, i, Val_int (ids[i]));
621 } elsif ($sig eq "conn, int : string array") {
623 CAMLlocal2 (rv, strv);
624 virConnectPtr conn = Connect_val (connv);
625 int i = Int_val (iv);
629 NONBLOCKING (r = $c_name (conn, names, i));
630 CHECK_ERROR (r == -1, conn, \"$c_name\");
632 rv = caml_alloc (r, 0);
633 for (i = 0; i < r; ++i) {
634 strv = caml_copy_string (names[i]);
635 Store_field (rv, i, strv);
641 } elsif ($sig =~ /^(\w+), 0U? : string$/) {
644 " . gen_unpack_args ($1) . "
647 NONBLOCKING (r = $c_name ($1, 0));
648 CHECK_ERROR (!r, conn, \"$c_name\");
650 rv = caml_copy_string (r);
654 } elsif ($sig =~ /^(\w+), 0U? : unit$/) {
656 " . gen_unpack_args ($1) . "
659 NONBLOCKING (r = $c_name ($1, 0));
660 CHECK_ERROR (r == -1, conn, \"$c_name\");
662 CAMLreturn (Val_unit);
664 } elsif ($sig =~ /^(\w+) : unit$/) {
666 " . gen_unpack_args ($1) . "
669 NONBLOCKING (r = $c_name ($1));
670 CHECK_ERROR (r == -1, conn, \"$c_name\");
672 CAMLreturn (Val_unit);
674 } elsif ($sig =~ /^(\w+) : free$/) {
676 " . gen_unpack_args ($1) . "
679 NONBLOCKING (r = $c_name ($1));
680 CHECK_ERROR (r == -1, conn, \"$c_name\");
682 /* So that we don't double-free in the finalizer: */
683 " . gen_free_arg ($1) . "
685 CAMLreturn (Val_unit);
687 } elsif ($sig =~ /^(\w+), string : unit$/) {
690 " . gen_unpack_args ($1) . "
691 char *str = String_val (strv);
694 NONBLOCKING (r = $c_name ($1, str));
695 CHECK_ERROR (r == -1, conn, \"$c_name\");
697 CAMLreturn (Val_unit);
699 } elsif ($sig =~ /^(\w+), string, 0U? : unit$/) {
702 " . gen_unpack_args ($1) . "
703 char *str = String_val (strv);
706 NONBLOCKING (r = $c_name ($1, str, 0));
707 CHECK_ERROR (!r, conn, \"$c_name\");
709 CAMLreturn (Val_unit);
711 } elsif ($sig =~ /^(\w+), string : (\w+)$/) {
712 my $c_ret_type = short_name_to_c_type ($2);
715 " . gen_unpack_args ($1) . "
716 char *str = String_val (strv);
719 NONBLOCKING (r = $c_name ($1, str));
720 CHECK_ERROR (!r, conn, \"$c_name\");
722 " . gen_pack_result ($2) . "
726 } elsif ($sig =~ /^(\w+), string, 0U? : (\w+)$/) {
727 my $c_ret_type = short_name_to_c_type ($2);
730 " . gen_unpack_args ($1) . "
731 char *str = String_val (strv);
734 NONBLOCKING (r = $c_name ($1, str, 0));
735 CHECK_ERROR (!r, conn, \"$c_name\");
737 " . gen_pack_result ($2) . "
741 } elsif ($sig =~ /^(\w+), int : (\w+)$/) {
742 my $c_ret_type = short_name_to_c_type ($2);
745 " . gen_unpack_args ($1) . "
746 int i = Int_val (iv);
749 NONBLOCKING (r = $c_name ($1, i));
750 CHECK_ERROR (!r, conn, \"$c_name\");
752 " . gen_pack_result ($2) . "
756 } elsif ($sig =~ /^(\w+), uuid : (\w+)$/) {
757 my $c_ret_type = short_name_to_c_type ($2);
760 " . gen_unpack_args ($1) . "
761 unsigned char *uuid = (unsigned char *) String_val (uuidv);
764 NONBLOCKING (r = $c_name ($1, uuid));
765 CHECK_ERROR (!r, conn, \"$c_name\");
767 " . gen_pack_result ($2) . "
771 } elsif ($sig =~ /^(\w+), 0U? : (\w+)$/) {
772 my $c_ret_type = short_name_to_c_type ($2);
775 " . gen_unpack_args ($1) . "
778 NONBLOCKING (r = $c_name ($1, 0));
779 CHECK_ERROR (!r, conn, \"$c_name\");
781 " . gen_pack_result ($2) . "
785 } elsif ($sig =~ /^(\w+) : (\w+)$/) {
786 my $c_ret_type = short_name_to_c_type ($2);
789 " . gen_unpack_args ($1) . "
792 NONBLOCKING (r = $c_name ($1));
793 CHECK_ERROR (!r, conn, \"$c_name\");
795 " . gen_pack_result ($2) . "
799 } elsif ($sig =~ /^(\w+), string : (\w+) from (\w+)$/) {
800 my $c_ret_type = short_name_to_c_type ($2);
802 CAMLlocal2 (rv, connv);
803 " . gen_unpack_args ($1) . "
804 char *str = String_val (strv);
807 NONBLOCKING (r = $c_name ($1, str));
808 CHECK_ERROR (!r, conn, \"$c_name\");
810 connv = Field ($3v, 1);
811 " . gen_pack_result ($2) . "
815 } elsif ($sig =~ /^(\w+), string, 0U? : (\w+) from (\w+)$/) {
816 my $c_ret_type = short_name_to_c_type ($2);
818 CAMLlocal2 (rv, connv);
819 " . gen_unpack_args ($1) . "
820 char *str = String_val (strv);
823 NONBLOCKING (r = $c_name ($1, str, 0));
824 CHECK_ERROR (!r, conn, \"$c_name\");
826 connv = Field ($3v, 1);
827 " . gen_pack_result ($2) . "
831 } elsif ($sig =~ /^(\w+), 0U? : (\w+) from (\w+)$/) {
832 my $c_ret_type = short_name_to_c_type ($2);
834 CAMLlocal2 (rv, connv);
835 " . gen_unpack_args ($1) . "
838 NONBLOCKING (r = $c_name ($1, 0));
839 CHECK_ERROR (!r, conn, \"$c_name\");
841 connv = Field ($3v, 1);
842 " . gen_pack_result ($2) . "
846 } elsif ($sig =~ /^(\w+) : (\w+) from (\w+)$/) {
847 my $c_ret_type = short_name_to_c_type ($2);
849 CAMLlocal2 (rv, connv);
850 " . gen_unpack_args ($1) . "
853 NONBLOCKING (r = $c_name ($1));
854 CHECK_ERROR (!r, conn, \"$c_name\");
856 connv = Field ($3v, 1);
857 " . gen_pack_result ($2) . "
862 die "unknown signature $sig"
866 # Generate each function.
868 foreach my $function (@functions) {
869 my $c_name = $function->{name};
870 my $is_weak = $function->{weak};
871 my $sig = $function->{sig};
873 my $is_pool_func = $c_name =~ /^virStoragePool/;
874 my $is_vol_func = $c_name =~ /^virStorageVol/;
876 # Generate an equivalent C-external name for the function, unless
877 # one is defined already.
879 if (exists ($function->{c_external_name})) {
880 $c_external_name = $function->{c_external_name};
881 } elsif ($c_name =~ /^vir/) {
882 $c_external_name = substr $c_name, 3;
883 $c_external_name = camel_case_to_underscores ($c_external_name);
884 $c_external_name = "ocaml_libvirt_" . $c_external_name;
886 die "cannot convert c_name $c_name to c_external_name"
890 /* Automatically generated binding for $c_name.
891 * In generator.pl this function has signature "$sig".
896 # Generate a full function prototype if the function is weak.
897 my $have_name = "HAVE_" . uc ($c_name);
899 my $c_sig = gen_c_signature ($sig, $c_name);
901 #ifdef HAVE_WEAK_SYMBOLS
903 extern $c_sig __attribute__((weak));
910 my @arg_names = gen_arg_names ($sig);
911 my $nr_arg_names = scalar @arg_names;
912 my $arg_names = join ", ", @arg_names;
913 my $arg_names_as_values = join (", ", map { "value $_" } @arg_names);
915 # Generate the start of the function, arguments.
918 $c_external_name ($arg_names_as_values)
920 CAMLparam$nr_arg_names ($arg_names);
923 # If weak, check the function exists at compile time or runtime.
927 /* Symbol $c_name not found at compile time. */
928 not_supported ("$c_name");
929 /* Suppresses a compiler warning. */
932 /* Check that the symbol $c_name
933 * is in runtime version of libvirt.
935 WEAK_SYMBOL_CHECK ($c_name);
939 # Generate the internals of the function.
940 print F (gen_c_code ($sig, $c_name));
942 # Finish off weak #ifdef.
949 # Finish off the function.
956 #----------------------------------------------------------------------
958 # Unimplemented functions.
960 printf "$0: warning: %d unimplemented functions\n", scalar (@unimplemented);
962 if (@unimplemented) {
964 /* The following functions are unimplemented and always fail.
965 * See generator.pl '@unimplemented'
970 foreach my $c_external_name (@unimplemented) {
975 failwith ("$c_external_name is unimplemented");
980 } # end if @unimplemented
982 #----------------------------------------------------------------------
984 # Write the epilogue.
987 #include "libvirt_c_epilogue.c"
993 print "$0: written $filename\n"