diff --git a/audio/audio_driver.c b/audio/audio_driver.c index 0974330646..63d2d97590 100644 --- a/audio/audio_driver.c +++ b/audio/audio_driver.c @@ -737,9 +737,16 @@ static void audio_driver_setup_rewind(void) static bool find_audio_driver(void) { + int i; + driver_ctx_info_t drv; settings_t *settings = config_get_ptr(); - int i = find_driver_index("audio_driver", settings->audio.driver); + drv.label = "audio_driver"; + drv.s = settings->audio.driver; + + driver_ctl(RARCH_DRIVER_CTL_FIND_INDEX, &drv); + + i = drv.len; if (i >= 0) current_audio = (const audio_driver_t*)audio_driver_find_handle(i); diff --git a/camera/camera_driver.c b/camera/camera_driver.c index 1691f47db4..55fd77e6da 100644 --- a/camera/camera_driver.c +++ b/camera/camera_driver.c @@ -90,8 +90,16 @@ const char* config_get_camera_driver_options(void) void find_camera_driver(void) { + int i; + driver_ctx_info_t drv; settings_t *settings = config_get_ptr(); - int i = find_driver_index("camera_driver", settings->camera.driver); + + drv.label = "camera_driver"; + drv.s = settings->camera.driver; + + driver_ctl(RARCH_DRIVER_CTL_FIND_INDEX, &drv); + + i = drv.len; if (i >= 0) camera_driver = (const camera_driver_t*)camera_driver_find_handle(i); diff --git a/driver.c b/driver.c index f18e2ac732..a10a33bfcf 100644 --- a/driver.c +++ b/driver.c @@ -120,7 +120,7 @@ static const void *find_driver_nonempty(const char *label, int i, } /** - * find_driver_index: + * driver_find_index: * @label : string of driver type to be found. * @drv : identifier of driver to be found. * @@ -129,7 +129,7 @@ static const void *find_driver_nonempty(const char *label, int i, * Returns: -1 if no driver based on @label and @drv found, otherwise * index number of the driver found in the array. **/ -int find_driver_index(const char * label, const char *drv) +static int driver_find_index(const char * label, const char *drv) { unsigned i; char str[256]; @@ -165,7 +165,7 @@ static bool driver_find_first(const char *label, char *s, size_t len) **/ static bool driver_find_prev(const char *label, char *s, size_t len) { - int i = find_driver_index(label, s); + int i = driver_find_index(label, s); if (i > 0) find_driver_nonempty(label, i - 1, s, len); else @@ -187,7 +187,7 @@ static bool driver_find_prev(const char *label, char *s, size_t len) **/ bool driver_find_next(const char *label, char *s, size_t len) { - int i = find_driver_index(label, s); + int i = driver_find_index(label, s); if (i >= 0 && !string_is_equal(s, "null")) find_driver_nonempty(label, i + 1, s, len); else @@ -496,6 +496,14 @@ bool driver_ctl(enum driver_ctl_state state, void *data) return false; return driver_find_next(drv->label, drv->s, drv->len); } + case RARCH_DRIVER_CTL_FIND_INDEX: + { + driver_ctx_info_t *drv = (driver_ctx_info_t*)data; + if (!drv) + return false; + drv->len = driver_find_index(drv->label, drv->s); + return true; + } case RARCH_DRIVER_CTL_NONE: default: break; diff --git a/driver.h b/driver.h index 51fd8054ed..d555a19be3 100644 --- a/driver.h +++ b/driver.h @@ -207,14 +207,18 @@ enum driver_ctl_state RARCH_DRIVER_CTL_FIND_PREV, - RARCH_DRIVER_CTL_FIND_NEXT + RARCH_DRIVER_CTL_FIND_NEXT, + + /* Find index of the driver, based on @label. */ + RARCH_DRIVER_CTL_FIND_INDEX + }; typedef struct driver_ctx_info { const char *label; char *s; - size_t len; + ssize_t len; } driver_ctx_info_t; @@ -233,18 +237,6 @@ typedef struct driver_ctx_info * Typically, if a driver intends to make use of this, it should * set this to true at the end of its 'init' function. */ -/** - * find_driver_index: - * @label : string of driver type to be found. - * @drv : identifier of driver to be found. - * - * Find index of the driver, based on @label. - * - * Returns: -1 if no driver based on @label and @drv found, otherwise - * index number of the driver found in the array. - **/ -int find_driver_index(const char * label, const char *drv); - bool driver_ctl(enum driver_ctl_state state, void *data); #ifdef __cplusplus diff --git a/gfx/video_driver.c b/gfx/video_driver.c index bedfd4f45e..3d778c7cce 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -235,6 +235,7 @@ const char* config_get_video_driver_options(void) static bool find_video_driver(void) { int i; + driver_ctx_info_t drv; settings_t *settings = config_get_ptr(); #if defined(HAVE_OPENGL) && defined(HAVE_FBO) @@ -255,7 +256,13 @@ static bool find_video_driver(void) RARCH_WARN("Frontend supports get_video_driver() but did not specify one.\n"); } - i = find_driver_index("video_driver", settings->video.driver); + drv.label = "video_driver"; + drv.s = settings->video.driver; + + driver_ctl(RARCH_DRIVER_CTL_FIND_INDEX, &drv); + + i = drv.len; + if (i >= 0) current_video = (video_driver_t*)video_driver_find_handle(i); else diff --git a/input/input_driver.c b/input/input_driver.c index f69a300f5f..96fbdd3441 100644 --- a/input/input_driver.c +++ b/input/input_driver.c @@ -737,9 +737,16 @@ bool input_driver_ctl(enum rarch_input_ctl_state state, void *data) return false; case RARCH_INPUT_CTL_FIND_DRIVER: { + int i; + driver_ctx_info_t drv; settings_t *settings = config_get_ptr(); - int i = find_driver_index("input_driver", - settings->input.driver); + + drv.label = "input_driver"; + drv.s = settings->input.driver; + + driver_ctl(RARCH_DRIVER_CTL_FIND_INDEX, &drv); + + i = drv.len; if (i >= 0) current_input = (const input_driver_t*)input_driver_find_handle(i); diff --git a/location/location_driver.c b/location/location_driver.c index 71f5c643b3..956cf83df9 100644 --- a/location/location_driver.c +++ b/location/location_driver.c @@ -85,8 +85,16 @@ const char* config_get_location_driver_options(void) void find_location_driver(void) { + int i; + driver_ctx_info_t drv; settings_t *settings = config_get_ptr(); - int i = find_driver_index("location_driver", settings->location.driver); + + drv.label = "location_driver"; + drv.s = settings->location.driver; + + driver_ctl(RARCH_DRIVER_CTL_FIND_INDEX, &drv); + + i = drv.len; if (i >= 0) location_driver = (const location_driver_t*)location_driver_find_handle(i); diff --git a/menu/menu_driver.c b/menu/menu_driver.c index 8ae0f75c75..53bc984e58 100644 --- a/menu/menu_driver.c +++ b/menu/menu_driver.c @@ -105,9 +105,17 @@ const char *config_get_menu_driver_options(void) void find_menu_driver(void) { + int i; + driver_ctx_info_t drv; settings_t *settings = config_get_ptr(); - int i = find_driver_index("menu_driver", settings->menu.driver); + drv.label = "menu_driver"; + drv.s = settings->menu.driver; + + driver_ctl(RARCH_DRIVER_CTL_FIND_INDEX, &drv); + + i = drv.len; + if (i >= 0) menu_driver_ctx = (const menu_ctx_driver_t*)menu_driver_find_handle(i); else diff --git a/record/record_driver.c b/record/record_driver.c index 8fbee8321d..c762e9076d 100644 --- a/record/record_driver.c +++ b/record/record_driver.c @@ -89,8 +89,16 @@ const char* config_get_record_driver_options(void) void find_record_driver(void) { + int i; + driver_ctx_info_t drv; settings_t *settings = config_get_ptr(); - int i = find_driver_index("record_driver", settings->record.driver); + + drv.label = "record_driver"; + drv.s = settings->record.driver; + + driver_ctl(RARCH_DRIVER_CTL_FIND_INDEX, &drv); + + i = drv.len; if (i >= 0) recording_driver = (const record_driver_t*)record_driver_find_handle(i);