Commit 73628833 authored by Jussi Kukkonen's avatar Jussi Kukkonen

sort providers by accuracy in Master

parent df764fee
...@@ -99,8 +99,7 @@ gc_iface_master_client_set_requirements (GcMasterClient *client, ...@@ -99,8 +99,7 @@ gc_iface_master_client_set_requirements (GcMasterClient *client,
// TODO: should have a return value to indicate provider existence? // TODO: should have a return value to indicate provider existence?
} else { } else {
/* TODO select which provider/interface to use out of the possible ones /* choose the most accurate provider (first one) */
* Now using the first one */
client->position_provider = providers->data; client->position_provider = providers->data;
g_signal_connect (G_OBJECT (client->position_provider), g_signal_connect (G_OBJECT (client->position_provider),
...@@ -122,12 +121,11 @@ gc_iface_master_client_set_requirements (GcMasterClient *client, ...@@ -122,12 +121,11 @@ gc_iface_master_client_set_requirements (GcMasterClient *client,
// TODO: should have a return value to indicate provider existence? // TODO: should have a return value to indicate provider existence?
} else { } else {
/* TODO select which provider/interface to use out of the possible ones /* choose the most accurate provider (first one) */
* Now using the first one */
client->address_provider = providers->data; client->address_provider = providers->data;
g_signal_connect (G_OBJECT (client->address_provider), g_signal_connect (G_OBJECT (client->address_provider),
"position-changed", "address-changed",
G_CALLBACK (address_changed), G_CALLBACK (address_changed),
client); client);
......
...@@ -820,7 +820,6 @@ gc_master_provider_network_status_changed (GcMasterProvider *provider, ...@@ -820,7 +820,6 @@ gc_master_provider_network_status_changed (GcMasterProvider *provider,
provider_status_changed (priv->geoclue, status, provider); provider_status_changed (priv->geoclue, status, provider);
/* update position cache */
/* FIXME what should happen when net is down: /* FIXME what should happen when net is down:
* should position cache be updated ? */ * should position cache be updated ? */
if (status == GEOCLUE_STATUS_AVAILABLE) { if (status == GEOCLUE_STATUS_AVAILABLE) {
...@@ -828,3 +827,14 @@ gc_master_provider_network_status_changed (GcMasterProvider *provider, ...@@ -828,3 +827,14 @@ gc_master_provider_network_status_changed (GcMasterProvider *provider,
} }
} }
} }
/* GCompareFunc for sorting providers by accuracy */
gint
gc_master_provider_compare_by_accuracy (GcMasterProvider *a,
GcMasterProvider *b)
{
GcMasterProviderPrivate *priv_a = GET_PRIVATE (a);
GcMasterProviderPrivate *priv_b = GET_PRIVATE (b);
return priv_b->accuracy_level - priv_a->accuracy_level;
}
...@@ -44,6 +44,8 @@ GType gc_master_provider_get_type (void); ...@@ -44,6 +44,8 @@ GType gc_master_provider_get_type (void);
GcMasterProvider *gc_master_provider_new (const char *filename, GcMasterProvider *gc_master_provider_new (const char *filename,
gboolean network_status_events); gboolean network_status_events);
gint gc_master_provider_compare_by_accuracy (GcMasterProvider *a, GcMasterProvider *b);
gboolean gc_master_provider_is_good (GcMasterProvider *provider, gboolean gc_master_provider_is_good (GcMasterProvider *provider,
GcInterfaceFlags iface_types, GcInterfaceFlags iface_types,
GeoclueAccuracyLevel min_accuracy, GeoclueAccuracyLevel min_accuracy,
......
...@@ -114,7 +114,9 @@ gc_master_add_new_provider (GcMaster *master, ...@@ -114,7 +114,9 @@ gc_master_add_new_provider (GcMaster *master,
return; return;
} }
providers = g_list_prepend (providers, provider); providers = g_list_insert_sorted
(providers, provider,
(GCompareFunc)gc_master_provider_compare_by_accuracy);
} }
/* Scan a directory for .provider files */ /* Scan a directory for .provider files */
...@@ -231,8 +233,6 @@ gc_master_get_providers (GcInterfaceFlags iface_type, ...@@ -231,8 +233,6 @@ gc_master_get_providers (GcInterfaceFlags iface_type,
return NULL; return NULL;
} }
/* we should probably return in some order?
* accuracy? */
for (l = providers; l; l = l->next) { for (l = providers; l; l = l->next) {
GcMasterProvider *provider = l->data; GcMasterProvider *provider = l->data;
...@@ -245,5 +245,6 @@ gc_master_get_providers (GcInterfaceFlags iface_type, ...@@ -245,5 +245,6 @@ gc_master_get_providers (GcInterfaceFlags iface_type,
} }
} }
/* return most accurate first */
return g_list_reverse (p); return g_list_reverse (p);
} }
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