core/playlist: Add a playlist_generic_deinit() function
We'll need this to clean up playlists once queue_deinit() goes away. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
2fb27178ee
commit
fda29aaf13
|
@ -31,7 +31,7 @@ static struct playlist *__artist_pl_alloc(struct artist *artist)
|
|||
static void __artist_pl_free(struct playlist *playlist)
|
||||
{
|
||||
if (playlist) {
|
||||
queue_deinit(&playlist->pl_queue);
|
||||
playlist_generic_deinit(playlist);
|
||||
g_free(playlist);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,6 +47,12 @@ void playlist_generic_init(struct playlist *playlist, struct queue_ops *ops)
|
|||
playlist->pl_private = NULL;
|
||||
}
|
||||
|
||||
void playlist_generic_deinit(struct playlist *playlist)
|
||||
{
|
||||
if (playlist)
|
||||
queue_deinit(&playlist->pl_queue);
|
||||
}
|
||||
|
||||
void playlist_generic_save(struct playlist *playlist, struct file *file,
|
||||
unsigned int flags)
|
||||
{
|
||||
|
|
|
@ -36,7 +36,7 @@ static struct playlist *__lib_pl_alloc(struct library *library)
|
|||
static void __lib_pl_free(struct playlist *playlist)
|
||||
{
|
||||
if (playlist) {
|
||||
queue_deinit(&playlist->pl_queue);
|
||||
playlist_generic_deinit(playlist);
|
||||
g_free(playlist);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -417,7 +417,7 @@ void pl_system_init(struct queue_ops *ops)
|
|||
void pl_system_deinit()
|
||||
{
|
||||
for (unsigned int i = 0; i < SYS_PL_NUM_PLAYLISTS; i++)
|
||||
queue_deinit(&pl_system_get(i)->pl_queue);
|
||||
playlist_generic_deinit(pl_system_get(i));
|
||||
}
|
||||
|
||||
void pl_system_new_track(struct track *track)
|
||||
|
|
|
@ -28,7 +28,7 @@ static struct db_entry *user_db_alloc(const gchar *name, unsigned int index)
|
|||
|
||||
static void user_db_free(struct db_entry *dbe)
|
||||
{
|
||||
queue_deinit(&USER_PLAYLIST(dbe)->pl_playlist.pl_queue);
|
||||
playlist_generic_deinit(&USER_PLAYLIST(dbe)->pl_playlist);
|
||||
g_free(USER_PLAYLIST(dbe)->pl_playlist.pl_name);
|
||||
g_free(USER_PLAYLIST(dbe));
|
||||
}
|
||||
|
|
|
@ -37,4 +37,7 @@ void queue_deinit(struct queue *queue)
|
|||
__queue_deinit(queue);
|
||||
g_slist_free(queue->q_sort);
|
||||
queue->q_sort = NULL;
|
||||
queue->q_length = 0;
|
||||
queue->q_cur.it_pos = UINT_MAX;
|
||||
queue->q_cur.it_iter = NULL;
|
||||
}
|
||||
|
|
|
@ -38,6 +38,9 @@ void playlist_generic_set_callbacks(struct playlist_callbacks *);
|
|||
/* Generic playlist init function. */
|
||||
void playlist_generic_init(struct playlist *, struct queue_ops *);
|
||||
|
||||
/* Generic playlist deinit function. */
|
||||
void playlist_generic_deinit(struct playlist *);
|
||||
|
||||
/* Generic playlist save function. */
|
||||
void playlist_generic_save(struct playlist *, struct file *, unsigned int);
|
||||
|
||||
|
|
|
@ -42,6 +42,8 @@ static void test_null()
|
|||
g_assert_null(playlist_new(PL_MAX_TYPE, NULL));
|
||||
g_assert_false(playlist_delete(NULL));
|
||||
|
||||
playlist_generic_deinit(NULL);
|
||||
|
||||
g_assert_null(playlist_lookup(PL_MAX_TYPE, "NULL"));
|
||||
g_assert_null(playlist_lookup(PL_MAX_TYPE, NULL));
|
||||
g_assert_null(playlist_get(PL_MAX_TYPE, 0));
|
||||
|
@ -151,6 +153,14 @@ static void test_playlist()
|
|||
g_assert_cmpuint(p.pl_queue.q_length, ==, 0);
|
||||
g_assert_cmpuint(p.pl_queue.q_cur.it_pos, ==, UINT_MAX);
|
||||
g_assert_null(p.pl_queue.q_cur.it_iter);
|
||||
|
||||
/* Deinitialize the playlist. */
|
||||
playlist_generic_deinit(&p);
|
||||
g_assert_cmpuint(playlist_size(&p), ==, 0);
|
||||
g_assert_cmpuint(p.pl_queue.q_length, ==, 0);
|
||||
g_assert_cmpuint(p.pl_queue.q_cur.it_pos, ==, UINT_MAX);
|
||||
g_assert_null(p.pl_queue.q_cur.it_iter);
|
||||
g_assert_null(p.pl_queue.q_sort);
|
||||
}
|
||||
|
||||
static void test_sorting()
|
||||
|
@ -227,6 +237,14 @@ static void test_sorting()
|
|||
}
|
||||
for (i = 0; i < 13; i++)
|
||||
g_assert_cmpuint(queue_at(&p.pl_queue, i)->tr_track, ==, 13 - i);
|
||||
|
||||
/* Deinitialize the playlist. */
|
||||
playlist_generic_deinit(&p);
|
||||
g_assert_cmpuint(playlist_size(&p), ==, 0);
|
||||
g_assert_cmpuint(p.pl_queue.q_length, ==, 0);
|
||||
g_assert_cmpuint(p.pl_queue.q_cur.it_pos, ==, UINT_MAX);
|
||||
g_assert_null(p.pl_queue.q_cur.it_iter);
|
||||
g_assert_null(p.pl_queue.q_sort);
|
||||
}
|
||||
|
||||
static void test_next()
|
||||
|
@ -265,6 +283,14 @@ static void test_next()
|
|||
g_assert_cmpuint(playlist_next()->tr_track, ==, 6);
|
||||
g_assert_cmpuint(playlist_next()->tr_track, ==, 1);
|
||||
g_assert_cmpuint(playlist_size(&p), ==, 13);
|
||||
|
||||
/* Deinitialize the playlist. */
|
||||
playlist_generic_deinit(&p);
|
||||
g_assert_cmpuint(playlist_size(&p), ==, 0);
|
||||
g_assert_cmpuint(p.pl_queue.q_length, ==, 0);
|
||||
g_assert_cmpuint(p.pl_queue.q_cur.it_pos, ==, UINT_MAX);
|
||||
g_assert_null(p.pl_queue.q_cur.it_iter);
|
||||
g_assert_null(p.pl_queue.q_sort);
|
||||
}
|
||||
|
||||
static void test_save_load()
|
||||
|
@ -309,6 +335,13 @@ static void test_save_load()
|
|||
g_assert(queue_iter_val(&s.pl_queue.q_cur) == queue_at(&q.pl_queue, 4));
|
||||
g_assert_cmpuint(g_slist_length(s.pl_queue.q_sort), ==, 0);
|
||||
g_assert_cmpuint(playlist_size(&s), ==, 13);
|
||||
|
||||
/* Deinitialize the playlist. */
|
||||
playlist_generic_deinit(&p);
|
||||
g_assert_cmpuint(playlist_size(&p), ==, 0);
|
||||
g_assert_cmpuint(p.pl_queue.q_length, ==, 0);
|
||||
g_assert_cmpuint(p.pl_queue.q_cur.it_pos, ==, UINT_MAX);
|
||||
g_assert_null(p.pl_queue.q_cur.it_iter);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
|
|
Loading…
Reference in New Issue