aboutsummaryrefslogtreecommitdiffstats
path: root/src/location-geoclue2.c
diff options
context:
space:
mode:
authorMattias Andrée <m@maandree.se>2025-03-05 19:26:58 +0100
committerMattias Andrée <m@maandree.se>2025-03-05 19:26:58 +0100
commitb42c9662303d1a33ebe038d1895c08945cdbd40f (patch)
treec05b169b1d28e8d42b111290f9181d2cbad1138b /src/location-geoclue2.c
parentMerge redshift.h into common.h (diff)
downloadredshift-ng-b42c9662303d1a33ebe038d1895c08945cdbd40f.tar.gz
redshift-ng-b42c9662303d1a33ebe038d1895c08945cdbd40f.tar.bz2
redshift-ng-b42c9662303d1a33ebe038d1895c08945cdbd40f.tar.xz
Cleanup and style update (avoid typedef)
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to 'src/location-geoclue2.c')
-rw-r--r--src/location-geoclue2.c66
1 files changed, 26 insertions, 40 deletions
diff --git a/src/location-geoclue2.c b/src/location-geoclue2.c
index c6c2bda..835b4c4 100644
--- a/src/location-geoclue2.c
+++ b/src/location-geoclue2.c
@@ -15,32 +15,18 @@
along with Redshift. If not, see <http://www.gnu.org/licenses/>.
Copyright (c) 2014-2017 Jon Lund Steffensen <jonlst@gmail.com>
+ Copyright (c) 2025 Mattias Andrée <m@maandree.se>
*/
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
+#include "common.h"
#include <glib.h>
#include <glib/gprintf.h>
#include <gio/gio.h>
-#include "common.h"
-
-#ifdef ENABLE_NLS
-# include <libintl.h>
-# define _(s) gettext(s)
-#else
-# define _(s) s
-#endif
-
#define DBUS_ACCESS_ERROR "org.freedesktop.DBus.Error.AccessDenied"
-typedef struct {
+struct location_state {
GMainLoop *loop;
GThread *thread;
GMutex lock;
@@ -50,7 +36,7 @@ typedef struct {
int error;
float latitude;
float longitude;
-} location_geoclue2_state_t;
+};
/* Print the message explaining denial from GeoClue. */
@@ -67,7 +53,7 @@ print_denial_message()
/* Indicate an unrecoverable error during GeoClue2 communication. */
static void
-mark_error(location_geoclue2_state_t *state)
+mark_error(struct location_state *state)
{
g_mutex_lock(&state->lock);
@@ -84,7 +70,7 @@ geoclue_client_signal_cb(GDBusProxy *client, gchar *sender_name,
gchar *signal_name, GVariant *parameters,
gpointer user_data)
{
- location_geoclue2_state_t *state = user_data;
+ struct location_state *state = user_data;
/* Only handle LocationUpdated signals */
if (g_strcmp0(signal_name, "LocationUpdated") != 0) {
@@ -136,7 +122,7 @@ static void
on_name_appeared(GDBusConnection *conn, const gchar *name,
const gchar *name_owner, gpointer user_data)
{
- location_geoclue2_state_t *state = user_data;
+ struct location_state *state = user_data;
/* Obtain GeoClue Manager */
GError *error = NULL;
@@ -277,7 +263,7 @@ static void
on_name_vanished(GDBusConnection *connection, const gchar *name,
gpointer user_data)
{
- location_geoclue2_state_t *state = user_data;
+ struct location_state *state = user_data;
g_mutex_lock(&state->lock);
@@ -292,7 +278,7 @@ on_name_vanished(GDBusConnection *connection, const gchar *name,
static gboolean
on_pipe_closed(GIOChannel *channel, GIOCondition condition, gpointer user_data)
{
- location_geoclue2_state_t *state = user_data;
+ struct location_state *state = user_data;
g_main_loop_quit(state->loop);
return FALSE;
@@ -303,7 +289,7 @@ on_pipe_closed(GIOChannel *channel, GIOCondition condition, gpointer user_data)
static void *
run_geoclue2_loop(void *state_)
{
- location_geoclue2_state_t *state = state_;
+ struct location_state *state = state_;
GMainContext *context = g_main_context_new();
g_main_context_push_thread_default(context);
@@ -340,18 +326,18 @@ run_geoclue2_loop(void *state_)
}
static int
-location_geoclue2_init(location_geoclue2_state_t **state)
+location_geoclue2_init(struct location_state **state)
{
#if !GLIB_CHECK_VERSION(2, 35, 0)
g_type_init();
#endif
- *state = malloc(sizeof(location_geoclue2_state_t));
+ *state = malloc(sizeof(struct location_state));
if (*state == NULL) return -1;
return 0;
}
static int
-location_geoclue2_start(location_geoclue2_state_t *state)
+location_geoclue2_start(struct location_state *state)
{
state->pipe_fd_read = -1;
state->pipe_fd_write = -1;
@@ -380,7 +366,7 @@ location_geoclue2_start(location_geoclue2_state_t *state)
}
static void
-location_geoclue2_free(location_geoclue2_state_t *state)
+location_geoclue2_free(struct location_state *state)
{
if (state->pipe_fd_read != -1) {
close(state->pipe_fd_read);
@@ -404,7 +390,7 @@ location_geoclue2_print_help(FILE *f)
}
static int
-location_geoclue2_set_option(location_geoclue2_state_t *state,
+location_geoclue2_set_option(struct location_state *state,
const char *key, const char *value)
{
fprintf(stderr, _("Unknown method parameter: `%s'.\n"), key);
@@ -412,15 +398,15 @@ location_geoclue2_set_option(location_geoclue2_state_t *state,
}
static int
-location_geoclue2_get_fd(location_geoclue2_state_t *state)
+location_geoclue2_get_fd(struct location_state *state)
{
return state->pipe_fd_read;
}
static int
location_geoclue2_handle(
- location_geoclue2_state_t *state,
- location_t *location, int *available)
+ struct location_state *state,
+ struct location *location, int *available)
{
pipeutils_handle_signal(state->pipe_fd_read);
@@ -439,13 +425,13 @@ location_geoclue2_handle(
}
-const location_provider_t geoclue2_location_provider = {
+const struct location_provider 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
+ &location_geoclue2_init,
+ &location_geoclue2_start,
+ &location_geoclue2_free,
+ &location_geoclue2_print_help,
+ &location_geoclue2_set_option,
+ &location_geoclue2_get_fd,
+ &location_geoclue2_handle
};