iface-modem-3gpp: setup context struct for periodic registration checks
This commit is contained in:
+52
-27
@@ -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);
|
||||
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) {
|
||||
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));
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
Reference in New Issue
Block a user