core/tempq: Convert file to C

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-12-14 13:55:50 -05:00
parent 187c56f328
commit 882ee6e1e7
12 changed files with 59 additions and 67 deletions

View File

@ -5,9 +5,9 @@
extern "C" {
#include <core/collection.h>
#include <core/history.h>
}
#include <core/deck.h>
#include <core/tempq.h>
#include <core/string.h>
}
static bool _pause_enabled = false;

View File

@ -3,13 +3,13 @@
*/
#include <core/audio.h>
#include <core/core.h>
#include <core/deck.h>
extern "C" {
#include <core/collection.h>
#include <core/filter.h>
#include <core/history.h>
#include <core/playlist.h>
#include <core/tags/tags.h>
#include <core/tempq.h>
}

View File

@ -1,12 +1,10 @@
/**
/*
* Copyright 2013 (c) Anna Schumaker.
*/
extern "C" {
#include <core/collection.h>
#include <core/history.h>
}
#include <core/deck.h>
#include <core/file.h>
#include <core/history.h>
#include <core/tempq.h>
#include <glib.h>
static GSList *tempq_list;
@ -14,7 +12,7 @@ static struct file tempq_file;
static struct queue *__tempq_alloc(struct queue_ops *ops, unsigned int flags)
{
struct queue *queue = new struct queue;
struct queue *queue = g_malloc(sizeof(struct queue));
tempq_list = g_slist_append(tempq_list, queue);
queue_init(queue, flags | Q_ENABLED | Q_SAVE_FLAGS | Q_SAVE_SORT, ops);
@ -25,7 +23,7 @@ static void __tempq_free(struct queue *queue)
{
tempq_list = g_slist_remove(tempq_list, queue);
queue_deinit(queue);
delete queue;
g_free(queue);
}
static struct queue *__tempq_read_queue()

View File

@ -4,7 +4,6 @@
extern "C" {
#include <core/history.h>
}
#include <core/deck.h>
#include <gui/tabs.h>
#include <gui/queue/label.h>

View File

@ -1,8 +1,10 @@
/*
* Copyright 2014 (c) Anna Schumaker.
*/
#include <core/deck.h>
extern "C" {
#include <core/string.h>
#include <core/tempq.h>
}
#include <gui/tabs.h>
#include <gui/queue/label.h>

View File

@ -1,11 +1,11 @@
/*
* Copyright 2014 (c) Anna Schumaker.
*/
#include <core/deck.h>
extern "C" {
#include <core/collection.h>
#include <core/playlist.h>
#include <core/string.h>
#include <core/tempq.h>
}
#include <gui/tabs.h>

View File

@ -2,8 +2,10 @@
* Copyright 2014 (c) Anna Schumaker.
*/
#include <core/audio.h>
#include <core/deck.h>
extern "C" {
#include <core/tempq.h>
#include <core/version.h>
}
#include <gui/ocarina.h>
#include <gui/tabs.h>

View File

@ -1,26 +1,19 @@
/**
/*
* Copyright 2013 (c) Anna Schumaker.
*
* The temporary queue manager controls access to any temporary
* queues created by the user. When saving to disk:
*
* length(tempq_list)
* flags num_tracks track_0 track_1 ... track_N
* flags num_tracks track_0 track_1 ... track_N
*/
#ifndef OCARINA_CORE_DECK_H
#define OCARINA_CORE_DECK_H
extern "C" {
#include <core/queue.h>
}
/**
* The deck is used to hold temporary queues created by the user. This
* code is also in charge of maintaining a "recently played" queue of
* songs that have just played.
*
* When saving to disk:
* ... << deck.size() << endl;
* ... << deck[0] << endl;
* ...
* ... << deck[N] <<< endl;
*/
/* Called to initialize the temporary queue manager. */
void tempq_init(struct queue_ops *);

View File

@ -2,7 +2,6 @@ audio
collection
database
date
deck
driver
file
filter
@ -14,4 +13,5 @@ queue
random
set
string
tempq
version

View File

@ -41,7 +41,7 @@ res += [ CoreTest("queue") ]
res += [ CoreTest("playlist") ]
res += [ CoreTest("collection") ]
res += [ CoreTest("history") ]
res += [ CoreTest("deck") ]
res += [ CoreTest("tempq") ]
res += [ CoreTest("audio") ]
Return("res")

View File

@ -8,8 +8,8 @@ extern "C" {
#include <core/history.h>
#include <core/playlist.h>
#include <core/tags/tags.h>
#include <core/tempq.h>
}
#include <core/deck.h>
#include "test.h"
struct track *TRACK_NULL = NULL;

View File

@ -1,16 +1,14 @@
/*
* Copyright 2013 (c) Anna Schumaker.
*/
#include <core/deck.h>
extern "C" {
#include <core/collection.h>
#include <core/filter.h>
#include <core/history.h>
#include <core/idle.h>
#include <core/playlist.h>
#include <core/tags/tags.h>
}
#include "test.h"
#include <core/tempq.h>
#include <tests/test.h>
static void test_init()
@ -21,11 +19,11 @@ static void test_init()
collection_init(NULL);
history_init(NULL);
test_equal(tempq_next(), NULL);
test_equal((void *)tempq_next(), NULL);
tempq_init(NULL);
test_equal(tempq_next(), NULL);
test_equal((void *)tempq_next(), NULL);
tempq_move(NULL, 1);
test_equal(tempq_get(0), NULL);
test_equal((void *)tempq_get(0), NULL);
test_equal(tempq_count(), 0);
}
@ -34,21 +32,21 @@ static void test_alloc()
struct queue *q0, *q1;
q0 = tempq_alloc(NULL, 0);
test_not_equal(q0, NULL);
test_equal(queue_has_flag(q0, Q_ENABLED), true);
test_equal(queue_has_flag(q0, Q_RANDOM), false);
test_equal(queue_has_flag(q0, Q_SAVE_SORT), true);
test_equal(queue_has_flag(q0, Q_SAVE_FLAGS), true);
test_equal(tempq_get(0), q0);
test_not_equal((void *)q0, NULL);
test_equal(queue_has_flag(q0, Q_ENABLED), (bool)true);
test_equal(queue_has_flag(q0, Q_RANDOM), (bool)false);
test_equal(queue_has_flag(q0, Q_SAVE_SORT), (bool)true);
test_equal(queue_has_flag(q0, Q_SAVE_FLAGS), (bool)true);
test_equal((void *)tempq_get(0), (void *)q0);
test_equal(tempq_count(), 1);
q1 = tempq_alloc(NULL, Q_RANDOM);
test_not_equal(q1, NULL);
test_equal(queue_has_flag(q1, Q_ENABLED), true);
test_equal(queue_has_flag(q1, Q_RANDOM), true);
test_equal(queue_has_flag(q1, Q_SAVE_SORT), true);
test_equal(queue_has_flag(q1, Q_SAVE_FLAGS), true);
test_equal(tempq_get(1), q1);
test_not_equal((void *)q1, NULL);
test_equal(queue_has_flag(q1, Q_ENABLED), (bool)true);
test_equal(queue_has_flag(q1, Q_RANDOM), (bool)true);
test_equal(queue_has_flag(q1, Q_SAVE_SORT), (bool)true);
test_equal(queue_has_flag(q1, Q_SAVE_FLAGS), (bool)true);
test_equal((void *)tempq_get(1), (void *)q1);
test_equal(tempq_count(), 2);
tempq_deinit();
@ -57,8 +55,8 @@ static void test_alloc()
q0 = tempq_get(0);
q1 = tempq_get(1);
test_equal(queue_has_flag(q0, Q_RANDOM), false);
test_equal(queue_has_flag(q1, Q_RANDOM), true);
test_equal(queue_has_flag(q0, Q_RANDOM), (bool)false);
test_equal(queue_has_flag(q1, Q_RANDOM), (bool)true);
}
static void test_move()
@ -67,14 +65,14 @@ static void test_move()
struct queue *q1 = tempq_get(1);
tempq_move(q1, 0);
test_equal(tempq_get(0), q1);
test_equal(tempq_get(1), q0);
test_equal(tempq_get(2), NULL);
test_equal((void *)tempq_get(0), (void *)q1);
test_equal((void *)tempq_get(1), (void *)q0);
test_equal((void *)tempq_get(2), NULL);
tempq_move(q0, 1);
test_equal(tempq_get(0), q1);
test_equal(tempq_get(1), q0);
test_equal(tempq_get(2), NULL);
test_equal((void *)tempq_get(0), (void *)q1);
test_equal((void *)tempq_get(1), (void *)q0);
test_equal((void *)tempq_get(2), NULL);
tempq_deinit();
test_equal(tempq_count(), 0);
@ -82,8 +80,8 @@ static void test_move()
q0 = tempq_get(1);
q1 = tempq_get(0);
test_equal(queue_has_flag(q0, Q_RANDOM), false);
test_equal(queue_has_flag(q1, Q_RANDOM), true);
test_equal(queue_has_flag(q0, Q_RANDOM), (bool)false);
test_equal(queue_has_flag(q1, Q_RANDOM), (bool)true);
}
static void test_free()
@ -92,11 +90,11 @@ static void test_free()
struct queue *q1 = tempq_get(0);
tempq_free(q0);
test_equal(tempq_get(0), q1);
test_equal((void *)tempq_get(0), (void *)q1);
test_equal(tempq_count(), 1);
tempq_free(q1);
test_equal(tempq_get(0), NULL);
test_equal((void *)tempq_get(0), NULL);
test_equal(tempq_count(), 0);
tempq_deinit();
@ -122,17 +120,17 @@ static void test_next()
for (i = 0; i < track_db->db_size; i++) {
test_loop_equal(queue_size(q0), track_db->db_size - i, i);
test_loop_equal(tempq_next(), track_get(i), i);
test_loop_equal((void *)tempq_next(), (void *)track_get(i), i);
} test_loop_passed();
test_equal(tempq_get(0), q1);
test_equal((void *)tempq_get(0), (void *)q1);
test_equal(tempq_count(), 1);
test_equal(queue_size(q1), track_db->db_size);
for (i = 0; i < track_db->db_size; i++) {
test_loop_equal(queue_size(q1), track_db->db_size - i, i);
test_loop_equal(tempq_next(), track_get(i), i);
test_loop_equal((void *)tempq_next(), (void *)track_get(i), i);
} test_loop_passed();
test_equal(tempq_get(0), NULL);
test_equal((void *)tempq_get(0), NULL);
test_equal(tempq_count(), 0);
tempq_deinit();