diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2011-03-10 12:32:22 +0000 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2011-03-15 12:16:50 +0000 |
commit | 4e0cf4dbf8a8a96288f70114fdc3939da0aa7ad1 (patch) | |
tree | 2418e32479a965eb392d08f2e648c53714118a91 /capitests/test-private-data.c | |
parent | 6d6b7edd1102f8383643866bf358e494e0d518ef (diff) | |
download | libguestfs-4e0cf4dbf8a8a96288f70114fdc3939da0aa7ad1.tar.gz libguestfs-4e0cf4dbf8a8a96288f70114fdc3939da0aa7ad1.tar.xz libguestfs-4e0cf4dbf8a8a96288f70114fdc3939da0aa7ad1.zip |
New event API (RHBZ#664558).
This API allows more than one callback to be registered for each
event, makes it possible to call the API from other languages, and
allows [nearly all] log, debug and trace messages to be rerouted from
stderr.
An older version of this API was discussed on the mailing list here:
https://www.redhat.com/archives/libguestfs/2010-December/msg00081.html
https://www.redhat.com/archives/libguestfs/2011-January/msg00012.html
This also updates guestfish to use the new API for its progress bars.
Diffstat (limited to 'capitests/test-private-data.c')
-rw-r--r-- | capitests/test-private-data.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/capitests/test-private-data.c b/capitests/test-private-data.c index fad88b58..f2ff647b 100644 --- a/capitests/test-private-data.c +++ b/capitests/test-private-data.c @@ -30,6 +30,34 @@ #define PREFIX "test_" +static size_t close_callback_called = 0; + +/* This callback deletes all test keys in the handle. */ +static void +close_callback (guestfs_h *g, + void *opaque, + uint64_t event, + int event_handle, + int flags, + const char *buf, size_t buf_len, + const uint64_t *array, size_t array_len) +{ + const char *key; + void *data; + + close_callback_called++; + + again: + data = guestfs_first_private (g, &key); + while (data != NULL) { + if (strncmp (key, PREFIX, strlen (PREFIX)) == 0) { + guestfs_set_private (g, key, NULL); + goto again; + } + data = guestfs_next_private (g, &key); + } +} + int main (int argc, char *argv[]) { @@ -44,6 +72,10 @@ main (int argc, char *argv[]) exit (EXIT_FAILURE); } + if (guestfs_set_event_callback (g, close_callback, GUESTFS_EVENT_CLOSE, + 0, NULL) == -1) + exit (EXIT_FAILURE); + guestfs_set_private (g, PREFIX "a", (void *) 1); guestfs_set_private (g, PREFIX "b", (void *) 2); guestfs_set_private (g, PREFIX "c", (void *) 3); @@ -79,7 +111,10 @@ main (int argc, char *argv[]) } assert (count == 1); + /* Closing should implicitly call the close_callback function. */ guestfs_close (g); + assert (close_callback_called == 1); + exit (EXIT_SUCCESS); } |