From e983aa4c35e763dea3462d03ef8d1af93231736c Mon Sep 17 00:00:00 2001 From: twinaphex Date: Thu, 19 Dec 2013 03:37:26 +0100 Subject: [PATCH] (Location) Implement stub Android location driver - will still need a couple of functions filled in --- apple/common/RAGameView.m | 26 +++++- driver.c | 1 + driver.h | 1 + griffin/griffin.c | 5 ++ location/android.c | 165 ++++++++++++++++++++++++++++++++++++++ settings.c | 2 - 6 files changed, 194 insertions(+), 6 deletions(-) create mode 100644 location/android.c diff --git a/apple/common/RAGameView.m b/apple/common/RAGameView.m index dd8fe0506e..c5e38d644d 100644 --- a/apple/common/RAGameView.m +++ b/apple/common/RAGameView.m @@ -314,6 +314,17 @@ didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer } #endif +- (void)onLocationSetInterval:(int)interval_update_ms interval_update_distance:(int)interval_distance +{ + (void)interval_update_ms; + + // Set a movement threshold for new events (in meters). + if (interval_distance == 0) + locationManager.distanceFilter = 500; + else + locationManager.distanceFilter = interval_distance; +} + - (void)onLocationInit:(int)interval_update_ms interval_update_distance:(int)interval_distance { // Create the location manager if this object does not @@ -323,9 +334,8 @@ didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer locationManager.delegate = self; locationManager.desiredAccuracy = kCLLocationAccuracyBest; - - // Set a movement threshold for new events. - locationManager.distanceFilter = 500; // meters - TODO - make configurable + + [[RAGameView get] onLocationSetInterval:interval_update_ms interval_update_distance:interval_distance]; } - (void)onLocationStart @@ -701,6 +711,13 @@ static void *apple_location_init(int interval_update_ms, int interval_distance) return applelocation; } +static void *apple_location_set_interval(void *data, int interval_update_ms, int interval_distance) +{ + (void)data; + + [[RAGameView get] onLocationSetInterval:interval_update_ms interval_update_distance:interval_distance]; +} + static void apple_location_free(void *data) { applelocation_t *applelocation = (applelocation_t*)data; @@ -749,6 +766,7 @@ const location_driver_t location_apple = { apple_location_stop, apple_location_get_longitude, apple_location_get_latitude, + apple_location_set_interval, "apple", }; -#endif \ No newline at end of file +#endif diff --git a/driver.c b/driver.c index d6f98c362c..153178d874 100644 --- a/driver.c +++ b/driver.c @@ -301,6 +301,7 @@ void find_next_camera_driver(void) #ifdef HAVE_LOCATION static const location_driver_t *location_drivers[] = { #ifdef ANDROID + &location_android, #endif #ifdef IOS &location_apple, diff --git a/driver.h b/driver.h index 137ee8f59b..a2cf09c883 100644 --- a/driver.h +++ b/driver.h @@ -377,6 +377,7 @@ typedef struct location_driver double (*get_longitude)(void *data); double (*get_latitude)(void *data); + void (*set_interval)(int interval_msecs, int interval_distance); const char *ident; } location_driver_t; diff --git a/griffin/griffin.c b/griffin/griffin.c index 12d15444a4..8f1be287de 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -373,6 +373,11 @@ CAMERA LOCATION ============================================================ */ #ifdef HAVE_LOCATION + +#if defined(ANDROID) +#include "../location/android.c" +#endif + #endif /*============================================================ diff --git a/location/android.c b/location/android.c new file mode 100644 index 0000000000..6e6bf3d984 --- /dev/null +++ b/location/android.c @@ -0,0 +1,165 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2013 - Hans-Kristian Arntzen + * Copyright (C) 2011-2013 - 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 "../driver.h" +#include "../android/native/jni/jni_macros.h" + +typedef struct android_location +{ + jmethodID onLocationInit; + jmethodID onLocationFree; + jmethodID onLocationStart; + jmethodID onLocationStop; + jmethodID onLocationSetInterval; + jmethodID onLocationGetLongitude; + jmethodID onLocationGetLatitude; +} androidlocation_t; + +static void *android_location_init(unsigned interval_ms, unsigned interval_distance) +{ + 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)); + if (!androidlocation) + return NULL; + + env = jni_thread_getenv(); + if (!env) + goto dealloc; + + GET_OBJECT_CLASS(env, class, android_app->activity->clazz); + if (class == NULL) + goto dealloc; + +#if 0 + /* TODO */ + GET_METHOD_ID(env, androidcamera->onCameraInit, class, "onCameraInit", "()V"); + if (!androidcamera->onCameraInit) + goto dealloc; +#endif + + GET_METHOD_ID(env, androidlocation->onLocationFree, class, "onLocationFree", "()V"); + if (!androidlocation->onLocationFree) + goto dealloc; + + GET_METHOD_ID(env, androidlocation->onLocationStart, class, "onLocationStart", "()V"); + if (!androidlocation->onLocationStart) + goto dealloc; + + GET_METHOD_ID(env, androidlocation->onLocationStop, class, "onLocationStop", "()V"); + if (!androidlocation->onLocationStop) + goto dealloc; + + /* TODO - grab method IDs for: + * onLocationGetLatitude + * onLocationGetLongitude + * onLocationSetInterval + */ + + CALL_VOID_METHOD(env, android_app->activity->clazz, androidlocation->onLocationInit); + + return androidlocation; +dealloc: + free(androidlocation); + return NULL; +} + +static void android_location_free(void *data) +{ + struct android_app *android_app = (struct android_app*)g_android; + androidlocation_t *androidlocation = (androidlocation_t*)data; + JNIEnv *env = jni_thread_getenv(); + if (!env) + return; + + CALL_VOID_METHOD(env, android_app->activity->clazz, androidlocation->onLocationFree); + + free(androidlocation); +} + +static bool android_camera_start(void *data) +{ + struct android_app *android_app = (struct android_app*)g_android; + androidlocation_t *androidlocation = (androidlocation_t*)data; + JNIEnv *env = jni_thread_getenv(); + if (!env) + return false; + + CALL_VOID_METHOD(env, android_app->activity->clazz, androidlocation->onLocationStart); + + return true; +} + +static void android_location_stop(void *data) +{ + struct android_app *android_app = (struct android_app*)g_android; + androidlocation_t *androidlocation = (androidlocation_t*)data; + JNIEnv *env = jni_thread_getenv(); + if (!env) + return; + + CALL_VOID_METHOD(env, android_app->activity->clazz, androidlocation->onLocationStop); +} + +static double android_location_get_latitude(void *data) +{ + struct android_app *android_app = (struct android_app*)g_android; + androidlocation_t *androidlocation = (androidlocation_t*)data; + JNIEnv *env = jni_thread_getenv(); + if (!env) + return; + + // TODO - CALL_DOUBLE_METHOD - onLocationGetLatitude + return 0.0f; +} + +static double android_location_get_longitude(void *data) +{ + struct android_app *android_app = (struct android_app*)g_android; + androidlocation_t *androidlocation = (androidlocation_t*)data; + JNIEnv *env = jni_thread_getenv(); + if (!env) + return; + + // TODO - CALL_DOUBLE_METHOD - onLocationGetLongitude + return 0.0f; +} + +static void android_location_set_interval(void *data, int interval_ms, int interval_distance) +{ + struct android_app *android_app = (struct android_app*)g_android; + androidlocation_t *androidlocation = (androidlocation_t*)data; + JNIEnv *env = jni_thread_getenv(); + if (!env) + return; + + // TODO - CALL_VOID_METHOD - onLocationSetInterval (with params) +} + +const location_driver_t location_android = { + android_location_init, + android_location_free, + android_location_start, + android_location_stop, + android_location_get_longitude, + android_location_get_latitude, + android_location_set_interval, + "android", +}; diff --git a/settings.c b/settings.c index ae972a203e..f22c8d1f13 100644 --- a/settings.c +++ b/settings.c @@ -189,12 +189,10 @@ const char *config_get_default_location(void) { switch (LOCATION_DEFAULT_DRIVER) { -#if 0 case LOCATION_ANDROID: return "android"; case LOCATION_APPLE: return "apple"; -#endif default: return NULL; }