3 # OCaml bindings for libvirt.
4 # (C) Copyright 2007-2015 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,
11 # with the OCaml linking exception described in ../COPYING.LIB.
13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # Lesser General Public License for more details.
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this library; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 # This generates libvirt_c.c (the core of the bindings). You don't
23 # need to run this program unless you are extending the bindings
24 # themselves (eg. because libvirt has been extended).
26 # Please read libvirt/README.
30 #----------------------------------------------------------------------
32 # The functions in the libvirt API that we can generate.
34 # The 'sig' (signature) doesn't have a meaning or any internal structure.
35 # It is interpreted by the generation functions below to indicate what
36 # "class" the function falls into, and to generate the right class of
40 { name => "virConnectClose", sig => "conn : free" },
41 { name => "virConnectGetHostname", sig => "conn : string" },
42 { name => "virConnectGetURI", sig => "conn : string" },
43 { name => "virConnectGetType", sig => "conn : static string" },
44 { name => "virConnectNumOfDomains", sig => "conn : int" },
45 { name => "virConnectListDomains", sig => "conn, int : int array" },
46 { name => "virConnectNumOfDefinedDomains", sig => "conn : int" },
47 { name => "virConnectListDefinedDomains",
48 sig => "conn, int : string array" },
49 { name => "virConnectNumOfNetworks", sig => "conn : int" },
50 { name => "virConnectListNetworks", sig => "conn, int : string array" },
51 { name => "virConnectNumOfDefinedNetworks", sig => "conn : int" },
52 { name => "virConnectListDefinedNetworks",
53 sig => "conn, int : string array" },
54 { name => "virConnectNumOfStoragePools", sig => "conn : int" },
55 { name => "virConnectListStoragePools",
56 sig => "conn, int : string array" },
57 { name => "virConnectNumOfDefinedStoragePools",
58 sig => "conn : int" },
59 { name => "virConnectListDefinedStoragePools",
60 sig => "conn, int : string array" },
61 { name => "virConnectGetCapabilities", sig => "conn : string" },
62 { name => "virConnectDomainEventDeregisterAny",
63 sig => "conn, int : unit" },
65 { name => "virDomainCreateLinux", sig => "conn, string, 0U : dom" },
66 { name => "virDomainCreateXML", sig => "conn, string, unsigned : dom" },
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 => "virDomainRestore", sig => "conn, string : unit" },
81 { name => "virDomainCoreDump", sig => "dom, string, 0 : unit" },
82 { name => "virDomainSuspend", sig => "dom : unit" },
83 { name => "virDomainResume", sig => "dom : unit" },
84 { name => "virDomainShutdown", sig => "dom : unit" },
85 { name => "virDomainReboot", sig => "dom, 0 : unit" },
86 { name => "virDomainDefineXML", sig => "conn, string : dom" },
87 { name => "virDomainUndefine", sig => "dom : unit" },
88 { name => "virDomainCreate", sig => "dom : unit" },
89 { name => "virDomainAttachDevice", sig => "dom, string : unit" },
90 { name => "virDomainDetachDevice", sig => "dom, string : unit" },
91 { name => "virDomainGetAutostart", sig => "dom : bool" },
92 { name => "virDomainSetAutostart", sig => "dom, bool : unit" },
94 { name => "virNetworkFree", sig => "net : free" },
95 { name => "virNetworkDestroy", sig => "net : free" },
96 { name => "virNetworkLookupByName", sig => "conn, string : net" },
97 { name => "virNetworkLookupByUUID", sig => "conn, uuid : net" },
98 { name => "virNetworkLookupByUUIDString", sig => "conn, string : net" },
99 { name => "virNetworkGetName", sig => "net : static string" },
100 { name => "virNetworkGetXMLDesc", sig => "net, 0 : string" },
101 { name => "virNetworkGetBridgeName", sig => "net : string" },
102 { name => "virNetworkGetUUID", sig => "net : uuid" },
103 { name => "virNetworkGetUUIDString", sig => "net : uuid string" },
104 { name => "virNetworkUndefine", sig => "net : unit" },
105 { name => "virNetworkCreateXML", sig => "conn, string : net" },
106 { name => "virNetworkDefineXML", sig => "conn, string : net" },
107 { name => "virNetworkCreate", sig => "net : unit" },
108 { name => "virNetworkGetAutostart", sig => "net : bool" },
109 { name => "virNetworkSetAutostart", sig => "net, bool : unit" },
111 { name => "virStoragePoolFree", sig => "pool : free" },
112 { name => "virStoragePoolDestroy", sig => "pool : free" },
113 { name => "virStoragePoolLookupByName",
114 sig => "conn, string : pool" },
115 { name => "virStoragePoolLookupByUUID",
116 sig => "conn, uuid : pool" },
117 { name => "virStoragePoolLookupByUUIDString",
118 sig => "conn, string : pool" },
119 { name => "virStoragePoolGetName",
120 sig => "pool : static string" },
121 { name => "virStoragePoolGetXMLDesc",
122 sig => "pool, 0U : string" },
123 { name => "virStoragePoolGetUUID",
124 sig => "pool : uuid" },
125 { name => "virStoragePoolGetUUIDString",
126 sig => "pool : uuid string" },
127 { name => "virStoragePoolCreateXML",
128 sig => "conn, string, 0U : pool" },
129 { name => "virStoragePoolDefineXML",
130 sig => "conn, string, 0U : pool" },
131 { name => "virStoragePoolBuild",
132 sig => "pool, uint : unit" },
133 { name => "virStoragePoolUndefine",
134 sig => "pool : unit" },
135 { name => "virStoragePoolCreate",
136 sig => "pool, 0U : unit" },
137 { name => "virStoragePoolDelete",
138 sig => "pool, uint : unit" },
139 { name => "virStoragePoolRefresh",
140 sig => "pool, 0U : unit" },
141 { name => "virStoragePoolGetAutostart",
142 sig => "pool : bool" },
143 { name => "virStoragePoolSetAutostart",
144 sig => "pool, bool : unit" },
145 { name => "virStoragePoolNumOfVolumes",
146 sig => "pool : int" },
147 { name => "virStoragePoolListVolumes",
148 sig => "pool, int : string array" },
150 { name => "virStorageVolFree", sig => "vol : free" },
151 { name => "virStorageVolDelete",
152 sig => "vol, uint : unit" },
153 { name => "virStorageVolLookupByName",
154 sig => "pool, string : vol from pool" },
155 { name => "virStorageVolLookupByKey",
156 sig => "conn, string : vol" },
157 { name => "virStorageVolLookupByPath",
158 sig => "conn, string : vol" },
159 { name => "virStorageVolCreateXML",
160 sig => "pool, string, 0U : vol from pool" },
161 { name => "virStorageVolGetXMLDesc",
162 sig => "vol, 0U : string" },
163 { name => "virStorageVolGetPath",
164 sig => "vol : string" },
165 { name => "virStorageVolGetKey",
166 sig => "vol : static string" },
167 { name => "virStorageVolGetName",
168 sig => "vol : static string" },
169 { name => "virStoragePoolLookupByVolume",
170 sig => "vol : pool from vol" },
174 # Functions we haven't implemented anywhere yet but which are mentioned
177 # We create stubs for these, but eventually they need to either be
178 # moved ^^^ so they are auto-generated, or implementations of them
179 # written in 'libvirt_c_oneoffs.c'.
181 my @unimplemented = (
184 #----------------------------------------------------------------------
186 # Open the output file.
188 my $filename = "libvirt_c.c";
189 open F, ">$filename" or die "$filename: $!";
191 # Write the prologue.
194 /* !!! WARNING WARNING WARNING WARNING WARNING WARNING WARNING !!!
196 * THIS FILE IS AUTOMATICALLY GENERATED BY 'generator.pl'.
198 * Any changes you make to this file may be overwritten.
201 /* OCaml bindings for libvirt.
202 * (C) Copyright 2007-2015 Richard W.M. Jones, Red Hat Inc.
203 * http://libvirt.org/
205 * This library is free software; you can redistribute it and/or
206 * modify it under the terms of the GNU Lesser General Public
207 * License as published by the Free Software Foundation; either
208 * version 2 of the License, or (at your option) any later version,
209 * with the OCaml linking exception described in ../COPYING.LIB.
211 * This library is distributed in the hope that it will be useful,
212 * but WITHOUT ANY WARRANTY; without even the implied warranty of
213 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
214 * Lesser General Public License for more details.
216 * You should have received a copy of the GNU Lesser General Public
217 * License along with this library; if not, write to the Free Software
218 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
227 #include <libvirt/libvirt.h>
228 #include <libvirt/virterror.h>
230 #include <caml/config.h>
231 #include <caml/alloc.h>
232 #include <caml/callback.h>
233 #include <caml/custom.h>
234 #include <caml/fail.h>
235 #include <caml/memory.h>
236 #include <caml/misc.h>
237 #include <caml/mlvalues.h>
238 #include <caml/signals.h>
240 #include "libvirt_c_prologue.c"
242 #include "libvirt_c_oneoffs.c"
246 #----------------------------------------------------------------------
248 sub camel_case_to_underscores
252 $name =~ s/([A-Z][a-z]+|XML|URI|OS|UUID)/$1,/g;
253 my @subs = split (/,/, $name);
254 @subs = map { lc($_) } @subs;
258 # Helper functions dealing with signatures.
260 sub short_name_to_c_type
264 if ($_ eq "conn") { "virConnectPtr" }
265 elsif ($_ eq "dom") { "virDomainPtr" }
266 elsif ($_ eq "net") { "virNetworkPtr" }
267 elsif ($_ eq "pool") { "virStoragePoolPtr" }
268 elsif ($_ eq "vol") { "virStorageVolPtr" }
270 die "unknown short name $_"
274 # OCaml argument names.
280 if ($sig =~ /^(\w+) : string$/) {
282 } elsif ($sig =~ /^(\w+) : static string$/) {
284 } elsif ($sig =~ /^(\w+) : int$/) {
286 } elsif ($sig =~ /^(\w+) : uuid$/) {
288 } elsif ($sig =~ /^(\w+) : uuid string$/) {
290 } elsif ($sig =~ /^(\w+) : bool$/) {
292 } elsif ($sig =~ /^(\w+), bool : unit$/) {
294 } elsif ($sig eq "conn, int : int array") {
296 } elsif ($sig =~ /^(\w+), int : string array$/) {
298 } elsif ($sig =~ /^(\w+), 0U? : string$/) {
300 } elsif ($sig =~ /^(\w+), 0U? : unit$/) {
302 } elsif ($sig =~ /^(\w+) : unit$/) {
304 } elsif ($sig =~ /^(\w+) : free$/) {
306 } elsif ($sig =~ /^(\w+), string : unit$/) {
308 } elsif ($sig =~ /^(\w+), string, 0U? : unit$/) {
310 } elsif ($sig =~ /^(\w+), string : (\w+)$/) {
312 } elsif ($sig =~ /^(\w+), string, 0U? : (\w+)$/) {
314 } elsif ($sig =~ /^(\w+), string, unsigned : (\w+)$/) {
315 ( "$1v", "strv", "uv" )
316 } elsif ($sig =~ /^(\w+), u?int : (\w+)$/) {
318 } elsif ($sig =~ /^(\w+), uuid : (\w+)$/) {
320 } elsif ($sig =~ /^(\w+), 0U? : (\w+)$/) {
322 } elsif ($sig =~ /^(\w+) : (\w+)$/) {
324 } elsif ($sig =~ /^(\w+), string : (\w+) from \w+$/) {
326 } elsif ($sig =~ /^(\w+), string, 0U? : (\w+) from \w+$/) {
328 } elsif ($sig =~ /^(\w+), 0U? : (\w+) from \w+$/) {
330 } elsif ($sig =~ /^(\w+) : (\w+) from \w+$/) {
333 die "unknown signature $sig"
337 # Unpack the first (object) argument.
344 "virConnectPtr conn = Connect_val (connv);"
345 } elsif ($_ eq "dom") {
346 "virDomainPtr dom = Domain_val (domv);"
347 } elsif ($_ eq "net") {
348 "virNetworkPtr net = Network_val (netv);"
349 } elsif ($_ eq "pool") {
350 "virStoragePoolPtr pool = Pool_val (poolv);"
351 } elsif ($_ eq "vol") {
352 "virStorageVolPtr vol = Volume_val (volv);"
354 die "unknown short name $_"
358 # Pack the result if it's an object.
364 if ($_ eq "dom") { "rv = Val_domain (r, connv);" }
365 elsif ($_ eq "net") { "rv = Val_network (r, connv);" }
366 elsif ($_ eq "pool") { "rv = Val_pool (r, connv);" }
367 elsif ($_ eq "vol") { "rv = Val_volume (r, connv);" }
369 die "unknown short name $_"
377 if ($_ eq "conn") { "Connect_val (connv) = NULL;" }
378 elsif ($_ eq "dom") { "Domain_val (domv) = NULL;" }
379 elsif ($_ eq "net") { "Network_val (netv) = NULL;" }
380 elsif ($_ eq "pool") { "Pool_val (poolv) = NULL;" }
381 elsif ($_ eq "vol") { "Volume_val (volv) = NULL;" }
383 die "unknown short name $_"
387 # Generate the C body for each signature (class of function).
394 if ($sig =~ /^(\w+) : string$/) {
397 " . gen_unpack_args ($1) . "
400 NONBLOCKING (r = $c_name ($1));
401 CHECK_ERROR (!r, \"$c_name\");
403 rv = caml_copy_string (r);
407 } elsif ($sig =~ /^(\w+) : static string$/) {
410 " . gen_unpack_args ($1) . "
413 NONBLOCKING (r = $c_name ($1));
414 CHECK_ERROR (!r, \"$c_name\");
416 rv = caml_copy_string (r);
419 } elsif ($sig =~ /^(\w+) : int$/) {
421 " . gen_unpack_args ($1) . "
424 NONBLOCKING (r = $c_name ($1));
425 CHECK_ERROR (r == -1, \"$c_name\");
427 CAMLreturn (Val_int (r));
429 } elsif ($sig =~ /^(\w+) : uuid$/) {
432 " . gen_unpack_args ($1) . "
433 unsigned char uuid[VIR_UUID_BUFLEN];
436 NONBLOCKING (r = $c_name ($1, uuid));
437 CHECK_ERROR (r == -1, \"$c_name\");
439 /* UUIDs are byte arrays with a fixed length. */
440 rv = caml_alloc_string (VIR_UUID_BUFLEN);
441 memcpy (String_val (rv), uuid, VIR_UUID_BUFLEN);
444 } elsif ($sig =~ /^(\w+) : uuid string$/) {
447 " . gen_unpack_args ($1) . "
448 char uuid[VIR_UUID_STRING_BUFLEN];
451 NONBLOCKING (r = $c_name ($1, uuid));
452 CHECK_ERROR (r == -1, \"$c_name\");
454 rv = caml_copy_string (uuid);
457 } elsif ($sig =~ /^(\w+) : bool$/) {
459 " . gen_unpack_args ($1) . "
462 NONBLOCKING (r = $c_name ($1, &b));
463 CHECK_ERROR (r == -1, \"$c_name\");
465 CAMLreturn (b ? Val_true : Val_false);
467 } elsif ($sig =~ /^(\w+), bool : unit$/) {
469 " . gen_unpack_args ($1) . "
472 b = bv == Val_true ? 1 : 0;
474 NONBLOCKING (r = $c_name ($1, b));
475 CHECK_ERROR (r == -1, \"$c_name\");
477 CAMLreturn (Val_unit);
479 } elsif ($sig eq "conn, int : int array") {
482 virConnectPtr conn = Connect_val (connv);
483 int i = Int_val (iv);
486 /* Some libvirt List* functions still throw exceptions if i == 0,
487 * so catch that and return an empty array directly. This changes
488 * the semantics slightly (masking other failures) but it's
489 * unlikely anyone will care. RWMJ 2008/06/10
492 rv = caml_alloc (0, 0);
496 NONBLOCKING (r = $c_name (conn, ids, i));
497 CHECK_ERROR (r == -1, \"$c_name\");
499 rv = caml_alloc (r, 0);
500 for (i = 0; i < r; ++i)
501 Store_field (rv, i, Val_int (ids[i]));
505 } elsif ($sig =~ /^(\w+), int : string array$/) {
507 CAMLlocal2 (rv, strv);
508 " . gen_unpack_args ($1) . "
509 int i = Int_val (iv);
513 /* Some libvirt List* functions still throw exceptions if i == 0,
514 * so catch that and return an empty array directly. This changes
515 * the semantics slightly (masking other failures) but it's
516 * unlikely anyone will care. RWMJ 2008/06/10
519 rv = caml_alloc (0, 0);
523 NONBLOCKING (r = $c_name ($1, names, i));
524 CHECK_ERROR (r == -1, \"$c_name\");
526 rv = caml_alloc (r, 0);
527 for (i = 0; i < r; ++i) {
528 strv = caml_copy_string (names[i]);
529 Store_field (rv, i, strv);
535 } elsif ($sig =~ /^(\w+), 0U? : string$/) {
538 " . gen_unpack_args ($1) . "
541 NONBLOCKING (r = $c_name ($1, 0));
542 CHECK_ERROR (!r, \"$c_name\");
544 rv = caml_copy_string (r);
548 } elsif ($sig =~ /^(\w+), 0U? : unit$/) {
550 " . gen_unpack_args ($1) . "
553 NONBLOCKING (r = $c_name ($1, 0));
554 CHECK_ERROR (r == -1, \"$c_name\");
556 CAMLreturn (Val_unit);
558 } elsif ($sig =~ /^(\w+) : unit$/) {
560 " . gen_unpack_args ($1) . "
563 NONBLOCKING (r = $c_name ($1));
564 CHECK_ERROR (r == -1, \"$c_name\");
566 CAMLreturn (Val_unit);
568 } elsif ($sig =~ /^(\w+) : free$/) {
570 " . gen_unpack_args ($1) . "
573 NONBLOCKING (r = $c_name ($1));
574 CHECK_ERROR (r == -1, \"$c_name\");
576 /* So that we don't double-free in the finalizer: */
577 " . gen_free_arg ($1) . "
579 CAMLreturn (Val_unit);
581 } elsif ($sig =~ /^(\w+), string : unit$/) {
583 " . gen_unpack_args ($1) . "
584 char *str = String_val (strv);
587 NONBLOCKING (r = $c_name ($1, str));
588 CHECK_ERROR (r == -1, \"$c_name\");
590 CAMLreturn (Val_unit);
592 } elsif ($sig =~ /^(\w+), string, 0U? : unit$/) {
595 " . gen_unpack_args ($1) . "
596 char *str = String_val (strv);
599 NONBLOCKING (r = $c_name ($1, str, 0));
600 CHECK_ERROR (!r, \"$c_name\");
602 CAMLreturn (Val_unit);
604 } elsif ($sig =~ /^(\w+), string : (\w+)$/) {
605 my $c_ret_type = short_name_to_c_type ($2);
608 " . gen_unpack_args ($1) . "
609 char *str = String_val (strv);
612 NONBLOCKING (r = $c_name ($1, str));
613 CHECK_ERROR (!r, \"$c_name\");
615 " . gen_pack_result ($2) . "
619 } elsif ($sig =~ /^(\w+), string, 0U? : (\w+)$/) {
620 my $c_ret_type = short_name_to_c_type ($2);
623 " . gen_unpack_args ($1) . "
624 char *str = String_val (strv);
627 NONBLOCKING (r = $c_name ($1, str, 0));
628 CHECK_ERROR (!r, \"$c_name\");
630 " . gen_pack_result ($2) . "
634 } elsif ($sig =~ /^(\w+), string, unsigned : (\w+)$/) {
635 my $c_ret_type = short_name_to_c_type ($2);
638 " . gen_unpack_args ($1) . "
639 char *str = String_val (strv);
640 unsigned int u = Int_val (uv);
643 NONBLOCKING (r = $c_name ($1, str, u));
644 CHECK_ERROR (!r, \"$c_name\");
646 " . gen_pack_result ($2) . "
650 } elsif ($sig =~ /^(\w+), (u?)int : unit$/) {
651 my $unsigned = $2 eq "u" ? "unsigned " : "";
653 " . gen_unpack_args ($1) . "
654 ${unsigned}int i = Int_val (iv);
657 NONBLOCKING (r = $c_name ($1, i));
658 CHECK_ERROR (r == -1, \"$c_name\");
660 CAMLreturn (Val_unit);
662 } elsif ($sig =~ /^(\w+), (u?)int : (\w+)$/) {
663 my $c_ret_type = short_name_to_c_type ($3);
664 my $unsigned = $2 eq "u" ? "unsigned " : "";
667 " . gen_unpack_args ($1) . "
668 ${unsigned}int i = Int_val (iv);
671 NONBLOCKING (r = $c_name ($1, i));
672 CHECK_ERROR (!r, \"$c_name\");
674 " . gen_pack_result ($3) . "
678 } elsif ($sig =~ /^(\w+), uuid : (\w+)$/) {
679 my $c_ret_type = short_name_to_c_type ($2);
682 " . gen_unpack_args ($1) . "
683 unsigned char *uuid = (unsigned char *) String_val (uuidv);
686 NONBLOCKING (r = $c_name ($1, uuid));
687 CHECK_ERROR (!r, \"$c_name\");
689 " . gen_pack_result ($2) . "
693 } elsif ($sig =~ /^(\w+), 0U? : (\w+)$/) {
694 my $c_ret_type = short_name_to_c_type ($2);
697 " . gen_unpack_args ($1) . "
700 NONBLOCKING (r = $c_name ($1, 0));
701 CHECK_ERROR (!r, \"$c_name\");
703 " . gen_pack_result ($2) . "
707 } elsif ($sig =~ /^(\w+) : (\w+)$/) {
708 my $c_ret_type = short_name_to_c_type ($2);
711 " . gen_unpack_args ($1) . "
714 NONBLOCKING (r = $c_name ($1));
715 CHECK_ERROR (!r, \"$c_name\");
717 " . gen_pack_result ($2) . "
721 } elsif ($sig =~ /^(\w+), string : (\w+) from (\w+)$/) {
722 my $c_ret_type = short_name_to_c_type ($2);
724 CAMLlocal2 (rv, connv);
725 " . gen_unpack_args ($1) . "
726 char *str = String_val (strv);
729 NONBLOCKING (r = $c_name ($1, str));
730 CHECK_ERROR (!r, \"$c_name\");
732 connv = Field ($3v, 1);
733 " . gen_pack_result ($2) . "
737 } elsif ($sig =~ /^(\w+), string, 0U? : (\w+) from (\w+)$/) {
738 my $c_ret_type = short_name_to_c_type ($2);
740 CAMLlocal2 (rv, connv);
741 " . gen_unpack_args ($1) . "
742 char *str = String_val (strv);
745 NONBLOCKING (r = $c_name ($1, str, 0));
746 CHECK_ERROR (!r, \"$c_name\");
748 connv = Field ($3v, 1);
749 " . gen_pack_result ($2) . "
753 } elsif ($sig =~ /^(\w+), 0U? : (\w+) from (\w+)$/) {
754 my $c_ret_type = short_name_to_c_type ($2);
756 CAMLlocal2 (rv, connv);
757 " . gen_unpack_args ($1) . "
760 NONBLOCKING (r = $c_name ($1, 0));
761 CHECK_ERROR (!r, \"$c_name\");
763 connv = Field ($3v, 1);
764 " . gen_pack_result ($2) . "
768 } elsif ($sig =~ /^(\w+) : (\w+) from (\w+)$/) {
769 my $c_ret_type = short_name_to_c_type ($2);
771 CAMLlocal2 (rv, connv);
772 " . gen_unpack_args ($1) . "
775 NONBLOCKING (r = $c_name ($1));
776 CHECK_ERROR (!r, \"$c_name\");
778 connv = Field ($3v, 1);
779 " . gen_pack_result ($2) . "
784 die "unknown signature $sig"
788 # Generate each function.
790 foreach my $function (@functions) {
791 my $c_name = $function->{name};
792 my $sig = $function->{sig};
794 #print "generating $c_name with sig \"$sig\" ...\n";
796 #my $is_pool_func = $c_name =~ /^virStoragePool/;
797 #my $is_vol_func = $c_name =~ /^virStorageVol/;
799 # Generate an equivalent C-external name for the function, unless
800 # one is defined already.
802 if (exists ($function->{c_external_name})) {
803 $c_external_name = $function->{c_external_name};
804 } elsif ($c_name =~ /^vir/) {
805 $c_external_name = substr $c_name, 3;
806 $c_external_name = camel_case_to_underscores ($c_external_name);
807 $c_external_name = "ocaml_libvirt_" . $c_external_name;
809 die "cannot convert c_name $c_name to c_external_name"
813 /* Automatically generated binding for $c_name.
814 * In generator.pl this function has signature "$sig".
819 my @arg_names = gen_arg_names ($sig);
820 my $nr_arg_names = scalar @arg_names;
821 my $arg_names = join ", ", @arg_names;
822 my $arg_names_as_values = join (", ", map { "value $_" } @arg_names);
824 # Generate the start of the function, arguments.
827 $c_external_name ($arg_names_as_values)
829 CAMLparam$nr_arg_names ($arg_names);
832 # Generate the internals of the function.
833 print F (gen_c_code ($sig, $c_name));
835 # Finish off the function.
842 #----------------------------------------------------------------------
844 # Unimplemented functions.
846 if (@unimplemented) {
847 printf "$0: warning: %d unimplemented functions\n", scalar (@unimplemented);
850 /* The following functions are unimplemented and always fail.
851 * See generator.pl '@unimplemented'
856 foreach my $c_external_name (@unimplemented) {
861 failwith ("$c_external_name is unimplemented");
866 } # end if @unimplemented
868 #----------------------------------------------------------------------
870 # Write the epilogue.
873 #include "libvirt_c_epilogue.c"
879 print "$0: written $filename\n"