zte: use common unsolicited messages handler setup
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
#include "mm-base-modem-at.h"
|
||||
#include "mm-iface-modem.h"
|
||||
#include "mm-iface-modem-3gpp.h"
|
||||
#include "mm-common-zte.h"
|
||||
#include "mm-broadband-modem-zte.h"
|
||||
|
||||
static void iface_modem_init (MMIfaceModem *iface);
|
||||
@@ -42,14 +43,8 @@ G_DEFINE_TYPE_EXTENDED (MMBroadbandModemZte, mm_broadband_modem_zte, MM_TYPE_BRO
|
||||
G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM_3GPP, iface_modem_3gpp_init));
|
||||
|
||||
struct _MMBroadbandModemZtePrivate {
|
||||
/* Regex for access-technology related notifications */
|
||||
GRegex *zpasr_regex;
|
||||
|
||||
/* Requests to always ignore */
|
||||
GRegex *zusimr_regex; /* SMS related */
|
||||
GRegex *zdonr_regex; /* Unsolicited operator display */
|
||||
GRegex *zpstm_regex; /* SIM request to Build Main Menu */
|
||||
GRegex *zend_regex; /* SIM request to Rebuild Main Menu */
|
||||
/* Unsolicited messaging setup */
|
||||
MMCommonZteUnsolicitedSetup *unsolicited_setup;
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -386,70 +381,6 @@ load_access_technologies (MMIfaceModem *self,
|
||||
/*****************************************************************************/
|
||||
/* Setup/Cleanup unsolicited events (3GPP interface) */
|
||||
|
||||
static void
|
||||
zpasr_received (MMAtSerialPort *port,
|
||||
GMatchInfo *info,
|
||||
MMBroadbandModemZte *self)
|
||||
{
|
||||
MMModemAccessTechnology act = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN;
|
||||
gchar *str;
|
||||
|
||||
str = g_match_info_fetch (info, 1);
|
||||
if (str) {
|
||||
act = mm_string_to_access_tech (str);
|
||||
g_free (str);
|
||||
}
|
||||
|
||||
mm_iface_modem_update_access_technologies (MM_IFACE_MODEM (self),
|
||||
act,
|
||||
MM_IFACE_MODEM_3GPP_ALL_ACCESS_TECHNOLOGIES_MASK);
|
||||
}
|
||||
|
||||
static void
|
||||
set_unsolicited_events_handlers (MMBroadbandModemZte *self,
|
||||
gboolean enable)
|
||||
{
|
||||
MMAtSerialPort *ports[2];
|
||||
guint i;
|
||||
|
||||
ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self));
|
||||
ports[1] = mm_base_modem_peek_port_secondary (MM_BASE_MODEM (self));
|
||||
|
||||
/* Enable unsolicited events in given port */
|
||||
for (i = 0; i < 2; i++) {
|
||||
if (!ports[i])
|
||||
continue;
|
||||
|
||||
/* Access technology related */
|
||||
mm_at_serial_port_add_unsolicited_msg_handler (
|
||||
ports[i],
|
||||
self->priv->zpasr_regex,
|
||||
enable ? (MMAtSerialUnsolicitedMsgFn)zpasr_received : NULL,
|
||||
enable ? self : NULL,
|
||||
NULL);
|
||||
|
||||
/* Other unsolicited events to always ignore */
|
||||
if (!enable) {
|
||||
mm_at_serial_port_add_unsolicited_msg_handler (
|
||||
ports[i],
|
||||
self->priv->zusimr_regex,
|
||||
NULL, NULL, NULL);
|
||||
mm_at_serial_port_add_unsolicited_msg_handler (
|
||||
ports[i],
|
||||
self->priv->zdonr_regex,
|
||||
NULL, NULL, NULL);
|
||||
mm_at_serial_port_add_unsolicited_msg_handler (
|
||||
ports[i],
|
||||
self->priv->zpstm_regex,
|
||||
NULL, NULL, NULL);
|
||||
mm_at_serial_port_add_unsolicited_msg_handler (
|
||||
ports[i],
|
||||
self->priv->zend_regex,
|
||||
NULL, NULL, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
modem_3gpp_setup_cleanup_unsolicited_events_finish (MMIfaceModem3gpp *self,
|
||||
GAsyncResult *res,
|
||||
@@ -469,7 +400,9 @@ parent_setup_unsolicited_events_ready (MMIfaceModem3gpp *self,
|
||||
g_simple_async_result_take_error (simple, error);
|
||||
else {
|
||||
/* Our own setup now */
|
||||
set_unsolicited_events_handlers (MM_BROADBAND_MODEM_ZTE (self), TRUE);
|
||||
mm_common_zte_set_unsolicited_events_handlers (MM_BROADBAND_MODEM (self),
|
||||
MM_BROADBAND_MODEM_ZTE (self)->priv->unsolicited_setup,
|
||||
TRUE);
|
||||
g_simple_async_result_set_op_res_gboolean (G_SIMPLE_ASYNC_RESULT (res), TRUE);
|
||||
}
|
||||
|
||||
@@ -524,7 +457,9 @@ modem_3gpp_cleanup_unsolicited_events (MMIfaceModem3gpp *self,
|
||||
modem_3gpp_cleanup_unsolicited_events);
|
||||
|
||||
/* Our own cleanup first */
|
||||
set_unsolicited_events_handlers (MM_BROADBAND_MODEM_ZTE (self), FALSE);
|
||||
mm_common_zte_set_unsolicited_events_handlers (MM_BROADBAND_MODEM (self),
|
||||
MM_BROADBAND_MODEM_ZTE (self)->priv->unsolicited_setup,
|
||||
FALSE);
|
||||
|
||||
/* And now chain up parent's cleanup */
|
||||
iface_modem_3gpp_parent->cleanup_unsolicited_events (
|
||||
@@ -559,7 +494,9 @@ setup_ports (MMBroadbandModem *self)
|
||||
}
|
||||
|
||||
/* Now reset the unsolicited messages we'll handle when enabled */
|
||||
set_unsolicited_events_handlers (MM_BROADBAND_MODEM_ZTE (self), FALSE);
|
||||
mm_common_zte_set_unsolicited_events_handlers (MM_BROADBAND_MODEM (self),
|
||||
MM_BROADBAND_MODEM_ZTE (self)->priv->unsolicited_setup,
|
||||
FALSE);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -587,18 +524,7 @@ mm_broadband_modem_zte_init (MMBroadbandModemZte *self)
|
||||
self->priv = G_TYPE_INSTANCE_GET_PRIVATE ((self),
|
||||
MM_TYPE_BROADBAND_MODEM_ZTE,
|
||||
MMBroadbandModemZtePrivate);
|
||||
|
||||
/* Prepare regular expressions to setup */
|
||||
self->priv->zusimr_regex = g_regex_new ("\\r\\n\\+ZUSIMR:(.*)\\r\\n",
|
||||
G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
self->priv->zdonr_regex = g_regex_new ("\\r\\n\\+ZDONR: (.*)\\r\\n",
|
||||
G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
self->priv->zpasr_regex = g_regex_new ("\\r\\n\\+ZPASR:\\s*(.*)\\r\\n",
|
||||
G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
self->priv->zpstm_regex = g_regex_new ("\\r\\n\\+ZPSTM: (.*)\\r\\n",
|
||||
G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
self->priv->zend_regex = g_regex_new ("\\r\\n\\+ZEND\\r\\n",
|
||||
G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
self->priv->unsolicited_setup = mm_common_zte_unsolicited_setup_new ();
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -606,11 +532,7 @@ finalize (GObject *object)
|
||||
{
|
||||
MMBroadbandModemZte *self = MM_BROADBAND_MODEM_ZTE (object);
|
||||
|
||||
g_regex_unref (self->priv->zusimr_regex);
|
||||
g_regex_unref (self->priv->zdonr_regex);
|
||||
g_regex_unref (self->priv->zpasr_regex);
|
||||
g_regex_unref (self->priv->zpstm_regex);
|
||||
g_regex_unref (self->priv->zend_regex);
|
||||
mm_common_zte_unsolicited_setup_free (self->priv->unsolicited_setup);
|
||||
|
||||
G_OBJECT_CLASS (mm_broadband_modem_zte_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user