diff options
Diffstat (limited to 'src/location-geoclue2.c')
-rw-r--r-- | src/location-geoclue2.c | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/src/location-geoclue2.c b/src/location-geoclue2.c index 6ebedb4..696867e 100644 --- a/src/location-geoclue2.c +++ b/src/location-geoclue2.c @@ -38,6 +38,19 @@ #define DBUS_ACCESS_ERROR "org.freedesktop.DBus.Error.AccessDenied" +typedef struct { + GMainLoop *loop; + GThread *thread; + GMutex lock; + int pipe_fd_read; + int pipe_fd_write; + int available; + int error; + float latitude; + float longitude; +} location_geoclue2_state_t; + + /* Print the message explaining denial from GeoClue. */ static void print_denial_message() @@ -285,7 +298,7 @@ on_pipe_closed(GIOChannel *channel, GIOCondition condition, gpointer user_data) /* Run loop for location provider thread. */ -void * +static void * run_geoclue2_loop(void *state_) { location_geoclue2_state_t *state = state_; @@ -324,16 +337,18 @@ run_geoclue2_loop(void *state_) return NULL; } -int -location_geoclue2_init(location_geoclue2_state_t *state) +static int +location_geoclue2_init(location_geoclue2_state_t **state) { #if !GLIB_CHECK_VERSION(2, 35, 0) g_type_init(); #endif + *state = malloc(sizeof(location_geoclue2_state_t)); + if (*state == NULL) return -1; return 0; } -int +static int location_geoclue2_start(location_geoclue2_state_t *state) { state->pipe_fd_read = -1; @@ -362,7 +377,7 @@ location_geoclue2_start(location_geoclue2_state_t *state) return 0; } -void +static void location_geoclue2_free(location_geoclue2_state_t *state) { if (state->pipe_fd_read != -1) { @@ -374,9 +389,11 @@ location_geoclue2_free(location_geoclue2_state_t *state) state->thread = NULL; g_mutex_clear(&state->lock); + + free(state); } -void +static void location_geoclue2_print_help(FILE *f) { fputs(_("Use the location as discovered by a GeoClue2 provider.\n"), @@ -384,7 +401,7 @@ location_geoclue2_print_help(FILE *f) fputs("\n", f); } -int +static int location_geoclue2_set_option(location_geoclue2_state_t *state, const char *key, const char *value) { @@ -392,13 +409,13 @@ location_geoclue2_set_option(location_geoclue2_state_t *state, return -1; } -int +static int location_geoclue2_get_fd(location_geoclue2_state_t *state) { return state->pipe_fd_read; } -int +static int location_geoclue2_handle( location_geoclue2_state_t *state, location_t *location, int *available) @@ -418,3 +435,15 @@ location_geoclue2_handle( return 0; } + + +const location_provider_t geoclue2_location_provider = { + "geoclue2", + (location_provider_init_func *)location_geoclue2_init, + (location_provider_start_func *)location_geoclue2_start, + (location_provider_free_func *)location_geoclue2_free, + (location_provider_print_help_func *)location_geoclue2_print_help, + (location_provider_set_option_func *)location_geoclue2_set_option, + (location_provider_get_fd_func *)location_geoclue2_get_fd, + (location_provider_handle_func *)location_geoclue2_handle +}; |