iface-modem: handle FactoryReset() calls

Also considering that reseting may not be implemented.
This commit is contained in:
Aleksander Morgado
2011-11-22 19:06:07 +01:00
parent 03490d1171
commit b9d60d2de4
2 changed files with 77 additions and 2 deletions

View File

@@ -172,13 +172,79 @@ handle_reset (MmGdbusModem *skeleton,
return TRUE;
}
/*****************************************************************************/
static void
factory_reset_ready (MMIfaceModem *self,
GAsyncResult *res,
DbusCallContext *ctx)
{
GError *error = NULL;
if (!MM_IFACE_MODEM_GET_INTERFACE (self)->factory_reset_finish (self,
res,
&error))
g_dbus_method_invocation_take_error (ctx->invocation,
error);
else
mm_gdbus_modem_complete_factory_reset (ctx->skeleton,
ctx->invocation);
dbus_call_context_free (ctx);
}
static gboolean
handle_factory_reset (MmGdbusModem *object,
handle_factory_reset (MmGdbusModem *skeleton,
GDBusMethodInvocation *invocation,
const gchar *arg_code,
MMIfaceModem *self)
{
return FALSE; /* Currently unhandled */
MMModemState modem_state;
/* If reseting is not implemented, report an error */
if (!MM_IFACE_MODEM_GET_INTERFACE (self)->factory_reset ||
!MM_IFACE_MODEM_GET_INTERFACE (self)->factory_reset_finish) {
g_dbus_method_invocation_return_error (invocation,
MM_CORE_ERROR,
MM_CORE_ERROR_UNSUPPORTED,
"Cannot reset the modem to factory defaults: "
"operation not supported");
return TRUE;
}
modem_state = MM_MODEM_STATE_UNKNOWN;
g_object_get (self,
MM_IFACE_MODEM_STATE, &modem_state,
NULL);
switch (modem_state) {
case MM_MODEM_STATE_UNKNOWN:
case MM_MODEM_STATE_LOCKED:
g_dbus_method_invocation_return_error (invocation,
MM_CORE_ERROR,
MM_CORE_ERROR_WRONG_STATE,
"Cannot reset the modem to factory defaults: "
"not initialized/unlocked yet");
break;
case MM_MODEM_STATE_DISABLED:
case MM_MODEM_STATE_DISABLING:
case MM_MODEM_STATE_ENABLING:
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_IFACE_MODEM_GET_INTERFACE (self)->factory_reset (self,
arg_code,
(GAsyncReadyCallback)factory_reset_ready,
dbus_call_context_new (skeleton,
invocation,
self));
break;
}
return TRUE;
}
static gboolean

View File

@@ -144,6 +144,15 @@ struct _MMIfaceModem {
gboolean (*reset_finish) (MMIfaceModem *self,
GAsyncResult *res,
GError **error);
/* Asynchronous factory-reset operation */
void (*factory_reset) (MMIfaceModem *self,
const gchar *code,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean (*factory_reset_finish) (MMIfaceModem *self,
GAsyncResult *res,
GError **error);
};
GType mm_iface_modem_get_type (void);