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:
Themaister 2013-12-19 10:15:55 +01:00
parent 031a9d05be
commit 855cb54def
6 changed files with 31 additions and 28 deletions

View File

@ -642,7 +642,7 @@ void driver_location_stop(void)
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)
driver.location->set_interval(driver.location_data, interval_msecs, interval_distance);
@ -779,7 +779,7 @@ void init_location(void)
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)
{
@ -837,14 +837,13 @@ void init_drivers(void)
#ifdef HAVE_CAMERA
// 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();
#endif
#ifdef HAVE_LOCATION
// FIXME
// 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();
#endif

View File

@ -369,7 +369,7 @@ typedef struct camera_driver
typedef struct location_driver
{
void *(*init)(int interval_msecs, int interval_distance);
void *(*init)(void);
void (*free)(void *data);
bool (*start)(void *data);
@ -377,7 +377,7 @@ typedef struct location_driver
double (*get_longitude)(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;
} location_driver_t;
@ -606,7 +606,7 @@ bool driver_location_start(void);
void driver_location_stop(void);
double driver_location_get_latitude(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
extern driver_t driver;

View File

@ -20,7 +20,7 @@
#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)

View File

@ -418,6 +418,12 @@ void uninit_libretro_sym(void)
// No longer valid.
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.
retro_perf_clear();
@ -832,6 +838,7 @@ bool rarch_environment_cb(unsigned cmd, void *data)
cb->start = driver_camera_start;
cb->stop = driver_camera_stop;
g_extern.system.camera_callback = *cb;
g_extern.camera_active = cb->caps != 0;
break;
}
#endif
@ -846,6 +853,7 @@ bool rarch_environment_cb(unsigned cmd, void *data)
cb->get_longitude = driver_location_get_longitude;
cb->set_interval = driver_location_set_interval;
g_extern.system.location_callback = *cb;
g_extern.location_active = true;
break;
}
#endif

View File

@ -749,32 +749,29 @@ struct retro_camera_callback
retro_camera_lifetime_status_t deinitialized;
};
//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
//interval_ms and interval_distance should be provided.
//interval_ms is the interval expressed in milliseconds
//interval_distance is the distance interval expressed in meters.
typedef void (*retro_location_set_interval_t)(int interval_ms, int interval_distance);
// 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
// interval_ms and interval_distance should be provided.
// interval_ms is the interval expressed in milliseconds.
// interval_distance is the distance interval expressed in meters.
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
//current location at regular intervals (which are defined with retro_location_set_interval_t).
// 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).
typedef bool (*retro_location_start_t)(void);
//Stop location services. The device will stop listening for changes to the current
//location.
// Stop location services. The device will stop listening for changes to the current
// location.
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);
//Get the longitude of the current location.
// Get the longitude of the current location.
typedef double (*retro_location_get_longitude_t)(void);
struct retro_location_callback
{
bool enable;
int interval_in_ms;
int interval_distance_in_meters;
retro_location_start_t start;
retro_location_stop_t stop;
retro_location_get_latitude_t get_latitude;

View File

@ -28,12 +28,10 @@ typedef struct android_location
jmethodID onLocationGetLatitude;
} androidlocation_t;
static void *android_location_init(int interval_ms, int interval_distance)
static void *android_location_init(void)
{
JNIEnv *env;
jclass class;
(void)interval_ms;
(void)interval_distance;
struct android_app *android_app = (struct android_app*)g_android;
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);
return androidlocation;
dealloc:
free(androidlocation);
return NULL;
@ -147,7 +146,7 @@ static double android_location_get_longitude(void *data)
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;
androidlocation_t *androidlocation = (androidlocation_t*)data;