changeset 45:4a859595eabd

Add debug logging when periodic checks are inhibited
author Guido Berhoerster <guido+pui@berhoerster.name>
date Thu, 05 Nov 2020 11:18:16 +0100
parents 3da32a3ffe3c
children 8ed91c5e0116
files pui-backend.c
diffstat 1 files changed, 21 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/pui-backend.c	Thu Oct 08 15:47:15 2020 +0200
+++ b/pui-backend.c	Thu Nov 05 11:18:16 2020 +0100
@@ -251,14 +251,16 @@
 static void
 check_inhibit(PuiBackend *self)
 {
+	gboolean	is_offline;
+	gboolean	is_disallowed_mobile;
 	gboolean	inhibited;
 	guint		elapsed_time;
 	guint		remaining_time;
 
-	inhibited = ((self->network_state == PK_NETWORK_ENUM_OFFLINE) ||
-	    (!self->use_mobile_connection &&
-	    (self->network_state == PK_NETWORK_ENUM_MOBILE)) ||
-	    self->is_battery_low);
+	is_offline = self->network_state == PK_NETWORK_ENUM_OFFLINE;
+	is_disallowed_mobile = !self->use_mobile_connection &&
+	    (self->network_state == PK_NETWORK_ENUM_MOBILE);
+	inhibited = is_offline || is_disallowed_mobile || self->is_battery_low;
 	if (self->inhibited == inhibited) {
 		return;
 	}
@@ -276,6 +278,17 @@
 			g_cancellable_cancel(self->cancellable);
 			g_clear_object(&self->cancellable);
 		}
+
+		if (is_offline) {
+			g_debug("perioidic checks inhibited: network offline");
+		}
+		if (is_disallowed_mobile) {
+			g_debug("perioidic checks inhibited: use of mobile "
+			    "connection not allowed");
+		}
+		if (self->is_battery_low) {
+			g_debug("perioidic checks inhibited: low battery");
+		}
 	} else {
 		/* schedule periodic checks when no longer inhibited */
 		elapsed_time = (g_get_monotonic_time() - self->last_check) /
@@ -290,6 +303,10 @@
 		    PUI_STARTUP_DELAY;
 		self->check_id = g_timeout_add_seconds(remaining_time,
 		    periodic_check, self);
+
+		g_debug("perioidic checks no longer inhibited, time since "
+		    "last check: %ds, next check in: %ds", elapsed_time,
+		    remaining_time);
 	}
 }