aboutsummaryrefslogtreecommitdiff
path: root/src/InotifyQueue.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-01-14 10:10:21 +0100
committerMax Kellermann <max@duempel.org>2013-01-14 10:13:28 +0100
commitc8b408beae9bf2118c7792dff5d37f3109646c39 (patch)
treeb408eccf2bb9a9c0f70b6432283270d49d19b9df /src/InotifyQueue.cxx
parent8e3982dd422671d26a653f393639cd12cd01ff18 (diff)
InotifyQueue: convert to a class
Diffstat (limited to 'src/InotifyQueue.cxx')
-rw-r--r--src/InotifyQueue.cxx57
1 files changed, 25 insertions, 32 deletions
diff --git a/src/InotifyQueue.cxx b/src/InotifyQueue.cxx
index b94abeaa..2b7899ec 100644
--- a/src/InotifyQueue.cxx
+++ b/src/InotifyQueue.cxx
@@ -23,9 +23,6 @@
#include "Main.hxx"
#include "event/Loop.hxx"
-#include <list>
-#include <string>
-
#include <glib.h>
#include <string.h>
@@ -42,28 +39,19 @@ enum {
INOTIFY_UPDATE_DELAY_S = 5,
};
-static std::list<std::string> inotify_queue;
-static guint queue_source_id;
-
-void
-mpd_inotify_queue_init(void)
+InotifyQueue::~InotifyQueue()
{
+ if (source_id != 0)
+ g_source_remove(source_id);
}
-void
-mpd_inotify_queue_finish(void)
-{
- if (queue_source_id != 0)
- g_source_remove(queue_source_id);
-}
-
-static gboolean
-mpd_inotify_run_update(G_GNUC_UNUSED gpointer data)
+inline bool
+InotifyQueue::Run()
{
unsigned id;
- while (!inotify_queue.empty()) {
- const char *uri_utf8 = inotify_queue.front().c_str();
+ while (!queue.empty()) {
+ const char *uri_utf8 = queue.front().c_str();
id = update_enqueue(uri_utf8, false);
if (id == 0)
@@ -72,14 +60,21 @@ mpd_inotify_run_update(G_GNUC_UNUSED gpointer data)
g_debug("updating '%s' job=%u", uri_utf8, id);
- inotify_queue.pop_front();
+ queue.pop_front();
}
/* done, remove the timer event by returning false */
- queue_source_id = 0;
+ source_id = 0;
return false;
}
+gboolean
+InotifyQueue::Run(gpointer data)
+{
+ InotifyQueue &queue = *(InotifyQueue *)data;
+ return queue.Run();
+}
+
static bool
path_in(const char *path, const char *possible_parent)
{
@@ -91,16 +86,14 @@ path_in(const char *path, const char *possible_parent)
}
void
-mpd_inotify_enqueue(const char *uri_utf8)
+InotifyQueue::Enqueue(const char *uri_utf8)
{
- if (queue_source_id != 0)
- g_source_remove(queue_source_id);
- queue_source_id = main_loop->AddTimeoutSeconds(INOTIFY_UPDATE_DELAY_S,
- mpd_inotify_run_update,
- nullptr);
-
- for (auto i = inotify_queue.begin(), end = inotify_queue.end();
- i != end;) {
+ if (source_id != 0)
+ g_source_remove(source_id);
+ source_id = main_loop->AddTimeoutSeconds(INOTIFY_UPDATE_DELAY_S,
+ Run, nullptr);
+
+ for (auto i = queue.begin(), end = queue.end(); i != end;) {
const char *current_uri = i->c_str();
if (path_in(uri_utf8, current_uri))
@@ -111,10 +104,10 @@ mpd_inotify_enqueue(const char *uri_utf8)
/* existing path is a sub-path of the new
path; we can dequeue the existing path and
update the new path instead */
- i = inotify_queue.erase(i);
+ i = queue.erase(i);
else
++i;
}
- inotify_queue.emplace_back(uri_utf8);
+ queue.emplace_back(uri_utf8);
}