Cleanup driver-contexts

This commit is contained in:
twinaphex 2014-08-13 08:55:29 +02:00
parent 147cac67ef
commit 38ec3146f3
5 changed files with 408 additions and 476 deletions

View File

@ -1,142 +0,0 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2014 - Daniel De Matteis
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
static const camera_driver_t *camera_drivers[] = {
#ifdef HAVE_V4L2
&camera_v4l2,
#endif
#ifdef EMSCRIPTEN
&camera_rwebcam,
#endif
#ifdef ANDROID
&camera_android,
#endif
#ifdef IOS
&camera_ios,
#endif
NULL,
};
static int find_camera_driver_index(const char *driver)
{
unsigned i;
for (i = 0; camera_drivers[i]; i++)
if (strcasecmp(driver, camera_drivers[i]->ident) == 0)
return i;
return -1;
}
static void find_camera_driver(void)
{
int i = find_camera_driver_index(g_settings.camera.driver);
if (i >= 0)
driver.camera = camera_drivers[i];
else
{
unsigned d;
RARCH_ERR("Couldn't find any camera driver named \"%s\"\n", g_settings.camera.driver);
RARCH_LOG_OUTPUT("Available camera drivers are:\n");
for (d = 0; camera_drivers[d]; d++)
RARCH_LOG_OUTPUT("\t%s\n", camera_drivers[d]->ident);
rarch_fail(1, "find_camera_driver()");
}
}
void find_prev_camera_driver(void)
{
int i = find_camera_driver_index(g_settings.camera.driver);
if (i > 0)
strlcpy(g_settings.camera.driver, camera_drivers[i - 1]->ident, sizeof(g_settings.camera.driver));
else
RARCH_WARN("Couldn't find any previous camera driver (current one: \"%s\").\n", g_settings.camera.driver);
}
void find_next_camera_driver(void)
{
int i = find_camera_driver_index(g_settings.camera.driver);
if (i >= 0 && camera_drivers[i + 1])
strlcpy(g_settings.camera.driver, camera_drivers[i + 1]->ident, sizeof(g_settings.camera.driver));
else
RARCH_WARN("Couldn't find any next camera driver (current one: \"%s\").\n", g_settings.camera.driver);
}
bool driver_camera_start(void)
{
if (driver.camera && driver.camera_data && driver.camera->start)
{
if (g_settings.camera.allow)
return driver.camera->start(driver.camera_data);
else
msg_queue_push(g_extern.msg_queue, "Camera is explicitly disabled.\n", 1, 180);
return false;
}
else
return false;
}
void driver_camera_stop(void)
{
if (driver.camera && driver.camera->stop && driver.camera_data)
driver.camera->stop(driver.camera_data);
}
void driver_camera_poll(void)
{
if (driver.camera && driver.camera->poll && driver.camera_data)
{
driver.camera->poll(driver.camera_data,
g_extern.system.camera_callback.frame_raw_framebuffer,
g_extern.system.camera_callback.frame_opengl_texture);
}
}
void init_camera(void)
{
// Resource leaks will follow if camera is initialized twice.
if (driver.camera_data)
return;
find_camera_driver();
driver.camera_data = camera_init_func(
*g_settings.camera.device ? g_settings.camera.device : NULL,
g_extern.system.camera_callback.caps,
g_settings.camera.width ? g_settings.camera.width : g_extern.system.camera_callback.width,
g_settings.camera.height ? g_settings.camera.height : g_extern.system.camera_callback.height);
if (!driver.camera_data)
{
RARCH_ERR("Failed to initialize camera driver. Will continue without camera.\n");
g_extern.camera_active = false;
}
if (g_extern.system.camera_callback.initialized)
g_extern.system.camera_callback.initialized();
}
void uninit_camera(void)
{
if (driver.camera_data && driver.camera)
{
if (g_extern.system.camera_callback.deinitialized)
g_extern.system.camera_callback.deinitialized();
if (driver.camera->free)
driver.camera->free(driver.camera_data);
}
driver.camera_data = NULL;
}

View File

