From 69079ff8914419d08c21720f022ef33da8225959 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 28 Nov 2011 14:42:43 +0100 Subject: [PATCH] iface-modem-3gpp: load `IMEI' during init --- src/mm-iface-modem-3gpp.c | 39 +++++++++++++++++++++++++++++++++++++++ src/mm-iface-modem-3gpp.h | 8 ++++++++ 2 files changed, 47 insertions(+) diff --git a/src/mm-iface-modem-3gpp.c b/src/mm-iface-modem-3gpp.c index f6a19b18..6b7cde2a 100644 --- a/src/mm-iface-modem-3gpp.c +++ b/src/mm-iface-modem-3gpp.c @@ -30,6 +30,7 @@ static void interface_initialization_step (InitializationContext *ctx); typedef enum { INITIALIZATION_STEP_FIRST, + INITIALIZATION_STEP_IMEI, INITIALIZATION_STEP_LAST } InitializationStep; @@ -74,6 +75,28 @@ initialization_context_free (InitializationContext *ctx) g_free (ctx); } +static void +load_imei_ready (MMIfaceModem3gpp *self, + GAsyncResult *res, + InitializationContext *ctx) +{ + GError *error = NULL; + gchar *imei; + + imei = MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->load_imei_finish (self, res, &error); + mm_gdbus_modem3gpp_set_imei (ctx->skeleton, imei); + g_free (imei); + + if (error) { + mm_warn ("couldn't load IMEI: '%s'", error->message); + g_error_free (error); + } + + /* Go on to next step */ + ctx->step++; + interface_initialization_step (ctx); +} + static void interface_initialization_step (InitializationContext *ctx) { @@ -82,6 +105,22 @@ interface_initialization_step (InitializationContext *ctx) /* Fall down to next step */ ctx->step++; + case INITIALIZATION_STEP_IMEI: + /* IMEI value is meant to be loaded only once during the whole + * lifetime of the modem. Therefore, if we already have it loaded, + * don't try to load it again. */ + if (!mm_gdbus_modem3gpp_get_imei (ctx->skeleton) && + MM_IFACE_MODEM_3GPP_GET_INTERFACE (ctx->self)->load_imei && + MM_IFACE_MODEM_3GPP_GET_INTERFACE (ctx->self)->load_imei_finish) { + MM_IFACE_MODEM_3GPP_GET_INTERFACE (ctx->self)->load_imei ( + ctx->self, + (GAsyncReadyCallback)load_imei_ready, + ctx); + return; + } + /* Fall down to next step */ + ctx->step++; + case INITIALIZATION_STEP_LAST: /* We are done without errors! */ g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE); diff --git a/src/mm-iface-modem-3gpp.h b/src/mm-iface-modem-3gpp.h index 0fcdde01..0dc7389d 100644 --- a/src/mm-iface-modem-3gpp.h +++ b/src/mm-iface-modem-3gpp.h @@ -32,6 +32,14 @@ typedef struct _MMIfaceModem3gpp MMIfaceModem3gpp; struct _MMIfaceModem3gpp { GTypeInterface g_iface; + + /* Loading of the IMEI property */ + void (*load_imei) (MMIfaceModem3gpp *self, + GAsyncReadyCallback callback, + gpointer user_data); + gchar * (*load_imei_finish) (MMIfaceModem3gpp *self, + GAsyncResult *res, + GError **error); }; GType mm_iface_modem_3gpp_get_type (void);