Mercurial > hg > xmms-sid
comparison src/xs_length.c @ 476:c67a7f2fd586
Moved the glue functions to xmms-sid.c
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 26 Jan 2007 12:52:05 +0000 |
parents | 3f02945a0c48 |
children | 81756f412b43 |
comparison
equal
deleted
inserted
replaced
475:34d48e513419 | 476:c67a7f2fd586 |
---|---|
20 with this program; if not, write to the Free Software Foundation, Inc., | 20 with this program; if not, write to the Free Software Foundation, Inc., |
21 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | 21 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
22 */ | 22 */ |
23 #include "xs_length.h" | 23 #include "xs_length.h" |
24 #include "xs_support.h" | 24 #include "xs_support.h" |
25 #include "xs_config.h" | |
26 #include <stdio.h> | 25 #include <stdio.h> |
27 #include <stdlib.h> | 26 #include <stdlib.h> |
28 #include <ctype.h> | 27 #include <ctype.h> |
29 #include <string.h> | 28 #include <string.h> |
30 | 29 |
564 else | 563 else |
565 pResult = NULL; | 564 pResult = NULL; |
566 | 565 |
567 return pResult; | 566 return pResult; |
568 } | 567 } |
569 | |
570 | |
571 /* | |
572 * These should be moved out of this module some day ... | |
573 */ | |
574 static t_xs_sldb *xs_sldb_db = NULL; | |
575 XS_MUTEX(xs_sldb_db); | |
576 | |
577 gint xs_songlen_init(void) | |
578 { | |
579 XS_MUTEX_LOCK(xs_cfg); | |
580 | |
581 if (!xs_cfg.songlenDBPath) { | |
582 XS_MUTEX_UNLOCK(xs_cfg); | |
583 return -1; | |
584 } | |
585 | |
586 XS_MUTEX_LOCK(xs_sldb_db); | |
587 | |
588 /* Check if already initialized */ | |
589 if (xs_sldb_db) | |
590 xs_sldb_free(xs_sldb_db); | |
591 | |
592 /* Allocate database */ | |
593 xs_sldb_db = (t_xs_sldb *) g_malloc0(sizeof(t_xs_sldb)); | |
594 if (!xs_sldb_db) { | |
595 XS_MUTEX_UNLOCK(xs_cfg); | |
596 XS_MUTEX_UNLOCK(xs_sldb_db); | |
597 return -2; | |
598 } | |
599 | |
600 /* Read the database */ | |
601 if (xs_sldb_read(xs_sldb_db, xs_cfg.songlenDBPath) != 0) { | |
602 xs_sldb_free(xs_sldb_db); | |
603 xs_sldb_db = NULL; | |
604 XS_MUTEX_UNLOCK(xs_cfg); | |
605 XS_MUTEX_UNLOCK(xs_sldb_db); | |
606 return -3; | |
607 } | |
608 | |
609 /* Create index */ | |
610 if (xs_sldb_index(xs_sldb_db) != 0) { | |
611 xs_sldb_free(xs_sldb_db); | |
612 xs_sldb_db = NULL; | |
613 XS_MUTEX_UNLOCK(xs_cfg); | |
614 XS_MUTEX_UNLOCK(xs_sldb_db); | |
615 return -4; | |
616 } | |
617 | |
618 XS_MUTEX_UNLOCK(xs_cfg); | |
619 XS_MUTEX_UNLOCK(xs_sldb_db); | |
620 return 0; | |
621 } | |
622 | |
623 | |
624 void xs_songlen_close(void) | |
625 { | |
626 XS_MUTEX_LOCK(xs_sldb_db); | |
627 xs_sldb_free(xs_sldb_db); | |
628 xs_sldb_db = NULL; | |
629 XS_MUTEX_UNLOCK(xs_sldb_db); | |
630 } | |
631 | |
632 | |
633 t_xs_sldb_node *xs_songlen_get(const gchar * pcFilename) | |
634 { | |
635 t_xs_sldb_node *pResult; | |
636 | |
637 XS_MUTEX_LOCK(xs_sldb_db); | |
638 | |
639 if (xs_cfg.songlenDBEnable && xs_sldb_db) | |
640 pResult = xs_sldb_get(xs_sldb_db, pcFilename); | |
641 else | |
642 pResult = NULL; | |
643 | |
644 XS_MUTEX_UNLOCK(xs_sldb_db); | |
645 | |
646 return pResult; | |
647 } |