diff options
Diffstat (limited to '')
-rw-r--r-- | src/InotifyUpdate.cxx (renamed from src/inotify_update.c) | 56 |
1 files changed, 30 insertions, 26 deletions
diff --git a/src/inotify_update.c b/src/InotifyUpdate.cxx index 3f4a8c0c4..7ed0e84ba 100644 --- a/src/inotify_update.c +++ b/src/InotifyUpdate.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2011 The Music Player Daemon Project + * Copyright (C) 2003-2013 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -18,17 +18,20 @@ */ #include "config.h" /* must be first for large file support */ -#include "inotify_update.h" -#include "inotify_source.h" -#include "inotify_queue.h" -#include "database.h" -#include "mapper.h" +#include "InotifyUpdate.hxx" +#include "InotifySource.hxx" +#include "InotifyQueue.hxx" +#include "Mapper.hxx" +#include "Main.hxx" + +extern "C" { #include "path.h" +} +#include <glib.h> #include <assert.h> #include <sys/inotify.h> #include <sys/stat.h> -#include <stdbool.h> #include <string.h> #include <dirent.h> #include <errno.h> @@ -54,7 +57,8 @@ struct watch_directory { GList *children; }; -static struct mpd_inotify_source *inotify_source; +static InotifySource *inotify_source; +static InotifyQueue *inotify_queue; static unsigned inotify_max_depth; static struct watch_directory inotify_root; @@ -90,7 +94,8 @@ tree_remove_watch_directory(struct watch_directory *directory) static struct watch_directory * tree_find_watch_directory(int wd) { - return g_tree_lookup(inotify_directories, GINT_TO_POINTER(wd)); + return (struct watch_directory *) + g_tree_lookup(inotify_directories, GINT_TO_POINTER(wd)); } static void @@ -109,12 +114,12 @@ remove_watch_directory(struct watch_directory *directory) tree_remove_watch_directory(directory); while (directory->children != NULL) - remove_watch_directory(directory->children->data); + remove_watch_directory((struct watch_directory *)directory->children->data); directory->parent->children = g_list_remove(directory->parent->children, directory); - mpd_inotify_source_rm(inotify_source, directory->descriptor); + inotify_source->Remove(directory->descriptor); g_free(directory->name); g_slice_free(struct watch_directory, directory); } @@ -192,8 +197,7 @@ recursive_watch_subdirectories(struct watch_directory *directory, continue; } - ret = mpd_inotify_source_add(inotify_source, child_path_fs, - IN_MASK, &error); + ret = inotify_source->Add(child_path_fs, IN_MASK, &error); if (ret < 0) { g_warning("Failed to register %s: %s", child_path_fs, error->message); @@ -292,10 +296,10 @@ mpd_inotify_callback(int wd, unsigned mask, ? fs_charset_to_utf8(uri_fs) : g_strdup(""); - if (uri_utf8 != NULL) - /* this function will take care of freeing - uri_utf8 */ - mpd_inotify_enqueue(uri_utf8); + if (uri_utf8 != NULL) { + inotify_queue->Enqueue(uri_utf8); + g_free(uri_utf8); + } } g_free(uri_fs); @@ -314,8 +318,9 @@ mpd_inotify_init(unsigned max_depth) return; } - inotify_source = mpd_inotify_source_new(mpd_inotify_callback, NULL, - &error); + inotify_source = InotifySource::Create(*main_loop, + mpd_inotify_callback, nullptr, + &error); if (inotify_source == NULL) { g_warning("%s", error->message); g_error_free(error); @@ -325,12 +330,11 @@ mpd_inotify_init(unsigned max_depth) inotify_max_depth = max_depth; inotify_root.name = g_strdup(path); - inotify_root.descriptor = mpd_inotify_source_add(inotify_source, path, - IN_MASK, &error); + inotify_root.descriptor = inotify_source->Add(path, IN_MASK, &error); if (inotify_root.descriptor < 0) { g_warning("%s", error->message); g_error_free(error); - mpd_inotify_source_free(inotify_source); + delete inotify_source; inotify_source = NULL; return; } @@ -340,7 +344,7 @@ mpd_inotify_init(unsigned max_depth) recursive_watch_subdirectories(&inotify_root, path, 0); - mpd_inotify_queue_init(); + inotify_queue = new InotifyQueue(*main_loop); g_debug("watching music directory"); } @@ -349,7 +353,7 @@ static gboolean free_watch_directory(G_GNUC_UNUSED gpointer key, gpointer value, G_GNUC_UNUSED gpointer data) { - struct watch_directory *directory = value; + struct watch_directory *directory = (struct watch_directory *)value; g_free(directory->name); g_list_free(directory->children); @@ -366,8 +370,8 @@ mpd_inotify_finish(void) if (inotify_source == NULL) return; - mpd_inotify_queue_finish(); - mpd_inotify_source_free(inotify_source); + delete inotify_queue; + delete inotify_source; g_tree_foreach(inotify_directories, free_watch_directory, NULL); g_tree_destroy(inotify_directories); |