a23efbd7504a802dbfe1775034cabc126a6a01fb
[virt-top.git] / libvirt / libvirt_c.c
1 /* !!! WARNING WARNING WARNING WARNING WARNING WARNING WARNING !!!
2  *
3  * THIS FILE IS AUTOMATICALLY GENERATED BY 'generator.pl'.
4  *
5  * Any changes you make to this file may be overwritten.
6  */
7
8 /* OCaml bindings for libvirt.
9  * (C) Copyright 2007-2008 Richard W.M. Jones, Red Hat Inc.
10  * http://libvirt.org/
11  *
12  * This library is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public
14  * License as published by the Free Software Foundation; either
15  * version 2 of the License, or (at your option) any later version.
16  *
17  * This library is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  * Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with this library; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
25  */
26
27 #include "config.h"
28
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32
33 #include <libvirt/libvirt.h>
34 #include <libvirt/virterror.h>
35
36 #include <caml/config.h>
37 #include <caml/alloc.h>
38 #include <caml/callback.h>
39 #include <caml/custom.h>
40 #include <caml/fail.h>
41 #include <caml/memory.h>
42 #include <caml/misc.h>
43 #include <caml/mlvalues.h>
44 #include <caml/signals.h>
45
46 #include "libvirt_c_prologue.c"
47
48 #include "libvirt_c_oneoffs.c"
49
50 CAMLprim value
51 ocaml_libvirt_connect_close (value connv)
52 {
53   CAMLparam1 (connv);
54
55   virConnectPtr conn = Connect_val (connv);
56   int r;
57
58   NONBLOCKING (r = virConnectClose (conn));
59   CHECK_ERROR (r == -1, conn, "virConnectClose");
60
61   /* So that we don't double-free in the finalizer: */
62   Connect_val (connv) = NULL;
63
64   CAMLreturn (Val_unit);
65 }
66
67 #ifdef HAVE_WEAK_SYMBOLS
68 #ifdef HAVE_VIRCONNECTGETHOSTNAME
69 extern char *virConnectGetHostname (virConnectPtr conn) __attribute__((weak));
70 #endif
71 #endif
72
73 CAMLprim value
74 ocaml_libvirt_connect_get_hostname (value connv)
75 {
76   CAMLparam1 (connv);
77 #ifndef HAVE_VIRCONNECTGETHOSTNAME
78   /* Symbol virConnectGetHostname not found at compile time. */
79   not_supported ("virConnectGetHostname");
80   /* Suppresses a compiler warning. */
81   (void) caml__frame;
82 #else
83   /* Check that the symbol virConnectGetHostname
84    * is in runtime version of libvirt.
85    */
86   WEAK_SYMBOL_CHECK (virConnectGetHostname);
87
88   CAMLlocal1 (rv);
89   virConnectPtr conn = Connect_val (connv);
90   char *r;
91
92   NONBLOCKING (r = virConnectGetHostname (conn));
93   CHECK_ERROR (!r, conn, "virConnectGetHostname");
94
95   rv = caml_copy_string (r);
96   free (r);
97   CAMLreturn (rv);
98 #endif
99 }
100
101 #ifdef HAVE_WEAK_SYMBOLS
102 #ifdef HAVE_VIRCONNECTGETURI
103 extern char *virConnectGetURI (virConnectPtr conn) __attribute__((weak));
104 #endif
105 #endif
106
107 CAMLprim value
108 ocaml_libvirt_connect_get_uri (value connv)
109 {
110   CAMLparam1 (connv);
111 #ifndef HAVE_VIRCONNECTGETURI
112   /* Symbol virConnectGetURI not found at compile time. */
113   not_supported ("virConnectGetURI");
114   /* Suppresses a compiler warning. */
115   (void) caml__frame;
116 #else
117   /* Check that the symbol virConnectGetURI
118    * is in runtime version of libvirt.
119    */
120   WEAK_SYMBOL_CHECK (virConnectGetURI);
121
122   CAMLlocal1 (rv);
123   virConnectPtr conn = Connect_val (connv);
124   char *r;
125
126   NONBLOCKING (r = virConnectGetURI (conn));
127   CHECK_ERROR (!r, conn, "virConnectGetURI");
128
129   rv = caml_copy_string (r);
130   free (r);
131   CAMLreturn (rv);
132 #endif
133 }
134
135 CAMLprim value
136 ocaml_libvirt_connect_get_type (value connv)
137 {
138   CAMLparam1 (connv);
139
140   CAMLlocal1 (rv);
141   virConnectPtr conn = Connect_val (connv);
142   const char *r;
143
144   NONBLOCKING (r = virConnectGetType (conn));
145   CHECK_ERROR (!r, conn, "virConnectGetType");
146
147   rv = caml_copy_string (r);
148   CAMLreturn (rv);
149 }
150
151 CAMLprim value
152 ocaml_libvirt_connect_num_of_domains (value connv)
153 {
154   CAMLparam1 (connv);
155
156   virConnectPtr conn = Connect_val (connv);
157   int r;
158
159   NONBLOCKING (r = virConnectNumOfDomains (conn));
160   CHECK_ERROR (r == -1, conn, "virConnectNumOfDomains");
161
162   CAMLreturn (Val_int (r));
163 }
164
165 CAMLprim value
166 ocaml_libvirt_connect_list_domains (value connv, value iv)
167 {
168   CAMLparam2 (connv, iv);
169
170   CAMLlocal1 (rv);
171   virConnectPtr conn = Connect_val (connv);
172   int i = Int_val (iv);
173   int ids[i], r;
174
175   NONBLOCKING (r = virConnectListDomains (conn, ids, i));
176   CHECK_ERROR (r == -1, conn, "virConnectListDomains");
177
178   rv = caml_alloc (r, 0);
179   for (i = 0; i < r; ++i)
180     Store_field (rv, i, Val_int (ids[i]));
181
182   CAMLreturn (rv);
183 }
184
185 CAMLprim value
186 ocaml_libvirt_connect_num_of_defined_domains (value connv)
187 {
188   CAMLparam1 (connv);
189
190   virConnectPtr conn = Connect_val (connv);
191   int r;
192
193   NONBLOCKING (r = virConnectNumOfDefinedDomains (conn));
194   CHECK_ERROR (r == -1, conn, "virConnectNumOfDefinedDomains");
195
196   CAMLreturn (Val_int (r));
197 }
198
199 CAMLprim value
200 ocaml_libvirt_connect_list_defined_domains (value connv, value iv)
201 {
202   CAMLparam2 (connv, iv);
203
204   CAMLlocal2 (rv, strv);
205   virConnectPtr conn = Connect_val (connv);
206   int i = Int_val (iv);
207   char *names[i];
208   int r;
209
210   NONBLOCKING (r = virConnectListDefinedDomains (conn, names, i));
211   CHECK_ERROR (r == -1, conn, "virConnectListDefinedDomains");
212
213   rv = caml_alloc (r, 0);
214   for (i = 0; i < r; ++i) {
215     strv = caml_copy_string (names[i]);
216     Store_field (rv, i, strv);
217     free (names[i]);
218   }
219
220   CAMLreturn (rv);
221 }
222
223 CAMLprim value
224 ocaml_libvirt_connect_num_of_networks (value connv)
225 {
226   CAMLparam1 (connv);
227
228   virConnectPtr conn = Connect_val (connv);
229   int r;
230
231   NONBLOCKING (r = virConnectNumOfNetworks (conn));
232   CHECK_ERROR (r == -1, conn, "virConnectNumOfNetworks");
233
234   CAMLreturn (Val_int (r));
235 }
236
237 CAMLprim value
238 ocaml_libvirt_connect_list_networks (value connv, value iv)
239 {
240   CAMLparam2 (connv, iv);
241
242   CAMLlocal2 (rv, strv);
243   virConnectPtr conn = Connect_val (connv);
244   int i = Int_val (iv);
245   char *names[i];
246   int r;
247
248   NONBLOCKING (r = virConnectListNetworks (conn, names, i));
249   CHECK_ERROR (r == -1, conn, "virConnectListNetworks");
250
251   rv = caml_alloc (r, 0);
252   for (i = 0; i < r; ++i) {
253     strv = caml_copy_string (names[i]);
254     Store_field (rv, i, strv);
255     free (names[i]);
256   }
257
258   CAMLreturn (rv);
259 }
260
261 CAMLprim value
262 ocaml_libvirt_connect_num_of_defined_networks (value connv)
263 {
264   CAMLparam1 (connv);
265
266   virConnectPtr conn = Connect_val (connv);
267   int r;
268
269   NONBLOCKING (r = virConnectNumOfDefinedNetworks (conn));
270   CHECK_ERROR (r == -1, conn, "virConnectNumOfDefinedNetworks");
271
272   CAMLreturn (Val_int (r));
273 }
274
275 CAMLprim value
276 ocaml_libvirt_connect_list_defined_networks (value connv, value iv)
277 {
278   CAMLparam2 (connv, iv);
279
280   CAMLlocal2 (rv, strv);
281   virConnectPtr conn = Connect_val (connv);
282   int i = Int_val (iv);
283   char *names[i];
284   int r;
285
286   NONBLOCKING (r = virConnectListDefinedNetworks (conn, names, i));
287   CHECK_ERROR (r == -1, conn, "virConnectListDefinedNetworks");
288
289   rv = caml_alloc (r, 0);
290   for (i = 0; i < r; ++i) {
291     strv = caml_copy_string (names[i]);
292     Store_field (rv, i, strv);
293     free (names[i]);
294   }
295
296   CAMLreturn (rv);
297 }
298
299 #ifdef HAVE_WEAK_SYMBOLS
300 #ifdef HAVE_VIRCONNECTNUMOFSTORAGEPOOLS
301 extern int virConnectNumOfStoragePools (virConnectPtr conn) __attribute__((weak));
302 #endif
303 #endif
304
305 CAMLprim value
306 ocaml_libvirt_connect_num_of_storage_pools (value connv)
307 {
308   CAMLparam1 (connv);
309 #ifndef HAVE_VIRCONNECTNUMOFSTORAGEPOOLS
310   /* Symbol virConnectNumOfStoragePools not found at compile time. */
311   not_supported ("virConnectNumOfStoragePools");
312   /* Suppresses a compiler warning. */
313   (void) caml__frame;
314 #else
315   /* Check that the symbol virConnectNumOfStoragePools
316    * is in runtime version of libvirt.
317    */
318   WEAK_SYMBOL_CHECK (virConnectNumOfStoragePools);
319
320   virConnectPtr conn = Connect_val (connv);
321   int r;
322
323   NONBLOCKING (r = virConnectNumOfStoragePools (conn));
324   CHECK_ERROR (r == -1, conn, "virConnectNumOfStoragePools");
325
326   CAMLreturn (Val_int (r));
327 #endif
328 }
329
330 #ifdef HAVE_WEAK_SYMBOLS
331 #ifdef HAVE_VIRCONNECTLISTSTORAGEPOOLS
332 extern int virConnectListStoragePools (virConnectPtr conn, char **const names, int maxnames) __attribute__((weak));
333 #endif
334 #endif
335
336 CAMLprim value
337 ocaml_libvirt_connect_list_storage_pools (value connv, value iv)
338 {
339   CAMLparam2 (connv, iv);
340 #ifndef HAVE_VIRCONNECTLISTSTORAGEPOOLS
341   /* Symbol virConnectListStoragePools not found at compile time. */
342   not_supported ("virConnectListStoragePools");
343   /* Suppresses a compiler warning. */
344   (void) caml__frame;
345 #else
346   /* Check that the symbol virConnectListStoragePools
347    * is in runtime version of libvirt.
348    */
349   WEAK_SYMBOL_CHECK (virConnectListStoragePools);
350
351   CAMLlocal2 (rv, strv);
352   virConnectPtr conn = Connect_val (connv);
353   int i = Int_val (iv);
354   char *names[i];
355   int r;
356
357   NONBLOCKING (r = virConnectListStoragePools (conn, names, i));
358   CHECK_ERROR (r == -1, conn, "virConnectListStoragePools");
359
360   rv = caml_alloc (r, 0);
361   for (i = 0; i < r; ++i) {
362     strv = caml_copy_string (names[i]);
363     Store_field (rv, i, strv);
364     free (names[i]);
365   }
366
367   CAMLreturn (rv);
368 #endif
369 }
370
371 #ifdef HAVE_WEAK_SYMBOLS
372 #ifdef HAVE_VIRCONNECTNUMOFDEFINEDSTORAGEPOOLS
373 extern int virConnectNumOfDefinedStoragePools (virConnectPtr conn) __attribute__((weak));
374 #endif
375 #endif
376
377 CAMLprim value
378 ocaml_libvirt_connect_num_of_defined_storage_pools (value connv)
379 {
380   CAMLparam1 (connv);
381 #ifndef HAVE_VIRCONNECTNUMOFDEFINEDSTORAGEPOOLS
382   /* Symbol virConnectNumOfDefinedStoragePools not found at compile time. */
383   not_supported ("virConnectNumOfDefinedStoragePools");
384   /* Suppresses a compiler warning. */
385   (void) caml__frame;
386 #else
387   /* Check that the symbol virConnectNumOfDefinedStoragePools
388    * is in runtime version of libvirt.
389    */
390   WEAK_SYMBOL_CHECK (virConnectNumOfDefinedStoragePools);
391
392   virConnectPtr conn = Connect_val (connv);
393   int r;
394
395   NONBLOCKING (r = virConnectNumOfDefinedStoragePools (conn));
396   CHECK_ERROR (r == -1, conn, "virConnectNumOfDefinedStoragePools");
397
398   CAMLreturn (Val_int (r));
399 #endif
400 }
401
402 #ifdef HAVE_WEAK_SYMBOLS
403 #ifdef HAVE_VIRCONNECTLISTDEFINEDSTORAGEPOOLS
404 extern int virConnectListDefinedStoragePools (virConnectPtr conn, char **const names, int maxnames) __attribute__((weak));
405 #endif
406 #endif
407
408 CAMLprim value
409 ocaml_libvirt_connect_list_defined_storage_pools (value connv, value iv)
410 {
411   CAMLparam2 (connv, iv);
412 #ifndef HAVE_VIRCONNECTLISTDEFINEDSTORAGEPOOLS
413   /* Symbol virConnectListDefinedStoragePools not found at compile time. */
414   not_supported ("virConnectListDefinedStoragePools");
415   /* Suppresses a compiler warning. */
416   (void) caml__frame;
417 #else
418   /* Check that the symbol virConnectListDefinedStoragePools
419    * is in runtime version of libvirt.
420    */
421   WEAK_SYMBOL_CHECK (virConnectListDefinedStoragePools);
422
423   CAMLlocal2 (rv, strv);
424   virConnectPtr conn = Connect_val (connv);
425   int i = Int_val (iv);
426   char *names[i];
427   int r;
428
429   NONBLOCKING (r = virConnectListDefinedStoragePools (conn, names, i));
430   CHECK_ERROR (r == -1, conn, "virConnectListDefinedStoragePools");
431
432   rv = caml_alloc (r, 0);
433   for (i = 0; i < r; ++i) {
434     strv = caml_copy_string (names[i]);
435     Store_field (rv, i, strv);
436     free (names[i]);
437   }
438
439   CAMLreturn (rv);
440 #endif
441 }
442
443 CAMLprim value
444 ocaml_libvirt_connect_get_capabilities (value connv)
445 {
446   CAMLparam1 (connv);
447
448   CAMLlocal1 (rv);
449   virConnectPtr conn = Connect_val (connv);
450   char *r;
451
452   NONBLOCKING (r = virConnectGetCapabilities (conn));
453   CHECK_ERROR (!r, conn, "virConnectGetCapabilities");
454
455   rv = caml_copy_string (r);
456   free (r);
457   CAMLreturn (rv);
458 }
459
460 CAMLprim value
461 ocaml_libvirt_domain_free (value domv)
462 {
463   CAMLparam1 (domv);
464
465   virDomainPtr dom = Domain_val (domv);
466   virConnectPtr conn = Connect_domv (domv);
467   int r;
468
469   NONBLOCKING (r = virDomainFree (dom));
470   CHECK_ERROR (r == -1, conn, "virDomainFree");
471
472   /* So that we don't double-free in the finalizer: */
473   Domain_val (domv) = NULL;
474
475   CAMLreturn (Val_unit);
476 }
477
478 CAMLprim value
479 ocaml_libvirt_domain_destroy (value domv)
480 {
481   CAMLparam1 (domv);
482
483   virDomainPtr dom = Domain_val (domv);
484   virConnectPtr conn = Connect_domv (domv);
485   int r;
486
487   NONBLOCKING (r = virDomainDestroy (dom));
488   CHECK_ERROR (r == -1, conn, "virDomainDestroy");
489
490   /* So that we don't double-free in the finalizer: */
491   Domain_val (domv) = NULL;
492
493   CAMLreturn (Val_unit);
494 }
495
496 CAMLprim value
497 ocaml_libvirt_domain_lookup_by_name (value connv, value strv)
498 {
499   CAMLparam2 (connv, strv);
500
501   CAMLlocal1 (rv);
502   virConnectPtr conn = Connect_val (connv);
503   char *str = String_val (strv);
504   virDomainPtr r;
505
506   NONBLOCKING (r = virDomainLookupByName (conn, str));
507   CHECK_ERROR (!r, conn, "virDomainLookupByName");
508
509   rv = Val_domain (r, connv);
510
511   CAMLreturn (rv);
512 }
513
514 CAMLprim value
515 ocaml_libvirt_domain_lookup_by_uuid_string (value connv, value strv)
516 {
517   CAMLparam2 (connv, strv);
518
519   CAMLlocal1 (rv);
520   virConnectPtr conn = Connect_val (connv);
521   char *str = String_val (strv);
522   virDomainPtr r;
523
524   NONBLOCKING (r = virDomainLookupByUUIDString (conn, str));
525   CHECK_ERROR (!r, conn, "virDomainLookupByUUIDString");
526
527   rv = Val_domain (r, connv);
528
529   CAMLreturn (rv);
530 }
531
532 CAMLprim value
533 ocaml_libvirt_domain_get_name (value domv)
534 {
535   CAMLparam1 (domv);
536
537   CAMLlocal1 (rv);
538   virDomainPtr dom = Domain_val (domv);
539   virConnectPtr conn = Connect_domv (domv);
540   const char *r;
541
542   NONBLOCKING (r = virDomainGetName (dom));
543   CHECK_ERROR (!r, conn, "virDomainGetName");
544
545   rv = caml_copy_string (r);
546   CAMLreturn (rv);
547 }
548
549 CAMLprim value
550 ocaml_libvirt_domain_get_os_type (value domv)
551 {
552   CAMLparam1 (domv);
553
554   CAMLlocal1 (rv);
555   virDomainPtr dom = Domain_val (domv);
556   virConnectPtr conn = Connect_domv (domv);
557   char *r;
558
559   NONBLOCKING (r = virDomainGetOSType (dom));
560   CHECK_ERROR (!r, conn, "virDomainGetOSType");
561
562   rv = caml_copy_string (r);
563   free (r);
564   CAMLreturn (rv);
565 }
566
567 CAMLprim value
568 ocaml_libvirt_domain_get_xml_desc (value domv)
569 {
570   CAMLparam1 (domv);
571
572   CAMLlocal1 (rv);
573   virDomainPtr dom = Domain_val (domv);
574   virConnectPtr conn = Connect_domv (domv);
575   char *r;
576
577   NONBLOCKING (r = virDomainGetXMLDesc (dom, 0));
578   CHECK_ERROR (!r, conn, "virDomainGetXMLDesc");
579
580   rv = caml_copy_string (r);
581   free (r);
582   CAMLreturn (rv);
583 }
584
585 CAMLprim value
586 ocaml_libvirt_domain_get_uuid (value domv)
587 {
588   CAMLparam1 (domv);
589
590   CAMLlocal1 (rv);
591   virDomainPtr dom = Domain_val (domv);
592   virConnectPtr conn = Connect_domv (domv);
593   unsigned char uuid[VIR_UUID_BUFLEN];
594   int r;
595
596   NONBLOCKING (r = virDomainGetUUID (dom, uuid));
597   CHECK_ERROR (r == -1, conn, "virDomainGetUUID");
598
599   rv = caml_copy_string ((char *) uuid);
600   CAMLreturn (rv);
601 }
602
603 CAMLprim value
604 ocaml_libvirt_domain_get_uuid_string (value domv)
605 {
606   CAMLparam1 (domv);
607
608   CAMLlocal1 (rv);
609   virDomainPtr dom = Domain_val (domv);
610   virConnectPtr conn = Connect_domv (domv);
611   char uuid[VIR_UUID_STRING_BUFLEN];
612   int r;
613
614   NONBLOCKING (r = virDomainGetUUIDString (dom, uuid));
615   CHECK_ERROR (r == -1, conn, "virDomainGetUUIDString");
616
617   rv = caml_copy_string (uuid);
618   CAMLreturn (rv);
619 }
620
621 CAMLprim value
622 ocaml_libvirt_domain_suspend (value domv)
623 {
624   CAMLparam1 (domv);
625
626   virDomainPtr dom = Domain_val (domv);
627   virConnectPtr conn = Connect_domv (domv);
628   int r;
629
630   NONBLOCKING (r = virDomainSuspend (dom));
631   CHECK_ERROR (r == -1, conn, "virDomainSuspend");
632
633   CAMLreturn (Val_unit);
634 }
635
636 CAMLprim value
637 ocaml_libvirt_domain_resume (value domv)
638 {
639   CAMLparam1 (domv);
640
641   virDomainPtr dom = Domain_val (domv);
642   virConnectPtr conn = Connect_domv (domv);
643   int r;
644
645   NONBLOCKING (r = virDomainResume (dom));
646   CHECK_ERROR (r == -1, conn, "virDomainResume");
647
648   CAMLreturn (Val_unit);
649 }
650
651 CAMLprim value
652 ocaml_libvirt_domain_shutdown (value domv)
653 {
654   CAMLparam1 (domv);
655
656   virDomainPtr dom = Domain_val (domv);
657   virConnectPtr conn = Connect_domv (domv);
658   int r;
659
660   NONBLOCKING (r = virDomainShutdown (dom));
661   CHECK_ERROR (r == -1, conn, "virDomainShutdown");
662
663   CAMLreturn (Val_unit);
664 }
665
666 CAMLprim value
667 ocaml_libvirt_domain_reboot (value domv)
668 {
669   CAMLparam1 (domv);
670
671   virDomainPtr dom = Domain_val (domv);
672   virConnectPtr conn = Connect_domv (domv);
673   int r;
674
675   NONBLOCKING (r = virDomainReboot (dom, 0));
676   CHECK_ERROR (r == -1, conn, "virDomainReboot");
677
678   CAMLreturn (Val_unit);
679 }
680
681 CAMLprim value
682 ocaml_libvirt_domain_undefine (value domv)
683 {
684   CAMLparam1 (domv);
685
686   virDomainPtr dom = Domain_val (domv);
687   virConnectPtr conn = Connect_domv (domv);
688   int r;
689
690   NONBLOCKING (r = virDomainUndefine (dom));
691   CHECK_ERROR (r == -1, conn, "virDomainUndefine");
692
693   CAMLreturn (Val_unit);
694 }
695
696 CAMLprim value
697 ocaml_libvirt_domain_create (value domv)
698 {
699   CAMLparam1 (domv);
700
701   virDomainPtr dom = Domain_val (domv);
702   virConnectPtr conn = Connect_domv (domv);
703   int r;
704
705   NONBLOCKING (r = virDomainCreate (dom));
706   CHECK_ERROR (r == -1, conn, "virDomainCreate");
707
708   CAMLreturn (Val_unit);
709 }
710
711 CAMLprim value
712 ocaml_libvirt_domain_get_autostart (value domv)
713 {
714   CAMLparam1 (domv);
715
716   virDomainPtr dom = Domain_val (domv);
717   virConnectPtr conn = Connect_domv (domv);
718   int r, b;
719
720   NONBLOCKING (r = virDomainGetAutostart (dom, &b));
721   CHECK_ERROR (r == -1, conn, "virDomainGetAutostart");
722
723   CAMLreturn (b ? Val_true : Val_false);
724 }
725
726 CAMLprim value
727 ocaml_libvirt_domain_set_autostart (value domv, value bv)
728 {
729   CAMLparam2 (domv, bv);
730
731   virDomainPtr dom = Domain_val (domv);
732   virConnectPtr conn = Connect_domv (domv);
733   int r, b;
734
735   b = bv == Val_true ? 1 : 0;
736
737   NONBLOCKING (r = virDomainSetAutostart (dom, b));
738   CHECK_ERROR (r == -1, conn, "virDomainSetAutostart");
739
740   CAMLreturn (Val_unit);
741 }
742
743 CAMLprim value
744 ocaml_libvirt_network_free (value netv)
745 {
746   CAMLparam1 (netv);
747
748   virNetworkPtr net = Network_val (netv);
749   virConnectPtr conn = Connect_netv (netv);
750   int r;
751
752   NONBLOCKING (r = virNetworkFree (net));
753   CHECK_ERROR (r == -1, conn, "virNetworkFree");
754
755   /* So that we don't double-free in the finalizer: */
756   Network_val (netv) = NULL;
757
758   CAMLreturn (Val_unit);
759 }
760
761 CAMLprim value
762 ocaml_libvirt_network_destroy (value netv)
763 {
764   CAMLparam1 (netv);
765
766   virNetworkPtr net = Network_val (netv);
767   virConnectPtr conn = Connect_netv (netv);
768   int r;
769
770   NONBLOCKING (r = virNetworkDestroy (net));
771   CHECK_ERROR (r == -1, conn, "virNetworkDestroy");
772
773   /* So that we don't double-free in the finalizer: */
774   Network_val (netv) = NULL;
775
776   CAMLreturn (Val_unit);
777 }
778
779 CAMLprim value
780 ocaml_libvirt_network_lookup_by_name (value connv, value strv)
781 {
782   CAMLparam2 (connv, strv);
783
784   CAMLlocal1 (rv);
785   virConnectPtr conn = Connect_val (connv);
786   char *str = String_val (strv);
787   virNetworkPtr r;
788
789   NONBLOCKING (r = virNetworkLookupByName (conn, str));
790   CHECK_ERROR (!r, conn, "virNetworkLookupByName");
791
792   rv = Val_network (r, connv);
793
794   CAMLreturn (rv);
795 }
796
797 CAMLprim value
798 ocaml_libvirt_network_lookup_by_uuid_string (value connv, value strv)
799 {
800   CAMLparam2 (connv, strv);
801
802   CAMLlocal1 (rv);
803   virConnectPtr conn = Connect_val (connv);
804   char *str = String_val (strv);
805   virNetworkPtr r;
806
807   NONBLOCKING (r = virNetworkLookupByUUIDString (conn, str));
808   CHECK_ERROR (!r, conn, "virNetworkLookupByUUIDString");
809
810   rv = Val_network (r, connv);
811
812   CAMLreturn (rv);
813 }
814
815 CAMLprim value
816 ocaml_libvirt_network_get_name (value netv)
817 {
818   CAMLparam1 (netv);
819
820   CAMLlocal1 (rv);
821   virNetworkPtr net = Network_val (netv);
822   virConnectPtr conn = Connect_netv (netv);
823   const char *r;
824
825   NONBLOCKING (r = virNetworkGetName (net));
826   CHECK_ERROR (!r, conn, "virNetworkGetName");
827
828   rv = caml_copy_string (r);
829   CAMLreturn (rv);
830 }
831
832 CAMLprim value
833 ocaml_libvirt_network_get_xml_desc (value netv)
834 {
835   CAMLparam1 (netv);
836
837   CAMLlocal1 (rv);
838   virNetworkPtr net = Network_val (netv);
839   virConnectPtr conn = Connect_netv (netv);
840   char *r;
841
842   NONBLOCKING (r = virNetworkGetXMLDesc (net, 0));
843   CHECK_ERROR (!r, conn, "virNetworkGetXMLDesc");
844
845   rv = caml_copy_string (r);
846   free (r);
847   CAMLreturn (rv);
848 }
849
850 CAMLprim value
851 ocaml_libvirt_network_get_bridge_name (value netv)
852 {
853   CAMLparam1 (netv);
854
855   CAMLlocal1 (rv);
856   virNetworkPtr net = Network_val (netv);
857   virConnectPtr conn = Connect_netv (netv);
858   char *r;
859
860   NONBLOCKING (r = virNetworkGetBridgeName (net));
861   CHECK_ERROR (!r, conn, "virNetworkGetBridgeName");
862
863   rv = caml_copy_string (r);
864   free (r);
865   CAMLreturn (rv);
866 }
867
868 CAMLprim value
869 ocaml_libvirt_network_get_uuid (value netv)
870 {
871   CAMLparam1 (netv);
872
873   CAMLlocal1 (rv);
874   virNetworkPtr net = Network_val (netv);
875   virConnectPtr conn = Connect_netv (netv);
876   unsigned char uuid[VIR_UUID_BUFLEN];
877   int r;
878
879   NONBLOCKING (r = virNetworkGetUUID (net, uuid));
880   CHECK_ERROR (r == -1, conn, "virNetworkGetUUID");
881
882   rv = caml_copy_string ((char *) uuid);
883   CAMLreturn (rv);
884 }
885
886 CAMLprim value
887 ocaml_libvirt_network_get_uuid_string (value netv)
888 {
889   CAMLparam1 (netv);
890
891   CAMLlocal1 (rv);
892   virNetworkPtr net = Network_val (netv);
893   virConnectPtr conn = Connect_netv (netv);
894   char uuid[VIR_UUID_STRING_BUFLEN];
895   int r;
896
897   NONBLOCKING (r = virNetworkGetUUIDString (net, uuid));
898   CHECK_ERROR (r == -1, conn, "virNetworkGetUUIDString");
899
900   rv = caml_copy_string (uuid);
901   CAMLreturn (rv);
902 }
903
904 CAMLprim value
905 ocaml_libvirt_network_undefine (value netv)
906 {
907   CAMLparam1 (netv);
908
909   virNetworkPtr net = Network_val (netv);
910   virConnectPtr conn = Connect_netv (netv);
911   int r;
912
913   NONBLOCKING (r = virNetworkUndefine (net));
914   CHECK_ERROR (r == -1, conn, "virNetworkUndefine");
915
916   CAMLreturn (Val_unit);
917 }
918
919 CAMLprim value
920 ocaml_libvirt_network_create (value netv)
921 {
922   CAMLparam1 (netv);
923
924   virNetworkPtr net = Network_val (netv);
925   virConnectPtr conn = Connect_netv (netv);
926   int r;
927
928   NONBLOCKING (r = virNetworkCreate (net));
929   CHECK_ERROR (r == -1, conn, "virNetworkCreate");
930
931   CAMLreturn (Val_unit);
932 }
933
934 CAMLprim value
935 ocaml_libvirt_network_get_autostart (value netv)
936 {
937   CAMLparam1 (netv);
938
939   virNetworkPtr net = Network_val (netv);
940   virConnectPtr conn = Connect_netv (netv);
941   int r, b;
942
943   NONBLOCKING (r = virNetworkGetAutostart (net, &b));
944   CHECK_ERROR (r == -1, conn, "virNetworkGetAutostart");
945
946   CAMLreturn (b ? Val_true : Val_false);
947 }
948
949 CAMLprim value
950 ocaml_libvirt_network_set_autostart (value netv, value bv)
951 {
952   CAMLparam2 (netv, bv);
953
954   virNetworkPtr net = Network_val (netv);
955   virConnectPtr conn = Connect_netv (netv);
956   int r, b;
957
958   b = bv == Val_true ? 1 : 0;
959
960   NONBLOCKING (r = virNetworkSetAutostart (net, b));
961   CHECK_ERROR (r == -1, conn, "virNetworkSetAutostart");
962
963   CAMLreturn (Val_unit);
964 }
965
966 #ifdef HAVE_WEAK_SYMBOLS
967 #ifdef HAVE_VIRSTORAGEPOOLFREE
968 extern int virStoragePoolFree (virStoragePoolPtr pool) __attribute__((weak));
969 #endif
970 #endif
971
972 CAMLprim value
973 ocaml_libvirt_storage_pool_free (value poolv)
974 {
975   CAMLparam1 (poolv);
976 #ifndef HAVE_VIRSTORAGEPOOLFREE
977   /* Symbol virStoragePoolFree not found at compile time. */
978   not_supported ("virStoragePoolFree");
979   /* Suppresses a compiler warning. */
980   (void) caml__frame;
981 #else
982   /* Check that the symbol virStoragePoolFree
983    * is in runtime version of libvirt.
984    */
985   WEAK_SYMBOL_CHECK (virStoragePoolFree);
986
987   virStoragePoolPtr pool = Pool_val (poolv);
988   virConnectPtr conn = Connect_polv (poolv);
989   int r;
990
991   NONBLOCKING (r = virStoragePoolFree (pool));
992   CHECK_ERROR (r == -1, conn, "virStoragePoolFree");
993
994   /* So that we don't double-free in the finalizer: */
995   Pool_val (poolv) = NULL;
996
997   CAMLreturn (Val_unit);
998 #endif
999 }
1000
1001 #ifdef HAVE_WEAK_SYMBOLS
1002 #ifdef HAVE_VIRSTORAGEPOOLDESTROY
1003 extern int virStoragePoolDestroy (virStoragePoolPtr pool) __attribute__((weak));
1004 #endif
1005 #endif
1006
1007 CAMLprim value
1008 ocaml_libvirt_storage_pool_destroy (value poolv)
1009 {
1010   CAMLparam1 (poolv);
1011 #ifndef HAVE_VIRSTORAGEPOOLDESTROY
1012   /* Symbol virStoragePoolDestroy not found at compile time. */
1013   not_supported ("virStoragePoolDestroy");
1014   /* Suppresses a compiler warning. */
1015   (void) caml__frame;
1016 #else
1017   /* Check that the symbol virStoragePoolDestroy
1018    * is in runtime version of libvirt.
1019    */
1020   WEAK_SYMBOL_CHECK (virStoragePoolDestroy);
1021
1022   virStoragePoolPtr pool = Pool_val (poolv);
1023   virConnectPtr conn = Connect_polv (poolv);
1024   int r;
1025
1026   NONBLOCKING (r = virStoragePoolDestroy (pool));
1027   CHECK_ERROR (r == -1, conn, "virStoragePoolDestroy");
1028
1029   /* So that we don't double-free in the finalizer: */
1030   Pool_val (poolv) = NULL;
1031
1032   CAMLreturn (Val_unit);
1033 #endif
1034 }
1035
1036 #ifdef HAVE_WEAK_SYMBOLS
1037 #ifdef HAVE_VIRSTORAGEPOOLLOOKUPBYNAME
1038 extern virStoragePoolPtr virStoragePoolLookupByName (virConnectPtr conn, const char *str) __attribute__((weak));
1039 #endif
1040 #endif
1041
1042 CAMLprim value
1043 ocaml_libvirt_storage_pool_lookup_by_name (value connv, value strv)
1044 {
1045   CAMLparam2 (connv, strv);
1046 #ifndef HAVE_VIRSTORAGEPOOLLOOKUPBYNAME
1047   /* Symbol virStoragePoolLookupByName not found at compile time. */
1048   not_supported ("virStoragePoolLookupByName");
1049   /* Suppresses a compiler warning. */
1050   (void) caml__frame;
1051 #else
1052   /* Check that the symbol virStoragePoolLookupByName
1053    * is in runtime version of libvirt.
1054    */
1055   WEAK_SYMBOL_CHECK (virStoragePoolLookupByName);
1056
1057   CAMLlocal1 (rv);
1058   virConnectPtr conn = Connect_val (connv);
1059   char *str = String_val (strv);
1060   virStoragePoolPtr r;
1061
1062   NONBLOCKING (r = virStoragePoolLookupByName (conn, str));
1063   CHECK_ERROR (!r, conn, "virStoragePoolLookupByName");
1064
1065   rv = Val_pool (r, connv);
1066
1067   CAMLreturn (rv);
1068 #endif
1069 }
1070
1071 #ifdef HAVE_WEAK_SYMBOLS
1072 #ifdef HAVE_VIRSTORAGEPOOLLOOKUPBYUUIDSTRING
1073 extern virStoragePoolPtr virStoragePoolLookupByUUIDString (virConnectPtr conn, const char *str) __attribute__((weak));
1074 #endif
1075 #endif
1076
1077 CAMLprim value
1078 ocaml_libvirt_storage_pool_lookup_by_uuid_string (value connv, value strv)
1079 {
1080   CAMLparam2 (connv, strv);
1081 #ifndef HAVE_VIRSTORAGEPOOLLOOKUPBYUUIDSTRING
1082   /* Symbol virStoragePoolLookupByUUIDString not found at compile time. */
1083   not_supported ("virStoragePoolLookupByUUIDString");
1084   /* Suppresses a compiler warning. */
1085   (void) caml__frame;
1086 #else
1087   /* Check that the symbol virStoragePoolLookupByUUIDString
1088    * is in runtime version of libvirt.
1089    */
1090   WEAK_SYMBOL_CHECK (virStoragePoolLookupByUUIDString);
1091
1092   CAMLlocal1 (rv);
1093   virConnectPtr conn = Connect_val (connv);
1094   char *str = String_val (strv);
1095   virStoragePoolPtr r;
1096
1097   NONBLOCKING (r = virStoragePoolLookupByUUIDString (conn, str));
1098   CHECK_ERROR (!r, conn, "virStoragePoolLookupByUUIDString");
1099
1100   rv = Val_pool (r, connv);
1101
1102   CAMLreturn (rv);
1103 #endif
1104 }
1105
1106 #ifdef HAVE_WEAK_SYMBOLS
1107 #ifdef HAVE_VIRSTORAGEPOOLGETNAME
1108 extern const char *virStoragePoolGetName (virStoragePoolPtr pool) __attribute__((weak));
1109 #endif
1110 #endif
1111
1112 CAMLprim value
1113 ocaml_libvirt_storage_pool_get_name (value poolv)
1114 {
1115   CAMLparam1 (poolv);
1116 #ifndef HAVE_VIRSTORAGEPOOLGETNAME
1117   /* Symbol virStoragePoolGetName not found at compile time. */
1118   not_supported ("virStoragePoolGetName");
1119   /* Suppresses a compiler warning. */
1120   (void) caml__frame;
1121 #else
1122   /* Check that the symbol virStoragePoolGetName
1123    * is in runtime version of libvirt.
1124    */
1125   WEAK_SYMBOL_CHECK (virStoragePoolGetName);
1126
1127   CAMLlocal1 (rv);
1128   virStoragePoolPtr pool = Pool_val (poolv);
1129   virConnectPtr conn = Connect_polv (poolv);
1130   const char *r;
1131
1132   NONBLOCKING (r = virStoragePoolGetName (pool));
1133   CHECK_ERROR (!r, conn, "virStoragePoolGetName");
1134
1135   rv = caml_copy_string (r);
1136   CAMLreturn (rv);
1137 #endif
1138 }
1139
1140 #ifdef HAVE_WEAK_SYMBOLS
1141 #ifdef HAVE_VIRSTORAGEPOOLGETXMLDESC
1142 extern char *virStoragePoolGetXMLDesc (virStoragePoolPtr pool,  int flags) __attribute__((weak));
1143 #endif
1144 #endif
1145
1146 CAMLprim value
1147 ocaml_libvirt_storage_pool_get_xml_desc (value poolv)
1148 {
1149   CAMLparam1 (poolv);
1150 #ifndef HAVE_VIRSTORAGEPOOLGETXMLDESC
1151   /* Symbol virStoragePoolGetXMLDesc not found at compile time. */
1152   not_supported ("virStoragePoolGetXMLDesc");
1153   /* Suppresses a compiler warning. */
1154   (void) caml__frame;
1155 #else
1156   /* Check that the symbol virStoragePoolGetXMLDesc
1157    * is in runtime version of libvirt.
1158    */
1159   WEAK_SYMBOL_CHECK (virStoragePoolGetXMLDesc);
1160
1161   CAMLlocal1 (rv);
1162   virStoragePoolPtr pool = Pool_val (poolv);
1163   virConnectPtr conn = Connect_polv (poolv);
1164   char *r;
1165
1166   NONBLOCKING (r = virStoragePoolGetXMLDesc (pool, 0));
1167   CHECK_ERROR (!r, conn, "virStoragePoolGetXMLDesc");
1168
1169   rv = caml_copy_string (r);
1170   free (r);
1171   CAMLreturn (rv);
1172 #endif
1173 }
1174
1175 #ifdef HAVE_WEAK_SYMBOLS
1176 #ifdef HAVE_VIRSTORAGEPOOLGETUUID
1177 extern int virStoragePoolGetUUID (virStoragePoolPtr pool, unsigned char *) __attribute__((weak));
1178 #endif
1179 #endif
1180
1181 CAMLprim value
1182 ocaml_libvirt_storage_pool_get_uuid (value poolv)
1183 {
1184   CAMLparam1 (poolv);
1185 #ifndef HAVE_VIRSTORAGEPOOLGETUUID
1186   /* Symbol virStoragePoolGetUUID not found at compile time. */
1187   not_supported ("virStoragePoolGetUUID");
1188   /* Suppresses a compiler warning. */
1189   (void) caml__frame;
1190 #else
1191   /* Check that the symbol virStoragePoolGetUUID
1192    * is in runtime version of libvirt.
1193    */
1194   WEAK_SYMBOL_CHECK (virStoragePoolGetUUID);
1195
1196   CAMLlocal1 (rv);
1197   virStoragePoolPtr pool = Pool_val (poolv);
1198   virConnectPtr conn = Connect_polv (poolv);
1199   unsigned char uuid[VIR_UUID_BUFLEN];
1200   int r;
1201
1202   NONBLOCKING (r = virStoragePoolGetUUID (pool, uuid));
1203   CHECK_ERROR (r == -1, conn, "virStoragePoolGetUUID");
1204
1205   rv = caml_copy_string ((char *) uuid);
1206   CAMLreturn (rv);
1207 #endif
1208 }
1209
1210 #ifdef HAVE_WEAK_SYMBOLS
1211 #ifdef HAVE_VIRSTORAGEPOOLGETUUIDSTRING
1212 extern int virStoragePoolGetUUIDString (virStoragePoolPtr pool, char *) __attribute__((weak));
1213 #endif
1214 #endif
1215
1216 CAMLprim value
1217 ocaml_libvirt_storage_pool_get_uuid_string (value poolv)
1218 {
1219   CAMLparam1 (poolv);
1220 #ifndef HAVE_VIRSTORAGEPOOLGETUUIDSTRING
1221   /* Symbol virStoragePoolGetUUIDString not found at compile time. */
1222   not_supported ("virStoragePoolGetUUIDString");
1223   /* Suppresses a compiler warning. */
1224   (void) caml__frame;
1225 #else
1226   /* Check that the symbol virStoragePoolGetUUIDString
1227    * is in runtime version of libvirt.
1228    */
1229   WEAK_SYMBOL_CHECK (virStoragePoolGetUUIDString);
1230
1231   CAMLlocal1 (rv);
1232   virStoragePoolPtr pool = Pool_val (poolv);
1233   virConnectPtr conn = Connect_polv (poolv);
1234   char uuid[VIR_UUID_STRING_BUFLEN];
1235   int r;
1236
1237   NONBLOCKING (r = virStoragePoolGetUUIDString (pool, uuid));
1238   CHECK_ERROR (r == -1, conn, "virStoragePoolGetUUIDString");
1239
1240   rv = caml_copy_string (uuid);
1241   CAMLreturn (rv);
1242 #endif
1243 }
1244
1245 #ifdef HAVE_WEAK_SYMBOLS
1246 #ifdef HAVE_VIRSTORAGEPOOLUNDEFINE
1247 extern int virStoragePoolUndefine (virStoragePoolPtr pool) __attribute__((weak));
1248 #endif
1249 #endif
1250
1251 CAMLprim value
1252 ocaml_libvirt_storage_pool_undefine (value poolv)
1253 {
1254   CAMLparam1 (poolv);
1255 #ifndef HAVE_VIRSTORAGEPOOLUNDEFINE
1256   /* Symbol virStoragePoolUndefine not found at compile time. */
1257   not_supported ("virStoragePoolUndefine");
1258   /* Suppresses a compiler warning. */
1259   (void) caml__frame;
1260 #else
1261   /* Check that the symbol virStoragePoolUndefine
1262    * is in runtime version of libvirt.
1263    */
1264   WEAK_SYMBOL_CHECK (virStoragePoolUndefine);
1265
1266   virStoragePoolPtr pool = Pool_val (poolv);
1267   virConnectPtr conn = Connect_polv (poolv);
1268   int r;
1269
1270   NONBLOCKING (r = virStoragePoolUndefine (pool));
1271   CHECK_ERROR (r == -1, conn, "virStoragePoolUndefine");
1272
1273   CAMLreturn (Val_unit);
1274 #endif
1275 }
1276
1277 #ifdef HAVE_WEAK_SYMBOLS
1278 #ifdef HAVE_VIRSTORAGEPOOLCREATE
1279 extern int virStoragePoolCreate (virStoragePoolPtr pool) __attribute__((weak));
1280 #endif
1281 #endif
1282
1283 CAMLprim value
1284 ocaml_libvirt_storage_pool_create (value poolv)
1285 {
1286   CAMLparam1 (poolv);
1287 #ifndef HAVE_VIRSTORAGEPOOLCREATE
1288   /* Symbol virStoragePoolCreate not found at compile time. */
1289   not_supported ("virStoragePoolCreate");
1290   /* Suppresses a compiler warning. */
1291   (void) caml__frame;
1292 #else
1293   /* Check that the symbol virStoragePoolCreate
1294    * is in runtime version of libvirt.
1295    */
1296   WEAK_SYMBOL_CHECK (virStoragePoolCreate);
1297
1298   virStoragePoolPtr pool = Pool_val (poolv);
1299   virConnectPtr conn = Connect_polv (poolv);
1300   int r;
1301
1302   NONBLOCKING (r = virStoragePoolCreate (pool));
1303   CHECK_ERROR (r == -1, conn, "virStoragePoolCreate");
1304
1305   CAMLreturn (Val_unit);
1306 #endif
1307 }
1308
1309 #ifdef HAVE_WEAK_SYMBOLS
1310 #ifdef HAVE_VIRSTORAGEPOOLSHUTDOWN
1311 extern int virStoragePoolShutdown (virStoragePoolPtr pool) __attribute__((weak));
1312 #endif
1313 #endif
1314
1315 CAMLprim value
1316 ocaml_libvirt_storage_pool_shutdown (value poolv)
1317 {
1318   CAMLparam1 (poolv);
1319 #ifndef HAVE_VIRSTORAGEPOOLSHUTDOWN
1320   /* Symbol virStoragePoolShutdown not found at compile time. */
1321   not_supported ("virStoragePoolShutdown");
1322   /* Suppresses a compiler warning. */
1323   (void) caml__frame;
1324 #else
1325   /* Check that the symbol virStoragePoolShutdown
1326    * is in runtime version of libvirt.
1327    */
1328   WEAK_SYMBOL_CHECK (virStoragePoolShutdown);
1329
1330   virStoragePoolPtr pool = Pool_val (poolv);
1331   virConnectPtr conn = Connect_polv (poolv);
1332   int r;
1333
1334   NONBLOCKING (r = virStoragePoolShutdown (pool));
1335   CHECK_ERROR (r == -1, conn, "virStoragePoolShutdown");
1336
1337   CAMLreturn (Val_unit);
1338 #endif
1339 }
1340
1341 #ifdef HAVE_WEAK_SYMBOLS
1342 #ifdef HAVE_VIRSTORAGEPOOLREFRESH
1343 extern int virStoragePoolRefresh (virStoragePoolPtr pool, unsigned  int flags) __attribute__((weak));
1344 #endif
1345 #endif
1346
1347 CAMLprim value
1348 ocaml_libvirt_storage_pool_refresh (value poolv)
1349 {
1350   CAMLparam1 (poolv);
1351 #ifndef HAVE_VIRSTORAGEPOOLREFRESH
1352   /* Symbol virStoragePoolRefresh not found at compile time. */
1353   not_supported ("virStoragePoolRefresh");
1354   /* Suppresses a compiler warning. */
1355   (void) caml__frame;
1356 #else
1357   /* Check that the symbol virStoragePoolRefresh
1358    * is in runtime version of libvirt.
1359    */
1360   WEAK_SYMBOL_CHECK (virStoragePoolRefresh);
1361
1362   virStoragePoolPtr pool = Pool_val (poolv);
1363   virConnectPtr conn = Connect_polv (poolv);
1364   int r;
1365
1366   NONBLOCKING (r = virStoragePoolRefresh (pool, 0));
1367   CHECK_ERROR (r == -1, conn, "virStoragePoolRefresh");
1368
1369   CAMLreturn (Val_unit);
1370 #endif
1371 }
1372
1373 #ifdef HAVE_WEAK_SYMBOLS
1374 #ifdef HAVE_VIRSTORAGEPOOLGETAUTOSTART
1375 extern int virStoragePoolGetAutostart (virStoragePoolPtr pool, int *r) __attribute__((weak));
1376 #endif
1377 #endif
1378
1379 CAMLprim value
1380 ocaml_libvirt_storage_pool_get_autostart (value poolv)
1381 {
1382   CAMLparam1 (poolv);
1383 #ifndef HAVE_VIRSTORAGEPOOLGETAUTOSTART
1384   /* Symbol virStoragePoolGetAutostart not found at compile time. */
1385   not_supported ("virStoragePoolGetAutostart");
1386   /* Suppresses a compiler warning. */
1387   (void) caml__frame;
1388 #else
1389   /* Check that the symbol virStoragePoolGetAutostart
1390    * is in runtime version of libvirt.
1391    */
1392   WEAK_SYMBOL_CHECK (virStoragePoolGetAutostart);
1393
1394   virStoragePoolPtr pool = Pool_val (poolv);
1395   virConnectPtr conn = Connect_polv (poolv);
1396   int r, b;
1397
1398   NONBLOCKING (r = virStoragePoolGetAutostart (pool, &b));
1399   CHECK_ERROR (r == -1, conn, "virStoragePoolGetAutostart");
1400
1401   CAMLreturn (b ? Val_true : Val_false);
1402 #endif
1403 }
1404
1405 #ifdef HAVE_WEAK_SYMBOLS
1406 #ifdef HAVE_VIRSTORAGEPOOLSETAUTOSTART
1407 extern int virStoragePoolSetAutostart (virStoragePoolPtr pool, int b) __attribute__((weak));
1408 #endif
1409 #endif
1410
1411 CAMLprim value
1412 ocaml_libvirt_storage_pool_set_autostart (value poolv, value bv)
1413 {
1414   CAMLparam2 (poolv, bv);
1415 #ifndef HAVE_VIRSTORAGEPOOLSETAUTOSTART
1416   /* Symbol virStoragePoolSetAutostart not found at compile time. */
1417   not_supported ("virStoragePoolSetAutostart");
1418   /* Suppresses a compiler warning. */
1419   (void) caml__frame;
1420 #else
1421   /* Check that the symbol virStoragePoolSetAutostart
1422    * is in runtime version of libvirt.
1423    */
1424   WEAK_SYMBOL_CHECK (virStoragePoolSetAutostart);
1425
1426   virStoragePoolPtr pool = Pool_val (poolv);
1427   virConnectPtr conn = Connect_polv (poolv);
1428   int r, b;
1429
1430   b = bv == Val_true ? 1 : 0;
1431
1432   NONBLOCKING (r = virStoragePoolSetAutostart (pool, b));
1433   CHECK_ERROR (r == -1, conn, "virStoragePoolSetAutostart");
1434
1435   CAMLreturn (Val_unit);
1436 #endif
1437 }
1438
1439 CAMLprim value
1440 ocaml_libvirt_storage_vol_free (value volv)
1441 {
1442   CAMLparam1 (volv);
1443
1444   virStorageVolPtr vol = Volume_val (volv);
1445   virConnectPtr conn = Connect_volv (volv);
1446   int r;
1447
1448   NONBLOCKING (r = virStorageVolFree (vol));
1449   CHECK_ERROR (r == -1, conn, "virStorageVolFree");
1450
1451   /* So that we don't double-free in the finalizer: */
1452   Volume_val (volv) = NULL;
1453
1454   CAMLreturn (Val_unit);
1455 }
1456
1457 CAMLprim value
1458 ocaml_libvirt_storage_vol_destroy (value volv)
1459 {
1460   CAMLparam1 (volv);
1461
1462   virStorageVolPtr vol = Volume_val (volv);
1463   virConnectPtr conn = Connect_volv (volv);
1464   int r;
1465
1466   NONBLOCKING (r = virStorageVolDestroy (vol));
1467   CHECK_ERROR (r == -1, conn, "virStorageVolDestroy");
1468
1469   /* So that we don't double-free in the finalizer: */
1470   Volume_val (volv) = NULL;
1471
1472   CAMLreturn (Val_unit);
1473 }
1474
1475 #ifdef HAVE_WEAK_SYMBOLS
1476 #ifdef HAVE_VIRSTORAGEVOLLOOKUPBYKEY
1477 extern virStorageVolPtr virStorageVolLookupByKey (virConnectPtr conn, const char *str) __attribute__((weak));
1478 #endif
1479 #endif
1480
1481 CAMLprim value
1482 ocaml_libvirt_storage_vol_lookup_by_key (value connv, value strv)
1483 {
1484   CAMLparam2 (connv, strv);
1485 #ifndef HAVE_VIRSTORAGEVOLLOOKUPBYKEY
1486   /* Symbol virStorageVolLookupByKey not found at compile time. */
1487   not_supported ("virStorageVolLookupByKey");
1488   /* Suppresses a compiler warning. */
1489   (void) caml__frame;
1490 #else
1491   /* Check that the symbol virStorageVolLookupByKey
1492    * is in runtime version of libvirt.
1493    */
1494   WEAK_SYMBOL_CHECK (virStorageVolLookupByKey);
1495
1496   CAMLlocal1 (rv);
1497   virConnectPtr conn = Connect_val (connv);
1498   char *str = String_val (strv);
1499   virStorageVolPtr r;
1500
1501   NONBLOCKING (r = virStorageVolLookupByKey (conn, str));
1502   CHECK_ERROR (!r, conn, "virStorageVolLookupByKey");
1503
1504   rv = Val_volume (r, connv);
1505
1506   CAMLreturn (rv);
1507 #endif
1508 }
1509
1510 #ifdef HAVE_WEAK_SYMBOLS
1511 #ifdef HAVE_VIRSTORAGEVOLLOOKUPBYPATH
1512 extern virStorageVolPtr virStorageVolLookupByPath (virConnectPtr conn, const char *str) __attribute__((weak));
1513 #endif
1514 #endif
1515
1516 CAMLprim value
1517 ocaml_libvirt_storage_vol_lookup_by_path (value connv, value strv)
1518 {
1519   CAMLparam2 (connv, strv);
1520 #ifndef HAVE_VIRSTORAGEVOLLOOKUPBYPATH
1521   /* Symbol virStorageVolLookupByPath not found at compile time. */
1522   not_supported ("virStorageVolLookupByPath");
1523   /* Suppresses a compiler warning. */
1524   (void) caml__frame;
1525 #else
1526   /* Check that the symbol virStorageVolLookupByPath
1527    * is in runtime version of libvirt.
1528    */
1529   WEAK_SYMBOL_CHECK (virStorageVolLookupByPath);
1530
1531   CAMLlocal1 (rv);
1532   virConnectPtr conn = Connect_val (connv);
1533   char *str = String_val (strv);
1534   virStorageVolPtr r;
1535
1536   NONBLOCKING (r = virStorageVolLookupByPath (conn, str));
1537   CHECK_ERROR (!r, conn, "virStorageVolLookupByPath");
1538
1539   rv = Val_volume (r, connv);
1540
1541   CAMLreturn (rv);
1542 #endif
1543 }
1544
1545 #ifdef HAVE_WEAK_SYMBOLS
1546 #ifdef HAVE_VIRSTORAGEVOLGETXMLDESC
1547 extern char *virStorageVolGetXMLDesc (virStorageVolPtr vol,  int flags) __attribute__((weak));
1548 #endif
1549 #endif
1550
1551 CAMLprim value
1552 ocaml_libvirt_storage_vol_get_xml_desc (value volv)
1553 {
1554   CAMLparam1 (volv);
1555 #ifndef HAVE_VIRSTORAGEVOLGETXMLDESC
1556   /* Symbol virStorageVolGetXMLDesc not found at compile time. */
1557   not_supported ("virStorageVolGetXMLDesc");
1558   /* Suppresses a compiler warning. */
1559   (void) caml__frame;
1560 #else
1561   /* Check that the symbol virStorageVolGetXMLDesc
1562    * is in runtime version of libvirt.
1563    */
1564   WEAK_SYMBOL_CHECK (virStorageVolGetXMLDesc);
1565
1566   CAMLlocal1 (rv);
1567   virStorageVolPtr vol = Volume_val (volv);
1568   virConnectPtr conn = Connect_volv (volv);
1569   char *r;
1570
1571   NONBLOCKING (r = virStorageVolGetXMLDesc (vol, 0));
1572   CHECK_ERROR (!r, conn, "virStorageVolGetXMLDesc");
1573
1574   rv = caml_copy_string (r);
1575   free (r);
1576   CAMLreturn (rv);
1577 #endif
1578 }
1579
1580 #ifdef HAVE_WEAK_SYMBOLS
1581 #ifdef HAVE_VIRSTORAGEVOLGETPATH
1582 extern char *virStorageVolGetPath (virStorageVolPtr vol) __attribute__((weak));
1583 #endif
1584 #endif
1585
1586 CAMLprim value
1587 ocaml_libvirt_storage_vol_get_path (value volv)
1588 {
1589   CAMLparam1 (volv);
1590 #ifndef HAVE_VIRSTORAGEVOLGETPATH
1591   /* Symbol virStorageVolGetPath not found at compile time. */
1592   not_supported ("virStorageVolGetPath");
1593   /* Suppresses a compiler warning. */
1594   (void) caml__frame;
1595 #else
1596   /* Check that the symbol virStorageVolGetPath
1597    * is in runtime version of libvirt.
1598    */
1599   WEAK_SYMBOL_CHECK (virStorageVolGetPath);
1600
1601   CAMLlocal1 (rv);
1602   virStorageVolPtr vol = Volume_val (volv);
1603   virConnectPtr conn = Connect_volv (volv);
1604   char *r;
1605
1606   NONBLOCKING (r = virStorageVolGetPath (vol));
1607   CHECK_ERROR (!r, conn, "virStorageVolGetPath");
1608
1609   rv = caml_copy_string (r);
1610   free (r);
1611   CAMLreturn (rv);
1612 #endif
1613 }
1614
1615 #ifdef HAVE_WEAK_SYMBOLS
1616 #ifdef HAVE_VIRSTORAGEVOLGETKEY
1617 extern const char *virStorageVolGetKey (virStorageVolPtr vol) __attribute__((weak));
1618 #endif
1619 #endif
1620
1621 CAMLprim value
1622 ocaml_libvirt_storage_vol_get_key (value volv)
1623 {
1624   CAMLparam1 (volv);
1625 #ifndef HAVE_VIRSTORAGEVOLGETKEY
1626   /* Symbol virStorageVolGetKey not found at compile time. */
1627   not_supported ("virStorageVolGetKey");
1628   /* Suppresses a compiler warning. */
1629   (void) caml__frame;
1630 #else
1631   /* Check that the symbol virStorageVolGetKey
1632    * is in runtime version of libvirt.
1633    */
1634   WEAK_SYMBOL_CHECK (virStorageVolGetKey);
1635
1636   CAMLlocal1 (rv);
1637   virStorageVolPtr vol = Volume_val (volv);
1638   virConnectPtr conn = Connect_volv (volv);
1639   const char *r;
1640
1641   NONBLOCKING (r = virStorageVolGetKey (vol));
1642   CHECK_ERROR (!r, conn, "virStorageVolGetKey");
1643
1644   rv = caml_copy_string (r);
1645   CAMLreturn (rv);
1646 #endif
1647 }
1648
1649 #ifdef HAVE_WEAK_SYMBOLS
1650 #ifdef HAVE_VIRSTORAGEVOLGETNAME
1651 extern const char *virStorageVolGetName (virStorageVolPtr vol) __attribute__((weak));
1652 #endif
1653 #endif
1654
1655 CAMLprim value
1656 ocaml_libvirt_storage_vol_get_name (value volv)
1657 {
1658   CAMLparam1 (volv);
1659 #ifndef HAVE_VIRSTORAGEVOLGETNAME
1660   /* Symbol virStorageVolGetName not found at compile time. */
1661   not_supported ("virStorageVolGetName");
1662   /* Suppresses a compiler warning. */
1663   (void) caml__frame;
1664 #else
1665   /* Check that the symbol virStorageVolGetName
1666    * is in runtime version of libvirt.
1667    */
1668   WEAK_SYMBOL_CHECK (virStorageVolGetName);
1669
1670   CAMLlocal1 (rv);
1671   virStorageVolPtr vol = Volume_val (volv);
1672   virConnectPtr conn = Connect_volv (volv);
1673   const char *r;
1674
1675   NONBLOCKING (r = virStorageVolGetName (vol));
1676   CHECK_ERROR (!r, conn, "virStorageVolGetName");
1677
1678   rv = caml_copy_string (r);
1679   CAMLreturn (rv);
1680 #endif
1681 }
1682
1683 /* The following functions are unimplemented and always fail.
1684  * See generator.pl '@unimplemented'
1685  */
1686
1687 CAMLprim value
1688 ocaml_libvirt_domain_create_job ()
1689 {
1690   failwith ("ocaml_libvirt_domain_create_job is unimplemented");
1691 }
1692
1693 CAMLprim value
1694 ocaml_libvirt_domain_core_dump_job ()
1695 {
1696   failwith ("ocaml_libvirt_domain_core_dump_job is unimplemented");
1697 }
1698
1699 CAMLprim value
1700 ocaml_libvirt_domain_restore_job ()
1701 {
1702   failwith ("ocaml_libvirt_domain_restore_job is unimplemented");
1703 }
1704
1705 CAMLprim value
1706 ocaml_libvirt_domain_save_job ()
1707 {
1708   failwith ("ocaml_libvirt_domain_save_job is unimplemented");
1709 }
1710
1711 CAMLprim value
1712 ocaml_libvirt_connect_create_linux_job ()
1713 {
1714   failwith ("ocaml_libvirt_connect_create_linux_job is unimplemented");
1715 }
1716
1717 CAMLprim value
1718 ocaml_libvirt_network_create_job ()
1719 {
1720   failwith ("ocaml_libvirt_network_create_job is unimplemented");
1721 }
1722
1723 CAMLprim value
1724 ocaml_libvirt_network_create_xml_job ()
1725 {
1726   failwith ("ocaml_libvirt_network_create_xml_job is unimplemented");
1727 }
1728
1729 CAMLprim value
1730 ocaml_libvirt_storage_pool_get_info ()
1731 {
1732   failwith ("ocaml_libvirt_storage_pool_get_info is unimplemented");
1733 }
1734
1735 CAMLprim value
1736 ocaml_libvirt_storage_pool_define_xml ()
1737 {
1738   failwith ("ocaml_libvirt_storage_pool_define_xml is unimplemented");
1739 }
1740
1741 CAMLprim value
1742 ocaml_libvirt_storage_pool_create_xml ()
1743 {
1744   failwith ("ocaml_libvirt_storage_pool_create_xml is unimplemented");
1745 }
1746
1747 CAMLprim value
1748 ocaml_libvirt_storage_pool_lookup_by_uuid ()
1749 {
1750   failwith ("ocaml_libvirt_storage_pool_lookup_by_uuid is unimplemented");
1751 }
1752
1753 CAMLprim value
1754 ocaml_libvirt_storage_vol_lookup_by_name ()
1755 {
1756   failwith ("ocaml_libvirt_storage_vol_lookup_by_name is unimplemented");
1757 }
1758
1759 CAMLprim value
1760 ocaml_libvirt_storage_vol_create_xml ()
1761 {
1762   failwith ("ocaml_libvirt_storage_vol_create_xml is unimplemented");
1763 }
1764
1765 CAMLprim value
1766 ocaml_libvirt_storage_vol_get_info ()
1767 {
1768   failwith ("ocaml_libvirt_storage_vol_get_info is unimplemented");
1769 }
1770
1771 CAMLprim value
1772 ocaml_libvirt_pool_of_volume ()
1773 {
1774   failwith ("ocaml_libvirt_pool_of_volume is unimplemented");
1775 }
1776
1777 CAMLprim value
1778 ocaml_libvirt_job_cancel ()
1779 {
1780   failwith ("ocaml_libvirt_job_cancel is unimplemented");
1781 }
1782
1783 CAMLprim value
1784 ocaml_libvirt_job_get_network ()
1785 {
1786   failwith ("ocaml_libvirt_job_get_network is unimplemented");
1787 }
1788
1789 CAMLprim value
1790 ocaml_libvirt_job_get_domain ()
1791 {
1792   failwith ("ocaml_libvirt_job_get_domain is unimplemented");
1793 }
1794
1795 CAMLprim value
1796 ocaml_libvirt_job_get_info ()
1797 {
1798   failwith ("ocaml_libvirt_job_get_info is unimplemented");
1799 }
1800
1801 #include "libvirt_c_epilogue.c"
1802
1803 /* EOF */