core/playlists/artist: Add pl_artist_{init, deinit}() functions
The pl_artist_init() function is used to allocate a playlist for each artist already in the database, and pl_artist_deinit() is then used to free up this memory during cleanup. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
11430f89cf
commit
12ae7cfee6
|
@ -2,11 +2,13 @@
|
|||
* Copyright 2013 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/playlist.h>
|
||||
#include <core/playlists/artist.h>
|
||||
#include <core/playlists/library.h>
|
||||
#include <core/playlists/system.h>
|
||||
|
||||
struct playlist_type *playlist_types[] = {
|
||||
[PL_SYSTEM] = &pl_system,
|
||||
[PL_ARTIST] = &pl_artist,
|
||||
[PL_LIBRARY] = &pl_library,
|
||||
};
|
||||
|
||||
|
@ -14,12 +16,14 @@ struct playlist_type *playlist_types[] = {
|
|||
void playlist_init(struct queue_ops *ops)
|
||||
{
|
||||
pl_system_init(ops);
|
||||
pl_artist_init(ops);
|
||||
pl_library_init(ops);
|
||||
}
|
||||
|
||||
void playlist_deinit()
|
||||
{
|
||||
pl_system_deinit();
|
||||
pl_artist_deinit();
|
||||
pl_library_deinit();
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright 2016 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/idle.h>
|
||||
#include <core/playlists/artist.h>
|
||||
|
||||
static struct queue_ops *artist_ops = NULL;
|
||||
|
||||
|
||||
static struct playlist *__artist_pl_alloc(gchar *name)
|
||||
{
|
||||
struct playlist *playlist = g_malloc(sizeof(struct playlist));
|
||||
|
||||
playlist->pl_name = name;
|
||||
playlist->pl_type = PL_ARTIST;
|
||||
queue_init(&playlist->pl_queue, Q_ENABLED | Q_REPEAT, artist_ops, playlist);
|
||||
|
||||
return playlist;
|
||||
}
|
||||
|
||||
static void __artist_pl_free(struct playlist *playlist)
|
||||
{
|
||||
if (playlist) {
|
||||
queue_deinit(&playlist->pl_queue);
|
||||
g_free(playlist);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct playlist_type pl_artist;
|
||||
|
||||
|
||||
static bool __artist_pl_init(void *data)
|
||||
{
|
||||
struct db_entry *dbe, *next;
|
||||
struct playlist *playlist;
|
||||
|
||||
db_for_each(dbe, next, artist_db_get()) {
|
||||
playlist = __artist_pl_alloc(ARTIST(dbe)->ar_name);
|
||||
ARTIST(dbe)->ar_playlist = playlist;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void pl_artist_init(struct queue_ops *ops)
|
||||
{
|
||||
artist_ops = ops;
|
||||
idle_schedule(IDLE_SYNC, __artist_pl_init, NULL);
|
||||
}
|
||||
|
||||
void pl_artist_deinit()
|
||||
{
|
||||
struct db_entry *dbe, *next;
|
||||
struct playlist *playlist;
|
||||
|
||||
db_for_each(dbe, next, artist_db_get()) {
|
||||
playlist = ARTIST(dbe)->ar_playlist;
|
||||
ARTIST(dbe)->ar_playlist = NULL;
|
||||
|
||||
__artist_pl_free(playlist);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
* Copyright 2016 (c) Anna Schumaker.
|
||||
*/
|
||||
#ifndef OCARINA_CORE_PLAYLISTS_ARTIST_H
|
||||
#define OCARINA_CORE_PLAYLISTS_ARTIST_H
|
||||
#include <core/playlists/type.h>
|
||||
|
||||
/* Artist playlist type. */
|
||||
extern struct playlist_type pl_artist;
|
||||
|
||||
|
||||
/* Called to initialize artist playlists. */
|
||||
void pl_artist_init(struct queue_ops *ops);
|
||||
|
||||
/* Called to deinitialize library playlists. */
|
||||
void pl_artist_deinit();
|
||||
|
||||
#endif /* OCARINA_CORE_PLAYLISTS_ARTIST_H */
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
enum playlist_type_t {
|
||||
PL_SYSTEM,
|
||||
PL_ARTIST,
|
||||
PL_LIBRARY,
|
||||
PL_MAX_TYPE,
|
||||
};
|
||||
|
|
|
@ -12,6 +12,7 @@ tags/library
|
|||
tags/track
|
||||
queue
|
||||
playlists/system
|
||||
playlists/artist
|
||||
playlists/library
|
||||
playlist
|
||||
collection
|
||||
|
|
|
@ -11,6 +11,7 @@ def PlaylistTest(name):
|
|||
return run
|
||||
|
||||
res += [ PlaylistTest("system") ]
|
||||
res += [ PlaylistTest("artist") ]
|
||||
res += [ PlaylistTest("library") ]
|
||||
|
||||
Return("res")
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright 2016 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/filter.h>
|
||||
#include <core/idle.h>
|
||||
#include <core/playlists/artist.h>
|
||||
#include <core/tags/artist.h>
|
||||
#include <core/tags/tags.h>
|
||||
#include <tests/test.h>
|
||||
|
||||
|
||||
void test_artist()
|
||||
{
|
||||
struct artist *artist;
|
||||
|
||||
idle_init_sync();
|
||||
filter_init();
|
||||
tags_init();
|
||||
while (idle_run_task()) {};
|
||||
|
||||
artist = artist_find("Koji Kondo");
|
||||
test_equal(artist->ar_playlist, NULL);
|
||||
|
||||
pl_artist_init(NULL);
|
||||
while (idle_run_task()) {};
|
||||
test_not_equal(artist->ar_playlist, NULL);
|
||||
|
||||
pl_artist_deinit();
|
||||
test_equal(artist->ar_playlist, NULL);
|
||||
|
||||
tags_deinit();
|
||||
filter_deinit();
|
||||
idle_deinit();
|
||||
}
|
||||
|
||||
DECLARE_UNIT_TESTS(
|
||||
UNIT_TEST("Artist Playlists", test_artist),
|
||||
);
|
Loading…
Reference in New Issue