#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;
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;