aboutsummaryrefslogtreecommitdiffstats
path: root/src/location-geoclue2.c
diff options
context:
space:
mode:
authorJon Lund Steffensen <jonlst@gmail.com>2017-08-16 21:20:06 -0700
committerJon Lund Steffensen <jonlst@gmail.com>2017-08-17 19:52:29 -0700
commit153dec0e21530d52b8ee82f6ec588620ec0857d2 (patch)
treedbfe089e0766447ccf7f594f82f14e11a56bc805 /src/location-geoclue2.c
parentMerge pull request #498 from jonls/osx-travis (diff)
downloadredshift-ng-153dec0e21530d52b8ee82f6ec588620ec0857d2.tar.gz
redshift-ng-153dec0e21530d52b8ee82f6ec588620ec0857d2.tar.bz2
redshift-ng-153dec0e21530d52b8ee82f6ec588620ec0857d2.tar.xz
Change location providers to allow updates
Change location provider implementations so it is possible for location providers to dynamically update the location. This commit adds the interfaces and infrastructure in redshift.c but none of the location provides are changed to become dynamic.
Diffstat (limited to 'src/location-geoclue2.c')
-rw-r--r--src/location-geoclue2.c97
1 files changed, 53 insertions, 44 deletions
diff --git a/src/location-geoclue2.c b/src/location-geoclue2.c
index abccbd3..ab57535 100644
--- a/src/location-geoclue2.c
+++ b/src/location-geoclue2.c
@@ -14,7 +14,7 @@
You should have received a copy of the GNU General Public License
along with Redshift. If not, see <http://www.gnu.org/licenses/>.
- Copyright (c) 2014 Jon Lund Steffensen <jonlst@gmail.com>
+ Copyright (c) 2014-2017 Jon Lund Steffensen <jonlst@gmail.com>
*/
#include <stdio.h>
@@ -39,50 +39,11 @@ typedef struct {
GMainLoop *loop;
int available;
+ int error;
location_t location;
} get_location_data_t;
-int
-location_geoclue2_init(void *state)
-{
-#if !GLIB_CHECK_VERSION(2, 35, 0)
- g_type_init();
-#endif
- return 0;
-}
-
-int
-location_geoclue2_start(void *state)
-{
- return 0;
-}
-
-void
-location_geoclue2_free(void *state)
-{
-}
-
-void
-location_geoclue2_print_help(FILE *f)
-{
- fputs(_("Use the location as discovered by a GeoClue2 provider.\n"), f);
- fputs("\n", f);
-
- fprintf(f, _("NOTE: currently Redshift doesn't recheck %s once started,\n"
- "which means it has to be restarted to take notice after travel.\n"),
- "GeoClue2");
- fputs("\n", f);
-}
-
-int
-location_geoclue2_set_option(void *state,
- const char *key, const char *value)
-{
- fprintf(stderr, _("Unknown method parameter: `%s'.\n"), key);
- return -1;
-}
-
/* Handle position change callbacks */
static void
geoclue_client_signal_cb(GDBusProxy *client, gchar *sender_name,
@@ -267,16 +228,63 @@ on_name_vanished(GDBusConnection *connection, const gchar *name,
get_location_data_t *data = (get_location_data_t *)user_data;
g_fprintf(stderr, _("Unable to connect to GeoClue.\n"));
+ data->error = 1;
g_main_loop_quit(data->loop);
}
int
-location_geoclue2_get_location(void *state,
- location_t *location)
+location_geoclue2_init(void *state)
+{
+#if !GLIB_CHECK_VERSION(2, 35, 0)
+ g_type_init();
+#endif
+ return 0;
+}
+
+int
+location_geoclue2_start(void *state)
+{
+ return 0;
+}
+
+void
+location_geoclue2_free(void *state)
+{
+}
+
+void
+location_geoclue2_print_help(FILE *f)
+{
+ fputs(_("Use the location as discovered by a GeoClue2 provider.\n"), f);
+ fputs("\n", f);
+
+ fprintf(f, _("NOTE: currently Redshift doesn't recheck %s once started,\n"
+ "which means it has to be restarted to take notice after travel.\n"),
+ "GeoClue2");
+ fputs("\n", f);
+}
+
+int
+location_geoclue2_set_option(void *state,
+ const char *key, const char *value)
+{
+ fprintf(stderr, _("Unknown method parameter: `%s'.\n"), key);
+ return -1;
+}
+
+int
+location_geoclue2_get_fd(void *state)
+{
+ return -1;
+}
+
+int
+location_geoclue2_handle(void *state, location_t *location, int *available)
{
get_location_data_t data;
data.available = 0;
+ data.error = 0;
guint watcher_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
"org.freedesktop.GeoClue2",
@@ -289,8 +297,9 @@ location_geoclue2_get_location(void *state,
g_bus_unwatch_name(watcher_id);
- if (!data.available) return -1;
+ if (data.error) return -1;
+ *available = data.available;
*location = data.location;
return 0;