iface-modem: move recent signal quality handling to iface-specific private context

This commit is contained in:
Aleksander Morgado
2022-05-16 11:24:03 +02:00
parent 9fde6f9162
commit 95da87046c

View File

@@ -42,11 +42,9 @@
#define SIGNAL_CHECK_INITIAL_TIMEOUT_SEC 3 #define SIGNAL_CHECK_INITIAL_TIMEOUT_SEC 3
#define SIGNAL_CHECK_TIMEOUT_SEC 30 #define SIGNAL_CHECK_TIMEOUT_SEC 30
#define SIGNAL_QUALITY_UPDATE_CONTEXT_TAG "signal-quality-update-context-tag"
#define SIGNAL_CHECK_CONTEXT_TAG "signal-check-context-tag" #define SIGNAL_CHECK_CONTEXT_TAG "signal-check-context-tag"
#define RESTART_INITIALIZE_IDLE_TAG "restart-initialize-tag" #define RESTART_INITIALIZE_IDLE_TAG "restart-initialize-tag"
static GQuark signal_quality_update_context_quark;
static GQuark signal_check_context_quark; static GQuark signal_check_context_quark;
static GQuark restart_initialize_idle_quark; static GQuark restart_initialize_idle_quark;
@@ -59,6 +57,9 @@ static GQuark private_quark;
typedef struct { typedef struct {
/* Subsystem specific states */ /* Subsystem specific states */
GArray *subsystem_states; GArray *subsystem_states;
/* Signal quality recent flag handling */
guint signal_quality_recent_timeout_source;
} Private; } Private;
static void static void
@@ -66,6 +67,8 @@ private_free (Private *priv)
{ {
if (priv->subsystem_states) if (priv->subsystem_states)
g_array_unref (priv->subsystem_states); g_array_unref (priv->subsystem_states);
if (priv->signal_quality_recent_timeout_source)
g_source_remove (priv->signal_quality_recent_timeout_source);
g_slice_free (Private, priv); g_slice_free (Private, priv);
} }
@@ -1422,23 +1425,23 @@ mm_iface_modem_update_access_technologies (MMIfaceModem *self,
/*****************************************************************************/ /*****************************************************************************/
typedef struct {
guint recent_timeout_source;
} SignalQualityUpdateContext;
static void static void
signal_quality_update_context_free (SignalQualityUpdateContext *ctx) signal_quality_recent_timeout_disable (MMIfaceModem *self)
{ {
if (ctx->recent_timeout_source) Private *priv;
g_source_remove (ctx->recent_timeout_source);
g_free (ctx); priv = get_private (self);
if (priv->signal_quality_recent_timeout_source) {
g_source_remove (priv->signal_quality_recent_timeout_source);
priv->signal_quality_recent_timeout_source = 0;
}
} }
static gboolean static gboolean
expire_signal_quality (MMIfaceModem *self) expire_signal_quality (MMIfaceModem *self)
{ {
MmGdbusModem *skeleton = NULL; g_autoptr(MmGdbusModemSkeleton) skeleton = NULL;
SignalQualityUpdateContext *ctx; Private *priv;
g_object_get (self, g_object_get (self,
MM_IFACE_MODEM_DBUS_SKELETON, &skeleton, MM_IFACE_MODEM_DBUS_SKELETON, &skeleton,
@@ -1446,10 +1449,10 @@ expire_signal_quality (MMIfaceModem *self)
if (skeleton) { if (skeleton) {
GVariant *old; GVariant *old;
guint signal_quality = 0; guint signal_quality = 0;
gboolean recent = FALSE; gboolean recent = FALSE;
old = mm_gdbus_modem_get_signal_quality (skeleton); old = mm_gdbus_modem_get_signal_quality (MM_GDBUS_MODEM (skeleton));
g_variant_get (old, g_variant_get (old,
"(ub)", "(ub)",
&signal_quality, &signal_quality,
@@ -1459,28 +1462,26 @@ expire_signal_quality (MMIfaceModem *self)
if (recent) { if (recent) {
mm_obj_dbg (self, "signal quality value not updated in %us, marking as not being recent", mm_obj_dbg (self, "signal quality value not updated in %us, marking as not being recent",
SIGNAL_QUALITY_RECENT_TIMEOUT_SEC); SIGNAL_QUALITY_RECENT_TIMEOUT_SEC);
mm_gdbus_modem_set_signal_quality (skeleton, mm_gdbus_modem_set_signal_quality (MM_GDBUS_MODEM (skeleton),
g_variant_new ("(ub)", g_variant_new ("(ub)",
signal_quality, signal_quality,
FALSE)); FALSE));
} }
g_object_unref (skeleton);
} }
/* Remove source id */ /* Remove source id */
ctx = g_object_get_qdata (G_OBJECT (self), signal_quality_update_context_quark); priv = get_private (self);
ctx->recent_timeout_source = 0; priv->signal_quality_recent_timeout_source = 0;
return G_SOURCE_REMOVE; return G_SOURCE_REMOVE;
} }
static void static void
update_signal_quality (MMIfaceModem *self, update_signal_quality (MMIfaceModem *self,
guint signal_quality, guint signal_quality,
gboolean expire) gboolean expire)
{ {
SignalQualityUpdateContext *ctx; g_autoptr(MmGdbusModemSkeleton) skeleton = NULL;
MmGdbusModem *skeleton = NULL; Private *priv;
g_object_get (self, g_object_get (self,
MM_IFACE_MODEM_DBUS_SKELETON, &skeleton, MM_IFACE_MODEM_DBUS_SKELETON, &skeleton,
@@ -1490,27 +1491,14 @@ update_signal_quality (MMIfaceModem *self,
if (!skeleton) if (!skeleton)
return; return;
if (G_UNLIKELY (!signal_quality_update_context_quark)) priv = get_private (self);
signal_quality_update_context_quark = (g_quark_from_static_string (
SIGNAL_QUALITY_UPDATE_CONTEXT_TAG));
ctx = g_object_get_qdata (G_OBJECT (self), signal_quality_update_context_quark);
if (!ctx) {
/* Create context and keep it as object data */
ctx = g_new0 (SignalQualityUpdateContext, 1);
g_object_set_qdata_full (
G_OBJECT (self),
signal_quality_update_context_quark,
ctx,
(GDestroyNotify)signal_quality_update_context_free);
}
/* Note: we always set the new value, even if the signal quality level /* Note: we always set the new value, even if the signal quality level
* is the same, in order to provide an up to date 'recent' flag. * is the same, in order to provide an up to date 'recent' flag.
* The only exception being if 'expire' is FALSE; in that case we assume * The only exception being if 'expire' is FALSE; in that case we assume
* the value won't expire and therefore can be considered obsolete * the value won't expire and therefore can be considered obsolete
* already. */ * already. */
mm_gdbus_modem_set_signal_quality (skeleton, mm_gdbus_modem_set_signal_quality (MM_GDBUS_MODEM (skeleton),
g_variant_new ("(ub)", g_variant_new ("(ub)",
signal_quality, signal_quality,
expire)); expire));
@@ -1518,24 +1506,22 @@ update_signal_quality (MMIfaceModem *self,
mm_obj_dbg (self, "signal quality updated (%u)", signal_quality); mm_obj_dbg (self, "signal quality updated (%u)", signal_quality);
/* Remove any previous expiration refresh timeout */ /* Remove any previous expiration refresh timeout */
if (ctx->recent_timeout_source) { if (priv->signal_quality_recent_timeout_source) {
g_source_remove (ctx->recent_timeout_source); g_source_remove (priv->signal_quality_recent_timeout_source);
ctx->recent_timeout_source = 0; priv->signal_quality_recent_timeout_source = 0;
} }
/* If we got a new expirable value, setup new timeout */ /* If we got a new expirable value, setup new timeout */
if (expire) if (expire)
ctx->recent_timeout_source = (g_timeout_add_seconds ( priv->signal_quality_recent_timeout_source = (g_timeout_add_seconds (
SIGNAL_QUALITY_RECENT_TIMEOUT_SEC, SIGNAL_QUALITY_RECENT_TIMEOUT_SEC,
(GSourceFunc)expire_signal_quality, (GSourceFunc)expire_signal_quality,
self)); self));
g_object_unref (skeleton);
} }
void void
mm_iface_modem_update_signal_quality (MMIfaceModem *self, mm_iface_modem_update_signal_quality (MMIfaceModem *self,
guint signal_quality) guint signal_quality)
{ {
update_signal_quality (self, signal_quality, TRUE); update_signal_quality (self, signal_quality, TRUE);
} }
@@ -6131,13 +6117,8 @@ mm_iface_modem_shutdown (MMIfaceModem *self)
* we're shutting down the interface anyway. */ * we're shutting down the interface anyway. */
periodic_signal_check_disable (self, FALSE); periodic_signal_check_disable (self, FALSE);
/* Remove SignalQualityUpdateContext object to make sure any pending /* Make sure recent flag handling is disabled. */
* invocation of expire_signal_quality is canceled before the DBus skeleton signal_quality_recent_timeout_disable (self);
* is removed. */
if (G_LIKELY (signal_quality_update_context_quark))
g_object_set_qdata (G_OBJECT (self),
signal_quality_update_context_quark,
NULL);
/* Remove running restart initialization idle, if any */ /* Remove running restart initialization idle, if any */
if (G_LIKELY (restart_initialize_idle_quark)) if (G_LIKELY (restart_initialize_idle_quark))