add rescan/full rescan methods to xml-rpc for ticket #121

This commit is contained in:
Ron Pedde 2006-06-15 07:10:05 +00:00
parent c6bcd7d1f3
commit 1dc1257f2c
7 changed files with 48 additions and 2 deletions

View File

@ -52,6 +52,7 @@ typedef struct tag_config {
int stop; /**< Time to exit? */
int reload; /**< Time to reload and/or rescan the database? */
int foreground; /**< Whether or not we are running in foreground */
int full_reload; /**< Whether the reload should be a full one */
#if 0
char *configfile; /**< path to config file */

View File

@ -64,6 +64,7 @@ typedef struct tag_db_functions {
int(*dbs_enum_fetch_row)(char **, PACKED_MP3FILE *, DBQUERYINFO *);
int(*dbs_enum_reset)(char **, DBQUERYINFO *);
int(*dbs_enum_end)(char **);
int(*dbs_force_rescan)(char **);
int(*dbs_start_scan)(void);
int(*dbs_end_song_scan)(void);
int(*dbs_end_scan)(void);
@ -96,6 +97,7 @@ DB_FUNCTIONS db_functions[] = {
db_sql_enum_fetch_row,
db_sql_enum_reset,
db_sql_enum_end,
db_sql_force_rescan,
db_sql_start_scan,
db_sql_end_song_scan,
db_sql_end_scan,
@ -126,6 +128,7 @@ DB_FUNCTIONS db_functions[] = {
db_sql_enum_fetch_row,
db_sql_enum_reset,
db_sql_enum_end,
db_sql_force_rescan,
db_sql_start_scan,
db_sql_end_song_scan,
db_sql_end_scan,
@ -795,6 +798,15 @@ M3UFILE *db_fetch_playlist(char **pe, char *path, int index) {
return retval;
}
int db_force_rescan(char **pe) {
int retval;
db_writelock();
retval = db_current->dbs_force_rescan(pe);
db_unlock();
return retval;
}
int db_start_scan(void) {
int retval;

View File

@ -202,7 +202,7 @@ extern int db_get_song_count(char **pe, int *count);
extern int db_get_playlist_count(char **pe, int *count);
extern void db_dispose_item(MP3FILE *pmp3);
extern void db_dispose_playlist(M3UFILE *pm3u);
extern int db_force_rescan(char **pe);
#define DB_E_SUCCESS 0x00
#define DB_E_SQL_ERROR 0x01 /**< some kind of sql error - typically bad syntax */

View File

@ -350,12 +350,20 @@ int db_sql_deinit(void) {
return db_sql_close_fn();
}
/**
* force a rescan
*/
int db_sql_force_rescan(char **pe) {
return db_sql_exec_fn(pe,E_LOG,"update songs set force_update=1");
}
/**
* start a background scan
*
* @returns DB_E_SUCCESS on success, error code otherwise
*/
int db_sql_start_scan(void) {
int db_sql_start_scan() {
DPRINTF(E_DBG,L_DB,"Starting db scan\n");
db_sql_event_fn(DB_SQL_EVENT_SONGSCANSTART);

View File

@ -42,6 +42,7 @@ extern int db_sql_enum_fetch(char **pe, DBQUERYINFO *pinfo, int *size, unsigned
extern int db_sql_enum_fetch_row(char **pe, PACKED_MP3FILE *row, DBQUERYINFO *pinfo);
extern int db_sql_enum_reset(char **pe, DBQUERYINFO *pinfo);
extern int db_sql_enum_end(char **pe);
extern int db_sql_force_rescan(char **pe);
extern int db_sql_start_scan(void);
extern int db_sql_end_song_scan(void);
extern int db_sql_end_scan(void);

View File

@ -512,6 +512,11 @@ int main(int argc, char *argv[]) {
DPRINTF(E_LOG,L_MAIN|L_DB|L_SCAN,"Rescanning database\n");
if(conf_get_array("general","mp3_dir",&mp3_dir_array)) {
if(config.full_reload) {
config.full_reload=0;
db_force_rescan(NULL);
}
if(scan_init(mp3_dir_array)) {
DPRINTF(E_LOG,L_MAIN|L_DB|L_SCAN,"Error rescanning... bad path?\n");
}

View File

@ -51,6 +51,7 @@ struct tag_xmlstruct {
void xml_get_stats(WS_CONNINFO *pwsc);
void xml_set_config(WS_CONNINFO *pwsc);
void xml_browse_path(WS_CONNINFO *pwsc);
void xml_rescan(WS_CONNINFO *pwsc);
void xml_return_error(WS_CONNINFO *pwsc, int err, char *errstr);
char *xml_entity_encode(char *original);
@ -180,6 +181,19 @@ void xml_update_config(WS_CONNINFO *pwsc) {
xml_return_error(pwsc,200,"Success");
}
/**
* rescan the database
*/
void xml_rescan(WS_CONNINFO *pwsc) {
if(ws_getvar(pwsc,"full")) {
config.full_reload=1;
}
config.reload=1;
xml_return_error(pwsc,200,"Success");
}
/**
* post settings back to the config file
*
@ -357,6 +371,11 @@ void xml_handle(WS_CONNINFO *pwsc) {
return;
}
if(strcasecmp(method,"rescan") == 0) {
xml_rescan(pwsc);
return;
}
xml_return_error(pwsc,500,"Invalid method");
return;
}