daemon: debug segv correct use of dereferencing NULL.
[libguestfs.git] / ocaml / examples / guestfs-ocaml.pod
1 =encoding utf8
2
3 =head1 NAME
4
5 guestfs-ocaml - How to use libguestfs from OCaml
6
7 =head1 SYNOPSIS
8
9 Module style:
10
11  let g = Guestfs.create () in
12  Guestfs.add_drive_opts g ~format:"raw" ~readonly:true "disk.img";
13  Guestfs.launch g;
14
15 Object-oriented style:
16
17  let g = new Guestfs.guestfs () in
18  g#add_drive_opts ~format:"raw" ~readonly:true "disk.img";
19  g#launch ();
20
21  ocamlfind opt prog.ml -package guestfs -linkpkg -o prog
22 or:
23  ocamlopt -I +guestfs mlguestfs.cmxa prog.ml -o prog
24
25 =head1 DESCRIPTION
26
27 This manual page documents how to call libguestfs from the OCaml
28 programming language.  This page just documents the differences from
29 the C API and gives some examples.  If you are not familiar with using
30 libguestfs, you also need to read L<guestfs(3)>.
31
32 =head2 PROGRAMMING STYLES
33
34 There are two different programming styles supported by the OCaml
35 bindings.  You can use a module style, with each C function mapped to
36 an OCaml function:
37
38  int guestfs_set_verbose (guestfs_h *g, int flag);
39
40 becomes:
41
42  val Guestfs.set_verbose : Guestfs.t -> bool -> unit
43
44 Alternately you can use an object-oriented style, calling methods
45 on the class C<Guestfs.guestfs>:
46
47  method set_verbose : bool -> unit
48
49 The object-oriented style is usually briefer, and the minor performance
50 penalty isn't noticable in the general overhead of performing
51 libguestfs functions.
52
53 =head2 CLOSING THE HANDLE
54
55 The handle is closed when it is reaped by the garbage collector.
56 Because libguestfs handles include a lot of state, it is also
57 possible to close (and hence free) them explicitly by calling
58 C<Guestfs.close> or the C<#close> method.
59
60 =head2 EXCEPTIONS
61
62 Errors from libguestfs functions are mapped into the C<Guestfs.Error>
63 exception.  This has a single parameter which is the error message (a
64 string).
65
66 Calling any function/method on a closed handle raises
67 C<Guestfs.Handle_closed>.  The single parameter is the name of the
68 function that you called.
69
70 =head1 EXAMPLE 1: CREATE A DISK IMAGE
71
72 @EXAMPLE1@
73
74 =head1 EXAMPLE 2: INSPECT A VIRTUAL MACHINE DISK IMAGE
75
76 @EXAMPLE2@
77
78 =head1 SEE ALSO
79
80 L<guestfs(3)>,
81 L<guestfs-examples(3)>,
82 L<guestfs-erlang(3)>,
83 L<guestfs-java(3)>,
84 L<guestfs-perl(3)>,
85 L<guestfs-python(3)>,
86 L<guestfs-recipes(1)>,
87 L<guestfs-ruby(3)>,
88 L<http://libguestfs.org/>,
89 L<http://caml.inria.fr/>.
90
91 =head1 AUTHORS
92
93 Richard W.M. Jones (C<rjones at redhat dot com>)
94
95 =head1 COPYRIGHT
96
97 Copyright (C) 2010 Red Hat Inc. L<http://libguestfs.org/>
98
99 The examples in this manual page may be freely copied, modified and
100 distributed without any restrictions.
101
102 This library is free software; you can redistribute it and/or
103 modify it under the terms of the GNU Lesser General Public
104 License as published by the Free Software Foundation; either
105 version 2 of the License, or (at your option) any later version.
106
107 This library is distributed in the hope that it will be useful,
108 but WITHOUT ANY WARRANTY; without even the implied warranty of
109 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
110 Lesser General Public License for more details.
111
112 You should have received a copy of the GNU Lesser General Public
113 License along with this library; if not, write to the Free Software
114 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA