Split up menu code into separate file menu_driver.c

This commit is contained in:
twinaphex 2015-01-12 20:00:43 +01:00
parent c4bf097d7f
commit 6b2fced631
6 changed files with 190 additions and 151 deletions

View File

@ -102,6 +102,7 @@ OBJ += frontend/frontend.o \
gfx/video_driver.o \
osk/osk_driver.o \
camera/camera_driver.o \
menu_driver.o \
location/location_driver.o \
driver.o \
settings.o \

138
driver.c
View File

@ -40,99 +40,6 @@
driver_t driver;
#ifdef HAVE_MENU
static const menu_ctx_driver_t *menu_ctx_drivers[] = {
#ifdef IOS
&menu_ctx_ios,
#endif
#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_GLUI)
&menu_ctx_glui,
#endif
#if defined(HAVE_XMB)
&menu_ctx_xmb,
#endif
#if defined(HAVE_RGUI)
&menu_ctx_rgui,
#endif
NULL
};
/**
* menu_driver_find_handle:
* @index : index of driver to get handle to.
*
* Returns: handle to menu driver at index. Can be NULL
* if nothing found.
**/
static const void *menu_driver_find_handle(int index)
{
const void *drv = menu_ctx_drivers[index];
if (!drv)
return NULL;
return drv;
}
/**
* menu_driver_find_ident:
* @index : index of driver to get handle to.
*
* Returns: Human-readable identifier of menu driver at index. Can be NULL
* if nothing found.
**/
static const char *menu_driver_find_ident(int index)
{
const menu_ctx_driver_t *drv = menu_ctx_drivers[index];
if (!drv)
return NULL;
return drv->ident;
}
/**
* config_get_menu_driver_options:
*
* Get an enumerated list of all menu driver names,
* separated by '|'.
*
* Returns: string listing of all menu driver names,
* separated by '|'.
**/
const char* config_get_menu_driver_options(void)
{
union string_list_elem_attr attr;
unsigned i;
char *options = NULL;
int options_len = 0;
struct string_list *options_l = string_list_new();
attr.i = 0;
for (i = 0; menu_driver_find_handle(i); i++)
{
const char *opt = menu_driver_find_ident(i);
options_len += strlen(opt) + 1;
string_list_append(options_l, opt, attr);
}
options = (char*)calloc(options_len, sizeof(char));
string_list_join_concat(options, options_len, options_l, "|");
string_list_free(options_l);
options_l = NULL;
return options;
}
#endif
/**
* joypad_driver_find_handle:
* @index : index of driver to get handle to.
@ -301,30 +208,6 @@ void find_next_driver(const char *label, char *str, size_t sizeof_str)
RARCH_WARN("Couldn't find any next driver (current one: \"%s\").\n", str);
}
#ifdef HAVE_MENU
static void find_menu_driver(void)
{
int i = find_driver_index("menu_driver", g_settings.menu.driver);
if (i >= 0)
driver.menu_ctx = menu_driver_find_handle(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_driver_find_handle(d); d++)
RARCH_LOG_OUTPUT("\t%s\n", menu_driver_find_ident(d));
RARCH_WARN("Going to default to first menu driver...\n");
driver.menu_ctx = menu_driver_find_handle(0);
if (!driver.menu_ctx)
rarch_fail(1, "find_menu_driver()");
}
}
#endif
/**
* init_drivers_pre:
*
@ -544,27 +427,6 @@ bool driver_update_system_av_info(const struct retro_system_av_info *info)
return true;
}
#ifdef HAVE_MENU
static void init_menu(void)
{
if (driver.menu)
return;
find_menu_driver();
if (!(driver.menu = (menu_handle_t*)menu_init(driver.menu_ctx)))
{
RARCH_ERR("Cannot initialize menu.\n");
rarch_fail(1, "init_menu()");
}
if (!(menu_init_list(driver.menu)))
{
RARCH_ERR("Cannot initialize menu lists.\n");
rarch_fail(1, "init_menu()");
}
}
#endif
static void deinit_pixel_converter(void)
{
scaler_ctx_gen_reset(&driver.scaler);

View File

@ -480,19 +480,6 @@ extern driver_t driver;
**/
const char* config_get_video_driver_options(void);
#ifdef HAVE_MENU
/**
* config_get_menu_driver_options:
*
* Get an enumerated list of all menu driver names,
* separated by '|'.
*
* Returns: string listing of all menu driver names,
* separated by '|'.
**/
const char* config_get_menu_driver_options(void);
#endif
/**
* find_driver_index:
* @label : string of driver type to be found.

View File

@ -502,6 +502,7 @@ DRIVERS
#include "../osk/osk_driver.c"
#include "../camera/camera_driver.c"
#include "../location/location_driver.c"
#include "../menu_driver.c"
#include "../driver.c"
/*============================================================

View File

@ -20,6 +20,7 @@
#include <stddef.h>
#include <stdint.h>
#include <boolean.h>
#include <retro_miscellaneous.h>
#include "menu_list.h"
#include "../settings_list.h"
@ -195,6 +196,39 @@ typedef struct menu_ctx_driver
const char *ident;
} menu_ctx_driver_t;
/**
* menu_driver_find_handle:
* @index : index of driver to get handle to.
*
* Returns: handle to menu driver at index. Can be NULL
* if nothing found.
**/
const void *menu_driver_find_handle(int index);
/**
* menu_driver_find_ident:
* @index : index of driver to get handle to.
*
* Returns: Human-readable identifier of menu driver at index. Can be NULL
* if nothing found.
**/
const char *menu_driver_find_ident(int index);
/**
* config_get_menu_driver_options:
*
* Get an enumerated list of all menu driver names,
* separated by '|'.
*
* Returns: string listing of all menu driver names,
* separated by '|'.
**/
const char* config_get_menu_driver_options(void);
void find_menu_driver(void);
void init_menu(void);
extern menu_ctx_driver_t menu_ctx_rmenu;
extern menu_ctx_driver_t menu_ctx_rmenu_xui;
extern menu_ctx_driver_t menu_ctx_rgui;