@ -1,141 +0,0 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2014 - Daniel De Matteis
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
static const location_driver_t *location_drivers[] = {
#ifdef ANDROID
&location_android,
#endif
#if defined(IOS) || defined(OSX)
&location_apple,
#endif
NULL,
};
static int find_location_driver_index(const char *driver)
{
unsigned i;
for (i = 0; location_drivers[i]; i++)
if (strcasecmp(driver, location_drivers[i]->ident) == 0)
return i;
return -1;
}
static void find_location_driver(void)
{
int i = find_location_driver_index(g_settings.location.driver);
if (i >= 0)
driver.location = location_drivers[i];
else
{
unsigned d;
RARCH_ERR("Couldn't find any location driver named \"%s\"\n", g_settings.location.driver);
RARCH_LOG_OUTPUT("Available location drivers are:\n");
for (d = 0; location_drivers[d]; d++)
RARCH_LOG_OUTPUT("\t%s\n", location_drivers[d]->ident);
rarch_fail(1, "find_location_driver()");
}
}
void find_prev_location_driver(void)
{
int i = find_location_driver_index(g_settings.location.driver);
if (i > 0)
strlcpy(g_settings.location.driver, location_drivers[i - 1]->ident, sizeof(g_settings.location.driver));
else
RARCH_WARN("Couldn't find any previous location driver (current one: \"%s\").\n", g_settings.location.driver);
}
void find_next_location_driver(void)
{
int i = find_location_driver_index(g_settings.location.driver);
if (i >= 0 && location_drivers[i + 1])
strlcpy(g_settings.location.driver, location_drivers[i + 1]->ident, sizeof(g_settings.location.driver));
else
RARCH_WARN("Couldn't find any next location driver (current one: \"%s\").\n", g_settings.location.driver);
}
bool driver_location_start(void)
{
if (driver.location && driver.location_data && driver.location->start)
{
if (g_settings.location.allow)
return driver.location->start(driver.location_data);
else
msg_queue_push(g_extern.msg_queue, "Location is explicitly disabled.\n", 1, 180);
return false;
}
else
return false;
}
void driver_location_stop(void)
{
if (driver.location && driver.location->stop && driver.location_data)
driver.location->stop(driver.location_data);
}
void driver_location_set_interval(unsigned interval_msecs, unsigned interval_distance)
{
if (driver.location && driver.location->set_interval && driver.location_data)
driver.location->set_interval(driver.location_data, interval_msecs, interval_distance);
}
bool driver_location_get_position(double *lat, double *lon, double *horiz_accuracy,
double *vert_accuracy)
{
if (driver.location && driver.location->get_position && driver.location_data)
return driver.location->get_position(driver.location_data, lat, lon, horiz_accuracy, vert_accuracy);
*lat = 0.0;
*lon = 0.0;
*horiz_accuracy = 0.0;
*vert_accuracy = 0.0;
return false;
}
void init_location(void)
{
// Resource leaks will follow if location interface is initialized twice.
if (driver.location_data)
return;
find_location_driver();
driver.location_data = location_init_func();
if (!driver.location_data)
{
RARCH_ERR("Failed to initialize location driver. Will continue without location.\n");
g_extern.location_active = false;
}
if (g_extern.system.location_callback.initialized)
g_extern.system.location_callback.initialized();
}
void uninit_location(void)
{
if (driver.location_data && driver.location)
{
if (g_extern.system.location_callback.deinitialized)
g_extern.system.location_callback.deinitialized();
if (driver.location->free)
driver.location->free(driver.location_data);
}
driver.location_data = NULL;
}

View File

@ -1,98 +0,0 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2014 - Daniel De Matteis
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
static const menu_ctx_driver_t *menu_ctx_drivers[] = {
#if defined(HAVE_RMENU)
&menu_ctx_rmenu,
#endif
#if defined(HAVE_RMENU_XUI)
&menu_ctx_rmenu_xui,
#endif
#if defined(HAVE_LAKKA)
&menu_ctx_lakka,
#endif
#if defined(HAVE_RGUI)
&menu_ctx_rgui,
#endif
NULL // zero length array is not valid
};
const void *menu_ctx_find_driver(const char *ident)
{
unsigned i;
for (i = 0; menu_ctx_drivers[i]; i++)
{
if (strcmp(menu_ctx_drivers[i]->ident, ident) == 0)
return menu_ctx_drivers[i];
}
return NULL;
}
static int find_menu_driver_index(const char *driver)
{
unsigned i;
for (i = 0; menu_ctx_drivers[i]; i++)
if (strcasecmp(driver, menu_ctx_drivers[i]->ident) == 0)
return i;
return -1;
}
void find_prev_menu_driver(void)
{
int i = find_menu_driver_index(g_settings.menu.driver);
if (i > 0)
{
strlcpy(g_settings.menu.driver, menu_ctx_drivers[i - 1]->ident, sizeof(g_settings.menu.driver));
driver.menu_ctx = (menu_ctx_driver_t*)menu_ctx_drivers[i - 1];
}
else
RARCH_WARN("Couldn't find any previous menu driver (current one: \"%s\").\n", g_settings.menu.driver);
}
void find_next_menu_driver(void)
{
int i = find_menu_driver_index(g_settings.menu.driver);
if (i >= 0 && menu_ctx_drivers[i + 1])
{
strlcpy(g_settings.menu.driver, menu_ctx_drivers[i + 1]->ident, sizeof(g_settings.menu.driver));
driver.menu_ctx = (menu_ctx_driver_t*)menu_ctx_drivers[i + 1];
}
else
RARCH_WARN("Couldn't find any next menu driver (current one: \"%s\").\n", g_settings.menu.driver);
}
void find_menu_driver(void)
{
int i = find_menu_driver_index(g_settings.menu.driver);
if (i >= 0)
driver.menu_ctx = menu_ctx_drivers[i];
else
{
unsigned d;
RARCH_WARN("Couldn't find any menu driver named \"%s\"\n", g_settings.menu.driver);
RARCH_LOG_OUTPUT("Available menu drivers are:\n");
for (d = 0; menu_ctx_drivers[d]; d++)
RARCH_LOG_OUTPUT("\t%s\n", menu_ctx_drivers[d]->ident);
RARCH_WARN("Going to default to first menu driver...\n");
driver.menu_ctx = menu_ctx_drivers[0];
if (!driver.menu_ctx)
rarch_fail(1, "find_menu_driver()");
}
}

View File

@ -1,91 +0,0 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2014 - Daniel De Matteis
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
static const input_osk_driver_t *osk_drivers[] = {
#ifdef __CELLOS_LV2__
&input_ps3_osk,
#endif
NULL,
};
static int find_osk_driver_index(const char *driver)
{
unsigned i;
for (i = 0; osk_drivers[i]; i++)
if (strcasecmp(driver, osk_drivers[i]->ident) == 0)
return i;
return -1;
}
static void find_osk_driver(void)
{
int i = find_osk_driver_index(g_settings.osk.driver);
if (i >= 0)
driver.osk = osk_drivers[i];
else
{
unsigned d;
RARCH_ERR("Couldn't find any OSK driver named \"%s\"\n", g_settings.osk.driver);
RARCH_LOG_OUTPUT("Available OSK drivers are:\n");
for (d = 0; osk_drivers[d]; d++)
RARCH_LOG_OUTPUT("\t%s\n", osk_drivers[d]->ident);
rarch_fail(1, "find_osk_driver()");
}
}
void find_prev_osk_driver(void)
{
int i = find_osk_driver_index(g_settings.osk.driver);
if (i > 0)
strlcpy(g_settings.osk.driver, osk_drivers[i - 1]->ident, sizeof(g_settings.osk.driver));
else
RARCH_WARN("Couldn't find any previous osk driver (current one: \"%s\").\n", g_settings.osk.driver);
}
void find_next_osk_driver(void)
{
int i = find_osk_driver_index(g_settings.osk.driver);
if (i >= 0 && osk_drivers[i + 1])
strlcpy(g_settings.osk.driver, osk_drivers[i + 1]->ident, sizeof(g_settings.osk.driver));
else
RARCH_WARN("Couldn't find any next osk driver (current one: \"%s\").\n", g_settings.osk.driver);
}
void init_osk(void)
{
// Resource leaks will follow if osk is initialized twice.
if (driver.osk_data)
return;
find_osk_driver();
//FIXME - refactor params later based on semantics
driver.osk_data = osk_init_func(0);
if (!driver.osk_data)
{
RARCH_ERR("Failed to initialize OSK driver. Will continue without OSK.\n");
g_extern.osk_active = false;
}
}
void uninit_osk(void)
{
if (driver.osk_data && driver.osk && driver.osk->free)
driver.osk->free(driver.osk_data);
driver.osk_data = NULL;
}

