From 6b2fced631d6348009aacc1e72d04ce2b591a3f4 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 12 Jan 2015 20:00:43 +0100 Subject: [PATCH] Split up menu code into separate file menu_driver.c --- Makefile.common | 1 + driver.c | 138 ---------------------------------------- driver.h | 13 ---- griffin/griffin.c | 1 + menu/menu_driver.h | 34 ++++++++++ menu_driver.c | 154 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 190 insertions(+), 151 deletions(-) create mode 100644 menu_driver.c diff --git a/Makefile.common b/Makefile.common index 69ef79a020..92b7b41792 100644 --- a/Makefile.common +++ b/Makefile.common @@ -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 \ diff --git a/driver.c b/driver.c index 838324d0d3..08d1dd98b9 100644 --- a/driver.c +++ b/driver.c @@ -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); diff --git a/driver.h b/driver.h index 1af3b652bc..770c9a09e2 100644 --- a/driver.h +++ b/driver.h @@ -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. diff --git a/griffin/griffin.c b/griffin/griffin.c index 16cddd60c4..83c0c832af 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -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" /*============================================================ diff --git a/menu/menu_driver.h b/menu/menu_driver.h index 2a054b255f..99bea6ee06 100644 --- a/menu/menu_driver.h +++ b/menu/menu_driver.h @@ -20,6 +20,7 @@ #include #include #include +#include #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; diff --git a/menu_driver.c b/menu_driver.c new file mode 100644 index 0000000000..59505695a7 --- /dev/null +++ b/menu_driver.c @@ -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 . + */ + +#include +#include +#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()"); + } +}