From b00c4099783cd4a994e7771ed275c7c61591a45b Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 8 Nov 2011 17:20:34 +0100 Subject: [PATCH] base-modem: new virtual initialize() method Whenever the first AT port is grabbed, we launch the initialize() method, which must have been implemented by the corresponding modem subclass. --- src/mm-base-modem.c | 40 ++++++++++++++++++++++++---------------- src/mm-base-modem.h | 10 ++++++++++ 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/mm-base-modem.c b/src/mm-base-modem.c index bbd4156c..104336e4 100644 --- a/src/mm-base-modem.c +++ b/src/mm-base-modem.c @@ -27,6 +27,7 @@ #include #include "mm-base-modem.h" + #include "mm-errors.h" #include "mm-log.h" #include "mm-at-serial-port.h" @@ -144,6 +145,23 @@ serial_port_timed_out_cb (MMSerialPort *port, } } +static void +initialize_ready (MMBaseModem *self, + GAsyncResult *res) +{ + GError *error = NULL; + + if (!MM_BASE_MODEM_GET_CLASS (self)->initialize_finish (self, res, &error)) { + mm_warn ("couldn't initialize the modem: '%s'", error->message); + mm_base_modem_set_valid (self, FALSE); + g_error_free (error); + return; + } + + mm_dbg ("modem properly initialized"); + mm_base_modem_set_valid (self, TRUE); +} + gboolean mm_base_modem_grab_port (MMBaseModem *self, const gchar *subsys, @@ -247,21 +265,12 @@ mm_base_modem_grab_port (MMBaseModem *self, if (!self->priv->data) self->priv->data = g_object_ref (port); - /* TODO: GSM */ - /* /\* Get the modem's general info *\/ */ - /* initial_info_check (self); */ - /* /\* Get modem's IMEI *\/ */ - /* initial_imei_check (self); */ - /* /\* Get modem's initial lock/unlock state; this also ensures the */ - /* * SIM is ready by waiting if necessary for the SIM to initalize. */ - /* *\/ */ - /* initial_pin_check (self); */ - - /* TODO: CDMA */ - /* /\* Get the modem's general info *\/ */ - /* initial_info_check (self); */ - /* /\* Get modem's ESN number *\/ */ - /* initial_esn_check (self); */ + /* As soon as we get the primary AT port, we initialize the + * modem */ + MM_BASE_MODEM_GET_CLASS (self)->initialize (self, + NULL, /* TODO: cancellable */ + (GAsyncReadyCallback)initialize_ready, + NULL); } else if (ptype == MM_PORT_TYPE_SECONDARY) self->priv->secondary = g_object_ref (port); @@ -293,7 +302,6 @@ mm_base_modem_grab_port (MMBaseModem *self, self->priv->data = g_object_ref (port); /* TODO: */ - /* g_object_notify (G_OBJECT (self), MM_MODEM_DATA_DEVICE); */ /* check_valid (self); */ } diff --git a/src/mm-base-modem.h b/src/mm-base-modem.h index 563f70c7..0945b630 100644 --- a/src/mm-base-modem.h +++ b/src/mm-base-modem.h @@ -55,6 +55,16 @@ struct _MMBaseModem { struct _MMBaseModemClass { MmGdbusObjectSkeletonClass parent; + + /* Modem initialization. + * Whenever the primary AT port is grabbed, this method gets called */ + void (* initialize) (MMBaseModem *self, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); + gboolean (*initialize_finish) (MMBaseModem *self, + GAsyncResult *res, + GError **error); }; GType mm_base_modem_get_type (void);