summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAngus Ainslie <angus@akkea.ca>2020-12-18 14:32:42 +0000
committerAngus Ainslie <angus@akkea.ca>2021-01-09 08:57:29 -0800
commitd3f47cb10bb3f2262dd4b2caec29f2427efbcaa3 (patch)
treeccd5867c76f29e8877eac0cdafe81b559e62e0a9
parent6ebfc32f636b6e48ffab32c6286348166a351cd2 (diff)
downloadgeoclue-d3f47cb10bb3f2262dd4b2caec29f2427efbcaa3.tar.gz
src/gclue-nmea-source.c: add the Unix socket nmea source
gps-share can export a Unix socket so open that as an nmea source Signed-off-by: Angus Ainslie <angus@akkea.ca>
-rw-r--r--src/gclue-nmea-source.c40
1 files changed, 33 insertions, 7 deletions
diff --git a/src/gclue-nmea-source.c b/src/gclue-nmea-source.c
index bf0bea8..7461b79 100644
--- a/src/gclue-nmea-source.c
+++ b/src/gclue-nmea-source.c
@@ -34,6 +34,7 @@
#include <avahi-common/malloc.h>
#include <avahi-common/error.h>
#include <avahi-glib/glib-watch.h>
+#include <gio/gunixsocketaddress.h>
typedef struct AvahiServiceInfo AvahiServiceInfo;
@@ -202,6 +203,12 @@ add_new_service (GClueNMEASource *source,
GEnumClass *enum_class;
GEnumValue *enum_value;
+ if (port == 0) {
+ accuracy = GCLUE_ACCURACY_LEVEL_EXACT;
+
+ goto CREATE_SERVICE;
+ }
+
node = avahi_string_list_find (txt, "accuracy");
if (node == NULL) {
@@ -598,6 +605,8 @@ static void
connect_to_service (GClueNMEASource *source)
{
GClueNMEASourcePrivate *priv = source->priv;
+ GSocketAddress *addr;
+ GSocketConnectable *connectable;
if (priv->all_services == NULL)
return;
@@ -610,13 +619,23 @@ connect_to_service (GClueNMEASource *source)
*/
priv->active_service = (AvahiServiceInfo *) priv->all_services->data;
- g_socket_client_connect_to_host_async
- (priv->client,
- priv->active_service->host_name,
- priv->active_service->port,
- priv->cancellable,
- on_connection_to_location_server,
- source);
+ if ( priv->active_service->port != 0 )
+ g_socket_client_connect_to_host_async
+ (priv->client,
+ priv->active_service->host_name,
+ priv->active_service->port,
+ priv->cancellable,
+ on_connection_to_location_server,
+ source);
+ else {
+ addr = g_unix_socket_address_new(priv->active_service->host_name);
+ connectable = G_SOCKET_CONNECTABLE (addr);
+ g_socket_client_connect_async (priv->client,
+ connectable,
+ priv->cancellable,
+ on_connection_to_location_server,
+ source);
+ }
}
static void
@@ -693,6 +712,13 @@ gclue_nmea_source_init (GClueNMEASource *source)
config = gclue_config_get_singleton ();
nmea_socket = gclue_config_get_nmea_socket (config);
+ if (nmea_socket != NULL) {
+ add_new_service (source,
+ "nmea-socket",
+ nmea_socket,
+ 0,
+ NULL);
+ }
avahi_client_new (poll_api,
0,