Commit 9ee96f6a authored by Jussi Kukkonen's avatar Jussi Kukkonen

update web provider caches using g_idle_add + status fixes

Master initilization no longer updates all web provider caches,
this is done in later with g_idle_add. MasterProvider also sets
GEOCLUE_STATUS_ACQUIRING now.
parent c988d01b
......@@ -111,7 +111,7 @@ status_changed (GcMasterProvider *provider,
{
GcMasterClientPrivate *priv = GET_PRIVATE (client);
g_debug ("client: provider %s status changed", gc_master_provider_get_name (provider));
g_debug ("client: provider %s status changed: %d", gc_master_provider_get_name (provider), status);
/* change providers if needed (and if we're not choosing provider already) */
......@@ -310,7 +310,9 @@ gc_master_client_get_best_provider (GcMasterClient *client,
g_debug (" ...trying provider %s", gc_master_provider_get_name (provider));
if (gc_master_provider_subscribe (provider, client, iface)) {
/* provider was started, so accuracy may have changed
* (which re-sorts provider lists), restart provider selection */
(which re-sorts provider lists), restart provider selection */
/* TODO re-think this: restarting provider selection leads to potentially
never-ending looping */
g_debug (" ...started %s (status %d), re-starting provider selection",
gc_master_provider_get_name (provider),
gc_master_provider_get_status (provider));
......
......@@ -304,6 +304,50 @@ gc_master_provider_handle_error (GcMasterProvider *provider, GError *error)
}
}
/* Sets master_status based on provider status and net_status
* Should be called whenever priv->status or priv->net_status change */
static void
gc_master_provider_handle_status_change (GcMasterProvider *provider)
{
GcMasterProviderPrivate *priv = GET_PRIVATE (provider);
GeoclueStatus new_master_status;
/* calculate new master status */
if (priv->required_resources & GEOCLUE_RESOURCE_NETWORK ||
priv->provides & GEOCLUE_PROVIDE_CACHEABLE_ON_CONNECTION) {
switch (priv->net_status) {
case GEOCLUE_CONNECTIVITY_UNKNOWN:
/* falling through */
case GEOCLUE_CONNECTIVITY_OFFLINE:
new_master_status = GEOCLUE_STATUS_UNAVAILABLE;
break;
case GEOCLUE_CONNECTIVITY_ACQUIRING:
if (priv->status == GEOCLUE_STATUS_AVAILABLE){
new_master_status = GEOCLUE_STATUS_ACQUIRING;
} else {
new_master_status = priv->status;
}
break;
case GEOCLUE_CONNECTIVITY_ONLINE:
new_master_status = priv->status;
break;
default:
g_assert_not_reached ();
}
} else {
new_master_status = priv->status;
}
if (new_master_status != priv->master_status) {
priv->master_status = new_master_status;
g_signal_emit (provider, signals[STATUS_CHANGED], 0, new_master_status);
}
}
static void
gc_master_provider_update_cache (GcMasterProvider *provider)
{
......@@ -318,6 +362,8 @@ gc_master_provider_update_cache (GcMasterProvider *provider)
}
g_debug ("%s: Updating cache ", priv->name);
priv->master_status = GEOCLUE_STATUS_ACQUIRING;
g_signal_emit (provider, signals[STATUS_CHANGED], 0, priv->master_status);
if (priv->position) {
int timestamp;
......@@ -361,52 +407,10 @@ gc_master_provider_update_cache (GcMasterProvider *provider)
accuracy,
error);
}
}
/* Sets master_status based on provider status and net_status
* Should be called whenever priv->status or priv->net_status change */
static void
gc_master_provider_handle_status_change (GcMasterProvider *provider)
{
GcMasterProviderPrivate *priv = GET_PRIVATE (provider);
GeoclueStatus new_master_status;
/* calculate new master status */
if (priv->required_resources & GEOCLUE_RESOURCE_NETWORK ||
priv->provides & GEOCLUE_PROVIDE_CACHEABLE_ON_CONNECTION) {
switch (priv->net_status) {
case GEOCLUE_CONNECTIVITY_UNKNOWN:
/* falling through */
case GEOCLUE_CONNECTIVITY_OFFLINE:
new_master_status = GEOCLUE_STATUS_UNAVAILABLE;
break;
case GEOCLUE_CONNECTIVITY_ACQUIRING:
if (priv->status == GEOCLUE_STATUS_AVAILABLE){
new_master_status = GEOCLUE_STATUS_ACQUIRING;
} else {
new_master_status = priv->status;
}
break;
case GEOCLUE_CONNECTIVITY_ONLINE:
new_master_status = priv->status;
break;
default:
g_assert_not_reached ();
}
} else {
new_master_status = priv->status;
}
if (new_master_status != priv->master_status) {
priv->master_status = new_master_status;
g_signal_emit (provider, signals[STATUS_CHANGED], 0, new_master_status);
}
gc_master_provider_handle_status_change (provider);
}
/* signal handlers for the actual providers signals */
static void
......@@ -739,7 +743,7 @@ static gboolean
gc_master_provider_initialize (GcMasterProvider *provider)
{
GcMasterProviderPrivate *priv;
GError *error;
GError *error = NULL;
priv = GET_PRIVATE (provider);
......@@ -783,7 +787,6 @@ gc_master_provider_initialize (GcMasterProvider *provider)
gc_master_provider_initialize_interfaces (provider);
gc_master_provider_update_cache (provider);
gc_master_provider_handle_status_change (provider);
#if DEBUG_INFO
gc_master_provider_dump_provider_details (provider);
#endif
......@@ -831,6 +834,16 @@ network_status_changed (gpointer *connectivity,
}
}
/* for updating cache on providers that are not running */
static gboolean
update_cache_and_deinit (GcMasterProvider *provider)
{
/* fill cache */
gc_master_provider_initialize (provider);
gc_master_provider_deinitialize (provider);
return FALSE;
}
/* public methods (for GcMaster and GcMasterClient) */
......@@ -918,23 +931,19 @@ gc_master_provider_new (const char *filename,
g_strfreev (interfaces);
}
/* this could be done on idle handler ? */
if (priv->provides & GEOCLUE_PROVIDE_CACHEABLE_ON_CONNECTION &&
priv->net_status == GEOCLUE_CONNECTIVITY_ONLINE) {
/* fill cache */
gc_master_provider_initialize (provider);
gc_master_provider_deinitialize (provider);
/* do this as idle so we can return without waiting for http queries */
g_idle_add ((GSourceFunc)update_cache_and_deinit, provider);
}
return provider;
}
/* client calls this when it wants to use the provider.
Returns true if provider was actually started, and
client should assume accuracy has changed.
Returns false if provider was not started (usually because it
was already running). */
Returns false if provider was not started (it was either already
running or starting the provider failed). */
gboolean
gc_master_provider_subscribe (GcMasterProvider *provider,
gpointer client,
......@@ -946,8 +955,7 @@ gc_master_provider_subscribe (GcMasterProvider *provider,
/* decide wether to run initialize or not */
if (!gc_master_provider_is_running (provider)) {
if (!(priv->provides & GEOCLUE_PROVIDE_CACHEABLE_ON_CONNECTION)) {
gc_master_provider_initialize (provider);
started = TRUE;
started = gc_master_provider_initialize (provider);
}
}
......
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