summaryrefslogtreecommitdiffstats
path: root/common/notify-inotify.c
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2007-01-13 21:39:57 +0000
committerMarcel Holtmann <marcel@holtmann.org>2007-01-13 21:39:57 +0000
commit84fa9983df320c0bd5c400735474b5c0e98e5efd (patch)
treed513c67ee2b10c91fab4c448350082cae92f30fa /common/notify-inotify.c
parent603a99217dc455370b09967e7628412c13b6663b (diff)
Add callback for notifications
Diffstat (limited to 'common/notify-inotify.c')
-rw-r--r--common/notify-inotify.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/common/notify-inotify.c b/common/notify-inotify.c
index 2b14b744..53ab7d55 100644
--- a/common/notify-inotify.c
+++ b/common/notify-inotify.c
@@ -41,6 +41,8 @@ static int wd = -1;
static char *name = NULL;
+static notify_func callback = NULL;
+
static gboolean io_event(GIOChannel *chan, GIOCondition cond, gpointer data)
{
unsigned char buf[129];
@@ -56,17 +58,17 @@ static gboolean io_event(GIOChannel *chan, GIOCondition cond, gpointer data)
if (len < sizeof(struct inotify_event))
return TRUE;
- if (evt->wd != wd)
+ if (evt->wd != wd || !callback)
return TRUE;
if (evt->mask & (IN_CREATE | IN_MOVED_TO))
- debug("File %s/%s created", name, evt->name);
+ callback(NOTIFY_CREATE, evt->name, NULL);
if (evt->mask & (IN_DELETE | IN_MOVED_FROM))
- debug("File %s/%s deleted", name, evt->name);
+ callback(NOTIFY_DELETE, evt->name, NULL);
if (evt->mask & IN_MODIFY)
- debug("File %s/%s modified", name, evt->name);
+ callback(NOTIFY_MODIFY, evt->name, NULL);
return TRUE;
}
@@ -115,7 +117,7 @@ void notify_close(void)
}
}
-void notify_add(const char *pathname)
+void notify_add(const char *pathname, notify_func func, void *user_data)
{
if (fd == -1 || wd != -1)
return;
@@ -131,6 +133,8 @@ void notify_add(const char *pathname)
IN_ONLYDIR | IN_CREATE | IN_DELETE | IN_MODIFY | IN_MOVE);
if (wd < 0)
error("Creation of watch for %s failed", pathname);
+
+ callback = func;
}
void notify_remove(const char *pathname)
@@ -140,4 +144,6 @@ void notify_remove(const char *pathname)
inotify_rm_watch(fd, wd);
wd = -1;
+
+ callback = NULL;
}