aboutsummaryrefslogtreecommitdiff
path: root/src/InotifySource.hxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-01-14 09:52:35 +0100
committerMax Kellermann <max@duempel.org>2013-01-14 10:08:26 +0100
commit8e3982dd422671d26a653f393639cd12cd01ff18 (patch)
tree3a2bca08d49b5f85d840c6351f19d353626afa0d /src/InotifySource.hxx
parente83f805b8fa34db8ac0b885d3fb78c0e6437c908 (diff)
InotifySource: convert to a class
Diffstat (limited to 'src/InotifySource.hxx')
-rw-r--r--src/InotifySource.hxx76
1 files changed, 48 insertions, 28 deletions
diff --git a/src/InotifySource.hxx b/src/InotifySource.hxx
index cde2bc26..6299d1e2 100644
--- a/src/InotifySource.hxx
+++ b/src/InotifySource.hxx
@@ -22,40 +22,60 @@
#include "gerror.h"
+#include <glib.h>
+
typedef void (*mpd_inotify_callback_t)(int wd, unsigned mask,
const char *name, void *ctx);
-struct mpd_inotify_source;
+class InotifySource {
+ mpd_inotify_callback_t callback;
+ void *callback_ctx;
-/**
- * Creates a new inotify source and registers it in the GLib main
- * loop.
- *
- * @param a callback invoked for events received from the kernel
- */
-struct mpd_inotify_source *
-mpd_inotify_source_new(mpd_inotify_callback_t callback, void *callback_ctx,
- GError **error_r);
+ int fd;
-void
-mpd_inotify_source_free(struct mpd_inotify_source *source);
+ GIOChannel *channel;
-/**
- * Adds a path to the notify list.
- *
- * @return a watch descriptor or -1 on error
- */
-int
-mpd_inotify_source_add(struct mpd_inotify_source *source,
- const char *path_fs, unsigned mask,
- GError **error_r);
+ /**
+ * The channel's source id in the GLib main loop.
+ */
+ guint id;
-/**
- * Removes a path from the notify list.
- *
- * @param wd the watch descriptor returned by mpd_inotify_source_add()
- */
-void
-mpd_inotify_source_rm(struct mpd_inotify_source *source, unsigned wd);
+ struct fifo_buffer *buffer;
+
+ InotifySource(mpd_inotify_callback_t callback, void *ctx, int fd);
+
+public:
+ /**
+ * Creates a new inotify source and registers it in the GLib main
+ * loop.
+ *
+ * @param a callback invoked for events received from the kernel
+ */
+ static InotifySource *Create(mpd_inotify_callback_t callback,
+ void *ctx,
+ GError **error_r);
+
+ ~InotifySource();
+
+
+ /**
+ * Adds a path to the notify list.
+ *
+ * @return a watch descriptor or -1 on error
+ */
+ int Add(const char *path_fs, unsigned mask, GError **error_r);
+
+ /**
+ * Removes a path from the notify list.
+ *
+ * @param wd the watch descriptor returned by mpd_inotify_source_add()
+ */
+ void Remove(unsigned wd);
+
+private:
+ void InEvent();
+ static gboolean InEvent(GIOChannel *source, GIOCondition condition,
+ gpointer data);
+};
#endif