gnss: Rework logic flow for exceptional conditions

This commit is contained in:
Denis Kenzior 2011-03-25 14:51:43 -05:00
parent 7ae093b97e
commit a23cc178be
1 changed files with 23 additions and 29 deletions

View File

@ -58,29 +58,23 @@ static void gnss_unregister_agent_cb(const struct ofono_error *error,
DBG(""); DBG("");
if (error->type != OFONO_ERROR_TYPE_NO_ERROR) { if (error->type != OFONO_ERROR_TYPE_NO_ERROR)
ofono_error("Disabling Location Reporting Failed"); ofono_error("Disabling Location Reporting Failed");
reply = __ofono_error_failed(gnss->pending);
__ofono_dbus_pending_reply(&gnss->pending, reply);
return;
}
gnss->enabled = FALSE; gnss->enabled = FALSE;
if (gnss->posr_agent) if (gnss->posr_agent)
gnss_agent_free(gnss->posr_agent); gnss_agent_free(gnss->posr_agent);
if (gnss->posr_agent) { reply = dbus_message_new_method_return(gnss->pending);
ofono_error("Releasing agent failed"); __ofono_dbus_pending_reply(&gnss->pending, reply);
reply = __ofono_error_failed(gnss->pending); }
__ofono_dbus_pending_reply(&gnss->pending, reply);
return;
}
if (gnss->pending) { static void gnss_disable_posr_cb(const struct ofono_error *error, void *data)
reply = dbus_message_new_method_return(gnss->pending); {
__ofono_dbus_pending_reply(&gnss->pending, reply); struct ofono_gnss *gnss = data;
}
gnss->enabled = FALSE;
} }
static void gnss_register_agent_cb(const struct ofono_error *error, static void gnss_register_agent_cb(const struct ofono_error *error,
@ -102,26 +96,27 @@ static void gnss_register_agent_cb(const struct ofono_error *error,
return; return;
} }
if (gnss->posr_agent) { reply = dbus_message_new_method_return(gnss->pending);
gnss->enabled = TRUE; __ofono_dbus_pending_reply(&gnss->pending, reply);
reply = dbus_message_new_method_return(gnss->pending);
__ofono_dbus_pending_reply(&gnss->pending, reply); gnss->enabled = TRUE;
} else
if (gnss->posr_agent == NULL)
gnss->driver->set_position_reporting(gnss, FALSE, gnss->driver->set_position_reporting(gnss, FALSE,
gnss_unregister_agent_cb, gnss_disable_posr_cb,
gnss); gnss);
} }
static void gnss_agent_notify(gpointer user_data) static void gnss_agent_notify(gpointer user_data)
{ {
struct ofono_gnss *gnss = user_data; struct ofono_gnss *gnss = user_data;
if (gnss->enabled)
gnss->driver->set_position_reporting(gnss, FALSE,
gnss_unregister_agent_cb,
gnss);
gnss->posr_agent = NULL; gnss->posr_agent = NULL;
if (gnss->enabled == TRUE)
gnss->driver->set_position_reporting(gnss, FALSE,
gnss_disable_posr_cb,
gnss);
} }
static DBusMessage *gnss_register_agent(DBusConnection *conn, static DBusMessage *gnss_register_agent(DBusConnection *conn,
@ -149,8 +144,6 @@ static DBusMessage *gnss_register_agent(DBusConnection *conn,
if (gnss->posr_agent == NULL) if (gnss->posr_agent == NULL)
return __ofono_error_failed(msg); return __ofono_error_failed(msg);
gnss->enabled = FALSE;
gnss_agent_set_removed_notify(gnss->posr_agent, gnss_agent_set_removed_notify(gnss->posr_agent,
gnss_agent_notify, gnss); gnss_agent_notify, gnss);
@ -185,6 +178,7 @@ static DBusMessage *gnss_unregister_agent(DBusConnection *conn,
gnss->pending = dbus_message_ref(msg); gnss->pending = dbus_message_ref(msg);
gnss->enabled = FALSE;
gnss->driver->set_position_reporting(gnss, FALSE, gnss->driver->set_position_reporting(gnss, FALSE,
gnss_unregister_agent_cb, gnss_unregister_agent_cb,
gnss); gnss);