412
driver.c
View File

@ -195,19 +195,423 @@ static const input_driver_t *input_drivers[] = {
};
#ifdef HAVE_OSK
#include "driver-contexts/osk_driver.c"
static const input_osk_driver_t *osk_drivers[] = {
#ifdef __CELLOS_LV2__
&input_ps3_osk,
#endif
NULL,
};
static int find_osk_driver_index(const char *driver)
{
unsigned i;
for (i = 0; osk_drivers[i]; i++)
if (strcasecmp(driver, osk_drivers[i]->ident) == 0)
return i;
return -1;
}
static void find_osk_driver(void)
{
int i = find_osk_driver_index(g_settings.osk.driver);
if (i >= 0)
driver.osk = osk_drivers[i];
else
{
unsigned d;
RARCH_ERR("Couldn't find any OSK driver named \"%s\"\n", g_settings.osk.driver);
RARCH_LOG_OUTPUT("Available OSK drivers are:\n");
for (d = 0; osk_drivers[d]; d++)
RARCH_LOG_OUTPUT("\t%s\n", osk_drivers[d]->ident);
rarch_fail(1, "find_osk_driver()");
}
}
void find_prev_osk_driver(void)
{
int i = find_osk_driver_index(g_settings.osk.driver);
if (i > 0)
strlcpy(g_settings.osk.driver, osk_drivers[i - 1]->ident, sizeof(g_settings.osk.driver));
else
RARCH_WARN("Couldn't find any previous osk driver (current one: \"%s\").\n", g_settings.osk.driver);
}
void find_next_osk_driver(void)
{
int i = find_osk_driver_index(g_settings.osk.driver);
if (i >= 0 && osk_drivers[i + 1])
strlcpy(g_settings.osk.driver, osk_drivers[i + 1]->ident, sizeof(g_settings.osk.driver));
else
RARCH_WARN("Couldn't find any next osk driver (current one: \"%s\").\n", g_settings.osk.driver);
}
void init_osk(void)
{
// Resource leaks will follow if osk is initialized twice.
if (driver.osk_data)
return;
find_osk_driver();
//FIXME - refactor params later based on semantics
driver.osk_data = osk_init_func(0);
if (!driver.osk_data)
{
RARCH_ERR("Failed to initialize OSK driver. Will continue without OSK.\n");
g_extern.osk_active = false;
}
}
void uninit_osk(void)
{
if (driver.osk_data && driver.osk && driver.osk->free)
driver.osk->free(driver.osk_data);
driver.osk_data = NULL;
}
#endif
#ifdef HAVE_CAMERA
#include "driver-contexts/camera_driver.c"
static const camera_driver_t *camera_drivers[] = {
#ifdef HAVE_V4L2
&camera_v4l2,
#endif
#ifdef EMSCRIPTEN
&camera_rwebcam,
#endif
#ifdef ANDROID
&camera_android,
#endif
#ifdef IOS
&camera_ios,
#endif
NULL,
};
static int find_camera_driver_index(const char *driver)
{
unsigned i;
for (i = 0; camera_drivers[i]; i++)
if (strcasecmp(driver, camera_drivers[i]->ident) == 0)
return i;
return -1;
}
static void find_camera_driver(void)
{
int i = find_camera_driver_index(g_settings.camera.driver);
if (i >= 0)
driver.camera = camera_drivers[i];
else
{
unsigned d;
RARCH_ERR("Couldn't find any camera driver named \"%s\"\n", g_settings.camera.driver);
RARCH_LOG_OUTPUT("Available camera drivers are:\n");
for (d = 0; camera_drivers[d]; d++)
RARCH_LOG_OUTPUT("\t%s\n", camera_drivers[d]->ident);
rarch_fail(1, "find_camera_driver()");
}
}
void find_prev_camera_driver(void)
{
int i = find_camera_driver_index(g_settings.camera.driver);
if (i > 0)
strlcpy(g_settings.camera.driver, camera_drivers[i - 1]->ident, sizeof(g_settings.camera.driver));
else
RARCH_WARN("Couldn't find any previous camera driver (current one: \"%s\").\n", g_settings.camera.driver);
}
void find_next_camera_driver(void)
{
int i = find_camera_driver_index(g_settings.camera.driver);
if (i >= 0 && camera_drivers[i + 1])
strlcpy(g_settings.camera.driver, camera_drivers[i + 1]->ident, sizeof(g_settings.camera.driver));
else
RARCH_WARN("Couldn't find any next camera driver (current one: \"%s\").\n", g_settings.camera.driver);
}
bool driver_camera_start(void)
{
if (driver.camera && driver.camera_data && driver.camera->start)
{
if (g_settings.camera.allow)
return driver.camera->start(driver.camera_data);
else
msg_queue_push(g_extern.msg_queue, "Camera is explicitly disabled.\n", 1, 180);
return false;
}
else
return false;
}
void driver_camera_stop(void)
{
if (driver.camera && driver.camera->stop && driver.camera_data)
driver.camera->stop(driver.camera_data);
}
void driver_camera_poll(void)
{
if (driver.camera && driver.camera->poll && driver.camera_data)
{
driver.camera->poll(driver.camera_data,
g_extern.system.camera_callback.frame_raw_framebuffer,
g_extern.system.camera_callback.frame_opengl_texture);
}
}
void init_camera(void)
{
// Resource leaks will follow if camera is initialized twice.
if (driver.camera_data)
return;
find_camera_driver();
driver.camera_data = camera_init_func(
*g_settings.camera.device ? g_settings.camera.device : NULL,
g_extern.system.camera_callback.caps,
g_settings.camera.width ? g_settings.camera.width : g_extern.system.camera_callback.width,
g_settings.camera.height ? g_settings.camera.height : g_extern.system.camera_callback.height);
if (!driver.camera_data)
{
RARCH_ERR("Failed to initialize camera driver. Will continue without camera.\n");
g_extern.camera_active = false;
}
if (g_extern.system.camera_callback.initialized)
g_extern.system.camera_callback.initialized();
}
void uninit_camera(void)
{
if (driver.camera_data && driver.camera)
{
if (g_extern.system.camera_callback.deinitialized)
g_extern.system.camera_callback.deinitialized();
if (driver.camera->free)
driver.camera->free(driver.camera_data);
}
driver.camera_data = NULL;
}
#endif
#ifdef HAVE_LOCATION
#include "driver-contexts/location_driver.c"
static const location_driver_t *location_drivers[] = {
#ifdef ANDROID
&location_android,
#endif
#if defined(IOS) || defined(OSX)
&location_apple,
#endif
NULL,
};
static int find_location_driver_index(const char *driver)
{
unsigned i;
for (i = 0; location_drivers[i]; i++)
if (strcasecmp(driver, location_drivers[i]->ident) == 0)
return i;
return -1;
}
static void find_location_driver(void)
{
int i = find_location_driver_index(g_settings.location.driver);
if (i >= 0)
driver.location = location_drivers[i];
else
{
unsigned d;
RARCH_ERR("Couldn't find any location driver named \"%s\"\n", g_settings.location.driver);
RARCH_LOG_OUTPUT("Available location drivers are:\n");
for (d = 0; location_drivers[d]; d++)
RARCH_LOG_OUTPUT("\t%s\n", location_drivers[d]->ident);
rarch_fail(1, "find_location_driver()");
}
}
void find_prev_location_driver(void)
{
int i = find_location_driver_index(g_settings.location.driver);
if (i > 0)
strlcpy(g_settings.location.driver, location_drivers[i - 1]->ident, sizeof(g_settings.location.driver));
else
RARCH_WARN("Couldn't find any previous location driver (current one: \"%s\").\n", g_settings.location.driver);
}
void find_next_location_driver(void)
{
int i = find_location_driver_index(g_settings.location.driver);
if (i >= 0 && location_drivers[i + 1])
strlcpy(g_settings.location.driver, location_drivers[i + 1]->ident, sizeof(g_settings.location.driver));
else
RARCH_WARN("Couldn't find any next location driver (current one: \"%s\").\n", g_settings.location.driver);
}
bool driver_location_start(void)
{
if (driver.location && driver.location_data && driver.location->start)
{
if (g_settings.location.allow)
return driver.location->start(driver.location_data);
else
msg_queue_push(g_extern.msg_queue, "Location is explicitly disabled.\n", 1, 180);
return false;
}
else
return false;
}
void driver_location_stop(void)
{
if (driver.location && driver.location->stop && driver.location_data)
driver.location->stop(driver.location_data);
}
void driver_location_set_interval(unsigned interval_msecs, unsigned interval_distance)
{
if (driver.location && driver.location->set_interval && driver.location_data)
driver.location->set_interval(driver.location_data, interval_msecs, interval_distance);
}
bool driver_location_get_position(double *lat, double *lon, double *horiz_accuracy,
double *vert_accuracy)
{
if (driver.location && driver.location->get_position && driver.location_data)
return driver.location->get_position(driver.location_data, lat, lon, horiz_accuracy, vert_accuracy);
*lat = 0.0;
*lon = 0.0;
*horiz_accuracy = 0.0;
*vert_accuracy = 0.0;
return false;
}
void init_location(void)
{
// Resource leaks will follow if location interface is initialized twice.
if (driver.location_data)
return;
find_location_driver();
driver.location_data = location_init_func();
if (!driver.location_data)
{
RARCH_ERR("Failed to initialize location driver. Will continue without location.\n");
g_extern.location_active = false;
}
if (g_extern.system.location_callback.initialized)
g_extern.system.location_callback.initialized();
}
void uninit_location(void)
{
if (driver.location_data && driver.location)
{
if (g_extern.system.location_callback.deinitialized)
g_extern.system.location_callback.deinitialized();
if (driver.location->free)
driver.location->free(driver.location_data);
}
driver.location_data = NULL;
}
#endif
#ifdef HAVE_MENU
#include "driver-contexts/menu_driver.c"
static const menu_ctx_driver_t *menu_ctx_drivers[] = {
#if defined(HAVE_RMENU)
&menu_ctx_rmenu,
#endif
#if defined(HAVE_RMENU_XUI)
&menu_ctx_rmenu_xui,
#endif
#if defined(HAVE_LAKKA)
&menu_ctx_lakka,
#endif
#if defined(HAVE_RGUI)
&menu_ctx_rgui,
#endif
NULL // zero length array is not valid
};
const void *menu_ctx_find_driver(const char *ident)
{
unsigned i;
for (i = 0; menu_ctx_drivers[i]; i++)
{
if (strcmp(menu_ctx_drivers[i]->ident, ident) == 0)
return menu_ctx_drivers[i];
}
return NULL;
}
static int find_menu_driver_index(const char *driver)
{
unsigned i;
for (i = 0; menu_ctx_drivers[i]; i++)
if (strcasecmp(driver, menu_ctx_drivers[i]->ident) == 0)
return i;
return -1;
}
void find_prev_menu_driver(void)
{
int i = find_menu_driver_index(g_settings.menu.driver);
if (i > 0)
{
strlcpy(g_settings.menu.driver, menu_ctx_drivers[i - 1]->ident, sizeof(g_settings.menu.driver));
driver.menu_ctx = (menu_ctx_driver_t*)menu_ctx_drivers[i - 1];
}
else
RARCH_WARN("Couldn't find any previous menu driver (current one: \"%s\").\n", g_settings.menu.driver);
}
void find_next_menu_driver(void)
{
int i = find_menu_driver_index(g_settings.menu.driver);
if (i >= 0 && menu_ctx_drivers[i + 1])
{
strlcpy(g_settings.menu.driver, menu_ctx_drivers[i + 1]->ident, sizeof(g_settings.menu.driver));
driver.menu_ctx = (menu_ctx_driver_t*)menu_ctx_drivers[i + 1];
}
else
RARCH_WARN("Couldn't find any next menu driver (current one: \"%s\").\n", g_settings.menu.driver);
}
void find_menu_driver(void)
{
int i = find_menu_driver_index(g_settings.menu.driver);
if (i >= 0)
driver.menu_ctx = menu_ctx_drivers[i];
else
{
unsigned d;
RARCH_WARN("Couldn't find any menu driver named \"%s\"\n", g_settings.menu.driver);
RARCH_LOG_OUTPUT("Available menu drivers are:\n");
for (d = 0; menu_ctx_drivers[d]; d++)
RARCH_LOG_OUTPUT("\t%s\n", menu_ctx_drivers[d]->ident);
RARCH_WARN("Going to default to first menu driver...\n");
driver.menu_ctx = menu_ctx_drivers[0];
if (!driver.menu_ctx)
rarch_fail(1, "find_menu_driver()");
}
}
#endif
static int find_audio_driver_index(const char *driver)