Mercurial > hg > xmms-sid
diff src/xs_stil.c @ 230:608f31f6c095
Raw cleanup.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 21 Dec 2004 09:25:03 +0000 |
parents | 92bad4c7b998 |
children | e613873c3379 |
line wrap: on
line diff
--- a/src/xs_stil.c Sun Dec 19 16:57:01 2004 +0000 +++ b/src/xs_stil.c Tue Dec 21 09:25:03 2004 +0000 @@ -21,6 +21,7 @@ */ #include "xs_stil.h" #include "xs_support.h" +#include "xs_config.h" #include <stdio.h> #include <stdlib.h> #include <ctype.h> @@ -383,24 +384,100 @@ } -/* Get from STIL database +/* + * These should be moved out of this module some day ... */ -t_xs_stil_node * xs_stildb_get(t_xs_stildb *db, gchar *hvscPath, gchar *pcFilename) +static t_xs_stildb *xs_stildb_db = NULL; +XS_MUTEX(xs_stildb_db); + +gint xs_stil_init(void) { + XS_MUTEX_LOCK(xs_cfg); + + if (!xs_cfg.stilDBPath) + { + XS_MUTEX_UNLOCK(xs_cfg); + return -1; + } + + XS_MUTEX_LOCK(xs_stildb_db); + + /* Check if already initialized */ + if (xs_stildb_db) xs_stildb_free(xs_stildb_db); + + /* Allocate database */ + xs_stildb_db = (t_xs_stildb *) g_malloc0(sizeof(t_xs_stildb)); + if (!xs_stildb_db) + { + XS_MUTEX_UNLOCK(xs_cfg); + XS_MUTEX_UNLOCK(xs_stildb_db); + return -2; + } + + /* Read the database */ + if (xs_stildb_read(xs_stildb_db, xs_cfg.stilDBPath) != 0) + { + xs_stildb_free(xs_stildb_db); + xs_stildb_db = NULL; + XS_MUTEX_UNLOCK(xs_cfg); + XS_MUTEX_UNLOCK(xs_stildb_db); + return -3; + } + + /* Create index */ + if (xs_stildb_index(xs_stildb_db) != 0) + { + xs_stildb_free(xs_stildb_db); + xs_stildb_db = NULL; + XS_MUTEX_UNLOCK(xs_cfg); + XS_MUTEX_UNLOCK(xs_stildb_db); + return -4; + } + + XS_MUTEX_UNLOCK(xs_cfg); + XS_MUTEX_UNLOCK(xs_stildb_db); + return 0; +} + + +void xs_stil_close(void) +{ + XS_MUTEX_LOCK(xs_stildb_db); + xs_stildb_free(xs_stildb_db); + xs_stildb_db = NULL; + XS_MUTEX_UNLOCK(xs_stildb_db); +} + + +t_xs_stil_node * xs_stil_get(gchar *pcFilename) +{ + t_xs_stil_node *pResult; gchar *tmpFilename; - /* Remove postfixed directory separator from HVSC-path */ - tmpFilename = xs_strrchr(hvscPath, '/'); - if (tmpFilename && (tmpFilename[1] == 0)) - tmpFilename[0] = 0; + XS_MUTEX_LOCK(xs_stildb_db); + XS_MUTEX_LOCK(xs_cfg); + + if (xs_cfg.hvscPath) + { + /* Remove postfixed directory separator from HVSC-path */ + tmpFilename = xs_strrchr(xs_cfg.hvscPath, '/'); + if (tmpFilename && (tmpFilename[1] == 0)) + tmpFilename[0] = 0; - /* Remove HVSC location-prefix from filename */ - tmpFilename = strstr(pcFilename, hvscPath); - if (tmpFilename) - tmpFilename += strlen(hvscPath); - else - tmpFilename = pcFilename; + /* Remove HVSC location-prefix from filename */ + tmpFilename = strstr(pcFilename, xs_cfg.hvscPath); + if (tmpFilename) + tmpFilename += strlen(xs_cfg.hvscPath); + else + tmpFilename = pcFilename; + } else + tmpFilename = pcFilename; + + pResult = xs_stildb_get_node(xs_stildb_db, tmpFilename); - return xs_stildb_get_node(db, pcFilename); + XS_MUTEX_UNLOCK(xs_stildb_db); + XS_MUTEX_UNLOCK(xs_cfg); + + return pResult; }