diff options
author | Mattias Andrée <m@maandree.se> | 2025-03-21 16:50:15 +0100 |
---|---|---|
committer | Mattias Andrée <m@maandree.se> | 2025-03-21 16:50:15 +0100 |
commit | 96a6575e23b5baebcdd38269b80f47cc02a2627e (patch) | |
tree | 0561580306c882e0e7a4f76c542130bb7ee44537 /src/location-corelocation.m | |
parent | Refactor (diff) | |
download | redshift-ng-96a6575e23b5baebcdd38269b80f47cc02a2627e.tar.gz redshift-ng-96a6575e23b5baebcdd38269b80f47cc02a2627e.tar.bz2 redshift-ng-96a6575e23b5baebcdd38269b80f47cc02a2627e.tar.xz |
Refactor
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to 'src/location-corelocation.m')
-rw-r--r-- | src/location-corelocation.m | 52 |
1 files changed, 46 insertions, 6 deletions
diff --git a/src/location-corelocation.m b/src/location-corelocation.m index 9f45899..c53ed14 100644 --- a/src/location-corelocation.m +++ b/src/location-corelocation.m @@ -1,4 +1,5 @@ -/* redshift-ng - Automatically adjust display colour temperature according the Sun +/*- + * redshift-ng - Automatically adjust display colour temperature according the Sun * * Copyright (c) 2009-2018 Jon Lund Steffensen <jonlst@gmail.com> * Copyright (c) 2014-2016, 2025 Mattias Andrée <m@maandree.se> @@ -22,17 +23,53 @@ #import <CoreLocation/CoreLocation.h> +/** + * Location data + */ struct location_data { + /** + * The user's geographical location + */ struct location location; + + /** + * Whether the location provider is available + */ int available; + + /** + * Whether an unrecoverable error has occurred + */ int error; }; + struct location_state { + /** + * Slave thread, used to receive location updates + */ NSThread *thread; + + /** + * Read-end of piped used to send location data + * from the slave thread to the master thread + */ int pipe_fd_read; + + /** + * Write-end of piped used to send location data + * from the slave thread to the master thread + */ int pipe_fd_write; + + /** + * Location data available from the slave thread + */ struct location_data data; + + /** + * Location data sent to the master thread + */ struct location_data saved_data; }; @@ -136,6 +173,7 @@ pipe_close_callback(CFFileDescriptorRef fdref, CFOptionFlags callBackTypes, void @property (nonatomic) struct location_state *state; @end + @implementation LocationThread; // Run loop for location provider thread. @@ -177,6 +215,7 @@ corelocation_create(struct location_state **state_out) return 0; } + static int corelocation_start(struct location_state *state) { @@ -192,11 +231,7 @@ corelocation_start(struct location_state *state) state->data.location.lon = 0; state->saved_data = state->data; - if (pipe_rdnonblock(pipefds)) { - weprintf(_("Failed to start CoreLocation provider!")); - return -1; - } - + pipe_rdnonblock(pipefds); state->pipe_fd_read = pipefds[0]; state->pipe_fd_write = pipefds[1]; @@ -210,6 +245,7 @@ corelocation_start(struct location_state *state) return 0; } + static void corelocation_free(struct location_state *state) { @@ -218,6 +254,7 @@ corelocation_free(struct location_state *state) free(state); } + static void corelocation_print_help(FILE *f) { @@ -225,6 +262,7 @@ corelocation_print_help(FILE *f) fputs("\n", f); } + static int corelocation_set_option(struct location_state *state, const char *key, const char *value) { @@ -234,12 +272,14 @@ corelocation_set_option(struct location_state *state, const char *key, const cha return -1; } + static int corelocation_get_fd(struct location_state *state) { return state->pipe_fd_read; } + static int corelocation_fetch(struct location_state *state, struct location *location_out, int *available_out) { |