driver: Track current driver with a pointer

This will let me implement drivers outside of this file allowing for
easier customization.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2014-12-19 14:19:18 -05:00
parent c103f27381
commit c12dbae73a
7 changed files with 64 additions and 36 deletions

View File

@ -4,9 +4,18 @@
*/
#include <core/driver.h>
static Driver *cur_driver = NULL;
Driver :: Driver() {}
Driver :: ~Driver() {}
Driver :: Driver()
{
cur_driver = this;
}
Driver :: ~Driver()
{
cur_driver = NULL;
}
#ifdef CONFIG_TEST
@ -151,14 +160,7 @@ void GSTDriver :: on_message(GstMessage *message)
#endif /* CONFIG_TEST */
#ifdef CONFIG_TEST
static TestDriver cur_driver;
#else /* CONFIG_TEST */
static GSTDriver cur_driver;
#endif /* CONFIG_TEST */
Driver *driver :: get_driver()
{
return &cur_driver;
return cur_driver;
}

17
gui/gst.cpp Normal file
View File

@ -0,0 +1,17 @@
/*
* Copyright 2014 (c) Anna Schumaker.
*/
#include <core/driver.h>
static GSTDriver *gst_driver;
void init_gst()
{
gst_driver = new GSTDriver();
}
void quit_gst()
{
delete gst_driver;
}

View File

@ -8,7 +8,7 @@
Gtk::Window *ocarina_init(int *argc, char ***argv)
{
init_gst();
lib :: init(argc, argv, "ocarina6.glade");
Gtk::Window *window = setup_gui();
@ -24,6 +24,7 @@ int main(int argc, char **argv)
Gtk::Window *window = ocarina_init(&argc, &argv);
ocarina->run(*window);
cleanup_tabs();
quit_gst();
return 0;
}
#endif /* CONFIG_TEST */

View File

@ -22,7 +22,7 @@ protected:
public:
Driver(); /**< Default Driver constructor. */
~Driver(); /**< Driver destructor. */
virtual ~Driver(); /**< Driver destructor. */
/**
* Initialize an audio driver.

View File

@ -24,6 +24,11 @@ void on_pq_created(Queue *, unsigned int);
void post_init_queue_tabs();
/* gst.cpp */
void init_gst();
void quit_gst();
/* window.cpp */
Gtk::Window *window_init();

View File

@ -162,6 +162,7 @@ void test_autopause()
int main(int argc, char **argv)
{
TestDriver driver;
run_test("Test Audio Pre-Init", test_pre_init);
run_test("Test Audio Init", test_init, argc, argv);
run_test("Test Audio Playback Controls", test_playback_controls);

View File

@ -4,7 +4,6 @@
#include <core/driver.h>
#include <tests/test.h>
static TestDriver *DRIVER_NULL = NULL;
static unsigned int eos_count = 0;
static unsigned int error_count = 0;
@ -20,42 +19,45 @@ void on_error()
void test_driver()
{
TestDriver *driver = (TestDriver *)driver :: get_driver();
test_equal(driver :: get_driver(), (Driver *)NULL);
TestDriver driver;
const std::string file = "/home/Zelda/Music/Wind Waker/1 - Outset Isle.ogg";
test_not_equal(driver, DRIVER_NULL);
test_not_equal(driver :: get_driver(), (Driver *)NULL);
test_equal((Driver *)&driver, driver :: get_driver());
driver->init(0, NULL, on_eos, on_error);
driver.init(0, NULL, on_eos, on_error);
driver->load(file);
test_equal(driver->cur_file, file);
driver.load(file);
test_equal(driver.cur_file, file);
test_equal(driver->play(), true);
test_equal(driver->playing, true);
test_equal(driver->is_playing(), true);
test_equal(driver.play(), true);
test_equal(driver.playing, true);
test_equal(driver.is_playing(), true);
test_equal(driver->pause(), true);
test_equal(driver->playing, false);
test_equal(driver->is_playing(), false);
test_equal(driver.pause(), true);
test_equal(driver.playing, false);
test_equal(driver.is_playing(), false);
driver->seek_to(4242);
test_equal(driver->cur_pos, (long)4242);
test_equal(driver->position(), (long)4242);
driver.seek_to(4242);
test_equal(driver.cur_pos, (long)4242);
test_equal(driver.position(), (long)4242);
driver->cur_duration = 424242;
test_equal(driver->duration(), (long)424242);
driver.cur_duration = 424242;
test_equal(driver.duration(), (long)424242);
driver->eos();
driver.eos();
test_equal(eos_count, (unsigned)1);
driver->error();
driver.error();
test_equal(error_count, (unsigned)1);
driver->play();
driver->seek_to(4242);
driver->load(file);
test_equal(driver->is_playing(), false);
test_equal(driver->position(), (long)0);
driver.play();
driver.seek_to(4242);
driver.load(file);
test_equal(driver.is_playing(), false);
test_equal(driver.position(), (long)0);
}
int main(int argc, char **argv)