broadband-modem: handle state checks during Enable() and Disable()

Before it was done in the interface; but we should really be doing it in the
implementation; so that mm_base_modem_enable()/disable() also has the state
checks.
This commit is contained in:
Aleksander Morgado
2011-12-21 21:55:44 +01:00
parent 9a80f58165
commit 8a636f6b16
2 changed files with 123 additions and 132 deletions

View File

@@ -2092,17 +2092,60 @@ disable (MMBaseModem *self,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
{ {
DisablingContext *ctx; GSimpleAsyncResult *result;
ctx = g_new0 (DisablingContext, 1); result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, disable);
ctx->self = g_object_ref (self);
ctx->result = g_simple_async_result_new (G_OBJECT (self),
callback,
user_data,
disable);
ctx->step = DISABLING_STEP_FIRST;
disabling_step (ctx); /* Check state before launching modem disabling */
switch (MM_BROADBAND_MODEM (self)->priv->modem_state) {
case MM_MODEM_STATE_UNKNOWN:
/* We should never have a UNKNOWN->DISABLED transition requested by
* the user. */
g_assert_not_reached ();
break;
case MM_MODEM_STATE_LOCKED:
case MM_MODEM_STATE_DISABLED:
/* Just return success, don't relaunch enabling */
g_simple_async_result_set_op_res_gboolean (result, TRUE);
break;
case MM_MODEM_STATE_DISABLING:
g_simple_async_result_set_error (result,
MM_CORE_ERROR,
MM_CORE_ERROR_WRONG_STATE,
"Cannot disable modem: "
"already being disabled");
break;
case MM_MODEM_STATE_ENABLING:
g_simple_async_result_set_error (result,
MM_CORE_ERROR,
MM_CORE_ERROR_WRONG_STATE,
"Cannot disable modem: "
"currently being enabled");
break;
case MM_MODEM_STATE_ENABLED:
case MM_MODEM_STATE_SEARCHING:
case MM_MODEM_STATE_REGISTERED:
case MM_MODEM_STATE_DISCONNECTING:
case MM_MODEM_STATE_CONNECTING:
case MM_MODEM_STATE_CONNECTED: {
DisablingContext *ctx;
ctx = g_new0 (DisablingContext, 1);
ctx->self = g_object_ref (self);
ctx->result = result;
ctx->step = DISABLING_STEP_FIRST;
disabling_step (ctx);
return;
}
}
g_simple_async_result_complete_in_idle (result);
g_object_unref (result);
} }
/*****************************************************************************/ /*****************************************************************************/
@@ -2249,17 +2292,64 @@ enable (MMBaseModem *self,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
{ {
EnablingContext *ctx; GSimpleAsyncResult *result;
ctx = g_new0 (EnablingContext, 1); result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, enable);
ctx->self = g_object_ref (self);
ctx->result = g_simple_async_result_new (G_OBJECT (self),
callback,
user_data,
enable);
ctx->step = ENABLING_STEP_FIRST;
enabling_step (ctx); /* Check state before launching modem enabling */
switch (MM_BROADBAND_MODEM (self)->priv->modem_state) {
case MM_MODEM_STATE_UNKNOWN:
/* We should never have a UNKNOWN->ENABLED transition */
g_assert_not_reached ();
break;
case MM_MODEM_STATE_LOCKED:
g_simple_async_result_set_error (result,
MM_CORE_ERROR,
MM_CORE_ERROR_WRONG_STATE,
"Cannot enable modem: device locked");
break;
case MM_MODEM_STATE_DISABLED: {
EnablingContext *ctx;
ctx = g_new0 (EnablingContext, 1);
ctx->self = g_object_ref (self);
ctx->result = result;
ctx->step = ENABLING_STEP_FIRST;
enabling_step (ctx);
return;
}
case MM_MODEM_STATE_DISABLING:
g_simple_async_result_set_error (result,
MM_CORE_ERROR,
MM_CORE_ERROR_WRONG_STATE,
"Cannot enable modem: "
"currently being disabled");
break;
case MM_MODEM_STATE_ENABLING:
g_simple_async_result_set_error (result,
MM_CORE_ERROR,
MM_CORE_ERROR_WRONG_STATE,
"Cannot enable modem: "
"already being enabled");
break;
case MM_MODEM_STATE_ENABLED:
case MM_MODEM_STATE_SEARCHING:
case MM_MODEM_STATE_REGISTERED:
case MM_MODEM_STATE_DISCONNECTING:
case MM_MODEM_STATE_CONNECTING:
case MM_MODEM_STATE_CONNECTED:
/* Just return success, don't relaunch enabling */
g_simple_async_result_set_op_res_gboolean (result, TRUE);
break;
}
g_simple_async_result_complete_in_idle (result);
g_object_unref (result);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@@ -382,117 +382,6 @@ enable_disable_ready (MMIfaceModem *self,
dbus_call_context_free (ctx); dbus_call_context_free (ctx);
} }
static gboolean
run_enable (MMIfaceModem *self,
MmGdbusModem *skeleton,
MMModemState modem_state,
GDBusMethodInvocation *invocation)
{
switch (modem_state) {
case MM_MODEM_STATE_UNKNOWN:
/* We should never have a UNKNOWN->ENABLED transition */
g_assert_not_reached ();
break;
case MM_MODEM_STATE_LOCKED:
g_dbus_method_invocation_return_error (invocation,
MM_CORE_ERROR,
MM_CORE_ERROR_WRONG_STATE,
"Cannot enable modem: device locked");
break;
case MM_MODEM_STATE_DISABLED:
MM_BASE_MODEM_GET_CLASS (self)->enable (MM_BASE_MODEM (self),
NULL, /* cancellable */
(GAsyncReadyCallback)enable_disable_ready,
dbus_call_context_new (skeleton,
invocation,
self));
break;
case MM_MODEM_STATE_DISABLING:
g_dbus_method_invocation_return_error (invocation,
MM_CORE_ERROR,
MM_CORE_ERROR_WRONG_STATE,
"Cannot enable modem: "
"currently being disabled");
break;
case MM_MODEM_STATE_ENABLING:
g_dbus_method_invocation_return_error (invocation,
MM_CORE_ERROR,
MM_CORE_ERROR_WRONG_STATE,
"Cannot enable modem: "
"already being enabled");
break;
case MM_MODEM_STATE_ENABLED:
case MM_MODEM_STATE_SEARCHING:
case MM_MODEM_STATE_REGISTERED:
case MM_MODEM_STATE_DISCONNECTING:
case MM_MODEM_STATE_CONNECTING:
case MM_MODEM_STATE_CONNECTED:
/* Just return success, don't relaunch enabling */
mm_gdbus_modem_complete_enable (skeleton, invocation);
break;
}
return TRUE;
}
static gboolean
run_disable (MMIfaceModem *self,
MmGdbusModem *skeleton,
MMModemState modem_state,
GDBusMethodInvocation *invocation)
{
switch (modem_state) {
case MM_MODEM_STATE_UNKNOWN:
/* We should never have a UNKNOWN->DISABLED transition requested by
* the user. */
g_assert_not_reached ();
break;
case MM_MODEM_STATE_LOCKED:
case MM_MODEM_STATE_DISABLED:
/* Just return success, don't relaunch enabling */
mm_gdbus_modem_complete_enable (skeleton, invocation);
break;
case MM_MODEM_STATE_DISABLING:
g_dbus_method_invocation_return_error (invocation,
MM_CORE_ERROR,
MM_CORE_ERROR_WRONG_STATE,
"Cannot disable modem: "
"already being disabled");
break;
case MM_MODEM_STATE_ENABLING:
g_dbus_method_invocation_return_error (invocation,
MM_CORE_ERROR,
MM_CORE_ERROR_WRONG_STATE,
"Cannot disable modem: "
"currently being enabled");
break;
case MM_MODEM_STATE_ENABLED:
case MM_MODEM_STATE_SEARCHING:
case MM_MODEM_STATE_REGISTERED:
case MM_MODEM_STATE_DISCONNECTING:
case MM_MODEM_STATE_CONNECTING:
case MM_MODEM_STATE_CONNECTED:
MM_BASE_MODEM_GET_CLASS (self)->disable (MM_BASE_MODEM (self),
NULL, /* cancellable */
(GAsyncReadyCallback)enable_disable_ready,
dbus_call_context_new (skeleton,
invocation,
self));
break;
}
return TRUE;
}
static gboolean static gboolean
handle_enable (MmGdbusModem *skeleton, handle_enable (MmGdbusModem *skeleton,
GDBusMethodInvocation *invocation, GDBusMethodInvocation *invocation,
@@ -509,9 +398,21 @@ handle_enable (MmGdbusModem *skeleton,
MM_IFACE_MODEM_STATE, &modem_state, MM_IFACE_MODEM_STATE, &modem_state,
NULL); NULL);
return (arg_enable ? if (arg_enable)
run_enable (self, skeleton, modem_state, invocation) : MM_BASE_MODEM_GET_CLASS (self)->enable (MM_BASE_MODEM (self),
run_disable (self, skeleton, modem_state, invocation)); NULL, /* cancellable */
(GAsyncReadyCallback)enable_disable_ready,
dbus_call_context_new (skeleton,
invocation,
self));
else
MM_BASE_MODEM_GET_CLASS (self)->disable (MM_BASE_MODEM (self),
NULL, /* cancellable */
(GAsyncReadyCallback)enable_disable_ready,
dbus_call_context_new (skeleton,
invocation,
self));
return TRUE;
} }
/*****************************************************************************/ /*****************************************************************************/