diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2011-05-17 09:35:23 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2011-06-06 16:26:11 +0200 |
commit | 696a1d775ef8fe6464a8f27e82dec6ec6cbc02ba (patch) | |
tree | 332d4191ea47b37eb19e69859d79cb14f603902e | |
parent | b4b816449a5c6c6b24fb70cc44e53c2c6b640758 (diff) | |
download | ModemManager-696a1d775ef8fe6464a8f27e82dec6ec6cbc02ba.tar.gz |
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.
-rw-r--r-- | plugins/mm-modem-huawei-gsm.c | 43 | ||||
-rw-r--r-- | plugins/mm-modem-mbm.c | 43 | ||||
-rwxr-xr-x | plugins/mm-modem-samsung-gsm.c | 43 | ||||
-rw-r--r-- | plugins/mm-modem-simtech-gsm.c | 43 | ||||
-rw-r--r-- | plugins/mm-modem-zte.c | 45 |
5 files changed, 138 insertions, 79 deletions
diff --git a/plugins/mm-modem-huawei-gsm.c b/plugins/mm-modem-huawei-gsm.c index 93cb4cca8..e038069ce 100644 --- a/plugins/mm-modem-huawei-gsm.c +++ b/plugins/mm-modem-huawei-gsm.c @@ -747,12 +747,6 @@ do_enable_power_up_done (MMGenericGsm *gsm, /*****************************************************************************/ -typedef struct { - MMModem *modem; - MMModemFn callback; - gpointer user_data; -} DisableInfo; - static void disable_unsolicited_done (MMAtSerialPort *port, GString *response, @@ -760,12 +754,29 @@ disable_unsolicited_done (MMAtSerialPort *port, gpointer user_data) { - MMModem *parent_modem_iface; - DisableInfo *info = user_data; + MMCallbackInfo *info = (MMCallbackInfo *) user_data; + + /* 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, info->callback, info->user_data); - g_free (info); + 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 @@ -774,12 +785,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); diff --git a/plugins/mm-modem-mbm.c b/plugins/mm-modem-mbm.c index 1a9fbf375..70faef425 100644 --- a/plugins/mm-modem-mbm.c +++ b/plugins/mm-modem-mbm.c @@ -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; + + /* If the modem has already been removed, return without + * scheduling callback */ + if (mm_callback_info_check_modem_removed (info)) + return; - 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); + /* 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); diff --git a/plugins/mm-modem-samsung-gsm.c b/plugins/mm-modem-samsung-gsm.c index fdd5f0626..d8736537b 100755 --- a/plugins/mm-modem-samsung-gsm.c +++ b/plugins/mm-modem-samsung-gsm.c @@ -425,11 +425,7 @@ get_access_technology (MMGenericGsm *gsm, mm_modem_icera_get_access_technology (MM_MODEM_ICERA (gsm), callback, user_data); } -typedef struct { - MMModem *modem; - MMModemFn callback; - gpointer user_data; -} DisableInfo; +/*****************************************************************************/ static void disable_unsolicited_done (MMAtSerialPort *port, @@ -438,12 +434,29 @@ disable_unsolicited_done (MMAtSerialPort *port, gpointer user_data) { - MMModem *parent_modem_iface; - DisableInfo *info = user_data; + MMCallbackInfo *info = (MMCallbackInfo *) user_data; + + /* 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, info->callback, info->user_data); - g_free (info); + 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 @@ -452,15 +465,15 @@ disable (MMModem *modem, gpointer user_data) { MMAtSerialPort *primary; - DisableInfo *info; + MMCallbackInfo *info; mm_modem_icera_cleanup (MM_MODEM_ICERA (modem)); mm_modem_icera_change_unsolicited_messages (MM_MODEM_ICERA (modem), FALSE); - 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); diff --git a/plugins/mm-modem-simtech-gsm.c b/plugins/mm-modem-simtech-gsm.c index 5d4203356..18df9c423 100644 --- a/plugins/mm-modem-simtech-gsm.c +++ b/plugins/mm-modem-simtech-gsm.c @@ -399,12 +399,6 @@ real_do_enable_power_up_done (MMGenericGsm *gsm, /*****************************************************************************/ -typedef struct { - MMModem *modem; - MMModemFn callback; - gpointer user_data; -} DisableInfo; - static void disable_unsolicited_done (MMAtSerialPort *port, GString *response, @@ -412,12 +406,29 @@ disable_unsolicited_done (MMAtSerialPort *port, gpointer user_data) { - MMModem *parent_modem_iface; - DisableInfo *info = user_data; + MMCallbackInfo *info = (MMCallbackInfo *) user_data; + + /* If the modem has already been removed, return without + * scheduling callback */ + if (mm_callback_info_check_modem_removed (info)) + return; - 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); + /* 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 @@ -426,12 +437,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); diff --git a/plugins/mm-modem-zte.c b/plugins/mm-modem-zte.c index 4b7abafa1..0f6932841 100644 --- a/plugins/mm-modem-zte.c +++ b/plugins/mm-modem-zte.c @@ -500,12 +500,6 @@ do_enable (MMGenericGsm *modem, MMModemFn callback, gpointer user_data) /*****************************************************************************/ -typedef struct { - MMModem *modem; - MMModemFn callback; - gpointer user_data; -} DisableInfo; - static void disable_unsolicited_done (MMAtSerialPort *port, GString *response, @@ -513,12 +507,29 @@ disable_unsolicited_done (MMAtSerialPort *port, gpointer user_data) { - MMModem *parent_modem_iface; - DisableInfo *info = user_data; + MMCallbackInfo *info = (MMCallbackInfo *) user_data; + + /* If the modem has already been removed, return without + * scheduling callback */ + if (mm_callback_info_check_modem_removed (info)) + return; - 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); + /* 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 @@ -528,14 +539,14 @@ disable (MMModem *modem, { MMModemZtePrivate *priv = MM_MODEM_ZTE_GET_PRIVATE (modem); MMAtSerialPort *primary; - DisableInfo *info; + MMCallbackInfo *info; - priv->init_retried = FALSE; + info = mm_callback_info_new_full (modem, + invoke_call_parent_disable_fn, + (GCallback)callback, + user_data); - info = g_malloc0 (sizeof (DisableInfo)); - info->callback = callback; - info->user_data = user_data; - info->modem = modem; + priv->init_retried = FALSE; primary = mm_generic_gsm_get_at_port (MM_GENERIC_GSM (modem), MM_PORT_TYPE_PRIMARY); g_assert (primary); |