base-call: fix logic when accepting calls

Don't return FALSE when call is successfully accepted, otherwise the
caller will get very confused:

    ModemManager[19952]: <debug> [1528968478.344338] (ttyACM2): --> 'ATA<CR>'
    ModemManager[19952]: <debug> [1528968478.361986] (ttyACM2): <-- '<CR><LF>OK<CR><LF>'

    (ModemManager:19952): GLib-GIO-CRITICAL **: 11:27:58.387: g_dbus_method_invocation_take_error: assertion 'error != NULL' failed

And also, make sure the async task is always finished, even when
mm_base_modem_at_command_finish() returns an error which is not
MM_SERIAL_ERROR_RESPONSE_TIMEOUT.
This commit is contained in:
Aleksander Morgado
2018-06-14 11:59:04 +02:00
committed by Dan Williams
parent fa67a4f9bb
commit 0ac15f6e22

View File

@@ -661,73 +661,53 @@ call_start (MMBaseCall *self,
} }
/*****************************************************************************/ /*****************************************************************************/
/* Accept the call */
/* Accept the CALL */
static gboolean static gboolean
call_accept_finish (MMBaseCall *self, call_accept_finish (MMBaseCall *self,
GAsyncResult *res, GAsyncResult *res,
GError **error) GError **error)
{ {
return g_task_propagate_boolean (G_TASK (res), error); return g_task_propagate_boolean (G_TASK (res), error);
} }
static void static void
call_accept_ready (MMBaseModem *modem, call_accept_ready (MMBaseModem *modem,
GAsyncResult *res, GAsyncResult *res,
GTask *task) GTask *task)
{ {
MMBaseCall *self; MMBaseCall *self;
GError *error = NULL; GError *error = NULL;
const gchar *response; const gchar *response;
self = g_task_get_source_object (task); self = g_task_get_source_object (task);
response = mm_base_modem_at_command_finish (modem, res, &error); response = mm_base_modem_at_command_finish (modem, res, &error);
if (error) {
if (g_error_matches (error, MM_SERIAL_ERROR, MM_SERIAL_ERROR_RESPONSE_TIMEOUT)) {
g_task_return_error (task, error);
g_object_unref (task);
return;
}
mm_dbg ("Couldn't accept call : '%s'", error->message);
g_error_free (error);
return;
}
/* check response for error */ /* check response for error */
if (response && response[0]) { if (response && response[0])
g_set_error (&error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, g_set_error (&error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
"Couldn't accept the call: " "Couldn't accept the call: Unhandled response '%s'", response);
"Unhandled response '%s'", response);
/* Update state */
mm_base_call_change_state (self, MM_CALL_STATE_TERMINATED, MM_CALL_STATE_REASON_ERROR);
} else {
/* Update state */
mm_base_call_change_state (self, MM_CALL_STATE_ACTIVE, MM_CALL_STATE_REASON_ACCEPTED);
}
if (error) { if (error) {
mm_base_call_change_state (self, MM_CALL_STATE_TERMINATED, MM_CALL_STATE_REASON_ERROR);
g_task_return_error (task, error); g_task_return_error (task, error);
g_object_unref (task); } else {
return; mm_base_call_change_state (self, MM_CALL_STATE_ACTIVE, MM_CALL_STATE_REASON_ACCEPTED);
g_task_return_boolean (task, TRUE);
} }
g_task_return_boolean (task, FALSE);
g_object_unref (task); g_object_unref (task);
} }
static void static void
call_accept (MMBaseCall *self, call_accept (MMBaseCall *self,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
{ {
GTask *task; GTask *task;
task = g_task_new (self, NULL, callback, user_data); task = g_task_new (self, NULL, callback, user_data);
mm_base_modem_at_command (self->priv->modem, mm_base_modem_at_command (self->priv->modem,
"ATA", "ATA",
2, 2,