154
menu_driver.c Normal file
View File

@ -0,0 +1,154 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2015 - 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/>.
*/
#include <string.h>
#include <string/string_list.h>
#include "menu/menu_driver.h"
#include "menu/menu.h"
#include "driver.h"
#include "general.h"
static const menu_ctx_driver_t *menu_ctx_drivers[] = {
#ifdef IOS
&menu_ctx_ios,
#endif
#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_GLUI)
&menu_ctx_glui,
#endif
#if defined(HAVE_XMB)
&menu_ctx_xmb,
#endif
#if defined(HAVE_RGUI)
&menu_ctx_rgui,
#endif
NULL
};
/**
* menu_driver_find_handle:
* @index : index of driver to get handle to.
*
* Returns: handle to menu driver at index. Can be NULL
* if nothing found.
**/
const void *menu_driver_find_handle(int index)
{
const void *drv = menu_ctx_drivers[index];
if (!drv)
return NULL;
return drv;
}
/**
* menu_driver_find_ident:
* @index : index of driver to get handle to.
*
* Returns: Human-readable identifier of menu driver at index. Can be NULL
* if nothing found.
**/
const char *menu_driver_find_ident(int index)
{
const menu_ctx_driver_t *drv = menu_ctx_drivers[index];
if (!drv)
return NULL;
return drv->ident;
}
/**
* config_get_menu_driver_options:
*
* Get an enumerated list of all menu driver names,
* separated by '|'.
*
* Returns: string listing of all menu driver names,
* separated by '|'.
**/
const char* config_get_menu_driver_options(void)
{
union string_list_elem_attr attr;
unsigned i;
char *options = NULL;
int options_len = 0;
struct string_list *options_l = string_list_new();
attr.i = 0;
for (i = 0; menu_driver_find_handle(i); i++)
{
const char *opt = menu_driver_find_ident(i);
options_len += strlen(opt) + 1;
string_list_append(options_l, opt, attr);
}
options = (char*)calloc(options_len, sizeof(char));
string_list_join_concat(options, options_len, options_l, "|");
string_list_free(options_l);
options_l = NULL;
return options;
}
void find_menu_driver(void)
{
int i = find_driver_index("menu_driver", g_settings.menu.driver);
if (i >= 0)
driver.menu_ctx = menu_driver_find_handle(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_driver_find_handle(d); d++)
RARCH_LOG_OUTPUT("\t%s\n", menu_driver_find_ident(d));
RARCH_WARN("Going to default to first menu driver...\n");
driver.menu_ctx = menu_driver_find_handle(0);
if (!driver.menu_ctx)
rarch_fail(1, "find_menu_driver()");
}
}
void init_menu(void)
{
if (driver.menu)
return;
find_menu_driver();
if (!(driver.menu = (menu_handle_t*)menu_init(driver.menu_ctx)))
{
RARCH_ERR("Cannot initialize menu.\n");
rarch_fail(1, "init_menu()");
}
if (!(menu_init_list(driver.menu)))
{
RARCH_ERR("Cannot initialize menu lists.\n");
rarch_fail(1, "init_menu()");
}
}