[cache/scan] Let notifications from db.c about library updates go through

filescanner/listener instead of directly to the cache
This commit is contained in:
ejurgensen
2017-01-08 00:21:47 +01:00
parent 79639c73ed
commit 60daf03f66
5 changed files with 107 additions and 87 deletions

View File

@@ -61,6 +61,7 @@
#include "player.h"
#include "cache.h"
#include "artwork.h"
#include "listener.h"
#include "commands.h"
#include "library.h"
@@ -107,13 +108,19 @@ struct stacked_dir {
static int inofd;
static struct event *inoev;
static struct event *updateev;
static struct deferred_pl *playlists;
static struct stacked_dir *dirstack;
// After being told by db that the library was updated through update_trigger(),
// wait 60 seconds before notifying listeners of LISTENER_DATABASE. This is to
// avoid bombarding the listeners while there are many db updates, and to make
// sure they only get a single update (useful for the cache).
static struct timeval library_update_wait = { 60, 0 };
/* From library.c */
extern struct event_base *evbase_lib;
#ifndef __linux__
struct deferred_file
{
@@ -841,6 +848,8 @@ bulk_scan(int flags)
{
DPRINTF(E_LOG, L_SCAN, "Bulk library scan completed in %.f sec\n", difftime(end, start));
}
listener_notify(LISTENER_DATABASE); // TODO Move to library.c
}
static int
@@ -1469,6 +1478,21 @@ filescanner_initscan()
return 0;
}
static void
update_trigger_cb(int fd, short what, void *arg)
{
listener_notify(LISTENER_DATABASE);
}
static enum command_state
update_trigger(void *arg, int *retval)
{
evtimer_add(updateev, &library_update_wait);
*retval = 0;
return COMMAND_END;
}
static int
filescanner_rescan()
{
@@ -1494,6 +1518,16 @@ filescanner_fullrescan()
return 0;
}
// TODO Move to abstraction
void
library_update_trigger(void)
{
if (scanning)
return;
commands_exec_async(cmdbase, update_trigger, NULL);
}
/* Thread: main */
static int
filescanner_init(void)
@@ -1501,8 +1535,20 @@ filescanner_init(void)
int ret;
ret = inofd_event_set();
if (ret < 0)
{
return -1;
}
return ret;
updateev = evtimer_new(evbase_lib, update_trigger_cb, NULL);
if (!updateev)
{
DPRINTF(E_FATAL, L_SCAN, "Could not create library update event\n");
close(inofd);
return -1;
}
return 0;
}
/* Thread: main */

View File

@@ -31,4 +31,7 @@ void
scan_itunes_itml(char *file);
#endif
void
library_update_trigger(void); // TODO Move to library abstraction
#endif /* !__FILESCANNER_H__ */