plugins: use MMCallbackInfo instead of custom DisableInfo

Implemented using a custom invoke method which doesn't call the callback, and
instead calls parent disable passing the callback as argument.

This fix ensures that if a modem gets removed, no invalid modem reference is
passed to the parent disable, as info->modem would be set to NULL and we can
detect it in the custom invoke method.
This commit is contained in:
Aleksander Morgado
2011-06-05 17:51:05 +02:00
parent d37dbaca2a
commit da55d11e72
5 changed files with 138 additions and 79 deletions
+28 -15
View File
@@ -473,11 +473,7 @@ do_enable (MMGenericGsm *self, MMModemFn callback, gpointer user_data)
mm_at_serial_port_queue_command (primary, "*EMRDY?", 5, mbm_emrdy_done, info);
}
typedef struct {
MMModem *modem;
MMModemFn callback;
gpointer user_data;
} DisableInfo;
/*****************************************************************************/
static void
disable_unsolicited_done (MMAtSerialPort *port,
@@ -486,12 +482,29 @@ disable_unsolicited_done (MMAtSerialPort *port,
gpointer user_data)
{
MMModem *parent_modem_iface;
DisableInfo *info = user_data;
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
parent_modem_iface = g_type_interface_peek_parent (MM_MODEM_GET_INTERFACE (info->modem));
parent_modem_iface->disable (info->modem, info->callback, info->user_data);
g_free (info);
/* If the modem has already been removed, return without
* scheduling callback */
if (mm_callback_info_check_modem_removed (info))
return;
/* Ignore all errors */
mm_callback_info_schedule (info);
}
static void
invoke_call_parent_disable_fn (MMCallbackInfo *info)
{
/* Note: we won't call the parent disable if info->modem is no longer
* valid. The invoke is called always once the info gets scheduled, which
* may happen during removed modem detection. */
if (info->modem) {
MMModem *parent_modem_iface;
parent_modem_iface = g_type_interface_peek_parent (MM_MODEM_GET_INTERFACE (info->modem));
parent_modem_iface->disable (info->modem, (MMModemFn)info->callback, info->user_data);
}
}
static void
@@ -500,12 +513,12 @@ disable (MMModem *modem,
gpointer user_data)
{
MMAtSerialPort *primary;
DisableInfo *info;
MMCallbackInfo *info;
info = g_malloc0 (sizeof (DisableInfo));
info->callback = callback;
info->user_data = user_data;
info->modem = modem;
info = mm_callback_info_new_full (modem,
invoke_call_parent_disable_fn,
(GCallback)callback,
user_data);
primary = mm_generic_gsm_get_at_port (MM_GENERIC_GSM (modem), MM_PORT_TYPE_PRIMARY);
g_assert (primary);