Anna Schumaker
d6e5e6c773
Databases can change either as part of an upgrade or through adding and removing entries. We can save a bit of memory by removing unallocated entries during startup. Implements #47: Automatic database defragment Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
69 lines
1.9 KiB
C
69 lines
1.9 KiB
C
/*
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
*
|
|
* The Library tag is used to store a single directory added
|
|
* to Ocarina by the user.
|
|
*
|
|
* When writing a Library tag to disk, write out the library_enabled
|
|
* and library_path fields for each tag.
|
|
*
|
|
* ... true /home/Zelda/Music
|
|
* ... false /home/Link/Music
|
|
*/
|
|
#ifndef OCARINA_CORE_TAGS_LIBRARY_H
|
|
#define OCARINA_CORE_TAGS_LIBRARY_H
|
|
|
|
#include <core/database.h>
|
|
|
|
struct library {
|
|
gchar *li_path; /* This library's root path. */
|
|
void *li_playlist; /* This library's associated playlist. */
|
|
struct db_entry li_dbe;
|
|
};
|
|
|
|
#define LIBRARY(dbe) ((struct library *)DBE_DATA(dbe))
|
|
|
|
|
|
/* Called to initialize the library database. */
|
|
void library_db_init();
|
|
|
|
/* Called to clean up the library database. */
|
|
void library_db_deinit();
|
|
|
|
/* Called to defragment the library database. */
|
|
bool library_db_defrag();
|
|
|
|
/* Called to access the library database. */
|
|
const struct database *library_db_get();
|
|
|
|
/*
|
|
* Called to find a library tag by library path. The difference is that
|
|
* library_find() will allocate a new library struct if the requested one
|
|
* doesn't exist yet, but library_lookup() will return NULL in this situation.
|
|
*/
|
|
struct library *library_find(const gchar *);
|
|
struct library *library_lookup(const gchar *);
|
|
|
|
/* Called to get a library tag with a specific index. */
|
|
struct library *library_get(const unsigned int);
|
|
|
|
/* Called to remove a specific library tag. */
|
|
void library_remove(struct library *);
|
|
|
|
/* Called to find the database index of the library tag. */
|
|
static inline unsigned int library_index(struct library *library)
|
|
{
|
|
return library->li_dbe.dbe_index;
|
|
}
|
|
|
|
/*
|
|
* Called to find the full path of files under the library directory.
|
|
* This function allocates a new string that MUST be freed with g_free().
|
|
*/
|
|
gchar *library_file(struct library *, const gchar *);
|
|
|
|
#ifdef CONFIG_TESTING
|
|
const struct db_ops *test_library_ops();
|
|
#endif /* CONFIG_TESTING */
|
|
#endif /* OCARINA_CORE_TAGS_LIBRARY_H */
|