icera: convert to GInterface
We'll need to store some private data later for authentication, and this makes it easier and clearer to access that private data.
This commit is contained in:
@@ -6,8 +6,8 @@
|
||||
noinst_LTLIBRARIES = libicera-utils.la
|
||||
|
||||
libicera_utils_la_SOURCES = \
|
||||
mm-icera-utils.c \
|
||||
mm-icera-utils.h
|
||||
mm-modem-icera.c \
|
||||
mm-modem-icera.h
|
||||
|
||||
libicera_utils_la_CPPFLAGS = \
|
||||
$(MM_CFLAGS) \
|
||||
|
@@ -22,8 +22,9 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "mm-icera-utils.h"
|
||||
#include "mm-modem-icera.h"
|
||||
|
||||
#include "mm-modem.h"
|
||||
#include "mm-errors.h"
|
||||
#include "mm-callback-info.h"
|
||||
#include "mm-at-serial-port.h"
|
||||
@@ -31,7 +32,7 @@
|
||||
#include "mm-modem-helpers.h"
|
||||
|
||||
static void
|
||||
icera_get_allowed_mode_done (MMAtSerialPort *port,
|
||||
get_allowed_mode_done (MMAtSerialPort *port,
|
||||
GString *response,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
@@ -77,25 +78,25 @@ icera_get_allowed_mode_done (MMAtSerialPort *port,
|
||||
}
|
||||
|
||||
void
|
||||
mm_icera_utils_get_allowed_mode (MMGenericGsm *gsm,
|
||||
mm_modem_icera_get_allowed_mode (MMModemIcera *self,
|
||||
MMModemUIntFn callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info;
|
||||
MMAtSerialPort *port;
|
||||
|
||||
info = mm_callback_info_uint_new (MM_MODEM (gsm), callback, user_data);
|
||||
info = mm_callback_info_uint_new (MM_MODEM (self), callback, user_data);
|
||||
|
||||
port = mm_generic_gsm_get_best_at_port (gsm, &info->error);
|
||||
port = mm_generic_gsm_get_best_at_port (MM_GENERIC_GSM (self), &info->error);
|
||||
if (!port) {
|
||||
mm_callback_info_schedule (info);
|
||||
return;
|
||||
}
|
||||
mm_at_serial_port_queue_command (port, "%IPSYS?", 3, icera_get_allowed_mode_done, info);
|
||||
mm_at_serial_port_queue_command (port, "%IPSYS?", 3, get_allowed_mode_done, info);
|
||||
}
|
||||
|
||||
static void
|
||||
icera_set_allowed_mode_done (MMAtSerialPort *port,
|
||||
set_allowed_mode_done (MMAtSerialPort *port,
|
||||
GString *response,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
@@ -109,7 +110,7 @@ icera_set_allowed_mode_done (MMAtSerialPort *port,
|
||||
}
|
||||
|
||||
void
|
||||
mm_icera_utils_set_allowed_mode (MMGenericGsm *gsm,
|
||||
mm_modem_icera_set_allowed_mode (MMModemIcera *self,
|
||||
MMModemGsmAllowedMode mode,
|
||||
MMModemFn callback,
|
||||
gpointer user_data)
|
||||
@@ -119,9 +120,9 @@ mm_icera_utils_set_allowed_mode (MMGenericGsm *gsm,
|
||||
char *command;
|
||||
int i;
|
||||
|
||||
info = mm_callback_info_new (MM_MODEM (gsm), callback, user_data);
|
||||
info = mm_callback_info_new (MM_MODEM (self), callback, user_data);
|
||||
|
||||
port = mm_generic_gsm_get_best_at_port (gsm, &info->error);
|
||||
port = mm_generic_gsm_get_best_at_port (MM_GENERIC_GSM (self), &info->error);
|
||||
if (!port) {
|
||||
mm_callback_info_schedule (info);
|
||||
return;
|
||||
@@ -147,7 +148,7 @@ mm_icera_utils_set_allowed_mode (MMGenericGsm *gsm,
|
||||
}
|
||||
|
||||
command = g_strdup_printf ("%%IPSYS=%d", i);
|
||||
mm_at_serial_port_queue_command (port, command, 3, icera_set_allowed_mode_done, info);
|
||||
mm_at_serial_port_queue_command (port, command, 3, set_allowed_mode_done, info);
|
||||
g_free (command);
|
||||
}
|
||||
|
||||
@@ -171,13 +172,12 @@ nwstate_to_act (const char *str)
|
||||
return MM_MODEM_GSM_ACCESS_TECH_UNKNOWN;
|
||||
}
|
||||
|
||||
#define LAST_ACT_TAG "icera-last-act"
|
||||
|
||||
static void
|
||||
icera_nwstate_changed (MMAtSerialPort *port,
|
||||
nwstate_changed (MMAtSerialPort *port,
|
||||
GMatchInfo *info,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMModemIcera *self = MM_MODEM_ICERA (user_data);
|
||||
MMModemGsmAccessTech act = MM_MODEM_GSM_ACCESS_TECH_UNKNOWN;
|
||||
char *str;
|
||||
int rssi = -1;
|
||||
@@ -195,28 +195,28 @@ icera_nwstate_changed (MMAtSerialPort *port,
|
||||
g_free (str);
|
||||
}
|
||||
|
||||
g_object_set_data (G_OBJECT (user_data), LAST_ACT_TAG, GUINT_TO_POINTER (act));
|
||||
mm_generic_gsm_update_access_technology (MM_GENERIC_GSM (user_data), act);
|
||||
self->last_act = act;
|
||||
mm_generic_gsm_update_access_technology (MM_GENERIC_GSM (self), act);
|
||||
}
|
||||
|
||||
void
|
||||
mm_icera_utils_register_unsolicted_handlers (MMGenericGsm *modem,
|
||||
mm_modem_icera_register_unsolicted_handlers (MMModemIcera *self,
|
||||
MMAtSerialPort *port)
|
||||
{
|
||||
GRegex *regex;
|
||||
|
||||
/* %NWSTATE: <rssi>,<mccmnc>,<tech>,<connected>,<regulation> */
|
||||
regex = g_regex_new ("\\r\\n%NWSTATE:\\s*(\\d+),(\\d+),([^,]*),([^,]*),(\\d+)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
mm_at_serial_port_add_unsolicited_msg_handler (port, regex, icera_nwstate_changed, modem, NULL);
|
||||
mm_at_serial_port_add_unsolicited_msg_handler (port, regex, nwstate_changed, self, NULL);
|
||||
g_regex_unref (regex);
|
||||
}
|
||||
|
||||
void
|
||||
mm_icera_utils_change_unsolicited_messages (MMGenericGsm *modem, gboolean enabled)
|
||||
mm_modem_icera_change_unsolicited_messages (MMModemIcera *self, gboolean enabled)
|
||||
{
|
||||
MMAtSerialPort *primary;
|
||||
|
||||
primary = mm_generic_gsm_get_at_port (modem, MM_PORT_TYPE_PRIMARY);
|
||||
primary = mm_generic_gsm_get_at_port (MM_GENERIC_GSM (self), MM_PORT_TYPE_PRIMARY);
|
||||
g_assert (primary);
|
||||
|
||||
mm_at_serial_port_queue_command (primary, enabled ? "%NWSTATE=1" : "%NWSTATE=0", 3, NULL, NULL);
|
||||
@@ -229,32 +229,32 @@ get_nwstate_done (MMAtSerialPort *port,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info = user_data;
|
||||
MMModemGsmAccessTech act = MM_MODEM_GSM_ACCESS_TECH_UNKNOWN;
|
||||
|
||||
info->error = mm_modem_check_removed (info->modem, error);
|
||||
if (!info->error) {
|
||||
MMModemIcera *self = MM_MODEM_ICERA (info->modem);
|
||||
|
||||
/* The unsolicited message handler will already have run and
|
||||
* removed the NWSTATE response, so we have to work around that.
|
||||
*/
|
||||
act = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (info->modem), LAST_ACT_TAG));
|
||||
mm_callback_info_set_result (info, GUINT_TO_POINTER (act), NULL);
|
||||
g_object_set_data (G_OBJECT (info->modem), LAST_ACT_TAG, NULL);
|
||||
mm_callback_info_set_result (info, GUINT_TO_POINTER (self->last_act), NULL);
|
||||
self->last_act = MM_MODEM_GSM_ACCESS_TECH_UNKNOWN;
|
||||
}
|
||||
|
||||
mm_callback_info_schedule (info);
|
||||
}
|
||||
|
||||
void
|
||||
mm_icera_utils_get_access_technology (MMGenericGsm *modem,
|
||||
mm_modem_icera_get_access_technology (MMModemIcera *self,
|
||||
MMModemUIntFn callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMAtSerialPort *port;
|
||||
MMCallbackInfo *info;
|
||||
|
||||
info = mm_callback_info_uint_new (MM_MODEM (modem), callback, user_data);
|
||||
info = mm_callback_info_uint_new (MM_MODEM (self), callback, user_data);
|
||||
|
||||
port = mm_generic_gsm_get_best_at_port (modem, &info->error);
|
||||
port = mm_generic_gsm_get_best_at_port (MM_GENERIC_GSM (self), &info->error);
|
||||
if (!port) {
|
||||
mm_callback_info_schedule (info);
|
||||
return;
|
||||
@@ -278,7 +278,7 @@ icera_check_done (MMAtSerialPort *port,
|
||||
}
|
||||
|
||||
void
|
||||
mm_icera_utils_is_icera (MMGenericGsm *modem,
|
||||
mm_modem_icera_is_icera (MMGenericGsm *modem,
|
||||
MMModemUIntFn callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
@@ -296,3 +296,50 @@ mm_icera_utils_is_icera (MMGenericGsm *modem,
|
||||
mm_at_serial_port_queue_command (port, "%IPSYS?", 5, icera_check_done, info);
|
||||
}
|
||||
|
||||
/****************************************************************/
|
||||
|
||||
void
|
||||
mm_modem_icera_dispose (MMModemIcera *self)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
mm_modem_icera_init (gpointer g_iface)
|
||||
{
|
||||
static gboolean initialized = FALSE;
|
||||
|
||||
if (!initialized) {
|
||||
initialized = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
GType
|
||||
mm_modem_icera_get_type (void)
|
||||
{
|
||||
static GType icera_type = 0;
|
||||
|
||||
if (!G_UNLIKELY (icera_type)) {
|
||||
const GTypeInfo icera_info = {
|
||||
sizeof (MMModemIcera), /* class_size */
|
||||
mm_modem_icera_init, /* base_init */
|
||||
NULL, /* base_finalize */
|
||||
NULL,
|
||||
NULL, /* class_finalize */
|
||||
NULL, /* class_data */
|
||||
0,
|
||||
0, /* n_preallocs */
|
||||
NULL
|
||||
};
|
||||
|
||||
icera_type = g_type_register_static (G_TYPE_INTERFACE,
|
||||
"MMModemIcera",
|
||||
&icera_info, 0);
|
||||
|
||||
g_type_interface_add_prerequisite (icera_type, G_TYPE_OBJECT);
|
||||
g_type_interface_add_prerequisite (icera_type, MM_TYPE_MODEM);
|
||||
g_type_interface_add_prerequisite (icera_type, MM_TYPE_GENERIC_GSM);
|
||||
}
|
||||
|
||||
return icera_type;
|
||||
}
|
||||
|
@@ -17,33 +17,53 @@
|
||||
* Generic utilities for Icera-based modems
|
||||
******************************************/
|
||||
|
||||
#ifndef MM_ICERA_UTILS_H
|
||||
#define MM_ICERA_UTILS_H
|
||||
#ifndef MM_MODEM_ICERA_H
|
||||
#define MM_MODEM_ICERA_H
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include "mm-modem-gsm.h"
|
||||
#include "mm-generic-gsm.h"
|
||||
|
||||
void mm_icera_utils_get_allowed_mode (MMGenericGsm *gsm,
|
||||
#define MM_TYPE_MODEM_ICERA (mm_modem_icera_get_type ())
|
||||
#define MM_MODEM_ICERA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM_ICERA, MMModemIcera))
|
||||
#define MM_IS_MODEM_ICERA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_ICERA))
|
||||
#define MM_MODEM_ICERA_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), MM_TYPE_MODEM_ICERA, MMModemIcera))
|
||||
|
||||
typedef struct _MMModemIcera MMModemIcera;
|
||||
|
||||
struct _MMModemIcera {
|
||||
GTypeInterface g_iface;
|
||||
|
||||
MMModemGsmAccessTech last_act;
|
||||
};
|
||||
|
||||
GType mm_modem_icera_get_type (void);
|
||||
|
||||
void mm_modem_icera_dispose (MMModemIcera *self);
|
||||
|
||||
void mm_modem_icera_get_allowed_mode (MMModemIcera *self,
|
||||
MMModemUIntFn callback,
|
||||
gpointer user_data);
|
||||
|
||||
void mm_icera_utils_set_allowed_mode (MMGenericGsm *gsm,
|
||||
void mm_modem_icera_set_allowed_mode (MMModemIcera *self,
|
||||
MMModemGsmAllowedMode mode,
|
||||
MMModemFn callback,
|
||||
gpointer user_data);
|
||||
|
||||
void mm_icera_utils_register_unsolicted_handlers (MMGenericGsm *modem,
|
||||
void mm_modem_icera_register_unsolicted_handlers (MMModemIcera *self,
|
||||
MMAtSerialPort *port);
|
||||
|
||||
void mm_icera_utils_change_unsolicited_messages (MMGenericGsm *modem,
|
||||
void mm_modem_icera_change_unsolicited_messages (MMModemIcera *self,
|
||||
gboolean enabled);
|
||||
|
||||
void mm_icera_utils_get_access_technology (MMGenericGsm *modem,
|
||||
void mm_modem_icera_get_access_technology (MMModemIcera *self,
|
||||
MMModemUIntFn callback,
|
||||
gpointer user_data);
|
||||
|
||||
void mm_icera_utils_is_icera (MMGenericGsm *modem,
|
||||
void mm_modem_icera_is_icera (MMGenericGsm *modem,
|
||||
MMModemUIntFn callback,
|
||||
gpointer user_data);
|
||||
|
||||
#endif /* MM_ICERA_UTILS_H */
|
||||
#endif /* MM_MODEM_ICERA_H */
|
||||
|
@@ -24,12 +24,14 @@
|
||||
#include "mm-errors.h"
|
||||
#include "mm-callback-info.h"
|
||||
#include "mm-modem-helpers.h"
|
||||
#include "mm-icera-utils.h"
|
||||
#include "mm-modem-icera.h"
|
||||
|
||||
static void modem_init (MMModem *modem_class);
|
||||
static void modem_icera_init (MMModemIcera *icera_class);
|
||||
|
||||
G_DEFINE_TYPE_EXTENDED (MMModemZte, mm_modem_zte, MM_TYPE_GENERIC_GSM, 0,
|
||||
G_IMPLEMENT_INTERFACE (MM_TYPE_MODEM, modem_init))
|
||||
G_IMPLEMENT_INTERFACE (MM_TYPE_MODEM, modem_init)
|
||||
G_IMPLEMENT_INTERFACE (MM_TYPE_MODEM_ICERA, modem_icera_init))
|
||||
|
||||
#define MM_MODEM_ZTE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_MODEM_ZTE, MMModemZtePrivate))
|
||||
|
||||
@@ -156,7 +158,7 @@ get_allowed_mode (MMGenericGsm *gsm,
|
||||
MMAtSerialPort *port;
|
||||
|
||||
if (MM_MODEM_ZTE_GET_PRIVATE (self)->is_icera) {
|
||||
mm_icera_utils_get_allowed_mode (gsm, callback, user_data);
|
||||
mm_modem_icera_get_allowed_mode (MM_MODEM_ICERA (self), callback, user_data);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -198,7 +200,7 @@ set_allowed_mode (MMGenericGsm *gsm,
|
||||
int cm_mode = 0, pref_acq = 0;
|
||||
|
||||
if (MM_MODEM_ZTE_GET_PRIVATE (self)->is_icera) {
|
||||
mm_icera_utils_set_allowed_mode (gsm, mode, callback, user_data);
|
||||
mm_modem_icera_set_allowed_mode (MM_MODEM_ICERA (self), mode, callback, user_data);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -271,7 +273,7 @@ get_access_technology (MMGenericGsm *gsm,
|
||||
MMCallbackInfo *info;
|
||||
|
||||
if (MM_MODEM_ZTE_GET_PRIVATE (self)->is_icera) {
|
||||
mm_icera_utils_get_access_technology (gsm, callback, user_data);
|
||||
mm_modem_icera_get_access_technology (MM_MODEM_ICERA (self), callback, user_data);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -336,7 +338,7 @@ cpms_try_done (MMAtSerialPort *port,
|
||||
|
||||
/* Turn on unsolicited network state messages */
|
||||
if (priv->is_icera)
|
||||
mm_icera_utils_change_unsolicited_messages (MM_GENERIC_GSM (info->modem), TRUE);
|
||||
mm_modem_icera_change_unsolicited_messages (MM_MODEM_ICERA (info->modem), TRUE);
|
||||
|
||||
mm_generic_gsm_enable_complete (MM_GENERIC_GSM (info->modem), error, info);
|
||||
}
|
||||
@@ -402,7 +404,7 @@ pre_init_done (MMAtSerialPort *port,
|
||||
mm_generic_gsm_enable_complete (MM_GENERIC_GSM (self), error, info);
|
||||
} else {
|
||||
/* Finish the initialization */
|
||||
mm_icera_utils_is_icera (MM_GENERIC_GSM (self), icera_check_cb, self);
|
||||
mm_modem_icera_is_icera (MM_GENERIC_GSM (self), icera_check_cb, self);
|
||||
mm_at_serial_port_queue_command (port, "Z E0 V1 X4 &C1 +CMEE=1;+CFUN=1;", 10, init_modem_done, info);
|
||||
}
|
||||
}
|
||||
@@ -476,7 +478,7 @@ disable (MMModem *modem,
|
||||
|
||||
/* Turn off unsolicited responses */
|
||||
if (priv->is_icera)
|
||||
mm_icera_utils_change_unsolicited_messages (MM_GENERIC_GSM (modem), FALSE);
|
||||
mm_modem_icera_change_unsolicited_messages (MM_MODEM_ICERA (modem), FALSE);
|
||||
|
||||
/* Random command to ensure unsolicited message disable completes */
|
||||
mm_at_serial_port_queue_command (primary, "E0", 5, disable_unsolicited_done, info);
|
||||
@@ -533,7 +535,7 @@ grab_port (MMModem *modem,
|
||||
g_regex_unref (regex);
|
||||
|
||||
/* Add Icera-specific handlers */
|
||||
mm_icera_utils_register_unsolicted_handlers (gsm, MM_AT_SERIAL_PORT (port));
|
||||
mm_modem_icera_register_unsolicted_handlers (MM_MODEM_ICERA (gsm), MM_AT_SERIAL_PORT (port));
|
||||
}
|
||||
|
||||
return !!port;
|
||||
@@ -548,6 +550,11 @@ modem_init (MMModem *modem_class)
|
||||
modem_class->grab_port = grab_port;
|
||||
}
|
||||
|
||||
static void
|
||||
modem_icera_init (MMModemIcera *icera_class)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
mm_modem_zte_init (MMModemZte *self)
|
||||
{
|
||||
@@ -561,6 +568,10 @@ dispose (GObject *object)
|
||||
|
||||
if (priv->cpms_timeout)
|
||||
g_source_remove (priv->cpms_timeout);
|
||||
|
||||
mm_modem_icera_dispose (MM_MODEM_ICERA (self));
|
||||
|
||||
G_OBJECT_CLASS (mm_modem_zte_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
|
Reference in New Issue
Block a user