Mercurial > hg > xmms-sid
comparison src/xs_length.c @ 230:608f31f6c095
Raw cleanup.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 21 Dec 2004 09:25:03 +0000 |
parents | 92bad4c7b998 |
children | 291715a519e2 |
comparison
equal
deleted
inserted
replaced
229:7bb9e20e3092 | 230:608f31f6c095 |
---|---|
19 along with this program; if not, write to the Free Software | 19 along with this program; if not, write to the Free Software |
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 */ | 21 */ |
22 #include "xs_length.h" | 22 #include "xs_length.h" |
23 #include "xs_support.h" | 23 #include "xs_support.h" |
24 #include "xs_config.h" | |
24 #include <stdio.h> | 25 #include <stdio.h> |
25 #include <stdlib.h> | 26 #include <stdlib.h> |
26 #include <ctype.h> | 27 #include <ctype.h> |
27 #include <string.h> | 28 #include <string.h> |
28 | 29 |
551 else | 552 else |
552 pResult = NULL; | 553 pResult = NULL; |
553 | 554 |
554 return pResult; | 555 return pResult; |
555 } | 556 } |
557 | |
558 | |
559 /* | |
560 * These should be moved out of this module some day ... | |
561 */ | |
562 static t_xs_sldb *xs_sldb_db = NULL; | |
563 XS_MUTEX(xs_sldb_db); | |
564 | |
565 gint xs_songlen_init(void) | |
566 { | |
567 XS_MUTEX_LOCK(xs_cfg); | |
568 | |
569 if (!xs_cfg.songlenDBPath) | |
570 { | |
571 XS_MUTEX_UNLOCK(xs_cfg); | |
572 return -1; | |
573 } | |
574 | |
575 XS_MUTEX_LOCK(xs_sldb_db); | |
576 | |
577 /* Check if already initialized */ | |
578 if (xs_sldb_db) xs_sldb_free(xs_sldb_db); | |
579 | |
580 /* Allocate database */ | |
581 xs_sldb_db = (t_xs_sldb *) g_malloc0(sizeof(t_xs_sldb)); | |
582 if (!xs_sldb_db) | |
583 { | |
584 XS_MUTEX_UNLOCK(xs_cfg); | |
585 XS_MUTEX_UNLOCK(xs_sldb_db); | |
586 return -2; | |
587 } | |
588 | |
589 /* Read the database */ | |
590 if (xs_sldb_read(xs_sldb_db, xs_cfg.songlenDBPath) != 0) | |
591 { | |
592 xs_sldb_free(xs_sldb_db); | |
593 xs_sldb_db = NULL; | |
594 XS_MUTEX_UNLOCK(xs_cfg); | |
595 XS_MUTEX_UNLOCK(xs_sldb_db); | |
596 return -3; | |
597 } | |
598 | |
599 /* Create index */ | |
600 if (xs_sldb_index(xs_sldb_db) != 0) | |
601 { | |
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 -4; | |
607 } | |
608 | |
609 XS_MUTEX_UNLOCK(xs_cfg); | |
610 XS_MUTEX_UNLOCK(xs_sldb_db); | |
611 return 0; | |
612 } | |
613 | |
614 | |
615 void xs_songlen_close(void) | |
616 { | |
617 XS_MUTEX_LOCK(xs_sldb_db); | |
618 xs_sldb_free(xs_sldb_db); | |
619 xs_sldb_db = NULL; | |
620 XS_MUTEX_UNLOCK(xs_sldb_db); | |
621 } | |
622 | |
623 | |
624 t_xs_sldb_node * xs_songlen_get(gchar *pcFilename) | |
625 { | |
626 t_xs_sldb_node *pResult; | |
627 | |
628 XS_MUTEX_LOCK(xs_sldb_db); | |
629 | |
630 if (xs_cfg.songlenDBEnable && xs_sldb_db) | |
631 pResult = xs_sldb_get(xs_sldb_db, pcFilename); | |
632 else | |
633 pResult = NULL; | |
634 | |
635 XS_MUTEX_UNLOCK(xs_sldb_db); | |
636 | |
637 return pResult; | |
638 } | |
639 |