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);\n".
347 " virConnectPtr conn = Connect_domv (domv);"
348 } elsif ($_ eq "net") {
349 "virNetworkPtr net = Network_val (netv);\n".
350 " virConnectPtr conn = Connect_netv (netv);"
351 } elsif ($_ eq "pool") {
352 "virStoragePoolPtr pool = Pool_val (poolv);\n".
353 " virConnectPtr conn = Connect_polv (poolv);"
354 } elsif ($_ eq "vol") {
355 "virStorageVolPtr vol = Volume_val (volv);\n".
356 " virConnectPtr conn = Connect_volv (volv);"
358 die "unknown short name $_"
362 # Pack the result if it's an object.
368 if ($_ eq "dom") { "rv = Val_domain (r, connv);" }
369 elsif ($_ eq "net") { "rv = Val_network (r, connv);" }
370 elsif ($_ eq "pool") { "rv = Val_pool (r, connv);" }
371 elsif ($_ eq "vol") { "rv = Val_volume (r, connv);" }
373 die "unknown short name $_"
381 if ($_ eq "conn") { "Connect_val (connv) = NULL;" }
382 elsif ($_ eq "dom") { "Domain_val (domv) = NULL;" }
383 elsif ($_ eq "net") { "Network_val (netv) = NULL;" }
384 elsif ($_ eq "pool") { "Pool_val (poolv) = NULL;" }
385 elsif ($_ eq "vol") { "Volume_val (volv) = NULL;" }
387 die "unknown short name $_"
391 # Generate the C body for each signature (class of function).
398 if ($sig =~ /^(\w+) : string$/) {
401 " . gen_unpack_args ($1) . "
404 NONBLOCKING (r = $c_name ($1));
405 CHECK_ERROR (!r, conn, \"$c_name\");
407 rv = caml_copy_string (r);
411 } elsif ($sig =~ /^(\w+) : static string$/) {
414 " . gen_unpack_args ($1) . "
417 NONBLOCKING (r = $c_name ($1));
418 CHECK_ERROR (!r, conn, \"$c_name\");
420 rv = caml_copy_string (r);
423 } elsif ($sig =~ /^(\w+) : int$/) {
425 " . gen_unpack_args ($1) . "
428 NONBLOCKING (r = $c_name ($1));
429 CHECK_ERROR (r == -1, conn, \"$c_name\");
431 CAMLreturn (Val_int (r));
433 } elsif ($sig =~ /^(\w+) : uuid$/) {
436 " . gen_unpack_args ($1) . "
437 unsigned char uuid[VIR_UUID_BUFLEN];
440 NONBLOCKING (r = $c_name ($1, uuid));
441 CHECK_ERROR (r == -1, conn, \"$c_name\");
443 /* UUIDs are byte arrays with a fixed length. */
444 rv = caml_alloc_string (VIR_UUID_BUFLEN);
445 memcpy (String_val (rv), uuid, VIR_UUID_BUFLEN);
448 } elsif ($sig =~ /^(\w+) : uuid string$/) {
451 " . gen_unpack_args ($1) . "
452 char uuid[VIR_UUID_STRING_BUFLEN];
455 NONBLOCKING (r = $c_name ($1, uuid));
456 CHECK_ERROR (r == -1, conn, \"$c_name\");
458 rv = caml_copy_string (uuid);
461 } elsif ($sig =~ /^(\w+) : bool$/) {
463 " . gen_unpack_args ($1) . "
466 NONBLOCKING (r = $c_name ($1, &b));
467 CHECK_ERROR (r == -1, conn, \"$c_name\");
469 CAMLreturn (b ? Val_true : Val_false);
471 } elsif ($sig =~ /^(\w+), bool : unit$/) {
473 " . gen_unpack_args ($1) . "
476 b = bv == Val_true ? 1 : 0;
478 NONBLOCKING (r = $c_name ($1, b));
479 CHECK_ERROR (r == -1, conn, \"$c_name\");
481 CAMLreturn (Val_unit);
483 } elsif ($sig eq "conn, int : int array") {
486 virConnectPtr conn = Connect_val (connv);
487 int i = Int_val (iv);
490 /* Some libvirt List* functions still throw exceptions if i == 0,
491 * so catch that and return an empty array directly. This changes
492 * the semantics slightly (masking other failures) but it's
493 * unlikely anyone will care. RWMJ 2008/06/10
496 rv = caml_alloc (0, 0);
500 NONBLOCKING (r = $c_name (conn, ids, i));
501 CHECK_ERROR (r == -1, conn, \"$c_name\");
503 rv = caml_alloc (r, 0);
504 for (i = 0; i < r; ++i)
505 Store_field (rv, i, Val_int (ids[i]));
509 } elsif ($sig =~ /^(\w+), int : string array$/) {
511 CAMLlocal2 (rv, strv);
512 " . gen_unpack_args ($1) . "
513 int i = Int_val (iv);
517 /* Some libvirt List* functions still throw exceptions if i == 0,
518 * so catch that and return an empty array directly. This changes
519 * the semantics slightly (masking other failures) but it's
520 * unlikely anyone will care. RWMJ 2008/06/10
523 rv = caml_alloc (0, 0);
527 NONBLOCKING (r = $c_name ($1, names, i));
528 CHECK_ERROR (r == -1, conn, \"$c_name\");
530 rv = caml_alloc (r, 0);
531 for (i = 0; i < r; ++i) {
532 strv = caml_copy_string (names[i]);
533 Store_field (rv, i, strv);
539 } elsif ($sig =~ /^(\w+), 0U? : string$/) {
542 " . gen_unpack_args ($1) . "
545 NONBLOCKING (r = $c_name ($1, 0));
546 CHECK_ERROR (!r, conn, \"$c_name\");
548 rv = caml_copy_string (r);
552 } elsif ($sig =~ /^(\w+), 0U? : unit$/) {
554 " . gen_unpack_args ($1) . "
557 NONBLOCKING (r = $c_name ($1, 0));
558 CHECK_ERROR (r == -1, conn, \"$c_name\");
560 CAMLreturn (Val_unit);
562 } elsif ($sig =~ /^(\w+) : unit$/) {
564 " . gen_unpack_args ($1) . "
567 NONBLOCKING (r = $c_name ($1));
568 CHECK_ERROR (r == -1, conn, \"$c_name\");
570 CAMLreturn (Val_unit);
572 } elsif ($sig =~ /^(\w+) : free$/) {
574 " . gen_unpack_args ($1) . "
577 NONBLOCKING (r = $c_name ($1));
578 CHECK_ERROR (r == -1, conn, \"$c_name\");
580 /* So that we don't double-free in the finalizer: */
581 " . gen_free_arg ($1) . "
583 CAMLreturn (Val_unit);
585 } elsif ($sig =~ /^(\w+), string : unit$/) {
587 " . gen_unpack_args ($1) . "
588 char *str = String_val (strv);
591 NONBLOCKING (r = $c_name ($1, str));
592 CHECK_ERROR (r == -1, conn, \"$c_name\");
594 CAMLreturn (Val_unit);
596 } elsif ($sig =~ /^(\w+), string, 0U? : unit$/) {
599 " . gen_unpack_args ($1) . "
600 char *str = String_val (strv);
603 NONBLOCKING (r = $c_name ($1, str, 0));
604 CHECK_ERROR (!r, conn, \"$c_name\");
606 CAMLreturn (Val_unit);
608 } elsif ($sig =~ /^(\w+), string : (\w+)$/) {
609 my $c_ret_type = short_name_to_c_type ($2);
612 " . gen_unpack_args ($1) . "
613 char *str = String_val (strv);
616 NONBLOCKING (r = $c_name ($1, str));
617 CHECK_ERROR (!r, conn, \"$c_name\");
619 " . gen_pack_result ($2) . "
623 } elsif ($sig =~ /^(\w+), string, 0U? : (\w+)$/) {
624 my $c_ret_type = short_name_to_c_type ($2);
627 " . gen_unpack_args ($1) . "
628 char *str = String_val (strv);
631 NONBLOCKING (r = $c_name ($1, str, 0));
632 CHECK_ERROR (!r, conn, \"$c_name\");
634 " . gen_pack_result ($2) . "
638 } elsif ($sig =~ /^(\w+), string, unsigned : (\w+)$/) {
639 my $c_ret_type = short_name_to_c_type ($2);
642 " . gen_unpack_args ($1) . "
643 char *str = String_val (strv);
644 unsigned int u = Int_val (uv);
647 NONBLOCKING (r = $c_name ($1, str, u));
648 CHECK_ERROR (!r, conn, \"$c_name\");
650 " . gen_pack_result ($2) . "
654 } elsif ($sig =~ /^(\w+), (u?)int : unit$/) {
655 my $unsigned = $2 eq "u" ? "unsigned " : "";
657 " . gen_unpack_args ($1) . "
658 ${unsigned}int i = Int_val (iv);
661 NONBLOCKING (r = $c_name ($1, i));
662 CHECK_ERROR (r == -1, conn, \"$c_name\");
664 CAMLreturn (Val_unit);
666 } elsif ($sig =~ /^(\w+), (u?)int : (\w+)$/) {
667 my $c_ret_type = short_name_to_c_type ($3);
668 my $unsigned = $2 eq "u" ? "unsigned " : "";
671 " . gen_unpack_args ($1) . "
672 ${unsigned}int i = Int_val (iv);
675 NONBLOCKING (r = $c_name ($1, i));
676 CHECK_ERROR (!r, conn, \"$c_name\");
678 " . gen_pack_result ($3) . "
682 } elsif ($sig =~ /^(\w+), uuid : (\w+)$/) {
683 my $c_ret_type = short_name_to_c_type ($2);
686 " . gen_unpack_args ($1) . "
687 unsigned char *uuid = (unsigned char *) String_val (uuidv);
690 NONBLOCKING (r = $c_name ($1, uuid));
691 CHECK_ERROR (!r, conn, \"$c_name\");
693 " . gen_pack_result ($2) . "
697 } elsif ($sig =~ /^(\w+), 0U? : (\w+)$/) {
698 my $c_ret_type = short_name_to_c_type ($2);
701 " . gen_unpack_args ($1) . "
704 NONBLOCKING (r = $c_name ($1, 0));
705 CHECK_ERROR (!r, conn, \"$c_name\");
707 " . gen_pack_result ($2) . "
711 } elsif ($sig =~ /^(\w+) : (\w+)$/) {
712 my $c_ret_type = short_name_to_c_type ($2);
715 " . gen_unpack_args ($1) . "
718 NONBLOCKING (r = $c_name ($1));
719 CHECK_ERROR (!r, conn, \"$c_name\");
721 " . gen_pack_result ($2) . "
725 } elsif ($sig =~ /^(\w+), string : (\w+) from (\w+)$/) {
726 my $c_ret_type = short_name_to_c_type ($2);
728 CAMLlocal2 (rv, connv);
729 " . gen_unpack_args ($1) . "
730 char *str = String_val (strv);
733 NONBLOCKING (r = $c_name ($1, str));
734 CHECK_ERROR (!r, conn, \"$c_name\");
736 connv = Field ($3v, 1);
737 " . gen_pack_result ($2) . "
741 } elsif ($sig =~ /^(\w+), string, 0U? : (\w+) from (\w+)$/) {
742 my $c_ret_type = short_name_to_c_type ($2);
744 CAMLlocal2 (rv, connv);
745 " . gen_unpack_args ($1) . "
746 char *str = String_val (strv);
749 NONBLOCKING (r = $c_name ($1, str, 0));
750 CHECK_ERROR (!r, conn, \"$c_name\");
752 connv = Field ($3v, 1);
753 " . gen_pack_result ($2) . "
757 } elsif ($sig =~ /^(\w+), 0U? : (\w+) from (\w+)$/) {
758 my $c_ret_type = short_name_to_c_type ($2);
760 CAMLlocal2 (rv, connv);
761 " . gen_unpack_args ($1) . "
764 NONBLOCKING (r = $c_name ($1, 0));
765 CHECK_ERROR (!r, conn, \"$c_name\");
767 connv = Field ($3v, 1);
768 " . gen_pack_result ($2) . "
772 } elsif ($sig =~ /^(\w+) : (\w+) from (\w+)$/) {
773 my $c_ret_type = short_name_to_c_type ($2);
775 CAMLlocal2 (rv, connv);
776 " . gen_unpack_args ($1) . "
779 NONBLOCKING (r = $c_name ($1));
780 CHECK_ERROR (!r, conn, \"$c_name\");
782 connv = Field ($3v, 1);
783 " . gen_pack_result ($2) . "
788 die "unknown signature $sig"
792 # Generate each function.
794 foreach my $function (@functions) {
795 my $c_name = $function->{name};
796 my $sig = $function->{sig};
798 #print "generating $c_name with sig \"$sig\" ...\n";
800 #my $is_pool_func = $c_name =~ /^virStoragePool/;
801 #my $is_vol_func = $c_name =~ /^virStorageVol/;
803 # Generate an equivalent C-external name for the function, unless
804 # one is defined already.
806 if (exists ($function->{c_external_name})) {
807 $c_external_name = $function->{c_external_name};
808 } elsif ($c_name =~ /^vir/) {
809 $c_external_name = substr $c_name, 3;
810 $c_external_name = camel_case_to_underscores ($c_external_name);
811 $c_external_name = "ocaml_libvirt_" . $c_external_name;
813 die "cannot convert c_name $c_name to c_external_name"
817 /* Automatically generated binding for $c_name.
818 * In generator.pl this function has signature "$sig".
823 my @arg_names = gen_arg_names ($sig);
824 my $nr_arg_names = scalar @arg_names;
825 my $arg_names = join ", ", @arg_names;
826 my $arg_names_as_values = join (", ", map { "value $_" } @arg_names);
828 # Generate the start of the function, arguments.
831 $c_external_name ($arg_names_as_values)
833 CAMLparam$nr_arg_names ($arg_names);
836 # Generate the internals of the function.
837 print F (gen_c_code ($sig, $c_name));
839 # Finish off the function.
846 #----------------------------------------------------------------------
848 # Unimplemented functions.
850 if (@unimplemented) {
851 printf "$0: warning: %d unimplemented functions\n", scalar (@unimplemented);
854 /* The following functions are unimplemented and always fail.
855 * See generator.pl '@unimplemented'
860 foreach my $c_external_name (@unimplemented) {
865 failwith ("$c_external_name is unimplemented");
870 } # end if @unimplemented
872 #----------------------------------------------------------------------
874 # Write the epilogue.
877 #include "libvirt_c_epilogue.c"
883 print "$0: written $filename\n"