base-modem: new port getters and peekers

* mm_base_modem_peek_port_* () will return either a port object (no new
reference), or NULL if none available.

You would usually peek() a port if you're going to use it just in the current
method, as there is no way to that reference to get invalid (we're single
threaded).

 * mm_base_modem_get_port_* () will return either NEW references to valid
port objects, or NULL if none available.

And, you would usually get() a port, whenever you want the port object to be
valid even out of the current method, for example when keeping it in the
context of an async operation.

Also, we need to consider that the primary AT port MAY BE NULL when you
peek() or get() it. This is due to the fact that we may be releasing ports
(due to device disconnection) in the middle of async operations.
This commit is contained in:
Aleksander Morgado
2012-03-08 12:47:45 +01:00
parent 48285dcfdf
commit cc6d4a97fb
16 changed files with 321 additions and 221 deletions

View File

@@ -121,7 +121,7 @@ enable_unsolicited_events (MMIfaceModem3gpp *self,
mm_base_modem_at_command_in_port ( mm_base_modem_at_command_in_port (
MM_BASE_MODEM (self), MM_BASE_MODEM (self),
/* Only primary port is expected in the Cinterion modems */ /* 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>]]]]] /* AT=CMER=[<mode>[,<keyp>[,<disp>[,<ind>[,<bfr>]]]]]
* but <ind> should be either not set, or equal to 0 or 2. * but <ind> should be either not set, or equal to 0 or 2.
* Enabled with 2. * Enabled with 2.

View File

@@ -57,6 +57,7 @@ typedef struct {
MMBearerIridium *self; MMBearerIridium *self;
GSimpleAsyncResult *result; GSimpleAsyncResult *result;
GCancellable *cancellable; GCancellable *cancellable;
MMAtSerialPort *primary;
GError *saved_error; GError *saved_error;
} ConnectContext; } ConnectContext;
@@ -66,6 +67,8 @@ connect_context_complete_and_free (ConnectContext *ctx)
g_simple_async_result_complete_in_idle (ctx->result); g_simple_async_result_complete_in_idle (ctx->result);
if (ctx->saved_error) if (ctx->saved_error)
g_error_free (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->cancellable);
g_object_unref (ctx->result); g_object_unref (ctx->result);
g_object_unref (ctx->self); 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 */ /* 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 && if (result &&
g_str_has_prefix (result, "+CEER: ") && g_str_has_prefix (result, "+CEER: ") &&
strlen (result) > 7) { strlen (result) > 7) {
@@ -143,11 +146,12 @@ dial_ready (MMBaseModem *modem,
/* DO NOT check for cancellable here. If we got here without errors, the /* 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 * bearer is really connected and therefore we need to reflect that in
* the state machine. */ * 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) { if (ctx->saved_error) {
/* Try to get more information why it failed */ /* Try to get more information why it failed */
mm_base_modem_at_command ( mm_base_modem_at_command_in_port (
modem, modem,
ctx->primary,
"+CEER", "+CEER",
3, 3,
FALSE, FALSE,
@@ -158,7 +162,7 @@ dial_ready (MMBaseModem *modem,
} }
/* Port is connected; update the state */ /* 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 */ /* Build IP config; always PPP based */
config = mm_bearer_ip_config_new (); config = mm_bearer_ip_config_new ();
@@ -166,7 +170,7 @@ dial_ready (MMBaseModem *modem,
/* Build result */ /* Build result */
result = g_new0 (ConnectResult, 1); 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->ipv4_config = config;
result->ipv6_config = g_object_ref (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 */ /* 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) { if (error) {
g_simple_async_result_take_error (ctx->result, error); g_simple_async_result_take_error (ctx->result, error);
connect_context_complete_and_free (ctx); 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 /* 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 * that we won't specify a specific port to use; Iridium modems only expose
* one. */ * one. */
mm_base_modem_at_command ( mm_base_modem_at_command_in_port (
modem, modem,
ctx->primary,
"ATDT008816000025", "ATDT008816000025",
60, 60,
FALSE, FALSE,
@@ -235,6 +240,7 @@ connect (MMBearer *self,
/* In this context, we only keep the stuff we'll need later */ /* In this context, we only keep the stuff we'll need later */
ctx = g_new0 (ConnectContext, 1); ctx = g_new0 (ConnectContext, 1);
ctx->self = g_object_ref (self); ctx->self = g_object_ref (self);
ctx->primary = mm_base_modem_get_port_primary (modem);
ctx->cancellable = g_object_ref (cancellable); ctx->cancellable = g_object_ref (cancellable);
ctx->result = g_simple_async_result_new (G_OBJECT (self), ctx->result = g_simple_async_result_new (G_OBJECT (self),
callback, callback,
@@ -243,8 +249,9 @@ connect (MMBearer *self,
/* Bearer service type set to 9600bps (V.110), which behaves better than the /* Bearer service type set to 9600bps (V.110), which behaves better than the
* default 9600bps (V.32). */ * default 9600bps (V.32). */
mm_base_modem_at_command ( mm_base_modem_at_command_in_port (
modem, modem,
ctx->primary,
"+CBST=71,0,1", "+CBST=71,0,1",
3, 3,
FALSE, FALSE,
@@ -258,6 +265,24 @@ connect (MMBearer *self,
/*****************************************************************************/ /*****************************************************************************/
/* Disconnect */ /* 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 static gboolean
disconnect_finish (MMBearer *self, disconnect_finish (MMBearer *self,
GAsyncResult *res, GAsyncResult *res,
@@ -269,7 +294,7 @@ disconnect_finish (MMBearer *self,
static void static void
primary_flash_ready (MMSerialPort *port, primary_flash_ready (MMSerialPort *port,
GError *error, GError *error,
GSimpleAsyncResult *result) DisconnectContext *ctx)
{ {
if (error) { if (error) {
/* Ignore "NO CARRIER" response when modem disconnects and any flash /* 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,
MM_SERIAL_ERROR_FLASH_FAILED)) { MM_SERIAL_ERROR_FLASH_FAILED)) {
/* Fatal */ /* Fatal */
g_simple_async_result_set_from_error (result, error); g_simple_async_result_set_from_error (ctx->result, error);
g_simple_async_result_complete (result); disconnect_context_complete_and_free (ctx);
g_object_unref (result);
return; return;
} }
mm_dbg ("Port flashing failed (not fatal): %s", error->message); 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) */ * already have set the port as disconnected (e.g the 3GPP one) */
mm_port_set_connected (MM_PORT (port), FALSE); mm_port_set_connected (MM_PORT (port), FALSE);
g_simple_async_result_set_op_res_gboolean (result, TRUE); g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
g_simple_async_result_complete (result); disconnect_context_complete_and_free (ctx);
g_object_unref (result);
} }
static gboolean static gboolean
after_disconnect_sleep_cb (GSimpleAsyncResult *simple) after_disconnect_sleep_cb (DisconnectContext *ctx)
{ {
GError *error = NULL; 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 */ /* Propagate errors when reopening the port */
if (!mm_serial_port_open (MM_SERIAL_PORT (primary), &error)) { if (!mm_serial_port_open (MM_SERIAL_PORT (ctx->primary), &error)) {
g_simple_async_result_take_error (simple, error); g_simple_async_result_take_error (ctx->result, error);
g_simple_async_result_complete (simple); disconnect_context_complete_and_free (ctx);
g_object_unref (simple); return FALSE;
} else {
mm_serial_port_flash (MM_SERIAL_PORT (primary),
1000,
TRUE,
(MMSerialFlashFn)primary_flash_ready,
simple);
} }
g_object_unref (modem); mm_serial_port_flash (MM_SERIAL_PORT (ctx->primary),
g_object_unref (self); 1000,
TRUE,
(MMSerialFlashFn)primary_flash_ready,
ctx);
return FALSE; return FALSE;
} }
@@ -336,42 +347,40 @@ disconnect (MMBearer *self,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
{ {
MMAtSerialPort *primary; DisconnectContext *ctx;
MMBaseModem *modem = NULL;
GSimpleAsyncResult *result;
ctx = g_new (DisconnectContext, 1);
ctx->self = g_object_ref (self);
g_object_get (self, g_object_get (self,
MM_BEARER_MODEM, &modem, MM_BEARER_MODEM, &ctx->modem,
NULL); NULL);
g_assert (modem != NULL); ctx->primary = mm_base_modem_get_port_primary (ctx->modem);
primary = mm_base_modem_get_port_primary (modem); ctx->result = g_simple_async_result_new (G_OBJECT (self),
g_object_unref (modem); callback,
user_data,
disconnect);
if (!mm_port_get_connected (MM_PORT (primary))) { if (!ctx->primary ||
g_simple_async_report_error_in_idle ( !mm_port_get_connected (MM_PORT (ctx->primary))) {
G_OBJECT (self), g_simple_async_result_set_error (
callback, ctx->result,
user_data,
MM_CORE_ERROR, MM_CORE_ERROR,
MM_CORE_ERROR_FAILED, MM_CORE_ERROR_FAILED,
"Couldn't disconnect Iridium: this bearer is not connected"); "Couldn't disconnect Iridium: this bearer is not connected");
disconnect_context_complete_and_free (ctx);
return; return;
} }
/* Just flash the primary port */ /* 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. /* 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 * We now need to fully close that one, as if we were disabled, and reopen
* it again afterwards. */ * it again afterwards. */
mm_serial_port_close (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 (primary))); g_warn_if_fail (!mm_serial_port_is_open (MM_SERIAL_PORT (ctx->primary)));
mm_dbg ("Waiting some seconds before reopening the port..."); 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);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@@ -381,12 +381,18 @@ create_bearer (MMIfaceModem *self,
static void static void
setup_ports (MMBroadbandModem *self) setup_ports (MMBroadbandModem *self)
{ {
MMAtSerialPort *primary;
/* Call parent's setup ports first always */ /* Call parent's setup ports first always */
MM_BROADBAND_MODEM_CLASS (mm_broadband_modem_iridium_parent_class)->setup_ports (self); MM_BROADBAND_MODEM_CLASS (mm_broadband_modem_iridium_parent_class)->setup_ports (self);
/* Set 9600 baudrate by default in the AT port */ /* Set 9600 baudrate by default in the AT port */
mm_dbg ("Baudrate will be set to 9600 bps..."); 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, MM_SERIAL_PORT_BAUD, 9600,
NULL); NULL);
} }

View File

@@ -277,7 +277,7 @@ mm_base_modem_at_sequence (MMBaseModem *self,
GError *error = NULL; GError *error = NULL;
/* No port given, so we'll try to guess which is best */ /* 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) { if (!port) {
g_assert (error != NULL); g_assert (error != NULL);
g_simple_async_report_take_gerror_in_idle (G_OBJECT (self), 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; GError *error = NULL;
/* No port given, so we'll try to guess which is best */ /* 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) { if (!port) {
g_assert (error != NULL); g_assert (error != NULL);
g_simple_async_report_take_gerror_in_idle (G_OBJECT (self), 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; MMAtSerialPort *port;
/* No port given, so we'll try to guess which is best */ /* 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) if (!port)
/* No valid port, and we ignore replies, so just exit. */ /* No valid port, and we ignore replies, so just exit. */
return; return;

View File

@@ -325,6 +325,14 @@ mm_base_modem_get_port_primary (MMBaseModem *self)
{ {
g_return_val_if_fail (MM_IS_BASE_MODEM (self), NULL); 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; 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); 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; return self->priv->secondary;
} }
@@ -341,11 +357,28 @@ mm_base_modem_get_port_qcdm (MMBaseModem *self)
{ {
g_return_val_if_fail (MM_IS_BASE_MODEM (self), NULL); 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; return self->priv->qcdm;
} }
MMPort * MMPort *
mm_base_modem_get_best_data_port (MMBaseModem *self) 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); g_return_val_if_fail (MM_IS_BASE_MODEM (self), NULL);
@@ -361,24 +394,32 @@ MMAtSerialPort *
mm_base_modem_get_best_at_port (MMBaseModem *self, mm_base_modem_get_best_at_port (MMBaseModem *self,
GError **error) 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 */ /* Decide which port to use */
port = mm_base_modem_get_port_primary (self); if (self->priv->primary &&
if (port && !mm_port_get_connected (MM_PORT (port))) !mm_port_get_connected (MM_PORT (self->priv->primary)))
return port; return self->priv->primary;
/* If primary port is connected, check if we can get the secondary /* If primary port is connected, check if we can get the secondary
* port */ * port */
port = mm_base_modem_get_port_secondary (self); if (self->priv->secondary &&
if (port && !mm_port_get_connected (MM_PORT (port))) !mm_port_get_connected (MM_PORT (self->priv->secondary)))
return port; return self->priv->secondary;
/* Otherwise, we cannot get any port */ /* Otherwise, we cannot get any port */
g_set_error (error, g_set_error (error,
MM_CORE_ERROR, MM_CORE_ERROR,
MM_CORE_ERROR_CONNECTED, MM_CORE_ERROR_CONNECTED,
"No port available to run command"); "No AT port available to run command");
return NULL; return NULL;
} }

View File

@@ -114,12 +114,20 @@ gboolean mm_base_modem_owns_port (MMBaseModem *self,
gboolean mm_base_modem_organize_ports (MMBaseModem *self, gboolean mm_base_modem_organize_ports (MMBaseModem *self,
GError **error); GError **error);
MMAtSerialPort *mm_base_modem_get_port_primary (MMBaseModem *self); MMAtSerialPort *mm_base_modem_peek_port_primary (MMBaseModem *self);
MMAtSerialPort *mm_base_modem_get_port_secondary (MMBaseModem *self); MMAtSerialPort *mm_base_modem_peek_port_secondary (MMBaseModem *self);
MMQcdmSerialPort *mm_base_modem_get_port_qcdm (MMBaseModem *self); MMQcdmSerialPort *mm_base_modem_peek_port_qcdm (MMBaseModem *self);
MMPort *mm_base_modem_get_best_data_port (MMBaseModem *self); MMAtSerialPort *mm_base_modem_peek_best_at_port (MMBaseModem *self,
MMAtSerialPort *mm_base_modem_get_best_at_port (MMBaseModem *self, GError **error);
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, void mm_base_modem_set_valid (MMBaseModem *self,
gboolean valid); gboolean valid);

View File

@@ -412,6 +412,8 @@ connect_cdma (MMBroadbandBearer *self,
{ {
DetailedConnectContext *ctx; DetailedConnectContext *ctx;
g_assert (primary != NULL);
ctx = detailed_connect_context_new (self, ctx = detailed_connect_context_new (self,
modem, modem,
primary, primary,
@@ -591,6 +593,8 @@ dial_3gpp (MMBroadbandBearer *self,
gchar *command; gchar *command;
Dial3gppContext *ctx; Dial3gppContext *ctx;
g_assert (primary != NULL);
ctx = dial_3gpp_context_new (self, ctx = dial_3gpp_context_new (self,
modem, modem,
primary, primary,
@@ -899,6 +903,8 @@ connect_3gpp (MMBroadbandBearer *self,
{ {
DetailedConnectContext *ctx; DetailedConnectContext *ctx;
g_assert (primary != NULL);
ctx = detailed_connect_context_new (self, ctx = detailed_connect_context_new (self,
modem, modem,
primary, primary,
@@ -1084,8 +1090,21 @@ connect (MMBearer *self,
NULL); NULL);
g_assert (modem != NULL); g_assert (modem != NULL);
/* We will launch the ATD call in the primary port */ /* We will launch the ATD call in the primary port... */
primary = mm_base_modem_get_port_primary (modem); 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))) { if (mm_port_get_connected (MM_PORT (primary))) {
g_simple_async_report_error_in_idle ( g_simple_async_report_error_in_idle (
G_OBJECT (self), G_OBJECT (self),
@@ -1099,7 +1118,7 @@ connect (MMBearer *self,
} }
/* Look for best data port, NULL if none available. */ /* 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) { if (!data) {
g_simple_async_report_error_in_idle ( g_simple_async_report_error_in_idle (
G_OBJECT (self), G_OBJECT (self),
@@ -1149,7 +1168,7 @@ connect (MMBearer *self,
MM_BROADBAND_BEARER (self), MM_BROADBAND_BEARER (self),
MM_BROADBAND_MODEM (modem), MM_BROADBAND_MODEM (modem),
primary, primary,
mm_base_modem_get_port_secondary (modem), mm_base_modem_peek_port_secondary (modem),
data, data,
cancellable, cancellable,
(GAsyncReadyCallback) connect_3gpp_ready, (GAsyncReadyCallback) connect_3gpp_ready,
@@ -1170,7 +1189,7 @@ connect (MMBearer *self,
MM_BROADBAND_BEARER (self), MM_BROADBAND_BEARER (self),
MM_BROADBAND_MODEM (modem), MM_BROADBAND_MODEM (modem),
primary, primary,
mm_base_modem_get_port_secondary (modem), mm_base_modem_peek_port_secondary (modem),
data, data,
cancellable, cancellable,
(GAsyncReadyCallback) connect_cdma_ready, (GAsyncReadyCallback) connect_cdma_ready,
@@ -1294,6 +1313,8 @@ disconnect_cdma (MMBroadbandBearer *self,
{ {
DetailedDisconnectContext *ctx; DetailedDisconnectContext *ctx;
g_assert (primary != NULL);
ctx = detailed_disconnect_context_new (self, ctx = detailed_disconnect_context_new (self,
modem, modem,
primary, primary,
@@ -1419,6 +1440,8 @@ disconnect_3gpp (MMBroadbandBearer *self,
{ {
DetailedDisconnectContext *ctx; DetailedDisconnectContext *ctx;
g_assert (primary != NULL);
ctx = detailed_disconnect_context_new (self, ctx = detailed_disconnect_context_new (self,
modem, modem,
primary, primary,
@@ -1552,6 +1575,7 @@ disconnect (MMBearer *self,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
{ {
MMAtSerialPort *primary;
MMBaseModem *modem = NULL; MMBaseModem *modem = NULL;
DisconnectContext *ctx; DisconnectContext *ctx;
@@ -1571,6 +1595,20 @@ disconnect (MMBearer *self,
NULL); NULL);
g_assert (modem != 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 */ /* In this context, we only keep the stuff we'll need later */
ctx = g_new0 (DisconnectContext, 1); ctx = g_new0 (DisconnectContext, 1);
ctx->self = g_object_ref (self); ctx->self = g_object_ref (self);
@@ -1585,8 +1623,8 @@ disconnect (MMBearer *self,
MM_BROADBAND_BEARER_GET_CLASS (self)->disconnect_3gpp ( MM_BROADBAND_BEARER_GET_CLASS (self)->disconnect_3gpp (
MM_BROADBAND_BEARER (self), MM_BROADBAND_BEARER (self),
MM_BROADBAND_MODEM (modem), MM_BROADBAND_MODEM (modem),
mm_base_modem_get_port_primary (modem), primary,
mm_base_modem_get_port_secondary (modem), mm_base_modem_peek_port_secondary (modem),
MM_BROADBAND_BEARER (self)->priv->port, MM_BROADBAND_BEARER (self)->priv->port,
(GAsyncReadyCallback) disconnect_3gpp_ready, (GAsyncReadyCallback) disconnect_3gpp_ready,
ctx); ctx);
@@ -1596,8 +1634,8 @@ disconnect (MMBearer *self,
MM_BROADBAND_BEARER_GET_CLASS (self)->disconnect_cdma ( MM_BROADBAND_BEARER_GET_CLASS (self)->disconnect_cdma (
MM_BROADBAND_BEARER (self), MM_BROADBAND_BEARER (self),
MM_BROADBAND_MODEM (modem), MM_BROADBAND_MODEM (modem),
mm_base_modem_get_port_primary (modem), primary,
mm_base_modem_get_port_secondary (modem), mm_base_modem_peek_port_secondary (modem),
MM_BROADBAND_BEARER (self)->priv->port, MM_BROADBAND_BEARER (self)->priv->port,
(GAsyncReadyCallback) disconnect_cdma_ready, (GAsyncReadyCallback) disconnect_cdma_ready,
ctx); ctx);
@@ -1655,8 +1693,11 @@ static void
init_async_context_free (InitAsyncContext *ctx, init_async_context_free (InitAsyncContext *ctx,
gboolean close_port) gboolean close_port)
{ {
if (close_port) if (ctx->port) {
mm_serial_port_close (MM_SERIAL_PORT (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->self);
g_object_unref (ctx->modem); g_object_unref (ctx->modem);
g_object_unref (ctx->result); g_object_unref (ctx->result);
@@ -1919,6 +1960,16 @@ initable_init_async (GAsyncInitable *initable,
NULL); NULL);
ctx->port = mm_base_modem_get_port_primary (ctx->modem); 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)) { if (!mm_serial_port_open (MM_SERIAL_PORT (ctx->port), &error)) {
g_simple_async_result_take_error (ctx->result, error); g_simple_async_result_take_error (ctx->result, error);
g_simple_async_result_complete_in_idle (ctx->result); g_simple_async_result_complete_in_idle (ctx->result);

View File

@@ -1246,7 +1246,6 @@ modem_load_signal_quality (MMIfaceModem *self,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
{ {
MMSerialPort *port;
SignalQualityContext *ctx; SignalQualityContext *ctx;
GError *error = NULL; GError *error = NULL;
@@ -1259,9 +1258,8 @@ modem_load_signal_quality (MMIfaceModem *self,
modem_load_signal_quality); modem_load_signal_quality);
/* Check whether we can get a non-connected AT port */ /* Check whether we can get a non-connected AT port */
port = (MMSerialPort *)mm_base_modem_get_best_at_port (MM_BASE_MODEM (self), &error); ctx->port = (MMSerialPort *)mm_base_modem_get_best_at_port (MM_BASE_MODEM (self), &error);
if (port) { if (ctx->port) {
ctx->port = g_object_ref (port);
if (MM_BROADBAND_MODEM (self)->priv->modem_cind_supported) if (MM_BROADBAND_MODEM (self)->priv->modem_cind_supported)
signal_quality_cind (ctx); signal_quality_cind (ctx);
else else
@@ -1270,10 +1268,9 @@ modem_load_signal_quality (MMIfaceModem *self,
} }
/* If no best AT port available (all connected), try with QCDM ports */ /* If no best AT port available (all connected), try with QCDM ports */
port = (MMSerialPort *)mm_base_modem_get_port_qcdm (MM_BASE_MODEM (self)); ctx->port = (MMSerialPort *)mm_base_modem_get_port_qcdm (MM_BASE_MODEM (self));
if (port) { if (ctx->port) {
g_error_free (error); g_error_free (error);
ctx->port = g_object_ref (port);
signal_quality_qcdm (ctx); signal_quality_qcdm (ctx);
return; return;
} }
@@ -1446,13 +1443,17 @@ set_unsolicited_events_handlers (MMIfaceModem3gpp *self,
set_unsolicited_events_handlers); set_unsolicited_events_handlers);
ciev_regex = mm_3gpp_ciev_regex_get (); ciev_regex = mm_3gpp_ciev_regex_get ();
ports[0] = mm_base_modem_get_port_primary (MM_BASE_MODEM (self)); ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self));
ports[1] = mm_base_modem_get_port_secondary (MM_BASE_MODEM (self)); ports[1] = mm_base_modem_peek_port_secondary (MM_BASE_MODEM (self));
/* Enable unsolicited events in given port */ /* 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 */ /* 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"); enable ? "Setting" : "Removing");
mm_at_serial_port_add_unsolicited_msg_handler ( mm_at_serial_port_add_unsolicited_msg_handler (
ports[i], ports[i],
@@ -1546,10 +1547,10 @@ run_unsolicited_events_setup (UnsolicitedEventsContext *ctx)
if (!ctx->cmer_primary_done) { if (!ctx->cmer_primary_done) {
ctx->cmer_primary_done = TRUE; 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) { } else if (!ctx->cmer_secondary_done) {
ctx->cmer_secondary_done = TRUE; 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 */ /* Enable unsolicited events in given port */
@@ -2295,31 +2296,31 @@ modem_3gpp_setup_unsolicited_registration (MMIfaceModem3gpp *self,
MMAtSerialPort *ports[2]; MMAtSerialPort *ports[2];
GPtrArray *array; GPtrArray *array;
guint i; guint i;
guint j;
mm_dbg ("setting up unsolicited registration messages handling");
result = g_simple_async_result_new (G_OBJECT (self), result = g_simple_async_result_new (G_OBJECT (self),
callback, callback,
user_data, user_data,
modem_3gpp_setup_unsolicited_registration); modem_3gpp_setup_unsolicited_registration);
ports[0] = mm_base_modem_get_port_primary (MM_BASE_MODEM (self)); ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self));
ports[1] = mm_base_modem_get_port_secondary (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 */ /* Set up CREG unsolicited message handlers in both ports */
array = mm_3gpp_creg_regex_get (FALSE); array = mm_3gpp_creg_regex_get (FALSE);
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
if (ports[i]) { if (!ports[i])
guint j; continue;
for (j = 0; j < array->len; j++) { mm_dbg ("(%s) setting up 3GPP unsolicited registration messages handlers",
mm_at_serial_port_add_unsolicited_msg_handler ( mm_port_get_device (MM_PORT (ports[i])));
MM_AT_SERIAL_PORT (ports[i]), for (j = 0; j < array->len; j++) {
(GRegex *) g_ptr_array_index (array, j), mm_at_serial_port_add_unsolicited_msg_handler (
(MMAtSerialUnsolicitedMsgFn)registration_state_changed, MM_AT_SERIAL_PORT (ports[i]),
self, (GRegex *) g_ptr_array_index (array, j),
NULL); (MMAtSerialUnsolicitedMsgFn)registration_state_changed,
} self,
NULL);
} }
} }
mm_3gpp_creg_regex_destroy (array); mm_3gpp_creg_regex_destroy (array);
@@ -2349,30 +2350,32 @@ modem_3gpp_cleanup_unsolicited_registration (MMIfaceModem3gpp *self,
MMAtSerialPort *ports[2]; MMAtSerialPort *ports[2];
GPtrArray *array; GPtrArray *array;
guint i; guint i;
guint j;
mm_dbg ("cleaning up unsolicited registration messages handling");
result = g_simple_async_result_new (G_OBJECT (self), result = g_simple_async_result_new (G_OBJECT (self),
callback, callback,
user_data, user_data,
modem_3gpp_cleanup_unsolicited_registration); modem_3gpp_cleanup_unsolicited_registration);
ports[0] = mm_base_modem_get_port_primary (MM_BASE_MODEM (self)); ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self));
ports[1] = mm_base_modem_get_port_secondary (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 */ /* Set up CREG unsolicited message handlers in both ports */
array = mm_3gpp_creg_regex_get (FALSE); array = mm_3gpp_creg_regex_get (FALSE);
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
if (ports[i]) { if (!ports[i])
guint j; continue;
for (j = 0; j < array->len; j++) { mm_dbg ("(%s) cleaning up unsolicited registration messages handlers",
mm_at_serial_port_add_unsolicited_msg_handler ( mm_port_get_device (MM_PORT (ports[i])));
MM_AT_SERIAL_PORT (ports[i]),
(GRegex *) g_ptr_array_index (array, j), for (j = 0; j < array->len; j++) {
NULL, mm_at_serial_port_add_unsolicited_msg_handler (
NULL, MM_AT_SERIAL_PORT (ports[i]),
NULL); (GRegex *) g_ptr_array_index (array, j),
} NULL,
NULL,
NULL);
} }
} }
mm_3gpp_creg_regex_destroy (array); mm_3gpp_creg_regex_destroy (array);
@@ -2858,7 +2861,7 @@ cleanup_registration_sequence_ready (MMBroadbandModem *self,
if (!ctx->secondary_done) { if (!ctx->secondary_done) {
MMAtSerialPort *secondary; 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) { if (secondary) {
/* Now use the same registration setup in secondary port, if any */ /* Now use the same registration setup in secondary port, if any */
ctx->secondary_done = TRUE; 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_at_command_in_port (
MM_BASE_MODEM (self), 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, ctx->command,
10, 10,
FALSE, FALSE,
@@ -2936,7 +2939,7 @@ modem_3gpp_cleanup_ps_registration (MMIfaceModem3gpp *self,
mm_base_modem_at_command_in_port ( mm_base_modem_at_command_in_port (
MM_BASE_MODEM (self), 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, ctx->command,
10, 10,
FALSE, FALSE,
@@ -3040,13 +3043,13 @@ setup_registration_sequence_ready (MMBroadbandModem *self,
return; 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) { if (secondary) {
/* Now use the same registration setup in secondary port, if any */ /* Now use the same registration setup in secondary port, if any */
ctx->secondary_done = TRUE; ctx->secondary_done = TRUE;
mm_base_modem_at_command_in_port ( mm_base_modem_at_command_in_port (
MM_BASE_MODEM (self), 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), g_variant_get_string (command, NULL),
3, 3,
FALSE, FALSE,
@@ -3078,7 +3081,7 @@ modem_3gpp_setup_cs_registration (MMIfaceModem3gpp *self,
modem_3gpp_setup_cs_registration); modem_3gpp_setup_cs_registration);
mm_base_modem_at_sequence_in_port ( mm_base_modem_at_sequence_in_port (
MM_BASE_MODEM (self), 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, cs_registration_sequence,
NULL, /* response processor context */ NULL, /* response processor context */
NULL, /* response processor context free */ NULL, /* response processor context free */
@@ -3101,7 +3104,7 @@ modem_3gpp_setup_ps_registration (MMIfaceModem3gpp *self,
modem_3gpp_setup_ps_registration); modem_3gpp_setup_ps_registration);
mm_base_modem_at_sequence_in_port ( mm_base_modem_at_sequence_in_port (
MM_BASE_MODEM (self), 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, ps_registration_sequence,
NULL, /* response processor context */ NULL, /* response processor context */
NULL, /* response processor context free */ NULL, /* response processor context free */
@@ -3501,13 +3504,16 @@ set_unsolicited_result_code_handlers (MMIfaceModem3gppUssd *self,
set_unsolicited_events_handlers); set_unsolicited_events_handlers);
cusd_regex = mm_3gpp_cusd_regex_get (); cusd_regex = mm_3gpp_cusd_regex_get ();
ports[0] = mm_base_modem_get_port_primary (MM_BASE_MODEM (self)); ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self));
ports[1] = mm_base_modem_get_port_secondary (MM_BASE_MODEM (self)); ports[1] = mm_base_modem_peek_port_secondary (MM_BASE_MODEM (self));
/* Enable unsolicited result codes in given port */ /* 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 */ /* 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"); enable ? "Setting" : "Removing");
mm_at_serial_port_add_unsolicited_msg_handler ( mm_at_serial_port_add_unsolicited_msg_handler (
ports[i], ports[i],
@@ -4150,13 +4156,17 @@ set_messaging_unsolicited_events_handlers (MMIfaceModemMessaging *self,
set_messaging_unsolicited_events_handlers); set_messaging_unsolicited_events_handlers);
cmti_regex = mm_3gpp_cmti_regex_get (); cmti_regex = mm_3gpp_cmti_regex_get ();
ports[0] = mm_base_modem_get_port_primary (MM_BASE_MODEM (self)); ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self));
ports[1] = mm_base_modem_get_port_secondary (MM_BASE_MODEM (self)); ports[1] = mm_base_modem_peek_port_secondary (MM_BASE_MODEM (self));
/* Enable unsolicited events in given port */ /* 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 */ /* 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"); enable ? "Setting" : "Removing");
mm_at_serial_port_add_unsolicited_msg_handler ( mm_at_serial_port_add_unsolicited_msg_handler (
ports[i], ports[i],
@@ -4679,7 +4689,7 @@ modem_cdma_get_hdr_state (MMIfaceModemCdma *self,
HdrStateContext *ctx; HdrStateContext *ctx;
GByteArray *hdrstate; 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) { if (!qcdm) {
g_simple_async_report_error_in_idle (G_OBJECT (self), g_simple_async_report_error_in_idle (G_OBJECT (self),
callback, callback,
@@ -4803,7 +4813,7 @@ modem_cdma_get_call_manager_state (MMIfaceModemCdma *self,
CallManagerStateContext *ctx; CallManagerStateContext *ctx;
GByteArray *cmstate; 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) { if (!qcdm) {
g_simple_async_report_error_in_idle (G_OBJECT (self), g_simple_async_report_error_in_idle (G_OBJECT (self),
callback, callback,
@@ -5093,8 +5103,6 @@ modem_cdma_get_cdma1x_serving_system (MMIfaceModemCdma *self,
if (ctx->qcdm) { if (ctx->qcdm) {
GByteArray *cdma_status; GByteArray *cdma_status;
g_object_ref (ctx->qcdm);
/* Setup command */ /* Setup command */
cdma_status = g_byte_array_sized_new (25); cdma_status = g_byte_array_sized_new (25);
cdma_status->len = qcdm_cmd_cdma_status_new ((char *) cdma_status->data, 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 /* The default implementation to get detailed registration state
* requires the use of an AT port; so if we cannot get any, just * requires the use of an AT port; so if we cannot get any, just
* return the error */ * 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) { if (!port) {
g_simple_async_report_take_gerror_in_idle (G_OBJECT (self), g_simple_async_report_take_gerror_in_idle (G_OBJECT (self),
callback, callback,
@@ -5534,7 +5542,7 @@ modem_cdma_setup_registration_checks (MMIfaceModemCdma *self,
modem_cdma_setup_registration_checks); modem_cdma_setup_registration_checks);
/* Check if we have a QCDM port */ /* 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 we have cached results of Sprint command checking, use them */
if (ctx->self->priv->checked_sprint_support) { if (ctx->self->priv->checked_sprint_support) {
@@ -5771,14 +5779,17 @@ setup_ports (MMBroadbandModem *self)
GPtrArray *array; GPtrArray *array;
gint i, j; gint i, j;
ports[0] = mm_base_modem_get_port_primary (MM_BASE_MODEM (self)); ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self));
ports[1] = mm_base_modem_get_port_secondary (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 */ /* Cleanup all unsolicited message handlers in all AT ports */
/* Set up CREG unsolicited message handlers, with NULL callbacks */ /* Set up CREG unsolicited message handlers, with NULL callbacks */
array = mm_3gpp_creg_regex_get (FALSE); 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++) { for (j = 0; j < array->len; j++) {
mm_at_serial_port_add_unsolicited_msg_handler (MM_AT_SERIAL_PORT (ports[i]), mm_at_serial_port_add_unsolicited_msg_handler (MM_AT_SERIAL_PORT (ports[i]),
(GRegex *)g_ptr_array_index (array, j), (GRegex *)g_ptr_array_index (array, j),
@@ -5791,7 +5802,10 @@ setup_ports (MMBroadbandModem *self)
/* Set up CIEV unsolicited message handler, with NULL callback */ /* Set up CIEV unsolicited message handler, with NULL callback */
regex = mm_3gpp_ciev_regex_get (); 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]), mm_at_serial_port_add_unsolicited_msg_handler (MM_AT_SERIAL_PORT (ports[i]),
regex, regex,
NULL, NULL,
@@ -5802,7 +5816,10 @@ setup_ports (MMBroadbandModem *self)
/* Set up CMTI unsolicited message handler, with NULL callback */ /* Set up CMTI unsolicited message handler, with NULL callback */
regex = mm_3gpp_cmti_regex_get (); 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]), mm_at_serial_port_add_unsolicited_msg_handler (MM_AT_SERIAL_PORT (ports[i]),
regex, regex,
NULL, NULL,
@@ -5813,7 +5830,10 @@ setup_ports (MMBroadbandModem *self)
/* Set up CUSD unsolicited message handler, with NULL callback */ /* Set up CUSD unsolicited message handler, with NULL callback */
regex = mm_3gpp_cusd_regex_get (); 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]), mm_at_serial_port_add_unsolicited_msg_handler (MM_AT_SERIAL_PORT (ports[i]),
regex, regex,
NULL, NULL,
@@ -6396,9 +6416,11 @@ initialize_context_complete_and_free (InitializeContext *ctx)
g_simple_async_result_complete_in_idle (ctx->result); g_simple_async_result_complete_in_idle (ctx->result);
g_object_unref (ctx->result); g_object_unref (ctx->result);
/* balance open/close count */ /* balance open/close count */
if (ctx->close_port) if (ctx->port) {
mm_serial_port_close (MM_SERIAL_PORT (ctx->port)); if (ctx->close_port)
g_object_unref (ctx->port); mm_serial_port_close (MM_SERIAL_PORT (ctx->port));
g_object_unref (ctx->port);
}
g_object_unref (ctx->self); g_object_unref (ctx->self);
g_free (ctx); g_free (ctx);
} }
@@ -6473,11 +6495,20 @@ initialize_step (InitializeContext *ctx)
case INITIALIZE_STEP_PRIMARY_OPEN: { case INITIALIZE_STEP_PRIMARY_OPEN: {
GError *error = NULL; 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. /* Open and send first commands to the primary serial port.
* We do keep the primary port open during the whole initialization * We do keep the primary port open during the whole initialization
* sequence. Note that this port is not really passed to the interfaces, * sequence. Note that this port is not really passed to the interfaces,
* they will get the primary port themselves. */ * 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)) { if (!mm_serial_port_open (MM_SERIAL_PORT (ctx->port), &error)) {
g_simple_async_result_take_error (ctx->result, error); g_simple_async_result_take_error (ctx->result, error);
initialize_context_complete_and_free (ctx); initialize_context_complete_and_free (ctx);

View File

@@ -405,7 +405,6 @@ typedef enum {
struct _DisablingContext { struct _DisablingContext {
MMIfaceModem3gppUssd *self; MMIfaceModem3gppUssd *self;
MMAtSerialPort *primary;
DisablingStep step; DisablingStep step;
GSimpleAsyncResult *result; GSimpleAsyncResult *result;
MmGdbusModem3gppUssd *skeleton; MmGdbusModem3gppUssd *skeleton;
@@ -420,7 +419,6 @@ disabling_context_new (MMIfaceModem3gppUssd *self,
ctx = g_new0 (DisablingContext, 1); ctx = g_new0 (DisablingContext, 1);
ctx->self = g_object_ref (self); 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), ctx->result = g_simple_async_result_new (G_OBJECT (self),
callback, callback,
user_data, user_data,
@@ -439,7 +437,6 @@ disabling_context_complete_and_free (DisablingContext *ctx)
{ {
g_simple_async_result_complete_in_idle (ctx->result); g_simple_async_result_complete_in_idle (ctx->result);
g_object_unref (ctx->self); g_object_unref (ctx->self);
g_object_unref (ctx->primary);
g_object_unref (ctx->result); g_object_unref (ctx->result);
g_object_unref (ctx->skeleton); g_object_unref (ctx->skeleton);
g_free (ctx); g_free (ctx);
@@ -551,7 +548,6 @@ typedef enum {
struct _EnablingContext { struct _EnablingContext {
MMIfaceModem3gppUssd *self; MMIfaceModem3gppUssd *self;
MMAtSerialPort *primary;
EnablingStep step; EnablingStep step;
GSimpleAsyncResult *result; GSimpleAsyncResult *result;
MmGdbusModem3gppUssd *skeleton; MmGdbusModem3gppUssd *skeleton;
@@ -566,7 +562,6 @@ enabling_context_new (MMIfaceModem3gppUssd *self,
ctx = g_new0 (EnablingContext, 1); ctx = g_new0 (EnablingContext, 1);
ctx->self = g_object_ref (self); 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), ctx->result = g_simple_async_result_new (G_OBJECT (self),
callback, callback,
user_data, user_data,
@@ -585,7 +580,6 @@ enabling_context_complete_and_free (EnablingContext *ctx)
{ {
g_simple_async_result_complete_in_idle (ctx->result); g_simple_async_result_complete_in_idle (ctx->result);
g_object_unref (ctx->self); g_object_unref (ctx->self);
g_object_unref (ctx->primary);
g_object_unref (ctx->result); g_object_unref (ctx->result);
g_object_unref (ctx->skeleton); g_object_unref (ctx->skeleton);
g_free (ctx); g_free (ctx);

View File

@@ -925,7 +925,6 @@ typedef enum {
struct _DisablingContext { struct _DisablingContext {
MMIfaceModem3gpp *self; MMIfaceModem3gpp *self;
MMAtSerialPort *primary;
DisablingStep step; DisablingStep step;
GSimpleAsyncResult *result; GSimpleAsyncResult *result;
MmGdbusModem *skeleton; MmGdbusModem *skeleton;
@@ -940,7 +939,6 @@ disabling_context_new (MMIfaceModem3gpp *self,
ctx = g_new0 (DisablingContext, 1); ctx = g_new0 (DisablingContext, 1);
ctx->self = g_object_ref (self); 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), ctx->result = g_simple_async_result_new (G_OBJECT (self),
callback, callback,
user_data, user_data,
@@ -959,7 +957,6 @@ disabling_context_complete_and_free (DisablingContext *ctx)
{ {
g_simple_async_result_complete_in_idle (ctx->result); g_simple_async_result_complete_in_idle (ctx->result);
g_object_unref (ctx->self); g_object_unref (ctx->self);
g_object_unref (ctx->primary);
g_object_unref (ctx->result); g_object_unref (ctx->result);
g_object_unref (ctx->skeleton); g_object_unref (ctx->skeleton);
g_free (ctx); g_free (ctx);
@@ -1148,7 +1145,6 @@ typedef enum {
struct _EnablingContext { struct _EnablingContext {
MMIfaceModem3gpp *self; MMIfaceModem3gpp *self;
MMAtSerialPort *primary;
EnablingStep step; EnablingStep step;
GSimpleAsyncResult *result; GSimpleAsyncResult *result;
MmGdbusModem3gpp *skeleton; MmGdbusModem3gpp *skeleton;
@@ -1163,7 +1159,6 @@ enabling_context_new (MMIfaceModem3gpp *self,
ctx = g_new0 (EnablingContext, 1); ctx = g_new0 (EnablingContext, 1);
ctx->self = g_object_ref (self); 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), ctx->result = g_simple_async_result_new (G_OBJECT (self),
callback, callback,
user_data, user_data,
@@ -1182,7 +1177,6 @@ enabling_context_complete_and_free (EnablingContext *ctx)
{ {
g_simple_async_result_complete_in_idle (ctx->result); g_simple_async_result_complete_in_idle (ctx->result);
g_object_unref (ctx->self); g_object_unref (ctx->self);
g_object_unref (ctx->primary);
g_object_unref (ctx->result); g_object_unref (ctx->result);
g_object_unref (ctx->skeleton); g_object_unref (ctx->skeleton);
g_free (ctx); g_free (ctx);

View File

@@ -1101,7 +1101,6 @@ typedef enum {
struct _DisablingContext { struct _DisablingContext {
MMIfaceModemCdma *self; MMIfaceModemCdma *self;
MMAtSerialPort *primary;
DisablingStep step; DisablingStep step;
GSimpleAsyncResult *result; GSimpleAsyncResult *result;
MmGdbusModemCdma *skeleton; MmGdbusModemCdma *skeleton;
@@ -1116,7 +1115,6 @@ disabling_context_new (MMIfaceModemCdma *self,
ctx = g_new0 (DisablingContext, 1); ctx = g_new0 (DisablingContext, 1);
ctx->self = g_object_ref (self); 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), ctx->result = g_simple_async_result_new (G_OBJECT (self),
callback, callback,
user_data, user_data,
@@ -1135,7 +1133,6 @@ disabling_context_complete_and_free (DisablingContext *ctx)
{ {
g_simple_async_result_complete_in_idle (ctx->result); g_simple_async_result_complete_in_idle (ctx->result);
g_object_unref (ctx->self); g_object_unref (ctx->self);
g_object_unref (ctx->primary);
g_object_unref (ctx->result); g_object_unref (ctx->result);
g_object_unref (ctx->skeleton); g_object_unref (ctx->skeleton);
g_free (ctx); g_free (ctx);
@@ -1196,7 +1193,6 @@ typedef enum {
struct _EnablingContext { struct _EnablingContext {
MMIfaceModemCdma *self; MMIfaceModemCdma *self;
MMAtSerialPort *primary;
EnablingStep step; EnablingStep step;
GSimpleAsyncResult *result; GSimpleAsyncResult *result;
MmGdbusModemCdma *skeleton; MmGdbusModemCdma *skeleton;
@@ -1211,7 +1207,6 @@ enabling_context_new (MMIfaceModemCdma *self,
ctx = g_new0 (EnablingContext, 1); ctx = g_new0 (EnablingContext, 1);
ctx->self = g_object_ref (self); 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), ctx->result = g_simple_async_result_new (G_OBJECT (self),
callback, callback,
user_data, user_data,
@@ -1230,7 +1225,6 @@ enabling_context_complete_and_free (EnablingContext *ctx)
{ {
g_simple_async_result_complete_in_idle (ctx->result); g_simple_async_result_complete_in_idle (ctx->result);
g_object_unref (ctx->self); g_object_unref (ctx->self);
g_object_unref (ctx->primary);
g_object_unref (ctx->result); g_object_unref (ctx->result);
g_object_unref (ctx->skeleton); g_object_unref (ctx->skeleton);
g_free (ctx); g_free (ctx);

View File

@@ -451,7 +451,6 @@ typedef enum {
struct _DisablingContext { struct _DisablingContext {
MMIfaceModemLocation *self; MMIfaceModemLocation *self;
MMAtSerialPort *primary;
DisablingStep step; DisablingStep step;
GSimpleAsyncResult *result; GSimpleAsyncResult *result;
MmGdbusModemLocation *skeleton; MmGdbusModemLocation *skeleton;
@@ -466,7 +465,6 @@ disabling_context_new (MMIfaceModemLocation *self,
ctx = g_new0 (DisablingContext, 1); ctx = g_new0 (DisablingContext, 1);
ctx->self = g_object_ref (self); 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), ctx->result = g_simple_async_result_new (G_OBJECT (self),
callback, callback,
user_data, user_data,
@@ -485,7 +483,6 @@ disabling_context_complete_and_free (DisablingContext *ctx)
{ {
g_simple_async_result_complete_in_idle (ctx->result); g_simple_async_result_complete_in_idle (ctx->result);
g_object_unref (ctx->self); g_object_unref (ctx->self);
g_object_unref (ctx->primary);
g_object_unref (ctx->result); g_object_unref (ctx->result);
g_object_unref (ctx->skeleton); g_object_unref (ctx->skeleton);
g_free (ctx); g_free (ctx);
@@ -575,7 +572,6 @@ typedef enum {
struct _EnablingContext { struct _EnablingContext {
MMIfaceModemLocation *self; MMIfaceModemLocation *self;
MMAtSerialPort *primary;
EnablingStep step; EnablingStep step;
GSimpleAsyncResult *result; GSimpleAsyncResult *result;
MmGdbusModemLocation *skeleton; MmGdbusModemLocation *skeleton;
@@ -590,7 +586,6 @@ enabling_context_new (MMIfaceModemLocation *self,
ctx = g_new0 (EnablingContext, 1); ctx = g_new0 (EnablingContext, 1);
ctx->self = g_object_ref (self); 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), ctx->result = g_simple_async_result_new (G_OBJECT (self),
callback, callback,
user_data, user_data,
@@ -609,7 +604,6 @@ enabling_context_complete_and_free (EnablingContext *ctx)
{ {
g_simple_async_result_complete_in_idle (ctx->result); g_simple_async_result_complete_in_idle (ctx->result);
g_object_unref (ctx->self); g_object_unref (ctx->self);
g_object_unref (ctx->primary);
g_object_unref (ctx->result); g_object_unref (ctx->result);
g_object_unref (ctx->skeleton); g_object_unref (ctx->skeleton);
g_free (ctx); g_free (ctx);

View File

@@ -486,7 +486,6 @@ typedef enum {
struct _DisablingContext { struct _DisablingContext {
MMIfaceModemMessaging *self; MMIfaceModemMessaging *self;
MMAtSerialPort *primary;
DisablingStep step; DisablingStep step;
GSimpleAsyncResult *result; GSimpleAsyncResult *result;
MmGdbusModemMessaging *skeleton; MmGdbusModemMessaging *skeleton;
@@ -501,7 +500,6 @@ disabling_context_new (MMIfaceModemMessaging *self,
ctx = g_new0 (DisablingContext, 1); ctx = g_new0 (DisablingContext, 1);
ctx->self = g_object_ref (self); 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), ctx->result = g_simple_async_result_new (G_OBJECT (self),
callback, callback,
user_data, user_data,
@@ -520,7 +518,6 @@ disabling_context_complete_and_free (DisablingContext *ctx)
{ {
g_simple_async_result_complete_in_idle (ctx->result); g_simple_async_result_complete_in_idle (ctx->result);
g_object_unref (ctx->self); g_object_unref (ctx->self);
g_object_unref (ctx->primary);
g_object_unref (ctx->result); g_object_unref (ctx->result);
g_object_unref (ctx->skeleton); g_object_unref (ctx->skeleton);
g_free (ctx); g_free (ctx);
@@ -648,7 +645,6 @@ typedef enum {
struct _EnablingContext { struct _EnablingContext {
MMIfaceModemMessaging *self; MMIfaceModemMessaging *self;
MMAtSerialPort *primary;
EnablingStep step; EnablingStep step;
GSimpleAsyncResult *result; GSimpleAsyncResult *result;
MmGdbusModemMessaging *skeleton; MmGdbusModemMessaging *skeleton;
@@ -665,7 +661,6 @@ enabling_context_new (MMIfaceModemMessaging *self,
ctx = g_new0 (EnablingContext, 1); ctx = g_new0 (EnablingContext, 1);
ctx->self = g_object_ref (self); 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), ctx->result = g_simple_async_result_new (G_OBJECT (self),
callback, callback,
user_data, user_data,
@@ -684,7 +679,6 @@ enabling_context_complete_and_free (EnablingContext *ctx)
{ {
g_simple_async_result_complete_in_idle (ctx->result); g_simple_async_result_complete_in_idle (ctx->result);
g_object_unref (ctx->self); g_object_unref (ctx->self);
g_object_unref (ctx->primary);
g_object_unref (ctx->result); g_object_unref (ctx->result);
g_object_unref (ctx->skeleton); g_object_unref (ctx->skeleton);
g_free (ctx); g_free (ctx);

View File

@@ -395,7 +395,6 @@ typedef enum {
struct _DisablingContext { struct _DisablingContext {
MMIfaceModemTime *self; MMIfaceModemTime *self;
MMAtSerialPort *primary;
DisablingStep step; DisablingStep step;
GSimpleAsyncResult *result; GSimpleAsyncResult *result;
MmGdbusModemTime *skeleton; MmGdbusModemTime *skeleton;
@@ -410,7 +409,6 @@ disabling_context_new (MMIfaceModemTime *self,
ctx = g_new0 (DisablingContext, 1); ctx = g_new0 (DisablingContext, 1);
ctx->self = g_object_ref (self); 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), ctx->result = g_simple_async_result_new (G_OBJECT (self),
callback, callback,
user_data, user_data,
@@ -429,7 +427,6 @@ disabling_context_complete_and_free (DisablingContext *ctx)
{ {
g_simple_async_result_complete_in_idle (ctx->result); g_simple_async_result_complete_in_idle (ctx->result);
g_object_unref (ctx->self); g_object_unref (ctx->self);
g_object_unref (ctx->primary);
g_object_unref (ctx->result); g_object_unref (ctx->result);
g_object_unref (ctx->skeleton); g_object_unref (ctx->skeleton);
g_free (ctx); g_free (ctx);
@@ -570,7 +567,6 @@ typedef enum {
struct _EnablingContext { struct _EnablingContext {
MMIfaceModemTime *self; MMIfaceModemTime *self;
MMAtSerialPort *primary;
EnablingStep step; EnablingStep step;
GSimpleAsyncResult *result; GSimpleAsyncResult *result;
MmGdbusModemTime *skeleton; MmGdbusModemTime *skeleton;
@@ -585,7 +581,6 @@ enabling_context_new (MMIfaceModemTime *self,
ctx = g_new0 (EnablingContext, 1); ctx = g_new0 (EnablingContext, 1);
ctx->self = g_object_ref (self); 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), ctx->result = g_simple_async_result_new (G_OBJECT (self),
callback, callback,
user_data, user_data,
@@ -604,7 +599,6 @@ enabling_context_complete_and_free (EnablingContext *ctx)
{ {
g_simple_async_result_complete_in_idle (ctx->result); g_simple_async_result_complete_in_idle (ctx->result);
g_object_unref (ctx->self); g_object_unref (ctx->self);
g_object_unref (ctx->primary);
g_object_unref (ctx->result); g_object_unref (ctx->result);
g_object_unref (ctx->skeleton); g_object_unref (ctx->skeleton);
g_free (ctx); g_free (ctx);

View File

@@ -2300,13 +2300,9 @@ disabling_context_new (MMIfaceModem *self,
ctx = g_new0 (DisablingContext, 1); ctx = g_new0 (DisablingContext, 1);
ctx->self = g_object_ref (self); 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)); 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)); 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), ctx->result = g_simple_async_result_new (G_OBJECT (self),
callback, callback,
user_data, user_data,
@@ -2341,7 +2337,8 @@ disabling_context_complete_and_free (DisablingContext *ctx)
MM_MODEM_STATE_CHANGE_REASON_UNKNOWN); MM_MODEM_STATE_CHANGE_REASON_UNKNOWN);
g_object_unref (ctx->self); g_object_unref (ctx->self);
g_object_unref (ctx->primary); if (ctx->primary)
g_object_unref (ctx->primary);
if (ctx->secondary) if (ctx->secondary)
g_object_unref (ctx->secondary); g_object_unref (ctx->secondary);
if (ctx->qcdm) 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. * be safe to check whether they are really open before trying to close.
*/ */
mm_dbg ("Closing all ports..."); 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)); mm_serial_port_close (MM_SERIAL_PORT (ctx->primary));
if (ctx->secondary && mm_serial_port_is_open (MM_SERIAL_PORT (ctx->secondary))) if (ctx->secondary && mm_serial_port_is_open (MM_SERIAL_PORT (ctx->secondary)))
mm_serial_port_close (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 = g_new0 (EnablingContext, 1);
ctx->self = g_object_ref (self); 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)); 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)); 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), ctx->result = g_simple_async_result_new (G_OBJECT (self),
callback, callback,
user_data, user_data,
@@ -2554,7 +2547,8 @@ enabling_context_complete_and_free (EnablingContext *ctx)
} }
g_object_unref (ctx->self); g_object_unref (ctx->self);
g_object_unref (ctx->primary); if (ctx->primary)
g_object_unref (ctx->primary);
if (ctx->secondary) if (ctx->secondary)
g_object_unref (ctx->secondary); g_object_unref (ctx->secondary);
if (ctx->qcdm) if (ctx->qcdm)
@@ -2737,6 +2731,15 @@ interface_enabling_step (EnablingContext *ctx)
GError *error = NULL; GError *error = NULL;
/* Open primary port */ /* 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)) { if (!mm_serial_port_open (MM_SERIAL_PORT (ctx->primary), &error)) {
g_simple_async_result_take_error (ctx->result, error); g_simple_async_result_take_error (ctx->result, error);
enabling_context_complete_and_free (ctx); enabling_context_complete_and_free (ctx);

View File

@@ -1386,15 +1386,11 @@ struct _InitAsyncContext {
MMSim *self; MMSim *self;
InitializationStep step; InitializationStep step;
guint sim_identifier_tries; guint sim_identifier_tries;
MMAtSerialPort *port;
}; };
static void static void
init_async_context_free (InitAsyncContext *ctx, init_async_context_free (InitAsyncContext *ctx)
gboolean close_port)
{ {
if (close_port)
mm_serial_port_close (MM_SERIAL_PORT (ctx->port));
g_object_unref (ctx->self); g_object_unref (ctx->self);
g_object_unref (ctx->result); g_object_unref (ctx->result);
if (ctx->cancellable) if (ctx->cancellable)
@@ -1569,7 +1565,7 @@ interface_initialization_step (InitAsyncContext *ctx)
/* We are done without errors! */ /* We are done without errors! */
g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE); g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
g_simple_async_result_complete_in_idle (ctx->result); g_simple_async_result_complete_in_idle (ctx->result);
init_async_context_free (ctx, TRUE); init_async_context_free (ctx);
return; return;
} }
@@ -1585,7 +1581,6 @@ common_init_async (GAsyncInitable *initable,
{ {
InitAsyncContext *ctx; InitAsyncContext *ctx;
GError *error = NULL;
ctx = g_new (InitAsyncContext, 1); ctx = g_new (InitAsyncContext, 1);
ctx->self = g_object_ref (initable); ctx->self = g_object_ref (initable);
@@ -1599,14 +1594,6 @@ common_init_async (GAsyncInitable *initable,
ctx->step = INITIALIZATION_STEP_FIRST; ctx->step = INITIALIZATION_STEP_FIRST;
ctx->sim_identifier_tries = 0; 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); interface_initialization_step (ctx);
} }