]> xenbits.xensource.com Git - xenclient/ioemu.git/commitdiff
xenstore register watch callback
authorJean Guyader <jean.guyader@eu.citrix.com>
Thu, 20 Nov 2008 15:52:39 +0000 (15:52 +0000)
committerJean Guyader <jean.guyader@eu.citrix.com>
Thu, 20 Nov 2008 15:52:39 +0000 (15:52 +0000)
qemu-xen.h
xenstore.c

index 7f2683c2992e23e46b5c8ab9e813dd102e0d1704..bb9eb1727f1bfd7cceaf5658ce3130c8fa69593b 100644 (file)
@@ -44,6 +44,8 @@ void handle_buffered_pio(void);
 #endif
 
 /* xenstore.c */
+typedef void (*xenstore_callback) (const char *token);
+void xenstore_watch_callback(const char *token, xenstore_callback fptr);
 void xenstore_parse_domain_config(int domid);
 int xenstore_fd(void);
 void xenstore_process_event(void *opaque);
index 5b04167155116aee8f0b67222ddb4e4bb5d7a923..485e9cde7ead424b735af62be02d9343a8595347 100644 (file)
@@ -38,6 +38,34 @@ static QEMUTimer *insert_timer = NULL;
 #define UWAIT_MAX (30*1000000) /* thirty seconds */
 #define UWAIT     (100000)     /* 1/10th second  */
 
+struct xenstore_watch_cb_t
+{
+    char                *token;
+    xenstore_callback   cb;
+};
+
+static struct xenstore_watch_cb_t *xenstore_watch_callbacks = NULL;
+
+void xenstore_watch_callback(const char *token, xenstore_callback fptr)
+{
+    int         i = 0;
+
+    if (!xenstore_watch_callbacks)
+    {
+        xenstore_watch_callbacks = malloc(sizeof (struct xenstore_watch_cb_t));
+        xenstore_watch_callbacks[0].token = NULL;
+    }
+
+    while (xenstore_watch_callbacks[i].token)
+        i++;
+
+    xenstore_watch_callbacks = realloc(xenstore_watch_callbacks,
+                                       (i + 2) * sizeof (struct xenstore_watch_cb_t));
+    xenstore_watch_callbacks[i].token = strdup(token);
+    xenstore_watch_callbacks[i].cb = fptr;
+    xenstore_watch_callbacks[i + 1].token = NULL;
+}
+
 static int pasprintf(char **buf, const char *fmt, ...)
 {
     va_list ap;
@@ -790,12 +818,16 @@ void xenstore_record_dm_state(char *state)
 void xenstore_process_event(void *opaque)
 {
     char **vec, *offset, *image = NULL;
-    unsigned int len, num, hd_index;
+    unsigned int len, num, hd_index, i;
 
     vec = xs_read_watch(xsh, &num);
     if (!vec)
         return;
 
+    for (i = 0; xenstore_watch_callbacks[i].token; i++)
+        if (!strcmp(vec[XS_WATCH_TOKEN], xenstore_watch_callbacks[i].token))
+            xenstore_watch_callbacks[i].cb(vec[XS_WATCH_TOKEN]);
+
     if (!strcmp(vec[XS_WATCH_TOKEN], "logdirty")) {
         xenstore_process_logdirty_event();
         goto out;