diff options
-rw-r--r-- | plugins/cinterion/mm-broadband-modem-cinterion.c | 2 | ||||
-rw-r--r-- | plugins/iridium/mm-bearer-iridium.c | 121 | ||||
-rw-r--r-- | plugins/iridium/mm-broadband-modem-iridium.c | 8 | ||||
-rw-r--r-- | src/mm-base-modem-at.c | 6 | ||||
-rw-r--r-- | src/mm-base-modem.c | 57 | ||||
-rw-r--r-- | src/mm-base-modem.h | 20 | ||||
-rw-r--r-- | src/mm-broadband-bearer.c | 73 | ||||
-rw-r--r-- | src/mm-broadband-modem.c | 177 | ||||
-rw-r--r-- | src/mm-iface-modem-3gpp-ussd.c | 6 | ||||
-rw-r--r-- | src/mm-iface-modem-3gpp.c | 6 | ||||
-rw-r--r-- | src/mm-iface-modem-cdma.c | 6 | ||||
-rw-r--r-- | src/mm-iface-modem-location.c | 6 | ||||
-rw-r--r-- | src/mm-iface-modem-messaging.c | 6 | ||||
-rw-r--r-- | src/mm-iface-modem-time.c | 6 | ||||
-rw-r--r-- | src/mm-iface-modem.c | 29 | ||||
-rw-r--r-- | src/mm-sim.c | 17 |
16 files changed, 323 insertions, 223 deletions
diff --git a/plugins/cinterion/mm-broadband-modem-cinterion.c b/plugins/cinterion/mm-broadband-modem-cinterion.c index f1359c04..814189bf 100644 --- a/plugins/cinterion/mm-broadband-modem-cinterion.c +++ b/plugins/cinterion/mm-broadband-modem-cinterion.c @@ -121,7 +121,7 @@ enable_unsolicited_events (MMIfaceModem3gpp *self, mm_base_modem_at_command_in_port ( MM_BASE_MODEM (self), /* Only primary port is expected in the Cinterion modems */ - mm_base_modem_get_port_primary (MM_BASE_MODEM (self)), + mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)), /* AT=CMER=[<mode>[,<keyp>[,<disp>[,<ind>[,<bfr>]]]]] * but <ind> should be either not set, or equal to 0 or 2. * Enabled with 2. diff --git a/plugins/iridium/mm-bearer-iridium.c b/plugins/iridium/mm-bearer-iridium.c index 7811fe90..d13f3666 100644 --- a/plugins/iridium/mm-bearer-iridium.c +++ b/plugins/iridium/mm-bearer-iridium.c @@ -57,6 +57,7 @@ typedef struct { MMBearerIridium *self; GSimpleAsyncResult *result; GCancellable *cancellable; + MMAtSerialPort *primary; GError *saved_error; } ConnectContext; @@ -66,6 +67,8 @@ connect_context_complete_and_free (ConnectContext *ctx) g_simple_async_result_complete_in_idle (ctx->result); if (ctx->saved_error) g_error_free (ctx->saved_error); + if (ctx->primary) + g_object_unref (ctx->primary); g_object_unref (ctx->cancellable); g_object_unref (ctx->result); g_object_unref (ctx->self); @@ -111,7 +114,7 @@ connect_report_ready (MMBaseModem *modem, } /* If we got a proper extended reply, build the new error to be set */ - result = mm_base_modem_at_command_finish (modem, res, NULL); + result = mm_base_modem_at_command_in_port_finish (modem, res, NULL); if (result && g_str_has_prefix (result, "+CEER: ") && strlen (result) > 7) { @@ -143,11 +146,12 @@ dial_ready (MMBaseModem *modem, /* DO NOT check for cancellable here. If we got here without errors, the * bearer is really connected and therefore we need to reflect that in * the state machine. */ - mm_base_modem_at_command_finish (modem, res, &(ctx->saved_error)); + mm_base_modem_at_command_in_port_finish (modem, res, &(ctx->saved_error)); if (ctx->saved_error) { /* Try to get more information why it failed */ - mm_base_modem_at_command ( + mm_base_modem_at_command_in_port ( modem, + ctx->primary, "+CEER", 3, FALSE, @@ -158,7 +162,7 @@ dial_ready (MMBaseModem *modem, } /* Port is connected; update the state */ - mm_port_set_connected (MM_PORT (mm_base_modem_get_port_primary (modem)), TRUE); + mm_port_set_connected (MM_PORT (ctx->primary), TRUE); /* Build IP config; always PPP based */ config = mm_bearer_ip_config_new (); @@ -166,7 +170,7 @@ dial_ready (MMBaseModem *modem, /* Build result */ result = g_new0 (ConnectResult, 1); - result->data = g_object_ref (mm_base_modem_get_port_primary (modem)); + result->data = g_object_ref (ctx->primary); result->ipv4_config = config; result->ipv6_config = g_object_ref (config); @@ -195,7 +199,7 @@ service_type_ready (MMBaseModem *modem, } /* Errors setting the service type will be critical */ - mm_base_modem_at_command_finish (modem, res, &error); + mm_base_modem_at_command_in_port_finish (modem, res, &error); if (error) { g_simple_async_result_take_error (ctx->result, error); connect_context_complete_and_free (ctx); @@ -205,8 +209,9 @@ service_type_ready (MMBaseModem *modem, /* We just use the default number to dial in the Iridium network. Also note * that we won't specify a specific port to use; Iridium modems only expose * one. */ - mm_base_modem_at_command ( + mm_base_modem_at_command_in_port ( modem, + ctx->primary, "ATDT008816000025", 60, FALSE, @@ -235,6 +240,7 @@ connect (MMBearer *self, /* In this context, we only keep the stuff we'll need later */ ctx = g_new0 (ConnectContext, 1); ctx->self = g_object_ref (self); + ctx->primary = mm_base_modem_get_port_primary (modem); ctx->cancellable = g_object_ref (cancellable); ctx->result = g_simple_async_result_new (G_OBJECT (self), callback, @@ -243,8 +249,9 @@ connect (MMBearer *self, /* Bearer service type set to 9600bps (V.110), which behaves better than the * default 9600bps (V.32). */ - mm_base_modem_at_command ( + mm_base_modem_at_command_in_port ( modem, + ctx->primary, "+CBST=71,0,1", 3, FALSE, @@ -258,6 +265,24 @@ connect (MMBearer *self, /*****************************************************************************/ /* Disconnect */ +typedef struct { + MMBearerIridium *self; + MMBaseModem *modem; + MMAtSerialPort *primary; + GSimpleAsyncResult *result; +} DisconnectContext; + +static void +disconnect_context_complete_and_free (DisconnectContext *ctx) +{ + g_simple_async_result_complete_in_idle (ctx->result); + g_object_unref (ctx->result); + if (ctx->primary) + g_object_unref (ctx->primary); + g_object_unref (ctx->modem); + g_object_unref (ctx->self); +} + static gboolean disconnect_finish (MMBearer *self, GAsyncResult *res, @@ -269,7 +294,7 @@ disconnect_finish (MMBearer *self, static void primary_flash_ready (MMSerialPort *port, GError *error, - GSimpleAsyncResult *result) + DisconnectContext *ctx) { if (error) { /* Ignore "NO CARRIER" response when modem disconnects and any flash @@ -282,9 +307,8 @@ primary_flash_ready (MMSerialPort *port, MM_SERIAL_ERROR, MM_SERIAL_ERROR_FLASH_FAILED)) { /* Fatal */ - g_simple_async_result_set_from_error (result, error); - g_simple_async_result_complete (result); - g_object_unref (result); + g_simple_async_result_set_from_error (ctx->result, error); + disconnect_context_complete_and_free (ctx); return; } mm_dbg ("Port flashing failed (not fatal): %s", error->message); @@ -294,40 +318,27 @@ primary_flash_ready (MMSerialPort *port, * already have set the port as disconnected (e.g the 3GPP one) */ mm_port_set_connected (MM_PORT (port), FALSE); - g_simple_async_result_set_op_res_gboolean (result, TRUE); - g_simple_async_result_complete (result); - g_object_unref (result); + g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE); + disconnect_context_complete_and_free (ctx); } static gboolean -after_disconnect_sleep_cb (GSimpleAsyncResult *simple) +after_disconnect_sleep_cb (DisconnectContext *ctx) { GError *error = NULL; - MMAtSerialPort *primary; - MMBearer *self; - MMBaseModem *modem; - - self = MM_BEARER (g_async_result_get_source_object (G_ASYNC_RESULT (simple))); - g_object_get (self, - MM_BEARER_MODEM, &modem, - NULL); - primary = mm_base_modem_get_port_primary (modem); /* Propagate errors when reopening the port */ - if (!mm_serial_port_open (MM_SERIAL_PORT (primary), &error)) { - g_simple_async_result_take_error (simple, error); - g_simple_async_result_complete (simple); - g_object_unref (simple); - } else { - mm_serial_port_flash (MM_SERIAL_PORT (primary), - 1000, - TRUE, - (MMSerialFlashFn)primary_flash_ready, - simple); + if (!mm_serial_port_open (MM_SERIAL_PORT (ctx->primary), &error)) { + g_simple_async_result_take_error (ctx->result, error); + disconnect_context_complete_and_free (ctx); + return FALSE; } - g_object_unref (modem); - g_object_unref (self); + mm_serial_port_flash (MM_SERIAL_PORT (ctx->primary), + 1000, + TRUE, + (MMSerialFlashFn)primary_flash_ready, + ctx); return FALSE; } @@ -336,42 +347,40 @@ disconnect (MMBearer *self, GAsyncReadyCallback callback, gpointer user_data) { - MMAtSerialPort *primary; - MMBaseModem *modem = NULL; - GSimpleAsyncResult *result; + DisconnectContext *ctx; + ctx = g_new (DisconnectContext, 1); + ctx->self = g_object_ref (self); g_object_get (self, - MM_BEARER_MODEM, &modem, + MM_BEARER_MODEM, &ctx->modem, NULL); - g_assert (modem != NULL); - primary = mm_base_modem_get_port_primary (modem); - g_object_unref (modem); + ctx->primary = mm_base_modem_get_port_primary (ctx->modem); + ctx->result = g_simple_async_result_new (G_OBJECT (self), + callback, + user_data, + disconnect); - if (!mm_port_get_connected (MM_PORT (primary))) { - g_simple_async_report_error_in_idle ( - G_OBJECT (self), - callback, - user_data, + if (!ctx->primary || + !mm_port_get_connected (MM_PORT (ctx->primary))) { + g_simple_async_result_set_error ( + ctx->result, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Couldn't disconnect Iridium: this bearer is not connected"); + disconnect_context_complete_and_free (ctx); return; } /* Just flash the primary port */ - result = g_simple_async_result_new (G_OBJECT (self), - callback, - user_data, - disconnect); /* When we enable the modem we kept one open count in the primary port. * We now need to fully close that one, as if we were disabled, and reopen * it again afterwards. */ - mm_serial_port_close (MM_SERIAL_PORT (primary)); - g_warn_if_fail (!mm_serial_port_is_open (MM_SERIAL_PORT (primary))); + mm_serial_port_close (MM_SERIAL_PORT (ctx->primary)); + g_warn_if_fail (!mm_serial_port_is_open (MM_SERIAL_PORT (ctx->primary))); mm_dbg ("Waiting some seconds before reopening the port..."); - g_timeout_add_seconds (5, (GSourceFunc)after_disconnect_sleep_cb, result); + g_timeout_add_seconds (5, (GSourceFunc)after_disconnect_sleep_cb, ctx); } /*****************************************************************************/ diff --git a/plugins/iridium/mm-broadband-modem-iridium.c b/plugins/iridium/mm-broadband-modem-iridium.c index 8ae7a8fc..78ccf3bd 100644 --- a/plugins/iridium/mm-broadband-modem-iridium.c +++ b/plugins/iridium/mm-broadband-modem-iridium.c @@ -381,12 +381,18 @@ create_bearer (MMIfaceModem *self, static void setup_ports (MMBroadbandModem *self) { + MMAtSerialPort *primary; + /* Call parent's setup ports first always */ MM_BROADBAND_MODEM_CLASS (mm_broadband_modem_iridium_parent_class)->setup_ports (self); /* Set 9600 baudrate by default in the AT port */ mm_dbg ("Baudrate will be set to 9600 bps..."); - g_object_set (G_OBJECT (mm_base_modem_get_port_primary (MM_BASE_MODEM (self))), + primary = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)); + if (!primary) + return; + + g_object_set (G_OBJECT (primary), MM_SERIAL_PORT_BAUD, 9600, NULL); } diff --git a/src/mm-base-modem-at.c b/src/mm-base-modem-at.c index 820063b8..70b4e41f 100644 --- a/src/mm-base-modem-at.c +++ b/src/mm-base-modem-at.c @@ -277,7 +277,7 @@ mm_base_modem_at_sequence (MMBaseModem *self, GError *error = NULL; /* No port given, so we'll try to guess which is best */ - port = mm_base_modem_get_best_at_port (self, &error); + port = mm_base_modem_peek_best_at_port (self, &error); if (!port) { g_assert (error != NULL); g_simple_async_report_take_gerror_in_idle (G_OBJECT (self), @@ -487,7 +487,7 @@ mm_base_modem_at_command (MMBaseModem *self, GError *error = NULL; /* No port given, so we'll try to guess which is best */ - port = mm_base_modem_get_best_at_port (self, &error); + port = mm_base_modem_peek_best_at_port (self, &error); if (!port) { g_assert (error != NULL); g_simple_async_report_take_gerror_in_idle (G_OBJECT (self), @@ -536,7 +536,7 @@ mm_base_modem_at_command_ignore_reply (MMBaseModem *self, MMAtSerialPort *port; /* No port given, so we'll try to guess which is best */ - port = mm_base_modem_get_best_at_port (self, NULL); + port = mm_base_modem_peek_best_at_port (self, NULL); if (!port) /* No valid port, and we ignore replies, so just exit. */ return; diff --git a/src/mm-base-modem.c b/src/mm-base-modem.c index 668199b9..74deb0ac 100644 --- a/src/mm-base-modem.c +++ b/src/mm-base-modem.c @@ -325,6 +325,14 @@ mm_base_modem_get_port_primary (MMBaseModem *self) { g_return_val_if_fail (MM_IS_BASE_MODEM (self), NULL); + return (self->priv->primary ? g_object_ref (self->priv->primary) : NULL); +} + +MMAtSerialPort * +mm_base_modem_peek_port_primary (MMBaseModem *self) +{ + g_return_val_if_fail (MM_IS_BASE_MODEM (self), NULL); + return self->priv->primary; } @@ -333,6 +341,14 @@ mm_base_modem_get_port_secondary (MMBaseModem *self) { g_return_val_if_fail (MM_IS_BASE_MODEM (self), NULL); + return (self->priv->secondary ? g_object_ref (self->priv->secondary) : NULL); +} + +MMAtSerialPort * +mm_base_modem_peek_port_secondary (MMBaseModem *self) +{ + g_return_val_if_fail (MM_IS_BASE_MODEM (self), NULL); + return self->priv->secondary; } @@ -341,12 +357,29 @@ mm_base_modem_get_port_qcdm (MMBaseModem *self) { g_return_val_if_fail (MM_IS_BASE_MODEM (self), NULL); + return (self->priv->qcdm ? g_object_ref (self->priv->qcdm) : NULL); +} + +MMQcdmSerialPort * +mm_base_modem_peek_port_qcdm (MMBaseModem *self) +{ + g_return_val_if_fail (MM_IS_BASE_MODEM (self), NULL); + return self->priv->qcdm; } MMPort * mm_base_modem_get_best_data_port (MMBaseModem *self) { + MMPort *port; + + port = mm_base_modem_peek_best_data_port (self); + return (port ? g_object_ref (port) : NULL); +} + +MMPort * +mm_base_modem_peek_best_data_port (MMBaseModem *self) +{ g_return_val_if_fail (MM_IS_BASE_MODEM (self), NULL); /* TODO: sometime we'll have a list of available data ports to use instead @@ -361,24 +394,32 @@ MMAtSerialPort * mm_base_modem_get_best_at_port (MMBaseModem *self, GError **error) { - MMAtSerialPort *port; + MMAtSerialPort *best; + best = mm_base_modem_peek_best_at_port (self, error); + return (best ? g_object_ref (best) : NULL); +} + +MMAtSerialPort * +mm_base_modem_peek_best_at_port (MMBaseModem *self, + GError **error) +{ /* Decide which port to use */ - port = mm_base_modem_get_port_primary (self); - if (port && !mm_port_get_connected (MM_PORT (port))) - return port; + if (self->priv->primary && + !mm_port_get_connected (MM_PORT (self->priv->primary))) + return self->priv->primary; /* If primary port is connected, check if we can get the secondary * port */ - port = mm_base_modem_get_port_secondary (self); - if (port && !mm_port_get_connected (MM_PORT (port))) - return port; + if (self->priv->secondary && + !mm_port_get_connected (MM_PORT (self->priv->secondary))) + return self->priv->secondary; /* Otherwise, we cannot get any port */ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_CONNECTED, - "No port available to run command"); + "No AT port available to run command"); return NULL; } diff --git a/src/mm-base-modem.h b/src/mm-base-modem.h index b572cf87..4318de3a 100644 --- a/src/mm-base-modem.h +++ b/src/mm-base-modem.h @@ -114,12 +114,20 @@ gboolean mm_base_modem_owns_port (MMBaseModem *self, gboolean mm_base_modem_organize_ports (MMBaseModem *self, GError **error); -MMAtSerialPort *mm_base_modem_get_port_primary (MMBaseModem *self); -MMAtSerialPort *mm_base_modem_get_port_secondary (MMBaseModem *self); -MMQcdmSerialPort *mm_base_modem_get_port_qcdm (MMBaseModem *self); -MMPort *mm_base_modem_get_best_data_port (MMBaseModem *self); -MMAtSerialPort *mm_base_modem_get_best_at_port (MMBaseModem *self, - GError **error); +MMAtSerialPort *mm_base_modem_peek_port_primary (MMBaseModem *self); +MMAtSerialPort *mm_base_modem_peek_port_secondary (MMBaseModem *self); +MMQcdmSerialPort *mm_base_modem_peek_port_qcdm (MMBaseModem *self); +MMAtSerialPort *mm_base_modem_peek_best_at_port (MMBaseModem *self, + GError **error); +MMPort *mm_base_modem_peek_best_data_port (MMBaseModem *self); + +MMAtSerialPort *mm_base_modem_get_port_primary (MMBaseModem *self); +MMAtSerialPort *mm_base_modem_get_port_secondary (MMBaseModem *self); +MMQcdmSerialPort *mm_base_modem_get_port_qcdm (MMBaseModem *self); +MMAtSerialPort *mm_base_modem_get_best_at_port (MMBaseModem *self, + GError **error); +MMPort *mm_base_modem_get_best_data_port (MMBaseModem *self); + void mm_base_modem_set_valid (MMBaseModem *self, gboolean valid); diff --git a/src/mm-broadband-bearer.c b/src/mm-broadband-bearer.c index 6201c041..64eec160 100644 --- a/src/mm-broadband-bearer.c +++ b/src/mm-broadband-bearer.c @@ -412,6 +412,8 @@ connect_cdma (MMBroadbandBearer *self, { DetailedConnectContext *ctx; + g_assert (primary != NULL); + ctx = detailed_connect_context_new (self, modem, primary, @@ -591,6 +593,8 @@ dial_3gpp (MMBroadbandBearer *self, gchar *command; Dial3gppContext *ctx; + g_assert (primary != NULL); + ctx = dial_3gpp_context_new (self, modem, primary, @@ -899,6 +903,8 @@ connect_3gpp (MMBroadbandBearer *self, { DetailedConnectContext *ctx; + g_assert (primary != NULL); + ctx = detailed_connect_context_new (self, modem, primary, @@ -1084,8 +1090,21 @@ connect (MMBearer *self, NULL); g_assert (modem != NULL); - /* We will launch the ATD call in the primary port */ - primary = mm_base_modem_get_port_primary (modem); + /* We will launch the ATD call in the primary port... */ + primary = mm_base_modem_peek_port_primary (modem); + if (!primary) { + g_simple_async_report_error_in_idle ( + G_OBJECT (self), + callback, + user_data, + MM_CORE_ERROR, + MM_CORE_ERROR_CONNECTED, + "Couldn't connect: couldn't get primary port"); + g_object_unref (modem); + return; + } + + /* ...only if not already connected */ if (mm_port_get_connected (MM_PORT (primary))) { g_simple_async_report_error_in_idle ( G_OBJECT (self), @@ -1099,7 +1118,7 @@ connect (MMBearer *self, } /* Look for best data port, NULL if none available. */ - data = mm_base_modem_get_best_data_port (modem); + data = mm_base_modem_peek_best_data_port (modem); if (!data) { g_simple_async_report_error_in_idle ( G_OBJECT (self), @@ -1149,7 +1168,7 @@ connect (MMBearer *self, MM_BROADBAND_BEARER (self), MM_BROADBAND_MODEM (modem), primary, - mm_base_modem_get_port_secondary (modem), + mm_base_modem_peek_port_secondary (modem), data, cancellable, (GAsyncReadyCallback) connect_3gpp_ready, @@ -1170,7 +1189,7 @@ connect (MMBearer *self, MM_BROADBAND_BEARER (self), MM_BROADBAND_MODEM (modem), primary, - mm_base_modem_get_port_secondary (modem), + mm_base_modem_peek_port_secondary (modem), data, cancellable, (GAsyncReadyCallback) connect_cdma_ready, @@ -1294,6 +1313,8 @@ disconnect_cdma (MMBroadbandBearer *self, { DetailedDisconnectContext *ctx; + g_assert (primary != NULL); + ctx = detailed_disconnect_context_new (self, modem, primary, @@ -1419,6 +1440,8 @@ disconnect_3gpp (MMBroadbandBearer *self, { DetailedDisconnectContext *ctx; + g_assert (primary != NULL); + ctx = detailed_disconnect_context_new (self, modem, primary, @@ -1552,6 +1575,7 @@ disconnect (MMBearer *self, GAsyncReadyCallback callback, gpointer user_data) { + MMAtSerialPort *primary; MMBaseModem *modem = NULL; DisconnectContext *ctx; @@ -1571,6 +1595,20 @@ disconnect (MMBearer *self, NULL); g_assert (modem != NULL); + /* We need the primary port to disconnect... */ + primary = mm_base_modem_peek_port_primary (modem); + if (!primary) { + g_simple_async_report_error_in_idle ( + G_OBJECT (self), + callback, + user_data, + MM_CORE_ERROR, + MM_CORE_ERROR_FAILED, + "Couldn't disconnect: couldn't get primary port"); + g_object_unref (modem); + return; + } + /* In this context, we only keep the stuff we'll need later */ ctx = g_new0 (DisconnectContext, 1); ctx->self = g_object_ref (self); @@ -1585,8 +1623,8 @@ disconnect (MMBearer *self, MM_BROADBAND_BEARER_GET_CLASS (self)->disconnect_3gpp ( MM_BROADBAND_BEARER (self), MM_BROADBAND_MODEM (modem), - mm_base_modem_get_port_primary (modem), - mm_base_modem_get_port_secondary (modem), + primary, + mm_base_modem_peek_port_secondary (modem), MM_BROADBAND_BEARER (self)->priv->port, (GAsyncReadyCallback) disconnect_3gpp_ready, ctx); @@ -1596,8 +1634,8 @@ disconnect (MMBearer *self, MM_BROADBAND_BEARER_GET_CLASS (self)->disconnect_cdma ( MM_BROADBAND_BEARER (self), MM_BROADBAND_MODEM (modem), - mm_base_modem_get_port_primary (modem), - mm_base_modem_get_port_secondary (modem), + primary, + mm_base_modem_peek_port_secondary (modem), MM_BROADBAND_BEARER (self)->priv->port, (GAsyncReadyCallback) disconnect_cdma_ready, ctx); @@ -1655,8 +1693,11 @@ static void init_async_context_free (InitAsyncContext *ctx, gboolean close_port) { - if (close_port) - mm_serial_port_close (MM_SERIAL_PORT (ctx->port)); + if (ctx->port) { + if (close_port) + mm_serial_port_close (MM_SERIAL_PORT (ctx->port)); + g_object_unref (ctx->port); + } g_object_unref (ctx->self); g_object_unref (ctx->modem); g_object_unref (ctx->result); @@ -1919,6 +1960,16 @@ initable_init_async (GAsyncInitable *initable, NULL); ctx->port = mm_base_modem_get_port_primary (ctx->modem); + if (!ctx->port) { + g_simple_async_result_set_error (ctx->result, + MM_CORE_ERROR, + MM_CORE_ERROR_FAILED, + "Couldn't get primary port"); + g_simple_async_result_complete_in_idle (ctx->result); + init_async_context_free (ctx, FALSE); + return; + } + if (!mm_serial_port_open (MM_SERIAL_PORT (ctx->port), &error)) { g_simple_async_result_take_error (ctx->result, error); g_simple_async_result_complete_in_idle (ctx->result); diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index 1391e437..60742d16 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -1246,7 +1246,6 @@ modem_load_signal_quality (MMIfaceModem *self, GAsyncReadyCallback callback, gpointer user_data) { - MMSerialPort *port; SignalQualityContext *ctx; GError *error = NULL; @@ -1259,9 +1258,8 @@ modem_load_signal_quality (MMIfaceModem *self, modem_load_signal_quality); /* Check whether we can get a non-connected AT port */ - port = (MMSerialPort *)mm_base_modem_get_best_at_port (MM_BASE_MODEM (self), &error); - if (port) { - ctx->port = g_object_ref (port); + ctx->port = (MMSerialPort *)mm_base_modem_get_best_at_port (MM_BASE_MODEM (self), &error); + if (ctx->port) { if (MM_BROADBAND_MODEM (self)->priv->modem_cind_supported) signal_quality_cind (ctx); else @@ -1270,10 +1268,9 @@ modem_load_signal_quality (MMIfaceModem *self, } /* If no best AT port available (all connected), try with QCDM ports */ - port = (MMSerialPort *)mm_base_modem_get_port_qcdm (MM_BASE_MODEM (self)); - if (port) { + ctx->port = (MMSerialPort *)mm_base_modem_get_port_qcdm (MM_BASE_MODEM (self)); + if (ctx->port) { g_error_free (error); - ctx->port = g_object_ref (port); signal_quality_qcdm (ctx); return; } @@ -1446,13 +1443,17 @@ set_unsolicited_events_handlers (MMIfaceModem3gpp *self, set_unsolicited_events_handlers); ciev_regex = mm_3gpp_ciev_regex_get (); - ports[0] = mm_base_modem_get_port_primary (MM_BASE_MODEM (self)); - ports[1] = mm_base_modem_get_port_secondary (MM_BASE_MODEM (self)); + ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)); + ports[1] = mm_base_modem_peek_port_secondary (MM_BASE_MODEM (self)); /* Enable unsolicited events in given port */ - for (i = 0; ports[i] && i < 2; i++) { + for (i = 0; i < 2; i++) { + if (!ports[i]) + continue; + /* Set/unset unsolicited CIEV event handler */ - mm_dbg ("%s unsolicited events handlers", + mm_dbg ("(%s) %s 3GPP unsolicited events handlers", + mm_port_get_device (MM_PORT (ports[i])), enable ? "Setting" : "Removing"); mm_at_serial_port_add_unsolicited_msg_handler ( ports[i], @@ -1546,10 +1547,10 @@ run_unsolicited_events_setup (UnsolicitedEventsContext *ctx) if (!ctx->cmer_primary_done) { ctx->cmer_primary_done = TRUE; - port = mm_base_modem_get_port_primary (MM_BASE_MODEM (ctx->self)); + port = mm_base_modem_peek_port_primary (MM_BASE_MODEM (ctx->self)); } else if (!ctx->cmer_secondary_done) { ctx->cmer_secondary_done = TRUE; - port = mm_base_modem_get_port_secondary (MM_BASE_MODEM (ctx->self)); + port = mm_base_modem_peek_port_secondary (MM_BASE_MODEM (ctx->self)); } /* Enable unsolicited events in given port */ @@ -2295,31 +2296,31 @@ modem_3gpp_setup_unsolicited_registration (MMIfaceModem3gpp *self, MMAtSerialPort *ports[2]; GPtrArray *array; guint i; - - mm_dbg ("setting up unsolicited registration messages handling"); + guint j; result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, modem_3gpp_setup_unsolicited_registration); - ports[0] = mm_base_modem_get_port_primary (MM_BASE_MODEM (self)); - ports[1] = mm_base_modem_get_port_secondary (MM_BASE_MODEM (self)); + ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)); + ports[1] = mm_base_modem_peek_port_secondary (MM_BASE_MODEM (self)); /* Set up CREG unsolicited message handlers in both ports */ array = mm_3gpp_creg_regex_get (FALSE); for (i = 0; i < 2; i++) { - if (ports[i]) { - guint j; - - for (j = 0; j < array->len; j++) { - mm_at_serial_port_add_unsolicited_msg_handler ( - MM_AT_SERIAL_PORT (ports[i]), - (GRegex *) g_ptr_array_index (array, j), - (MMAtSerialUnsolicitedMsgFn)registration_state_changed, - self, - NULL); - } + if (!ports[i]) + continue; + + mm_dbg ("(%s) setting up 3GPP unsolicited registration messages handlers", + mm_port_get_device (MM_PORT (ports[i]))); + for (j = 0; j < array->len; j++) { + mm_at_serial_port_add_unsolicited_msg_handler ( + MM_AT_SERIAL_PORT (ports[i]), + (GRegex *) g_ptr_array_index (array, j), + (MMAtSerialUnsolicitedMsgFn)registration_state_changed, + self, + NULL); } } mm_3gpp_creg_regex_destroy (array); @@ -2349,30 +2350,32 @@ modem_3gpp_cleanup_unsolicited_registration (MMIfaceModem3gpp *self, MMAtSerialPort *ports[2]; GPtrArray *array; guint i; + guint j; - mm_dbg ("cleaning up unsolicited registration messages handling"); result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, modem_3gpp_cleanup_unsolicited_registration); - ports[0] = mm_base_modem_get_port_primary (MM_BASE_MODEM (self)); - ports[1] = mm_base_modem_get_port_secondary (MM_BASE_MODEM (self)); + ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)); + ports[1] = mm_base_modem_peek_port_secondary (MM_BASE_MODEM (self)); /* Set up CREG unsolicited message handlers in both ports */ array = mm_3gpp_creg_regex_get (FALSE); for (i = 0; i < 2; i++) { - if (ports[i]) { - guint j; - - for (j = 0; j < array->len; j++) { - mm_at_serial_port_add_unsolicited_msg_handler ( - MM_AT_SERIAL_PORT (ports[i]), - (GRegex *) g_ptr_array_index (array, j), - NULL, - NULL, - NULL); - } + if (!ports[i]) + continue; + + mm_dbg ("(%s) cleaning up unsolicited registration messages handlers", + mm_port_get_device (MM_PORT (ports[i]))); + + for (j = 0; j < array->len; j++) { + mm_at_serial_port_add_unsolicited_msg_handler ( + MM_AT_SERIAL_PORT (ports[i]), + (GRegex *) g_ptr_array_index (array, j), + NULL, + NULL, + NULL); } } mm_3gpp_creg_regex_destroy (array); @@ -2858,7 +2861,7 @@ cleanup_registration_sequence_ready (MMBroadbandModem *self, if (!ctx->secondary_done) { MMAtSerialPort *secondary; - secondary = mm_base_modem_get_port_secondary (MM_BASE_MODEM (self)); + secondary = mm_base_modem_peek_port_secondary (MM_BASE_MODEM (self)); if (secondary) { /* Now use the same registration setup in secondary port, if any */ ctx->secondary_done = TRUE; @@ -2911,7 +2914,7 @@ modem_3gpp_cleanup_cs_registration (MMIfaceModem3gpp *self, mm_base_modem_at_command_in_port ( MM_BASE_MODEM (self), - mm_base_modem_get_port_primary (MM_BASE_MODEM (self)), + mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)), ctx->command, 10, FALSE, @@ -2936,7 +2939,7 @@ modem_3gpp_cleanup_ps_registration (MMIfaceModem3gpp *self, mm_base_modem_at_command_in_port ( MM_BASE_MODEM (self), - mm_base_modem_get_port_primary (MM_BASE_MODEM (self)), + mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)), ctx->command, 10, FALSE, @@ -3040,13 +3043,13 @@ setup_registration_sequence_ready (MMBroadbandModem *self, return; } - secondary = mm_base_modem_get_port_secondary (MM_BASE_MODEM (self)); + secondary = mm_base_modem_peek_port_secondary (MM_BASE_MODEM (self)); if (secondary) { /* Now use the same registration setup in secondary port, if any */ ctx->secondary_done = TRUE; mm_base_modem_at_command_in_port ( MM_BASE_MODEM (self), - mm_base_modem_get_port_primary (MM_BASE_MODEM (self)), + mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)), g_variant_get_string (command, NULL), 3, FALSE, @@ -3078,7 +3081,7 @@ modem_3gpp_setup_cs_registration (MMIfaceModem3gpp *self, modem_3gpp_setup_cs_registration); mm_base_modem_at_sequence_in_port ( MM_BASE_MODEM (self), - mm_base_modem_get_port_primary (MM_BASE_MODEM (self)), + mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)), cs_registration_sequence, NULL, /* response processor context */ NULL, /* response processor context free */ @@ -3101,7 +3104,7 @@ modem_3gpp_setup_ps_registration (MMIfaceModem3gpp *self, modem_3gpp_setup_ps_registration); mm_base_modem_at_sequence_in_port ( MM_BASE_MODEM (self), - mm_base_modem_get_port_primary (MM_BASE_MODEM (self)), + mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)), ps_registration_sequence, NULL, /* response processor context */ NULL, /* response processor context free */ @@ -3501,13 +3504,16 @@ set_unsolicited_result_code_handlers (MMIfaceModem3gppUssd *self, set_unsolicited_events_handlers); cusd_regex = mm_3gpp_cusd_regex_get (); - ports[0] = mm_base_modem_get_port_primary (MM_BASE_MODEM (self)); - ports[1] = mm_base_modem_get_port_secondary (MM_BASE_MODEM (self)); + ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)); + ports[1] = mm_base_modem_peek_port_secondary (MM_BASE_MODEM (self)); /* Enable unsolicited result codes in given port */ - for (i = 0; ports[i] && i < 2; i++) { + for (i = 0; i < 2; i++) { + if (!ports[i]) + continue; /* Set/unset unsolicited CUSD event handler */ - mm_dbg ("%s unsolicited result code handlers", + mm_dbg ("(%s) %s unsolicited result code handlers", + mm_port_get_device (MM_PORT (ports[i])), enable ? "Setting" : "Removing"); mm_at_serial_port_add_unsolicited_msg_handler ( ports[i], @@ -4150,13 +4156,17 @@ set_messaging_unsolicited_events_handlers (MMIfaceModemMessaging *self, set_messaging_unsolicited_events_handlers); cmti_regex = mm_3gpp_cmti_regex_get (); - ports[0] = mm_base_modem_get_port_primary (MM_BASE_MODEM (self)); - ports[1] = mm_base_modem_get_port_secondary (MM_BASE_MODEM (self)); + ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)); + ports[1] = mm_base_modem_peek_port_secondary (MM_BASE_MODEM (self)); /* Enable unsolicited events in given port */ - for (i = 0; ports[i] && i < 2; i++) { + for (i = 0; i < 2; i++) { + if (!ports[i]) + continue; + /* Set/unset unsolicited CMTI event handler */ - mm_dbg ("%s messaging unsolicited events handlers", + mm_dbg ("(%s) %s messaging unsolicited events handlers", + mm_port_get_device (MM_PORT (ports[i])), enable ? "Setting" : "Removing"); mm_at_serial_port_add_unsolicited_msg_handler ( ports[i], @@ -4679,7 +4689,7 @@ modem_cdma_get_hdr_state (MMIfaceModemCdma *self, HdrStateContext *ctx; GByteArray *hdrstate; - qcdm = mm_base_modem_get_port_qcdm (MM_BASE_MODEM (self)); + qcdm = mm_base_modem_peek_port_qcdm (MM_BASE_MODEM (self)); if (!qcdm) { g_simple_async_report_error_in_idle (G_OBJECT (self), callback, @@ -4803,7 +4813,7 @@ modem_cdma_get_call_manager_state (MMIfaceModemCdma *self, CallManagerStateContext *ctx; GByteArray *cmstate; - qcdm = mm_base_modem_get_port_qcdm (MM_BASE_MODEM (self)); + qcdm = mm_base_modem_peek_port_qcdm (MM_BASE_MODEM (self)); if (!qcdm) { g_simple_async_report_error_in_idle (G_OBJECT (self), callback, @@ -5093,8 +5103,6 @@ modem_cdma_get_cdma1x_serving_system (MMIfaceModemCdma *self, if (ctx->qcdm) { GByteArray *cdma_status; - g_object_ref (ctx->qcdm); - /* Setup command */ cdma_status = g_byte_array_sized_new (25); cdma_status->len = qcdm_cmd_cdma_status_new ((char *) cdma_status->data, 25); @@ -5351,7 +5359,7 @@ modem_cdma_get_detailed_registration_state (MMIfaceModemCdma *self, /* The default implementation to get detailed registration state * requires the use of an AT port; so if we cannot get any, just * return the error */ - port = mm_base_modem_get_best_at_port (MM_BASE_MODEM (self), &error); + port = mm_base_modem_peek_best_at_port (MM_BASE_MODEM (self), &error); if (!port) { g_simple_async_report_take_gerror_in_idle (G_OBJECT (self), callback, @@ -5534,7 +5542,7 @@ modem_cdma_setup_registration_checks (MMIfaceModemCdma *self, modem_cdma_setup_registration_checks); /* Check if we have a QCDM port */ - ctx->has_qcdm_port = !!mm_base_modem_get_port_qcdm (MM_BASE_MODEM (self)); + ctx->has_qcdm_port = !!mm_base_modem_peek_port_qcdm (MM_BASE_MODEM (self)); /* If we have cached results of Sprint command checking, use them */ if (ctx->self->priv->checked_sprint_support) { @@ -5771,14 +5779,17 @@ setup_ports (MMBroadbandModem *self) GPtrArray *array; gint i, j; - ports[0] = mm_base_modem_get_port_primary (MM_BASE_MODEM (self)); - ports[1] = mm_base_modem_get_port_secondary (MM_BASE_MODEM (self)); + ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)); + ports[1] = mm_base_modem_peek_port_secondary (MM_BASE_MODEM (self)); /* Cleanup all unsolicited message handlers in all AT ports */ /* Set up CREG unsolicited message handlers, with NULL callbacks */ array = mm_3gpp_creg_regex_get (FALSE); - for (i = 0; ports[i] && i < 2; i++) { + for (i = 0; i < 2; i++) { + if (!ports[i]) + continue; + for (j = 0; j < array->len; j++) { mm_at_serial_port_add_unsolicited_msg_handler (MM_AT_SERIAL_PORT (ports[i]), (GRegex *)g_ptr_array_index (array, j), @@ -5791,7 +5802,10 @@ setup_ports (MMBroadbandModem *self) /* Set up CIEV unsolicited message handler, with NULL callback */ regex = mm_3gpp_ciev_regex_get (); - for (i = 0; ports[i] && i < 2; i++) { + for (i = 0; i < 2; i++) { + if (!ports[i]) + continue; + mm_at_serial_port_add_unsolicited_msg_handler (MM_AT_SERIAL_PORT (ports[i]), regex, NULL, @@ -5802,7 +5816,10 @@ setup_ports (MMBroadbandModem *self) /* Set up CMTI unsolicited message handler, with NULL callback */ regex = mm_3gpp_cmti_regex_get (); - for (i = 0; ports[i] && i < 2; i++) { + for (i = 0; i < 2; i++) { + if (!ports[i]) + continue; + mm_at_serial_port_add_unsolicited_msg_handler (MM_AT_SERIAL_PORT (ports[i]), regex, NULL, @@ -5813,7 +5830,10 @@ setup_ports (MMBroadbandModem *self) /* Set up CUSD unsolicited message handler, with NULL callback */ regex = mm_3gpp_cusd_regex_get (); - for (i = 0; ports[i] && i < 2; i++) { + for (i = 0; i < 2; i++) { + if (!ports[i]) + continue; + mm_at_serial_port_add_unsolicited_msg_handler (MM_AT_SERIAL_PORT (ports[i]), regex, NULL, @@ -6396,9 +6416,11 @@ initialize_context_complete_and_free (InitializeContext *ctx) g_simple_async_result_complete_in_idle (ctx->result); g_object_unref (ctx->result); /* balance open/close count */ - if (ctx->close_port) - mm_serial_port_close (MM_SERIAL_PORT (ctx->port)); - g_object_unref (ctx->port); + if (ctx->port) { + if (ctx->close_port) + mm_serial_port_close (MM_SERIAL_PORT (ctx->port)); + g_object_unref (ctx->port); + } g_object_unref (ctx->self); g_free (ctx); } @@ -6473,11 +6495,20 @@ initialize_step (InitializeContext *ctx) case INITIALIZE_STEP_PRIMARY_OPEN: { GError *error = NULL; + ctx->port = mm_base_modem_get_port_primary (MM_BASE_MODEM (ctx->self)); + if (!ctx->port) { + g_simple_async_result_set_error (ctx->result, + MM_CORE_ERROR, + MM_CORE_ERROR_FAILED, + "Cannot initialize: couldn't get primary port"); + initialize_context_complete_and_free (ctx); + return; + } + /* Open and send first commands to the primary serial port. * We do keep the primary port open during the whole initialization * sequence. Note that this port is not really passed to the interfaces, * they will get the primary port themselves. */ - ctx->port = g_object_ref (mm_base_modem_get_port_primary (MM_BASE_MODEM (ctx->self))); if (!mm_serial_port_open (MM_SERIAL_PORT (ctx->port), &error)) { g_simple_async_result_take_error (ctx->result, error); initialize_context_complete_and_free (ctx); diff --git a/src/mm-iface-modem-3gpp-ussd.c b/src/mm-iface-modem-3gpp-ussd.c index 4e6b47f4..fd902142 100644 --- a/src/mm-iface-modem-3gpp-ussd.c +++ b/src/mm-iface-modem-3gpp-ussd.c @@ -405,7 +405,6 @@ typedef enum { struct _DisablingContext { MMIfaceModem3gppUssd *self; - MMAtSerialPort *primary; DisablingStep step; GSimpleAsyncResult *result; MmGdbusModem3gppUssd *skeleton; @@ -420,7 +419,6 @@ disabling_context_new (MMIfaceModem3gppUssd *self, ctx = g_new0 (DisablingContext, 1); ctx->self = g_object_ref (self); - ctx->primary = g_object_ref (mm_base_modem_get_port_primary (MM_BASE_MODEM (self))); ctx->result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, @@ -439,7 +437,6 @@ disabling_context_complete_and_free (DisablingContext *ctx) { g_simple_async_result_complete_in_idle (ctx->result); g_object_unref (ctx->self); - g_object_unref (ctx->primary); g_object_unref (ctx->result); g_object_unref (ctx->skeleton); g_free (ctx); @@ -551,7 +548,6 @@ typedef enum { struct _EnablingContext { MMIfaceModem3gppUssd *self; - MMAtSerialPort *primary; EnablingStep step; GSimpleAsyncResult *result; MmGdbusModem3gppUssd *skeleton; @@ -566,7 +562,6 @@ enabling_context_new (MMIfaceModem3gppUssd *self, ctx = g_new0 (EnablingContext, 1); ctx->self = g_object_ref (self); - ctx->primary = g_object_ref (mm_base_modem_get_port_primary (MM_BASE_MODEM (self))); ctx->result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, @@ -585,7 +580,6 @@ enabling_context_complete_and_free (EnablingContext *ctx) { g_simple_async_result_complete_in_idle (ctx->result); g_object_unref (ctx->self); - g_object_unref (ctx->primary); g_object_unref (ctx->result); g_object_unref (ctx->skeleton); g_free (ctx); diff --git a/src/mm-iface-modem-3gpp.c b/src/mm-iface-modem-3gpp.c index 03a86967..78cf94d3 100644 --- a/src/mm-iface-modem-3gpp.c +++ b/src/mm-iface-modem-3gpp.c @@ -925,7 +925,6 @@ typedef enum { struct _DisablingContext { MMIfaceModem3gpp *self; - MMAtSerialPort *primary; DisablingStep step; GSimpleAsyncResult *result; MmGdbusModem *skeleton; @@ -940,7 +939,6 @@ disabling_context_new (MMIfaceModem3gpp *self, ctx = g_new0 (DisablingContext, 1); ctx->self = g_object_ref (self); - ctx->primary = g_object_ref (mm_base_modem_get_port_primary (MM_BASE_MODEM (self))); ctx->result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, @@ -959,7 +957,6 @@ disabling_context_complete_and_free (DisablingContext *ctx) { g_simple_async_result_complete_in_idle (ctx->result); g_object_unref (ctx->self); - g_object_unref (ctx->primary); g_object_unref (ctx->result); g_object_unref (ctx->skeleton); g_free (ctx); @@ -1148,7 +1145,6 @@ typedef enum { struct _EnablingContext { MMIfaceModem3gpp *self; - MMAtSerialPort *primary; EnablingStep step; GSimpleAsyncResult *result; MmGdbusModem3gpp *skeleton; @@ -1163,7 +1159,6 @@ enabling_context_new (MMIfaceModem3gpp *self, ctx = g_new0 (EnablingContext, 1); ctx->self = g_object_ref (self); - ctx->primary = g_object_ref (mm_base_modem_get_port_primary (MM_BASE_MODEM (self))); ctx->result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, @@ -1182,7 +1177,6 @@ enabling_context_complete_and_free (EnablingContext *ctx) { g_simple_async_result_complete_in_idle (ctx->result); g_object_unref (ctx->self); - g_object_unref (ctx->primary); g_object_unref (ctx->result); g_object_unref (ctx->skeleton); g_free (ctx); diff --git a/src/mm-iface-modem-cdma.c b/src/mm-iface-modem-cdma.c index c5983ddf..ec5d27e6 100644 --- a/src/mm-iface-modem-cdma.c +++ b/src/mm-iface-modem-cdma.c @@ -1101,7 +1101,6 @@ typedef enum { struct _DisablingContext { MMIfaceModemCdma *self; - MMAtSerialPort *primary; DisablingStep step; GSimpleAsyncResult *result; MmGdbusModemCdma *skeleton; @@ -1116,7 +1115,6 @@ disabling_context_new (MMIfaceModemCdma *self, ctx = g_new0 (DisablingContext, 1); ctx->self = g_object_ref (self); - ctx->primary = g_object_ref (mm_base_modem_get_port_primary (MM_BASE_MODEM (self))); ctx->result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, @@ -1135,7 +1133,6 @@ disabling_context_complete_and_free (DisablingContext *ctx) { g_simple_async_result_complete_in_idle (ctx->result); g_object_unref (ctx->self); - g_object_unref (ctx->primary); g_object_unref (ctx->result); g_object_unref (ctx->skeleton); g_free (ctx); @@ -1196,7 +1193,6 @@ typedef enum { struct _EnablingContext { MMIfaceModemCdma *self; - MMAtSerialPort *primary; EnablingStep step; GSimpleAsyncResult *result; MmGdbusModemCdma *skeleton; @@ -1211,7 +1207,6 @@ enabling_context_new (MMIfaceModemCdma *self, ctx = g_new0 (EnablingContext, 1); ctx->self = g_object_ref (self); - ctx->primary = g_object_ref (mm_base_modem_get_port_primary (MM_BASE_MODEM (self))); ctx->result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, @@ -1230,7 +1225,6 @@ enabling_context_complete_and_free (EnablingContext *ctx) { g_simple_async_result_complete_in_idle (ctx->result); g_object_unref (ctx->self); - g_object_unref (ctx->primary); g_object_unref (ctx->result); g_object_unref (ctx->skeleton); g_free (ctx); diff --git a/src/mm-iface-modem-location.c b/src/mm-iface-modem-location.c index a021a563..09933375 100644 --- a/src/mm-iface-modem-location.c +++ b/src/mm-iface-modem-location.c @@ -451,7 +451,6 @@ typedef enum { struct _DisablingContext { MMIfaceModemLocation *self; - MMAtSerialPort *primary; DisablingStep step; GSimpleAsyncResult *result; MmGdbusModemLocation *skeleton; @@ -466,7 +465,6 @@ disabling_context_new (MMIfaceModemLocation *self, ctx = g_new0 (DisablingContext, 1); ctx->self = g_object_ref (self); - ctx->primary = g_object_ref (mm_base_modem_get_port_primary (MM_BASE_MODEM (self))); ctx->result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, @@ -485,7 +483,6 @@ disabling_context_complete_and_free (DisablingContext *ctx) { g_simple_async_result_complete_in_idle (ctx->result); g_object_unref (ctx->self); - g_object_unref (ctx->primary); g_object_unref (ctx->result); g_object_unref (ctx->skeleton); g_free (ctx); @@ -575,7 +572,6 @@ typedef enum { struct _EnablingContext { MMIfaceModemLocation *self; - MMAtSerialPort *primary; EnablingStep step; GSimpleAsyncResult *result; MmGdbusModemLocation *skeleton; @@ -590,7 +586,6 @@ enabling_context_new (MMIfaceModemLocation *self, ctx = g_new0 (EnablingContext, 1); ctx->self = g_object_ref (self); - ctx->primary = g_object_ref (mm_base_modem_get_port_primary (MM_BASE_MODEM (self))); ctx->result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, @@ -609,7 +604,6 @@ enabling_context_complete_and_free (EnablingContext *ctx) { g_simple_async_result_complete_in_idle (ctx->result); g_object_unref (ctx->self); - g_object_unref (ctx->primary); g_object_unref (ctx->result); g_object_unref (ctx->skeleton); g_free (ctx); diff --git a/src/mm-iface-modem-messaging.c b/src/mm-iface-modem-messaging.c index 2545cdc0..cf9f0d34 100644 --- a/src/mm-iface-modem-messaging.c +++ b/src/mm-iface-modem-messaging.c @@ -486,7 +486,6 @@ typedef enum { struct _DisablingContext { MMIfaceModemMessaging *self; - MMAtSerialPort *primary; DisablingStep step; GSimpleAsyncResult *result; MmGdbusModemMessaging *skeleton; @@ -501,7 +500,6 @@ disabling_context_new (MMIfaceModemMessaging *self, ctx = g_new0 (DisablingContext, 1); ctx->self = g_object_ref (self); - ctx->primary = g_object_ref (mm_base_modem_get_port_primary (MM_BASE_MODEM (self))); ctx->result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, @@ -520,7 +518,6 @@ disabling_context_complete_and_free (DisablingContext *ctx) { g_simple_async_result_complete_in_idle (ctx->result); g_object_unref (ctx->self); - g_object_unref (ctx->primary); g_object_unref (ctx->result); g_object_unref (ctx->skeleton); g_free (ctx); @@ -648,7 +645,6 @@ typedef enum { struct _EnablingContext { MMIfaceModemMessaging *self; - MMAtSerialPort *primary; EnablingStep step; GSimpleAsyncResult *result; MmGdbusModemMessaging *skeleton; @@ -665,7 +661,6 @@ enabling_context_new (MMIfaceModemMessaging *self, ctx = g_new0 (EnablingContext, 1); ctx->self = g_object_ref (self); - ctx->primary = g_object_ref (mm_base_modem_get_port_primary (MM_BASE_MODEM (self))); ctx->result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, @@ -684,7 +679,6 @@ enabling_context_complete_and_free (EnablingContext *ctx) { g_simple_async_result_complete_in_idle (ctx->result); g_object_unref (ctx->self); - g_object_unref (ctx->primary); g_object_unref (ctx->result); g_object_unref (ctx->skeleton); g_free (ctx); diff --git a/src/mm-iface-modem-time.c b/src/mm-iface-modem-time.c index 2502ceca..70f3ed05 100644 --- a/src/mm-iface-modem-time.c +++ b/src/mm-iface-modem-time.c @@ -395,7 +395,6 @@ typedef enum { struct _DisablingContext { MMIfaceModemTime *self; - MMAtSerialPort *primary; DisablingStep step; GSimpleAsyncResult *result; MmGdbusModemTime *skeleton; @@ -410,7 +409,6 @@ disabling_context_new (MMIfaceModemTime *self, ctx = g_new0 (DisablingContext, 1); ctx->self = g_object_ref (self); - ctx->primary = g_object_ref (mm_base_modem_get_port_primary (MM_BASE_MODEM (self))); ctx->result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, @@ -429,7 +427,6 @@ disabling_context_complete_and_free (DisablingContext *ctx) { g_simple_async_result_complete_in_idle (ctx->result); g_object_unref (ctx->self); - g_object_unref (ctx->primary); g_object_unref (ctx->result); g_object_unref (ctx->skeleton); g_free (ctx); @@ -570,7 +567,6 @@ typedef enum { struct _EnablingContext { MMIfaceModemTime *self; - MMAtSerialPort *primary; EnablingStep step; GSimpleAsyncResult *result; MmGdbusModemTime *skeleton; @@ -585,7 +581,6 @@ enabling_context_new (MMIfaceModemTime *self, ctx = g_new0 (EnablingContext, 1); ctx->self = g_object_ref (self); - ctx->primary = g_object_ref (mm_base_modem_get_port_primary (MM_BASE_MODEM (self))); ctx->result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, @@ -604,7 +599,6 @@ enabling_context_complete_and_free (EnablingContext *ctx) { g_simple_async_result_complete_in_idle (ctx->result); g_object_unref (ctx->self); - g_object_unref (ctx->primary); g_object_unref (ctx->result); g_object_unref (ctx->skeleton); g_free (ctx); diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c index 32f66a7a..0e3b0017 100644 --- a/src/mm-iface-modem.c +++ b/src/mm-iface-modem.c @@ -2300,13 +2300,9 @@ disabling_context_new (MMIfaceModem *self, ctx = g_new0 (DisablingContext, 1); ctx->self = g_object_ref (self); - ctx->primary = g_object_ref (mm_base_modem_get_port_primary (MM_BASE_MODEM (self))); + ctx->primary = mm_base_modem_get_port_primary (MM_BASE_MODEM (self)); ctx->secondary = mm_base_modem_get_port_secondary (MM_BASE_MODEM (self)); - if (ctx->secondary) - g_object_ref (ctx->secondary); ctx->qcdm = mm_base_modem_get_port_qcdm (MM_BASE_MODEM (self)); - if (ctx->qcdm) - g_object_ref (ctx->qcdm); ctx->result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, @@ -2341,7 +2337,8 @@ disabling_context_complete_and_free (DisablingContext *ctx) MM_MODEM_STATE_CHANGE_REASON_UNKNOWN); g_object_unref (ctx->self); - g_object_unref (ctx->primary); + if (ctx->primary) + g_object_unref (ctx->primary); if (ctx->secondary) g_object_unref (ctx->secondary); if (ctx->qcdm) @@ -2427,7 +2424,7 @@ interface_disabling_step (DisablingContext *ctx) * be safe to check whether they are really open before trying to close. */ mm_dbg ("Closing all ports..."); - if (mm_serial_port_is_open (MM_SERIAL_PORT (ctx->primary))) + if (ctx->primary && mm_serial_port_is_open (MM_SERIAL_PORT (ctx->primary))) mm_serial_port_close (MM_SERIAL_PORT (ctx->primary)); if (ctx->secondary && mm_serial_port_is_open (MM_SERIAL_PORT (ctx->secondary))) mm_serial_port_close (MM_SERIAL_PORT (ctx->secondary)); @@ -2503,13 +2500,9 @@ enabling_context_new (MMIfaceModem *self, ctx = g_new0 (EnablingContext, 1); ctx->self = g_object_ref (self); - ctx->primary = g_object_ref (mm_base_modem_get_port_primary (MM_BASE_MODEM (self))); + ctx->primary = mm_base_modem_get_port_primary (MM_BASE_MODEM (self)); ctx->secondary = mm_base_modem_get_port_secondary (MM_BASE_MODEM (self)); - if (ctx->secondary) - g_object_ref (ctx->secondary); ctx->qcdm = mm_base_modem_get_port_qcdm (MM_BASE_MODEM (self)); - if (ctx->qcdm) - g_object_ref (ctx->qcdm); ctx->result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, @@ -2554,7 +2547,8 @@ enabling_context_complete_and_free (EnablingContext *ctx) } g_object_unref (ctx->self); - g_object_unref (ctx->primary); + if (ctx->primary) + g_object_unref (ctx->primary); if (ctx->secondary) g_object_unref (ctx->secondary); if (ctx->qcdm) @@ -2737,6 +2731,15 @@ interface_enabling_step (EnablingContext *ctx) GError *error = NULL; /* Open primary port */ + if (!ctx->primary) { + g_simple_async_result_set_error (ctx->result, + MM_CORE_ERROR, + MM_CORE_ERROR_FAILED, + "Cannot enable: no primary port"); + enabling_context_complete_and_free (ctx); + return; + } + if (!mm_serial_port_open (MM_SERIAL_PORT (ctx->primary), &error)) { g_simple_async_result_take_error (ctx->result, error); enabling_context_complete_and_free (ctx); diff --git a/src/mm-sim.c b/src/mm-sim.c index 95a1eec5..fbb20752 100644 --- a/src/mm-sim.c +++ b/src/mm-sim.c @@ -1386,15 +1386,11 @@ struct _InitAsyncContext { MMSim *self; InitializationStep step; guint sim_identifier_tries; - MMAtSerialPort *port; }; static void -init_async_context_free (InitAsyncContext *ctx, - gboolean close_port) +init_async_context_free (InitAsyncContext *ctx) { - if (close_port) - mm_serial_port_close (MM_SERIAL_PORT (ctx->port)); g_object_unref (ctx->self); g_object_unref (ctx->result); if (ctx->cancellable) @@ -1569,7 +1565,7 @@ interface_initialization_step (InitAsyncContext *ctx) /* We are done without errors! */ g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE); g_simple_async_result_complete_in_idle (ctx->result); - init_async_context_free (ctx, TRUE); + init_async_context_free (ctx); return; } @@ -1585,7 +1581,6 @@ common_init_async (GAsyncInitable *initable, { InitAsyncContext *ctx; - GError *error = NULL; ctx = g_new (InitAsyncContext, 1); ctx->self = g_object_ref (initable); @@ -1599,14 +1594,6 @@ common_init_async (GAsyncInitable *initable, ctx->step = INITIALIZATION_STEP_FIRST; ctx->sim_identifier_tries = 0; - ctx->port = mm_base_modem_get_port_primary (ctx->self->priv->modem); - if (!mm_serial_port_open (MM_SERIAL_PORT (ctx->port), &error)) { - g_simple_async_result_take_error (ctx->result, error); - g_simple_async_result_complete_in_idle (ctx->result); - init_async_context_free (ctx, FALSE); - return; - } - interface_initialization_step (ctx); } |