icera: fix abuse of GInterface
The GInterface structure for MMModemIcera isn't instance data, thus we shouldn't be storing an instance pointer in it. Instead, make implemtors store the intstance data in their private structure, and have them implement an accessor for the Icera-private data. This makes everone (especially GObject) happy. It's a bit of additional indirection, but we still get to use the MM_MODEM_ICERA_GET_PRIVATE() and we still get to cast the passed-in GInterface MMModemIcera into the various GSM MMModem subclasses, which is all we ever wanted anyway.
This commit is contained in:
@@ -45,7 +45,7 @@ struct _MMModemIceraPrivate {
|
||||
MMModemGsmAccessTech last_act;
|
||||
};
|
||||
|
||||
#define MM_MODEM_ICERA_GET_PRIVATE(m) (MM_MODEM_ICERA_GET_INTERFACE(m)->priv)
|
||||
#define MM_MODEM_ICERA_GET_PRIVATE(m) (MM_MODEM_ICERA_GET_INTERFACE (m)->get_private(m))
|
||||
|
||||
static void
|
||||
get_allowed_mode_done (MMAtSerialPort *port,
|
||||
@@ -447,10 +447,10 @@ icera_connect_timed_out (gpointer data)
|
||||
}
|
||||
|
||||
static void
|
||||
icera_enabled (MMAtSerialPort *port,
|
||||
GString *response,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
icera_connected (MMAtSerialPort *port,
|
||||
GString *response,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||
|
||||
@@ -478,7 +478,7 @@ old_context_clear_done (MMAtSerialPort *port,
|
||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||
|
||||
/* Activate the PDP context and start the data session */
|
||||
icera_call_control (MM_MODEM_ICERA (info->modem), TRUE, icera_enabled, info);
|
||||
icera_call_control (MM_MODEM_ICERA (info->modem), TRUE, icera_connected, info);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -731,14 +731,6 @@ mm_modem_icera_is_icera (MMModemIcera *self,
|
||||
mm_at_serial_port_queue_command (port, "%IPSYS?", 5, is_icera_done, info);
|
||||
}
|
||||
|
||||
/****************************************************************/
|
||||
|
||||
void
|
||||
mm_modem_icera_prepare (MMModemIcera *self)
|
||||
{
|
||||
self->priv = g_malloc0 (sizeof (MMModemIceraPrivate));
|
||||
}
|
||||
|
||||
void
|
||||
mm_modem_icera_cleanup (MMModemIcera *self)
|
||||
{
|
||||
@@ -748,20 +740,32 @@ mm_modem_icera_cleanup (MMModemIcera *self)
|
||||
connect_pending_done (self);
|
||||
|
||||
g_free (priv->username);
|
||||
priv->username = NULL;
|
||||
g_free (priv->password);
|
||||
priv->password = NULL;
|
||||
}
|
||||
|
||||
memset (priv, 0, sizeof (MMModemIceraPrivate));
|
||||
/****************************************************************/
|
||||
|
||||
MMModemIceraPrivate *
|
||||
mm_modem_icera_init_private (void)
|
||||
{
|
||||
return g_malloc0 (sizeof (MMModemIceraPrivate));
|
||||
}
|
||||
|
||||
void
|
||||
mm_modem_icera_dispose_private (MMModemIcera *self)
|
||||
{
|
||||
MMModemIceraPrivate *priv = MM_MODEM_ICERA_GET_PRIVATE (self);
|
||||
|
||||
mm_modem_icera_cleanup (self);
|
||||
memset (priv, 0, sizeof (*priv));
|
||||
g_free (priv);
|
||||
}
|
||||
|
||||
static void
|
||||
mm_modem_icera_init (gpointer g_iface)
|
||||
{
|
||||
static gboolean initialized = FALSE;
|
||||
|
||||
if (!initialized) {
|
||||
initialized = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
GType
|
||||
|
@@ -37,12 +37,16 @@ typedef struct _MMModemIcera MMModemIcera;
|
||||
struct _MMModemIcera {
|
||||
GTypeInterface g_iface;
|
||||
|
||||
MMModemIceraPrivate *priv;
|
||||
/* Returns the implementing object's pointer to an internal
|
||||
* MMModemIceraPrivate pointer.
|
||||
*/
|
||||
MMModemIceraPrivate * (*get_private) (MMModemIcera *icera);
|
||||
};
|
||||
|
||||
GType mm_modem_icera_get_type (void);
|
||||
|
||||
void mm_modem_icera_prepare (MMModemIcera *self);
|
||||
MMModemIceraPrivate *mm_modem_icera_init_private (void);
|
||||
void mm_modem_icera_dispose_private (MMModemIcera *self);
|
||||
|
||||
void mm_modem_icera_cleanup (MMModemIcera *self);
|
||||
|
||||
|
@@ -43,6 +43,7 @@ typedef struct {
|
||||
guint32 cpms_tries;
|
||||
guint cpms_timeout;
|
||||
gboolean is_icera;
|
||||
MMModemIceraPrivate *icera;
|
||||
} MMModemZtePrivate;
|
||||
|
||||
MMModem *
|
||||
@@ -52,17 +53,23 @@ mm_modem_zte_new (const char *device,
|
||||
guint32 vendor,
|
||||
guint32 product)
|
||||
{
|
||||
MMModem *modem;
|
||||
|
||||
g_return_val_if_fail (device != NULL, NULL);
|
||||
g_return_val_if_fail (driver != NULL, NULL);
|
||||
g_return_val_if_fail (plugin != NULL, NULL);
|
||||
|
||||
return MM_MODEM (g_object_new (MM_TYPE_MODEM_ZTE,
|
||||
MM_MODEM_MASTER_DEVICE, device,
|
||||
MM_MODEM_DRIVER, driver,
|
||||
MM_MODEM_PLUGIN, plugin,
|
||||
MM_MODEM_HW_VID, vendor,
|
||||
MM_MODEM_HW_PID, product,
|
||||
NULL));
|
||||
modem = MM_MODEM (g_object_new (MM_TYPE_MODEM_ZTE,
|
||||
MM_MODEM_MASTER_DEVICE, device,
|
||||
MM_MODEM_DRIVER, driver,
|
||||
MM_MODEM_PLUGIN, plugin,
|
||||
MM_MODEM_HW_VID, vendor,
|
||||
MM_MODEM_HW_PID, product,
|
||||
NULL));
|
||||
if (modem)
|
||||
MM_MODEM_ZTE_GET_PRIVATE (modem)->icera = mm_modem_icera_init_private ();
|
||||
|
||||
return modem;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -620,6 +627,14 @@ grab_port (MMModem *modem,
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static MMModemIceraPrivate *
|
||||
get_icera_private (MMModemIcera *icera)
|
||||
{
|
||||
return MM_MODEM_ZTE_GET_PRIVATE (icera)->icera;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
modem_init (MMModem *modem_class)
|
||||
{
|
||||
@@ -630,9 +645,9 @@ modem_init (MMModem *modem_class)
|
||||
}
|
||||
|
||||
static void
|
||||
modem_icera_init (MMModemIcera *icera_class)
|
||||
modem_icera_init (MMModemIcera *icera)
|
||||
{
|
||||
mm_modem_icera_prepare (icera_class);
|
||||
icera->get_private = get_icera_private;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -655,7 +670,7 @@ dispose (GObject *object)
|
||||
if (priv->cpms_timeout)
|
||||
g_source_remove (priv->cpms_timeout);
|
||||
|
||||
mm_modem_icera_cleanup (MM_MODEM_ICERA (self));
|
||||
mm_modem_icera_dispose_private (MM_MODEM_ICERA (self));
|
||||
|
||||
G_OBJECT_CLASS (mm_modem_zte_parent_class)->dispose (object);
|
||||
}
|
||||
|
Reference in New Issue
Block a user