aboutsummaryrefslogtreecommitdiff
path: root/src/mm-iface-modem-3gpp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mm-iface-modem-3gpp.c')
-rw-r--r--src/mm-iface-modem-3gpp.c81
1 files changed, 53 insertions, 28 deletions
diff --git a/src/mm-iface-modem-3gpp.c b/src/mm-iface-modem-3gpp.c
index 517bb29e..ac12bbdd 100644
--- a/src/mm-iface-modem-3gpp.c
+++ b/src/mm-iface-modem-3gpp.c
@@ -685,16 +685,28 @@ mm_iface_modem_3gpp_update_registration_state (MMIfaceModem3gpp *self,
/*****************************************************************************/
-#define PERIODIC_REG_CHECK_ENABLED_TAG "3gpp-reg-check-timeout-enabled-tag"
-#define PERIODIC_REG_CHECK_RUNNING_TAG "3gpp-reg-check-timeout-running-tag"
+#define REGISTRATION_CHECK_TIMEOUT_SEC 30
+#define REGISTRATION_CHECK_CONTEXT_TAG "registration-check-context-tag"
+static GQuark registration_check_context_quark;
-static GQuark check_enabled;
-static GQuark check_running;
+typedef struct {
+ guint timeout_source;
+ gboolean running;
+} RegistrationCheckContext;
+
+static void
+registration_check_context_free (RegistrationCheckContext *ctx)
+{
+ if (ctx->timeout_source)
+ g_source_remove (ctx->timeout_source);
+ g_free (ctx);
+}
static void
periodic_registration_checks_ready (MMIfaceModem3gpp *self,
GAsyncResult *res)
{
+ RegistrationCheckContext *ctx;
GError *error = NULL;
mm_iface_modem_3gpp_run_all_registration_checks_finish (self, res, &error);
@@ -704,15 +716,19 @@ periodic_registration_checks_ready (MMIfaceModem3gpp *self,
}
/* Remove the running tag */
- g_object_set_qdata (G_OBJECT (self), check_running, GUINT_TO_POINTER (FALSE));
+ ctx = g_object_get_qdata (G_OBJECT (self), registration_check_context_quark);
+ ctx->running = FALSE;
}
static gboolean
periodic_registration_check (MMIfaceModem3gpp *self)
{
+ RegistrationCheckContext *ctx;
+
/* Only launch a new one if not one running already */
- if (!GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (self), check_running))) {
- g_object_set_qdata (G_OBJECT (self), check_running, GUINT_TO_POINTER (TRUE));
+ ctx = g_object_get_qdata (G_OBJECT (self), registration_check_context_quark);
+ if (!ctx->running) {
+ ctx->running = TRUE;
mm_iface_modem_3gpp_run_all_registration_checks (
self,
(GAsyncReadyCallback)periodic_registration_checks_ready,
@@ -724,34 +740,43 @@ periodic_registration_check (MMIfaceModem3gpp *self)
static void
periodic_registration_check_disable (MMIfaceModem3gpp *self)
{
- guint timeout_source;
+ if (G_UNLIKELY (!registration_check_context_quark))
+ registration_check_context_quark = (g_quark_from_static_string (
+ REGISTRATION_CHECK_CONTEXT_TAG));
- timeout_source = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (self), check_enabled));
- if (timeout_source) {
- g_source_remove (timeout_source);
- g_object_set_qdata (G_OBJECT (self), check_enabled, GUINT_TO_POINTER (FALSE));
- mm_dbg ("Periodic registration checks disabled");
- }
+ /* Overwriting the data will free the previous context */
+ g_object_set_qdata (G_OBJECT (self),
+ registration_check_context_quark,
+ NULL);
+
+ mm_dbg ("Periodic registration checks disabled");
}
static void
periodic_registration_check_enable (MMIfaceModem3gpp *self)
{
- guint timeout_source;
+ RegistrationCheckContext *ctx;
- if (G_UNLIKELY (!check_enabled))
- check_enabled = g_quark_from_static_string (PERIODIC_REG_CHECK_ENABLED_TAG);
- if (G_UNLIKELY (!check_running))
- check_running = g_quark_from_static_string (PERIODIC_REG_CHECK_RUNNING_TAG);
-
- timeout_source = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (self), check_enabled));
- if (!timeout_source) {
- mm_dbg ("Periodic registration checks enabled");
- timeout_source = g_timeout_add_seconds (30,
- (GSourceFunc)periodic_registration_check,
- self);
- g_object_set_qdata (G_OBJECT (self), check_enabled, GUINT_TO_POINTER (timeout_source));
- }
+ if (G_UNLIKELY (!registration_check_context_quark))
+ registration_check_context_quark = (g_quark_from_static_string (
+ REGISTRATION_CHECK_CONTEXT_TAG));
+
+ ctx = g_object_get_qdata (G_OBJECT (self), registration_check_context_quark);
+
+ /* If context is already there, we're already enabled */
+ if (ctx)
+ return;
+
+ /* Create context and keep it as object data */
+ mm_dbg ("Periodic registration checks enabled");
+ ctx = g_new0 (RegistrationCheckContext, 1);
+ ctx->timeout_source = g_timeout_add_seconds (REGISTRATION_CHECK_TIMEOUT_SEC,
+ (GSourceFunc)periodic_registration_check,
+ self);
+ g_object_set_qdata_full (G_OBJECT (self),
+ registration_check_context_quark,
+ ctx,
+ (GDestroyNotify)registration_check_context_free);
}
/*****************************************************************************/