diff --git a/driver.c b/driver.c index 9506810d10..3d3de1b9f7 100644 --- a/driver.c +++ b/driver.c @@ -369,7 +369,7 @@ void init_drivers(int flags) if (flags & DRIVER_CAMERA) camera_driver_ctl(RARCH_CAMERA_CTL_UNSET_OWN_DRIVER, NULL); if (flags & DRIVER_LOCATION) - driver->location_data_own = false; + location_driver_ctl(RARCH_LOCATION_CTL_UNSET_OWN_DRIVER, NULL); #ifdef HAVE_MENU /* By default, we want the menu to persist through driver reinits. */ @@ -403,7 +403,7 @@ void init_drivers(int flags) init_camera(); /* Only initialize location driver if we're ever going to use it. */ - if ((flags & DRIVER_LOCATION) && driver->location_active) + if ((flags & DRIVER_LOCATION) && location_driver_ctl(RARCH_LOCATION_CTL_IS_ACTIVE, NULL)) init_location(); #ifdef HAVE_MENU @@ -446,7 +446,7 @@ void uninit_drivers(int flags) } #endif - if ((flags & DRIVER_LOCATION) && !driver->location_data_own) + if ((flags & DRIVER_LOCATION) && !location_driver_ctl(RARCH_LOCATION_CTL_OWNS_DRIVER, NULL)) { uninit_location(); driver->location_data = NULL; diff --git a/driver.h b/driver.h index ba26e1717d..703ef41395 100644 --- a/driver.h +++ b/driver.h @@ -189,8 +189,6 @@ typedef struct driver const location_driver_t *location; void *location_data; - bool location_active; - bool location_data_own; const record_driver_t *recording; void *recording_data; diff --git a/dynamic.c b/dynamic.c index 135b262163..596b1c9628 100644 --- a/dynamic.c +++ b/dynamic.c @@ -509,8 +509,6 @@ void init_libretro_sym(enum rarch_core_type type) **/ void uninit_libretro_sym(void) { - driver_t *driver = driver_get_ptr(); - #ifdef HAVE_DYNAMIC if (lib_handle) dylib_close(lib_handle); @@ -546,7 +544,7 @@ void uninit_libretro_sym(void) rarch_system_info_free(); camera_driver_ctl(RARCH_CAMERA_CTL_UNSET_ACTIVE, NULL); - driver->location_active = false; + location_driver_ctl(RARCH_LOCATION_CTL_UNSET_ACTIVE, NULL); /* Performance counters no longer valid. */ retro_perf_clear(); @@ -1140,7 +1138,8 @@ bool rarch_environment_cb(unsigned cmd, void *data) cb->get_position = driver_location_get_position; cb->set_interval = driver_location_set_interval; system->location_callback = *cb; - driver->location_active = true; + + location_driver_ctl(RARCH_LOCATION_CTL_UNSET_ACTIVE, NULL); break; } diff --git a/location/location_driver.c b/location/location_driver.c index f75cb33c2a..5679223a17 100644 --- a/location/location_driver.c +++ b/location/location_driver.c @@ -204,7 +204,7 @@ void init_location(void) if (!driver->location_data) { RARCH_ERR("Failed to initialize location driver. Will continue without location.\n"); - driver->location_active = false; + location_driver_ctl(RARCH_LOCATION_CTL_UNSET_ACTIVE, NULL); } if (system->location_callback.initialized) @@ -226,3 +226,33 @@ void uninit_location(void) } driver->location_data = NULL; } + +bool location_driver_ctl(enum rarch_location_ctl_state state, void *data) +{ + static bool location_driver_active = false; + static bool location_driver_data_own = false; + + switch (state) + { + case RARCH_LOCATION_CTL_SET_OWN_DRIVER: + location_driver_data_own = true; + break; + case RARCH_LOCATION_CTL_UNSET_OWN_DRIVER: + location_driver_data_own = false; + break; + case RARCH_LOCATION_CTL_OWNS_DRIVER: + return location_driver_data_own; + case RARCH_LOCATION_CTL_SET_ACTIVE: + location_driver_active = true; + break; + case RARCH_LOCATION_CTL_UNSET_ACTIVE: + location_driver_active = false; + break; + case RARCH_LOCATION_CTL_IS_ACTIVE: + return location_driver_active; + default: + break; + } + + return false; +} diff --git a/location/location_driver.h b/location/location_driver.h index 7b4a42838c..827a9620ff 100644 --- a/location/location_driver.h +++ b/location/location_driver.h @@ -25,6 +25,17 @@ extern "C" { #endif +enum rarch_location_ctl_state +{ + RARCH_LOCATION_CTL_NONE = 0, + RARCH_LOCATION_CTL_SET_OWN_DRIVER, + RARCH_LOCATION_CTL_UNSET_OWN_DRIVER, + RARCH_LOCATION_CTL_OWNS_DRIVER, + RARCH_LOCATION_CTL_SET_ACTIVE, + RARCH_LOCATION_CTL_UNSET_ACTIVE, + RARCH_LOCATION_CTL_IS_ACTIVE +}; + typedef struct location_driver { void *(*init)(void); @@ -126,6 +137,8 @@ void init_location(void); void uninit_location(void); +bool location_driver_ctl(enum rarch_location_ctl_state state, void *data); + #ifdef __cplusplus } #endif