diff options
Diffstat (limited to 'src/location-geoclue2.c')
-rw-r--r-- | src/location-geoclue2.c | 56 |
1 files changed, 32 insertions, 24 deletions
diff --git a/src/location-geoclue2.c b/src/location-geoclue2.c index 329348e..773e99d 100644 --- a/src/location-geoclue2.c +++ b/src/location-geoclue2.c @@ -70,6 +70,10 @@ geoclue_client_signal_cb(GDBusProxy *client, gchar *sender_name, gpointer user_data) { struct location_state *state = user_data; + const gchar *location_path; + GDBusProxy *location; + GError *error; + GVariant *lat_v, *lon_v; /* Only handle LocationUpdated signals */ if (g_strcmp0(signal_name, "LocationUpdated") != 0) { @@ -77,12 +81,11 @@ geoclue_client_signal_cb(GDBusProxy *client, gchar *sender_name, } /* Obtain location path */ - const gchar *location_path; g_variant_get_child(parameters, 1, "&o", &location_path); /* Obtain location */ - GError *error = NULL; - GDBusProxy *location = g_dbus_proxy_new_sync( + error = NULL; + location = g_dbus_proxy_new_sync( g_dbus_proxy_get_connection(client), G_DBUS_PROXY_FLAGS_NONE, NULL, @@ -101,12 +104,10 @@ geoclue_client_signal_cb(GDBusProxy *client, gchar *sender_name, g_mutex_lock(&state->lock); /* Read location properties */ - GVariant *lat_v = g_dbus_proxy_get_cached_property( - location, "Latitude"); + lat_v = g_dbus_proxy_get_cached_property(location, "Latitude"); state->location.lat = g_variant_get_double(lat_v); - GVariant *lon_v = g_dbus_proxy_get_cached_property( - location, "Longitude"); + lon_v = g_dbus_proxy_get_cached_property(location, "Longitude"); state->location.lon = g_variant_get_double(lon_v); state->available = 1; @@ -122,10 +123,16 @@ on_name_appeared(GDBusConnection *conn, const gchar *name, const gchar *name_owner, gpointer user_data) { struct location_state *state = user_data; + const gchar *client_path; + GDBusProxy *geoclue_client; + GVariant *client_path_v; + GDBusProxy *geoclue_manager; + GError *error; + GVariant *ret_v; /* Obtain GeoClue Manager */ - GError *error = NULL; - GDBusProxy *geoclue_manager = g_dbus_proxy_new_sync( + error = NULL; + geoclue_manager = g_dbus_proxy_new_sync( conn, G_DBUS_PROXY_FLAGS_NONE, NULL, @@ -143,7 +150,7 @@ on_name_appeared(GDBusConnection *conn, const gchar *name, /* Obtain GeoClue Client path */ error = NULL; - GVariant *client_path_v = + client_path_v = g_dbus_proxy_call_sync(geoclue_manager, "GetClient", NULL, @@ -158,12 +165,11 @@ on_name_appeared(GDBusConnection *conn, const gchar *name, return; } - const gchar *client_path; g_variant_get(client_path_v, "(&o)", &client_path); /* Obtain GeoClue client */ error = NULL; - GDBusProxy *geoclue_client = g_dbus_proxy_new_sync( + geoclue_client = g_dbus_proxy_new_sync( conn, G_DBUS_PROXY_FLAGS_NONE, NULL, @@ -185,7 +191,7 @@ on_name_appeared(GDBusConnection *conn, const gchar *name, /* Set desktop id (basename of the .desktop file) */ error = NULL; - GVariant *ret_v = g_dbus_proxy_call_sync( + ret_v = g_dbus_proxy_call_sync( geoclue_client, "org.freedesktop.DBus.Properties.Set", g_variant_new("(ssv)", @@ -289,12 +295,16 @@ static void * run_geoclue2_loop(void *state_) { struct location_state *state = state_; + GMainContext *context; + guint watcher_id; + GIOChannel *pipe_channel; + GSource *pipe_source; - GMainContext *context = g_main_context_new(); + context = g_main_context_new(); g_main_context_push_thread_default(context); state->loop = g_main_loop_new(context, FALSE); - guint watcher_id = g_bus_watch_name( + watcher_id = g_bus_watch_name( G_BUS_TYPE_SYSTEM, "org.freedesktop.GeoClue2", G_BUS_NAME_WATCHER_FLAGS_AUTO_START, @@ -303,11 +313,9 @@ run_geoclue2_loop(void *state_) state, NULL); /* Listen for closure of pipe */ - GIOChannel *pipe_channel = g_io_channel_unix_new(state->pipe_fd_write); - GSource *pipe_source = g_io_create_watch( - pipe_channel, G_IO_IN | G_IO_HUP | G_IO_ERR); - g_source_set_callback( - pipe_source, (GSourceFunc)on_pipe_closed, state, NULL); + pipe_channel = g_io_channel_unix_new(state->pipe_fd_write); + pipe_source = g_io_create_watch(pipe_channel, G_IO_IN | G_IO_HUP | G_IO_ERR); + g_source_set_callback(pipe_source, (GSourceFunc)on_pipe_closed, state, NULL); g_source_attach(pipe_source, context); g_main_loop_run(state->loop); @@ -330,7 +338,7 @@ location_geoclue2_init(struct location_state **state) #if !GLIB_CHECK_VERSION(2, 35, 0) g_type_init(); #endif - *state = malloc(sizeof(struct location_state)); + *state = malloc(sizeof(**state)); if (*state == NULL) return -1; return 0; } @@ -338,6 +346,8 @@ location_geoclue2_init(struct location_state **state) static int location_geoclue2_start(struct location_state *state) { + int pipefds[2]; + state->pipe_fd_read = -1; state->pipe_fd_write = -1; @@ -346,9 +356,7 @@ location_geoclue2_start(struct location_state *state) state->location.lat = 0; state->location.lon = 0; - int pipefds[2]; - int r = pipeutils_create_nonblocking(pipefds); - if (r < 0) { + if (pipeutils_create_nonblocking(pipefds)) { fputs(_("Failed to start GeoClue2 provider!\n"), stderr); return -1; } |