mirror of
https://github.com/libretro/RetroArch
synced 2025-02-27 18:41:01 +00:00
Some cleanups to location interface.
Avoid three redundant fields in struct. Use unsigned instead of int for argument for API consistency.
This commit is contained in:
parent
031a9d05be
commit
855cb54def
9
driver.c
9
driver.c
@ -642,7 +642,7 @@ void driver_location_stop(void)
|
|||||||
driver.location->stop(driver.location_data);
|
driver.location->stop(driver.location_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void driver_location_set_interval(int interval_msecs, int interval_distance)
|
void driver_location_set_interval(unsigned interval_msecs, unsigned interval_distance)
|
||||||
{
|
{
|
||||||
if (driver.location && driver.location_data)
|
if (driver.location && driver.location_data)
|
||||||
driver.location->set_interval(driver.location_data, interval_msecs, interval_distance);
|
driver.location->set_interval(driver.location_data, interval_msecs, interval_distance);
|
||||||
@ -779,7 +779,7 @@ void init_location(void)
|
|||||||
|
|
||||||
find_location_driver();
|
find_location_driver();
|
||||||
|
|
||||||
driver.location_data = location_init_func(g_extern.system.location_callback.interval_in_ms, g_extern.system.location_callback.interval_distance_in_meters);
|
driver.location_data = location_init_func();
|
||||||
|
|
||||||
if (!driver.location_data)
|
if (!driver.location_data)
|
||||||
{
|
{
|
||||||
@ -837,14 +837,13 @@ void init_drivers(void)
|
|||||||
|
|
||||||
#ifdef HAVE_CAMERA
|
#ifdef HAVE_CAMERA
|
||||||
// Only init camera driver if we're ever going to use it.
|
// Only init camera driver if we're ever going to use it.
|
||||||
if (g_extern.system.camera_callback.caps)
|
if (g_extern.camera_active)
|
||||||
init_camera();
|
init_camera();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_LOCATION
|
#ifdef HAVE_LOCATION
|
||||||
// FIXME
|
|
||||||
// Only init location driver if we're ever going to use it.
|
// Only init location driver if we're ever going to use it.
|
||||||
if (g_extern.system.location_callback.enable)
|
if (g_extern.location_active)
|
||||||
init_location();
|
init_location();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
6
driver.h
6
driver.h
@ -369,7 +369,7 @@ typedef struct camera_driver
|
|||||||
|
|
||||||
typedef struct location_driver
|
typedef struct location_driver
|
||||||
{
|
{
|
||||||
void *(*init)(int interval_msecs, int interval_distance);
|
void *(*init)(void);
|
||||||
void (*free)(void *data);
|
void (*free)(void *data);
|
||||||
|
|
||||||
bool (*start)(void *data);
|
bool (*start)(void *data);
|
||||||
@ -377,7 +377,7 @@ typedef struct location_driver
|
|||||||
|
|
||||||
double (*get_longitude)(void *data);
|
double (*get_longitude)(void *data);
|
||||||
double (*get_latitude)(void *data);
|
double (*get_latitude)(void *data);
|
||||||
void (*set_interval)(void *data, int interval_msecs, int interval_distance);
|
void (*set_interval)(void *data, unsigned interval_msecs, unsigned interval_distance);
|
||||||
const char *ident;
|
const char *ident;
|
||||||
} location_driver_t;
|
} location_driver_t;
|
||||||
|
|
||||||
@ -606,7 +606,7 @@ bool driver_location_start(void);
|
|||||||
void driver_location_stop(void);
|
void driver_location_stop(void);
|
||||||
double driver_location_get_latitude(void);
|
double driver_location_get_latitude(void);
|
||||||
double driver_location_get_longitude(void);
|
double driver_location_get_longitude(void);
|
||||||
void driver_location_set_interval(int, int);
|
void driver_location_set_interval(unsigned interval_msecs, unsigned interval_distance);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern driver_t driver;
|
extern driver_t driver;
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
#define camera_init_func(device, caps, width, height) driver.camera->init(device, caps, width, height)
|
#define camera_init_func(device, caps, width, height) driver.camera->init(device, caps, width, height)
|
||||||
|
|
||||||
#define location_init_func(interval_msecs, interval_distance) driver.location->init(interval_msecs, interval_distance)
|
#define location_init_func() driver.location->init()
|
||||||
|
|
||||||
#define osk_init_func(unknown) driver.osk->init(unknown)
|
#define osk_init_func(unknown) driver.osk->init(unknown)
|
||||||
|
|
||||||
|
@ -418,6 +418,12 @@ void uninit_libretro_sym(void)
|
|||||||
|
|
||||||
// No longer valid.
|
// No longer valid.
|
||||||
memset(&g_extern.system, 0, sizeof(g_extern.system));
|
memset(&g_extern.system, 0, sizeof(g_extern.system));
|
||||||
|
#ifdef HAVE_CAMERA
|
||||||
|
g_extern.camera_active = false;
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_LOCATION
|
||||||
|
g_extern.location_active = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Performance counters no longer valid.
|
// Performance counters no longer valid.
|
||||||
retro_perf_clear();
|
retro_perf_clear();
|
||||||
@ -832,6 +838,7 @@ bool rarch_environment_cb(unsigned cmd, void *data)
|
|||||||
cb->start = driver_camera_start;
|
cb->start = driver_camera_start;
|
||||||
cb->stop = driver_camera_stop;
|
cb->stop = driver_camera_stop;
|
||||||
g_extern.system.camera_callback = *cb;
|
g_extern.system.camera_callback = *cb;
|
||||||
|
g_extern.camera_active = cb->caps != 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -846,6 +853,7 @@ bool rarch_environment_cb(unsigned cmd, void *data)
|
|||||||
cb->get_longitude = driver_location_get_longitude;
|
cb->get_longitude = driver_location_get_longitude;
|
||||||
cb->set_interval = driver_location_set_interval;
|
cb->set_interval = driver_location_set_interval;
|
||||||
g_extern.system.location_callback = *cb;
|
g_extern.system.location_callback = *cb;
|
||||||
|
g_extern.location_active = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
27
libretro.h
27
libretro.h
@ -749,32 +749,29 @@ struct retro_camera_callback
|
|||||||
retro_camera_lifetime_status_t deinitialized;
|
retro_camera_lifetime_status_t deinitialized;
|
||||||
};
|
};
|
||||||
|
|
||||||
//Sets the interval of time and/or distance at which to update/poll location-based data.
|
// Sets the interval of time and/or distance at which to update/poll location-based data.
|
||||||
//To ensure compatibility with all location-based implementations, values for both
|
// To ensure compatibility with all location-based implementations, values for both
|
||||||
//interval_ms and interval_distance should be provided.
|
// interval_ms and interval_distance should be provided.
|
||||||
//interval_ms is the interval expressed in milliseconds
|
// interval_ms is the interval expressed in milliseconds.
|
||||||
//interval_distance is the distance interval expressed in meters.
|
// interval_distance is the distance interval expressed in meters.
|
||||||
typedef void (*retro_location_set_interval_t)(int interval_ms, int interval_distance);
|
typedef void (*retro_location_set_interval_t)(unsigned interval_ms, unsigned interval_distance);
|
||||||
|
|
||||||
//Start location services. The device will start listening for changes to the
|
// Start location services. The device will start listening for changes to the
|
||||||
//current location at regular intervals (which are defined with retro_location_set_interval_t).
|
// current location at regular intervals (which are defined with retro_location_set_interval_t).
|
||||||
typedef bool (*retro_location_start_t)(void);
|
typedef bool (*retro_location_start_t)(void);
|
||||||
|
|
||||||
//Stop location services. The device will stop listening for changes to the current
|
// Stop location services. The device will stop listening for changes to the current
|
||||||
//location.
|
// location.
|
||||||
typedef void (*retro_location_stop_t)(void);
|
typedef void (*retro_location_stop_t)(void);
|
||||||
|
|
||||||
//Get the latitude of the current location.
|
// Get the latitude of the current location.
|
||||||
typedef double (*retro_location_get_latitude_t)(void);
|
typedef double (*retro_location_get_latitude_t)(void);
|
||||||
|
|
||||||
//Get the longitude of the current location.
|
// Get the longitude of the current location.
|
||||||
typedef double (*retro_location_get_longitude_t)(void);
|
typedef double (*retro_location_get_longitude_t)(void);
|
||||||
|
|
||||||
struct retro_location_callback
|
struct retro_location_callback
|
||||||
{
|
{
|
||||||
bool enable;
|
|
||||||
int interval_in_ms;
|
|
||||||
int interval_distance_in_meters;
|
|
||||||
retro_location_start_t start;
|
retro_location_start_t start;
|
||||||
retro_location_stop_t stop;
|
retro_location_stop_t stop;
|
||||||
retro_location_get_latitude_t get_latitude;
|
retro_location_get_latitude_t get_latitude;
|
||||||
|
@ -28,12 +28,10 @@ typedef struct android_location
|
|||||||
jmethodID onLocationGetLatitude;
|
jmethodID onLocationGetLatitude;
|
||||||
} androidlocation_t;
|
} androidlocation_t;
|
||||||
|
|
||||||
static void *android_location_init(int interval_ms, int interval_distance)
|
static void *android_location_init(void)
|
||||||
{
|
{
|
||||||
JNIEnv *env;
|
JNIEnv *env;
|
||||||
jclass class;
|
jclass class;
|
||||||
(void)interval_ms;
|
|
||||||
(void)interval_distance;
|
|
||||||
|
|
||||||
struct android_app *android_app = (struct android_app*)g_android;
|
struct android_app *android_app = (struct android_app*)g_android;
|
||||||
androidlocation_t *androidlocation = (androidlocation_t*)calloc(1, sizeof(androidlocation_t));
|
androidlocation_t *androidlocation = (androidlocation_t*)calloc(1, sizeof(androidlocation_t));
|
||||||
@ -79,6 +77,7 @@ static void *android_location_init(int interval_ms, int interval_distance)
|
|||||||
CALL_VOID_METHOD(env, android_app->activity->clazz, androidlocation->onLocationInit);
|
CALL_VOID_METHOD(env, android_app->activity->clazz, androidlocation->onLocationInit);
|
||||||
|
|
||||||
return androidlocation;
|
return androidlocation;
|
||||||
|
|
||||||
dealloc:
|
dealloc:
|
||||||
free(androidlocation);
|
free(androidlocation);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -147,7 +146,7 @@ static double android_location_get_longitude(void *data)
|
|||||||
return longitude;
|
return longitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void android_location_set_interval(void *data, int interval_ms, int interval_distance)
|
static void android_location_set_interval(void *data, unsigned interval_ms, unsigned interval_distance)
|
||||||
{
|
{
|
||||||
struct android_app *android_app = (struct android_app*)g_android;
|
struct android_app *android_app = (struct android_app*)g_android;
|
||||||
androidlocation_t *androidlocation = (androidlocation_t*)data;
|
androidlocation_t *androidlocation = (androidlocation_t*)data;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user