summaryrefslogtreecommitdiffstats
path: root/generator/generator_python.ml
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2011-04-22 21:36:41 +0100
committerRichard W.M. Jones <rjones@redhat.com>2011-04-22 21:50:16 +0100
commit2cac52000a6a96a583af72e289a4296c596047d5 (patch)
tree840bb620f64d674ba01a9bcefbb3c2096d371aff /generator/generator_python.ml
parent16da7589e91b0030fb5564553447f80b97c0b18c (diff)
python: Implement new event API.
This implements set_event_callback and delete_event_callback so that Python programs can use the new event mechanism.
Diffstat (limited to 'generator/generator_python.ml')
-rw-r--r--generator/generator_python.ml42
1 files changed, 42 insertions, 0 deletions
diff --git a/generator/generator_python.ml b/generator/generator_python.ml
index f3a2a942..ffd63daa 100644
--- a/generator/generator_python.ml
+++ b/generator/generator_python.ml
@@ -28,6 +28,7 @@ open Generator_optgroups
open Generator_actions
open Generator_structs
open Generator_c
+open Generator_events
(* Generate Python C module. *)
let rec generate_python_c () =
@@ -455,6 +456,10 @@ free_strings (char **argv)
pr "static PyMethodDef methods[] = {\n";
pr " { (char *) \"create\", py_guestfs_create, METH_VARARGS, NULL },\n";
pr " { (char *) \"close\", py_guestfs_close, METH_VARARGS, NULL },\n";
+ pr " { (char *) \"set_event_callback\",\n";
+ pr " py_guestfs_set_event_callback, METH_VARARGS, NULL },\n";
+ pr " { (char *) \"delete_event_callback\",\n";
+ pr " py_guestfs_delete_event_callback, METH_VARARGS, NULL },\n";
List.iter (
fun (name, _, _, _, _, _, _) ->
pr " { (char *) \"%s\", py_guestfs_%s, METH_VARARGS, NULL },\n"
@@ -531,6 +536,15 @@ logvols = g.lvs ()
import libguestfsmod
+";
+
+ List.iter (
+ fun (name, bitmask) ->
+ pr "EVENT_%s = 0x%x\n" (String.uppercase name) bitmask
+ ) events;
+ pr "\n";
+
+ pr "\
class GuestFS:
\"\"\"Instances of this class are libguestfs API handles.\"\"\"
@@ -541,6 +555,34 @@ class GuestFS:
def __del__ (self):
libguestfsmod.close (self._o)
+ def set_event_callback (self, cb, event_bitmask):
+ u\"\"\"Register an event callback.
+
+ Register \"cb\" as a callback function for all of the
+ events in \"event_bitmask\". \"event_bitmask\" should be
+ one or more \"guestfs.EVENT_*\" flags logically or'd together.
+
+ This function returns an event handle which can be used
+ to delete the callback (see \"delete_event_callback\").
+
+ The callback function receives 4 parameters:
+
+ cb (event, event_handle, buf, array)
+
+ \"event\" is one of the \"EVENT_*\" flags. \"buf\" is a
+ message buffer (only for some types of events). \"array\"
+ is an array of integers (only for some types of events).
+
+ You should read the documentation for
+ \"guestfs_set_event_callback\" in guestfs(3) before using
+ this function.
+ \"\"\"
+ return libguestfsmod.set_event_callback (self._o, cb, event_bitmask)
+
+ def delete_event_callback (self, event_handle):
+ u\"\"\"Delete an event callback.\"\"\"
+ libguestfsmod.delete_event_callback (self._o, event_handle)
+
";
List.iter (