Commit ae4b0728 authored by Zeeshan Ali's avatar Zeeshan Ali

service: Allow disabling of all sources through config

Fixes #46.
parent 00a4e96d
......@@ -13,9 +13,30 @@ whitelist=@demo_agent@gnome-shell;io.elementary.desktop.agent-geoclue2
# Fetch location from NMEA sources on local network?
enable=true
# 3G source configuration options
[3g]
# Enable 3G source
enable=true
# CDMA source configuration options
[cdma]
# Enable CDMA source
enable=true
# Modem GPS source configuration options
[modem-gps]
# Enable Modem-GPS source
enable=true
# WiFi source configuration options
[wifi]
# Enable WiFi source
enable=true
# URL to the wifi geolocation service. The key can currenty be anything, just
# needs to be present but that is likely going to change in future.
url=https://location.services.mozilla.com/v1/geolocate?key=geoclue
......
......@@ -58,6 +58,10 @@ struct _GClueConfigPrivate
char *wifi_url;
gboolean wifi_submit;
gboolean enable_nmea_source;
gboolean enable_3g_source;
gboolean enable_cdma_source;
gboolean enable_modem_gps_source;
gboolean enable_wifi_source;
char *wifi_submit_url;
char *wifi_submit_nick;
......@@ -113,7 +117,9 @@ load_agent_config (GClueConfig *config)
static void
load_app_configs (GClueConfig *config)
{
const char *known_groups[] = { "agent", "wifi", "network-nmea", NULL };
const char *known_groups[] = { "agent", "wifi", "3g", "cdma",
"modem-gps", "network-nmea",
NULL };
GClueConfigPrivate *priv = config->priv;
gsize num_groups = 0, i;
char **groups;
......@@ -182,6 +188,32 @@ error_out:
g_strfreev (groups);
}
static gboolean
load_enable_source_config (GClueConfig *config,
const char *source_name)
{
GClueConfigPrivate *priv = config->priv;
GError *error = NULL;
gboolean enable;
enable = g_key_file_get_boolean (priv->key_file,
source_name,
"enable",
&error);
if (error != NULL) {
g_debug ("Failed to get config %s/enable:"
" %s",
source_name,
error->message);
g_error_free (error);
/* Source should be enabled by default */
return TRUE;
}
return enable;
}
#define DEFAULT_WIFI_URL "https://location.services.mozilla.com/v1/geolocate?key=geoclue"
#define DEFAULT_WIFI_SUBMIT_URL "https://location.services.mozilla.com/v1/submit?key=geoclue"
......@@ -191,6 +223,8 @@ load_wifi_config (GClueConfig *config)
GClueConfigPrivate *priv = config->priv;
GError *error = NULL;
priv->enable_wifi_source = load_enable_source_config (config, "wifi");
priv->wifi_url = g_key_file_get_string (priv->key_file,
"wifi",
"url",
......@@ -234,23 +268,31 @@ load_wifi_config (GClueConfig *config)
}
static void
load_network_nmea_config (GClueConfig *config)
load_3g_config (GClueConfig *config)
{
GClueConfigPrivate *priv = config->priv;
GError *error = NULL;
config->priv->enable_3g_source =
load_enable_source_config (config, "3g");
}
priv->enable_nmea_source = g_key_file_get_boolean (priv->key_file,
"network-nmea",
"enable",
&error);
if (error != NULL) {
g_debug ("Failed to get config network-nmea/enable:"
" %s",
error->message);
g_error_free (error);
static void
load_cdma_config (GClueConfig *config)
{
config->priv->enable_cdma_source =
load_enable_source_config (config, "cdma");
}
return;
}
static void
load_modem_gps_config (GClueConfig *config)
{
config->priv->enable_modem_gps_source =
load_enable_source_config (config, "modem-gps");
}
static void
load_network_nmea_config (GClueConfig *config)
{
config->priv->enable_nmea_source =
load_enable_source_config (config, "network-nmea");
}
static void
......@@ -278,6 +320,9 @@ gclue_config_init (GClueConfig *config)
load_agent_config (config);
load_app_configs (config);
load_wifi_config (config);
load_3g_config (config);
load_cdma_config (config);
load_modem_gps_config (config);
load_network_nmea_config (config);
}
......@@ -412,6 +457,30 @@ gclue_config_get_wifi_submit_data (GClueConfig *config)
return config->priv->wifi_submit;
}
gboolean
gclue_config_get_enable_wifi_source (GClueConfig *config)
{
return config->priv->enable_wifi_source;
}
gboolean
gclue_config_get_enable_3g_source (GClueConfig *config)
{
return config->priv->enable_3g_source;
}
gboolean
gclue_config_get_enable_modem_gps_source (GClueConfig *config)
{
return config->priv->enable_modem_gps_source;
}
gboolean
gclue_config_get_enable_cdma_source (GClueConfig *config)
{
return config->priv->enable_cdma_source;
}
gboolean
gclue_config_get_enable_nmea_source (GClueConfig *config)
{
......
......@@ -79,6 +79,11 @@ const char * gclue_config_get_wifi_submit_nick (GClueConfig *config
void gclue_config_set_wifi_submit_nick (GClueConfig *config,
const char *nick);
gboolean gclue_config_get_wifi_submit_data (GClueConfig *config);
gboolean gclue_config_get_enable_wifi_source (GClueConfig *config);
gboolean gclue_config_get_enable_3g_source (GClueConfig *config);
gboolean gclue_config_get_enable_cdma_source (GClueConfig *config);
gboolean gclue_config_get_enable_modem_gps_source
(GClueConfig *config);
gboolean gclue_config_get_enable_nmea_source (GClueConfig *config);
void gclue_config_set_wifi_submit_data (GClueConfig *config,
gboolean submit);
......
......@@ -332,29 +332,40 @@ gclue_locator_constructed (GObject *object)
{
GClueLocator *locator = GCLUE_LOCATOR (object);
GClueLocationSource *submit_source = NULL;
#if GCLUE_USE_NMEA_SOURCE
GClueConfig *gconfig = gclue_config_get_singleton ();
#endif
GClueWifi *wifi;
GList *node;
GClueMinUINT *threshold;
G_OBJECT_CLASS (gclue_locator_parent_class)->constructed (object);
#if GCLUE_USE_3G_SOURCE
GClue3G *source = gclue_3g_get_singleton ();
locator->priv->sources = g_list_append (locator->priv->sources, source);
if (gclue_config_get_enable_3g_source (gconfig)) {
GClue3G *source = gclue_3g_get_singleton ();
locator->priv->sources = g_list_append (locator->priv->sources,
source);
}
#endif
#if GCLUE_USE_CDMA_SOURCE
GClueCDMA *cdma = gclue_cdma_get_singleton ();
locator->priv->sources = g_list_append (locator->priv->sources, cdma);
if (gclue_config_get_enable_cdma_source (gconfig)) {
GClueCDMA *cdma = gclue_cdma_get_singleton ();
locator->priv->sources = g_list_append (locator->priv->sources,
cdma);
}
#endif
GClueWifi *wifi = gclue_wifi_get_singleton (locator->priv->accuracy_level);
locator->priv->sources = g_list_append (locator->priv->sources,
wifi);
if (gclue_config_get_enable_wifi_source (gconfig))
wifi = gclue_wifi_get_singleton (locator->priv->accuracy_level);
else
/* City-level accuracy will give us GeoIP-only source */
wifi = gclue_wifi_get_singleton (GCLUE_ACCURACY_LEVEL_CITY);
locator->priv->sources = g_list_append (locator->priv->sources, wifi);
#if GCLUE_USE_MODEM_GPS_SOURCE
GClueModemGPS *gps = gclue_modem_gps_get_singleton ();
locator->priv->sources = g_list_append (locator->priv->sources, gps);
submit_source = GCLUE_LOCATION_SOURCE (gps);
if (gclue_config_get_enable_modem_gps_source (gconfig)) {
GClueModemGPS *gps = gclue_modem_gps_get_singleton ();
locator->priv->sources = g_list_append (locator->priv->sources,
gps);
submit_source = GCLUE_LOCATION_SOURCE (gps);
}
#endif
#if GCLUE_USE_NMEA_SOURCE
if (gclue_config_get_enable_nmea_source (gconfig)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment