diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2013-02-20 16:07:02 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2013-02-20 16:07:02 +0100 |
commit | 9bef8531c189887954cb20938a304b2b51f40a94 (patch) | |
tree | b379706ca182b811076c3395861f779fe2221432 | |
parent | 000bb642255ecfefe10f7b6629493c34877399c7 (diff) |
iridium: use generic disconnection logic
The generic disconnection logic now already handles getting the port fully
closed and a wait time before reopening it, so no need for a custom
disconnection logic any more.
-rw-r--r-- | plugins/iridium/mm-bearer-iridium.c | 124 |
1 files changed, 0 insertions, 124 deletions
diff --git a/plugins/iridium/mm-bearer-iridium.c b/plugins/iridium/mm-bearer-iridium.c index e19d427b..411906c8 100644 --- a/plugins/iridium/mm-bearer-iridium.c +++ b/plugins/iridium/mm-bearer-iridium.c @@ -235,128 +235,6 @@ 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); - g_free (ctx); -} - -static gboolean -disconnect_finish (MMBearer *self, - GAsyncResult *res, - GError **error) -{ - return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error); -} - -static void -primary_flash_ready (MMSerialPort *port, - GError *error, - DisconnectContext *ctx) -{ - if (error) { - /* Ignore "NO CARRIER" response when modem disconnects and any flash - * failures we might encounter. Other errors are hard errors. - */ - if (!g_error_matches (error, - MM_CONNECTION_ERROR, - MM_CONNECTION_ERROR_NO_CARRIER) && - !g_error_matches (error, - MM_SERIAL_ERROR, - MM_SERIAL_ERROR_FLASH_FAILED)) { - /* Fatal */ - 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); - } - - /* Port is disconnected; update the state. Note: implementations may - * 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 (ctx->result, TRUE); - disconnect_context_complete_and_free (ctx); -} - -static gboolean -after_disconnect_sleep_cb (DisconnectContext *ctx) -{ - GError *error = NULL; - - /* Propagate errors when reopening the port */ - 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; - } - - mm_serial_port_flash (MM_SERIAL_PORT (ctx->primary), - 1000, - TRUE, - (MMSerialFlashFn)primary_flash_ready, - ctx); - return FALSE; -} - -static void -disconnect (MMBearer *self, - GAsyncReadyCallback callback, - gpointer user_data) -{ - DisconnectContext *ctx; - - ctx = g_new (DisconnectContext, 1); - ctx->self = g_object_ref (self); - g_object_get (self, - MM_BEARER_MODEM, &ctx->modem, - NULL); - 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 (!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 */ - - /* 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 (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, ctx); -} - -/*****************************************************************************/ MMBearer * mm_bearer_iridium_new (MMBroadbandModemIridium *modem, @@ -392,6 +270,4 @@ mm_bearer_iridium_class_init (MMBearerIridiumClass *klass) /* Virtual methods */ bearer_class->connect = connect; bearer_class->connect_finish = connect_finish; - bearer_class->disconnect = disconnect; - bearer_class->disconnect_finish = disconnect_finish; } |