[ofono] network: Use ofono_dbus_queue for queuing D-Bus requests

This commit is contained in:
Slava Monich
2017-10-18 17:51:02 +03:00
parent c3bead1c9b
commit c2ee34e51c

View File

@@ -36,6 +36,7 @@
#include "simutil.h"
#include "util.h"
#include "storage.h"
#include "dbus-queue.h"
#define SETTINGS_STORE "netreg"
#define SETTINGS_GROUP "Settings"
@@ -61,9 +62,7 @@ struct ofono_netreg {
GSList *operator_list;
struct ofono_network_registration_ops *ops;
int flags;
DBusMessage *pending;
GSList *pending_auto;
GSList *pending_list;
struct ofono_dbus_queue *q;
int signal_strength;
struct sim_spdi *spdi;
struct sim_eons *eons;
@@ -219,14 +218,11 @@ static void set_registration_mode(struct ofono_netreg *netreg, int mode)
static void register_callback(const struct ofono_error *error, void *data)
{
struct ofono_netreg *netreg = data;
DBusMessage *reply;
if (error->type == OFONO_ERROR_TYPE_NO_ERROR)
reply = dbus_message_new_method_return(netreg->pending);
__ofono_dbus_queue_reply_ok(netreg->q);
else
reply = __ofono_error_failed(netreg->pending);
__ofono_dbus_pending_reply(&netreg->pending, reply);
__ofono_dbus_queue_reply_failed(netreg->q);
if (netreg->driver->registration_status == NULL)
return;
@@ -601,13 +597,11 @@ static DBusMessage *network_operator_register(DBusConnection *conn,
if (netreg->mode == NETWORK_REGISTRATION_MODE_AUTO_ONLY)
return __ofono_error_access_denied(msg);
if (netreg->pending || netreg->pending_auto || netreg->pending_list)
return __ofono_error_busy(msg);
if (netreg->driver->register_manual == NULL)
return __ofono_error_not_implemented(msg);
netreg->pending = dbus_message_ref(msg);
if (!__ofono_dbus_queue_set_pending(netreg->q, msg))
return __ofono_error_busy(msg);
netreg->driver->register_manual(netreg, opd->mcc, opd->mnc,
register_callback, netreg);
@@ -855,42 +849,13 @@ static DBusMessage *network_get_properties(DBusConnection *conn,
return reply;
}
static void network_reply_ok(gpointer data)
{
DBusMessage *msg = data;
__ofono_dbus_pending_reply(&msg, dbus_message_new_method_return(msg));
}
static void network_reply_failed(gpointer data)
{
DBusMessage *msg = data;
__ofono_dbus_pending_reply(&msg, __ofono_error_failed(msg));
}
static void network_reply_canceled(gpointer data)
{
DBusMessage *msg = data;
__ofono_dbus_pending_reply(&msg, __ofono_error_canceled(msg));
}
static void register_auto_callback(const struct ofono_error *error, void *data)
static DBusMessage *network_register_fn(DBusMessage *msg, void *data)
{
struct ofono_netreg *netreg = data;
if (error->type == OFONO_ERROR_TYPE_NO_ERROR)
g_slist_free_full(netreg->pending_auto, network_reply_ok);
else
g_slist_free_full(netreg->pending_auto, network_reply_failed);
netreg->pending_auto = NULL;
if (netreg->driver->registration_status)
netreg->driver->registration_status(netreg,
registration_status_callback,
netreg);
netreg->driver->register_auto(netreg, register_callback, netreg);
set_registration_mode(netreg, NETWORK_REGISTRATION_MODE_AUTO);
return NULL;
}
static DBusMessage *network_register(DBusConnection *conn,
@@ -901,20 +866,11 @@ static DBusMessage *network_register(DBusConnection *conn,
if (netreg->mode == NETWORK_REGISTRATION_MODE_AUTO_ONLY)
return __ofono_error_access_denied(msg);
if (netreg->pending || netreg->pending_list)
return __ofono_error_busy(msg);
if (netreg->driver->register_auto == NULL)
return __ofono_error_not_implemented(msg);
netreg->pending_auto = g_slist_append(netreg->pending_auto,
dbus_message_ref(msg));
if (!netreg->pending_auto->next) {
netreg->driver->register_auto(netreg, register_auto_callback,
__ofono_dbus_queue_request(netreg->q, network_register_fn, msg,
netreg);
set_registration_mode(netreg, NETWORK_REGISTRATION_MODE_AUTO);
}
return NULL;
}
@@ -989,12 +945,6 @@ static void network_signal_operators_changed(struct ofono_netreg *netreg)
signal = dbus_message_new_signal(path,
OFONO_NETWORK_REGISTRATION_INTERFACE, "OperatorsChanged");
if (signal == NULL) {
ofono_error("Unable to allocate new "
OFONO_NETWORK_REGISTRATION_INTERFACE
".OperatorsChanged signal");
return;
}
dbus_message_iter_init_append(signal, &iter);
dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
@@ -1013,10 +963,9 @@ static void network_signal_operators_changed(struct ofono_netreg *netreg)
g_dbus_send_message(conn, signal);
}
static void operator_list_reply(gpointer data, gpointer user_data)
static DBusMessage *operator_list_reply(DBusMessage *msg, gpointer user_data)
{
struct ofono_netreg *netreg = user_data;
DBusMessage *msg = data;
DBusMessage *reply;
DBusMessageIter iter;
DBusMessageIter array;
@@ -1038,7 +987,7 @@ static void operator_list_reply(gpointer data, gpointer user_data)
append_operator_struct_list(netreg, &array);
dbus_message_iter_close_container(&iter, &array);
__ofono_dbus_pending_reply(&msg, reply);
return reply;
}
static void operator_list_callback(const struct ofono_error *error, int total,
@@ -1049,20 +998,25 @@ static void operator_list_callback(const struct ofono_error *error, int total,
if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
DBG("Error occurred during operator list");
g_slist_free_full(netreg->pending_list, network_reply_failed);
__ofono_dbus_queue_reply_all_failed(netreg-> q);
} else {
gboolean changed = update_operator_list(netreg, total, list);
g_slist_foreach(netreg->pending_list, operator_list_reply,
netreg);
g_slist_free(netreg->pending_list);
__ofono_dbus_queue_reply_all_fn_param(netreg->q,
operator_list_reply, netreg);
DBG("operator list %schanged", changed ? "" : "not ");
if (changed)
network_signal_operators_changed(netreg);
}
}
netreg->pending_list = NULL;
static DBusMessage *network_scan_cb(DBusMessage *msg, void *data)
{
struct ofono_netreg *netreg = data;
netreg->driver->list_operators(netreg, operator_list_callback, netreg);
return NULL;
}
static DBusMessage *network_scan(DBusConnection *conn,
@@ -1073,17 +1027,10 @@ static DBusMessage *network_scan(DBusConnection *conn,
if (netreg->mode == NETWORK_REGISTRATION_MODE_AUTO_ONLY)
return __ofono_error_access_denied(msg);
if (netreg->pending || netreg->pending_auto)
return __ofono_error_busy(msg);
if (netreg->driver->list_operators == NULL)
return __ofono_error_not_implemented(msg);
netreg->pending_list = g_slist_append(netreg->pending_list,
dbus_message_ref(msg));
if (!netreg->pending_list->next)
netreg->driver->list_operators(netreg, operator_list_callback,
netreg);
__ofono_dbus_queue_request(netreg->q, network_scan_cb, msg, netreg);
return NULL;
}
@@ -1959,14 +1906,7 @@ static void netreg_remove(struct ofono_atom *atom)
if (netreg->driver != NULL && netreg->driver->remove != NULL)
netreg->driver->remove(netreg);
if (netreg->pending) {
__ofono_dbus_pending_reply(&netreg->pending,
__ofono_error_canceled(netreg->pending));
} else if (netreg->pending_auto) {
g_slist_free_full(netreg->pending_auto, network_reply_canceled);
} else if (netreg->pending_list) {
g_slist_free_full(netreg->pending_list, network_reply_canceled);
}
__ofono_dbus_queue_free(netreg->q);
sim_eons_free(netreg->eons);
sim_spdi_free(netreg->spdi);
@@ -2194,6 +2134,7 @@ void ofono_netreg_register(struct ofono_netreg *netreg)
}
netreg->status_watches = __ofono_watchlist_new(g_free);
netreg->q = __ofono_dbus_queue_new();
ofono_modem_add_interface(modem, OFONO_NETWORK_REGISTRATION_INTERFACE);