Enable dynamic library updating

Modifications to db.c to enable the DAAP server to determine when
the media library has changed, and notify clients via an update.
Updates should show up to clients within 10 seconds.

Tested on iTunes 9.2.1
This commit is contained in:
Craig Markwardt 2011-08-24 00:47:27 -04:00
parent 7a021b2332
commit 732ec9239a
3 changed files with 21 additions and 6 deletions

View File

@ -268,6 +268,15 @@ static const char *sort_clause[] =
static char *db_path;
static __thread sqlite3 *hdl;
/*
* Starting database revision. A number of 2 ensures that remote clients
* always get a fresh update. (they start with 1)
*/
static int db_rev = 2;
/* Update the database revision number. Don't worry about multiple threads,
we don't care about an accurate count of the number of revisions, just
that revisions have occurred or not. */
#define db_rev_increment() { db_rev ++; }
/* Forward */
static int
@ -279,6 +288,14 @@ db_smartpl_count_items(const char *smartpl_query);
struct playlist_info *
db_pl_fetch_byid(int id);
/*
* db_revision_number - return current database revision number to external modules
*/
int
db_revision_number()
{
return db_rev;
}
char *
db_escape_string(const char *str)
@ -2007,6 +2024,7 @@ db_file_add(struct media_file_info *mfi)
}
sqlite3_free(query);
db_rev_increment();
return 0;
@ -2081,6 +2099,7 @@ db_file_update(struct media_file_info *mfi)
}
sqlite3_free(query);
db_rev_increment();
return 0;

View File

@ -470,6 +470,8 @@ db_watch_enum_end(struct watch_enum *we);
int
db_watch_enum_fetchwd(struct watch_enum *we, uint32_t *wd);
int
db_revision_number(void);
int
db_perthread_init(void);

View File

@ -65,12 +65,6 @@ extern struct event_base *evbase_httpd;
/* How often we poll for database changes */
#define DAAP_UPDATE_MONITOR_TIMEOUT 10
/* XXX Workaround before adding revision support in db.c;
Client will not get dynamic updates. The state of the
database at the time of connection is all the client
gets. */
#define db_revision_number() (2)
struct uri_map {
regex_t preg;
char *regexp;