[Spice-devel] [PATCH 08/18] introduce new watch api

Gerd Hoffmann kraxel at redhat.com
Mon Mar 29 08:08:44 PDT 2010


This patch adds a new file handle watch interface to libspice, featuring
three callbacks:

  (1) watch_add() -- create a new file watch.
  (2) watch_update_mask() -- change event mask.  spice frequently
                             enables/disables write notification.
  (3) watch_remove() -- remove a file watch.

libspice users must implement these functions to allow libspice
monitoring file handles.

The old interface (set_file_handlers) doesn't explicitly express the
lifecycle of a watch.  Also it maps 1:1 to a qemu-internal function.
In case the way qemu implements file watches changes (someone sayed
QemuIONotifier?) this will break horribly.  Beside that it is very
bad style.

Follwing patches will switch over users one by one to the new interface
and finally zap the old one.
---
 server/vd_interface.h |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/server/vd_interface.h b/server/vd_interface.h
index a3a312b..3ae4ce9 100644
--- a/server/vd_interface.h
+++ b/server/vd_interface.h
@@ -68,6 +68,12 @@ typedef void (*vd_interface_change_notifier_t)(void *opaque, VDInterface *interf
                                                VDInterfaceChangeType change);
 typedef void (*timer_callback_t)(void *opaque);
 
+#define SPICE_WATCH_EVENT_READ  (1 << 0)
+#define SPICE_WATCH_EVENT_WRITE (1 << 1)
+
+typedef struct SpiceWatch SpiceWatch;
+typedef void (*SpiceWatchFunc)(int fd, int event, void *opaque);
+
 struct CoreInterface {
     VDInterface base;
 
@@ -80,6 +86,11 @@ struct CoreInterface {
                              void (*on_read)(void *),
                              void (*on_write)(void *),
                              void *opaque);
+
+    SpiceWatch *(*watch_add)(int fd, int event_mask, SpiceWatchFunc func, void *opaque);
+    void (*watch_update_mask)(SpiceWatch *watch, int event_mask);
+    void (*watch_remove)(SpiceWatch *watch);
+
 };
 
 #define VD_INTERFACE_QXL "qxl"
-- 
1.6.6.1



More information about the Spice-devel mailing list