iface-modem-3gpp-ussd: implement logic to setup/cleanup URC message handlers

This commit is contained in:
Aleksander Morgado
2012-03-15 14:14:57 +01:00
parent 259ce3439b
commit fdbb07ca42
2 changed files with 84 additions and 20 deletions
+68 -20
View File
@@ -48,6 +48,7 @@ static void interface_disabling_step (DisablingContext *ctx);
typedef enum {
DISABLING_STEP_FIRST,
DISABLING_STEP_DISABLE_UNSOLICITED_RESULT_CODES,
DISABLING_STEP_CLEANUP_UNSOLICITED_RESULT_CODES,
DISABLING_STEP_LAST
} DisablingStep;
@@ -122,6 +123,27 @@ disable_unsolicited_result_codes_ready (MMIfaceModem3gppUssd *self,
interface_disabling_step (ctx);
}
static void
cleanup_unsolicited_result_codes_ready (MMIfaceModem3gppUssd *self,
GAsyncResult *res,
DisablingContext *ctx)
{
GError *error = NULL;
MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->cleanup_unsolicited_result_codes_finish (self,
res,
&error);
if (error) {
/* This error shouldn't be treated as critical */
mm_dbg ("Couldn't cleanup unsolicited result codes: '%s'", error->message);
g_error_free (error);
}
/* Go on to next step */
ctx->step++;
interface_disabling_step (ctx);
}
static void
interface_disabling_step (DisablingContext *ctx)
{
@@ -131,16 +153,18 @@ interface_disabling_step (DisablingContext *ctx)
ctx->step++;
case DISABLING_STEP_DISABLE_UNSOLICITED_RESULT_CODES:
if (MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (ctx->self)->disable_unsolicited_result_codes &&
MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (ctx->self)->disable_unsolicited_result_codes_finish) {
MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (ctx->self)->disable_unsolicited_result_codes (
ctx->self,
(GAsyncReadyCallback)disable_unsolicited_result_codes_ready,
ctx);
return;
}
/* Fall down to next step */
ctx->step++;
MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (ctx->self)->disable_unsolicited_result_codes (
ctx->self,
(GAsyncReadyCallback)disable_unsolicited_result_codes_ready,
ctx);
return;
case DISABLING_STEP_CLEANUP_UNSOLICITED_RESULT_CODES:
MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (ctx->self)->cleanup_unsolicited_result_codes (
ctx->self,
(GAsyncReadyCallback)cleanup_unsolicited_result_codes_ready,
ctx);
return;
case DISABLING_STEP_LAST:
/* We are done without errors! */
@@ -169,6 +193,7 @@ static void interface_enabling_step (EnablingContext *ctx);
typedef enum {
ENABLING_STEP_FIRST,
ENABLING_STEP_SETUP_UNSOLICITED_RESULT_CODES,
ENABLING_STEP_ENABLE_UNSOLICITED_RESULT_CODES,
ENABLING_STEP_LAST
} EnablingStep;
@@ -223,6 +248,27 @@ mm_iface_modem_3gpp_ussd_enable_finish (MMIfaceModem3gppUssd *self,
return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
}
static void
setup_unsolicited_result_codes_ready (MMIfaceModem3gppUssd *self,
GAsyncResult *res,
EnablingContext *ctx)
{
GError *error = NULL;
MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (self)->setup_unsolicited_result_codes_finish (self,
res,
&error);
if (error) {
/* This error shouldn't be treated as critical */
mm_dbg ("Couldn't setup unsolicited result codes: '%s'", error->message);
g_error_free (error);
}
/* Go on to next step */
ctx->step++;
interface_enabling_step (ctx);
}
static void
enable_unsolicited_result_codes_ready (MMIfaceModem3gppUssd *self,
GAsyncResult *res,
@@ -252,17 +298,19 @@ interface_enabling_step (EnablingContext *ctx)
/* Fall down to next step */
ctx->step++;
case ENABLING_STEP_SETUP_UNSOLICITED_RESULT_CODES:
MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (ctx->self)->setup_unsolicited_result_codes (
ctx->self,
(GAsyncReadyCallback)setup_unsolicited_result_codes_ready,
ctx);
return;
case ENABLING_STEP_ENABLE_UNSOLICITED_RESULT_CODES:
if (MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (ctx->self)->enable_unsolicited_result_codes &&
MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (ctx->self)->enable_unsolicited_result_codes_finish) {
MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (ctx->self)->enable_unsolicited_result_codes (
ctx->self,
(GAsyncReadyCallback)enable_unsolicited_result_codes_ready,
ctx);
return;
}
/* Fall down to next step */
ctx->step++;
MM_IFACE_MODEM_3GPP_USSD_GET_INTERFACE (ctx->self)->enable_unsolicited_result_codes (
ctx->self,
(GAsyncReadyCallback)enable_unsolicited_result_codes_ready,
ctx);
return;
case ENABLING_STEP_LAST:
/* We are done without errors! */
+16
View File
@@ -43,6 +43,14 @@ struct _MMIfaceModem3gppUssd {
GAsyncResult *res,
GError **error);
/* Asynchronous setup of unsolicited result codes */
void (*setup_unsolicited_result_codes) (MMIfaceModem3gppUssd *self,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean (*setup_unsolicited_result_codes_finish) (MMIfaceModem3gppUssd *self,
GAsyncResult *res,
GError **error);
/* Asynchronous enabling of unsolicited result codes */
void (*enable_unsolicited_result_codes) (MMIfaceModem3gppUssd *self,
GAsyncReadyCallback callback,
@@ -58,6 +66,14 @@ struct _MMIfaceModem3gppUssd {
gboolean (*disable_unsolicited_result_codes_finish) (MMIfaceModem3gppUssd *self,
GAsyncResult *res,
GError **error);
/* Asynchronous cleaning up of unsolicited result codes */
void (*cleanup_unsolicited_result_codes) (MMIfaceModem3gppUssd *self,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean (*cleanup_unsolicited_result_codes_finish) (MMIfaceModem3gppUssd *self,
GAsyncResult *res,
GError **error);
};
GType mm_iface_modem_3gpp_ussd_get_type (void);