diff options
author | Christian Kellner <christian@kellner.me> | 2017-02-22 17:45:28 +0100 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2017-09-08 18:05:18 +0200 |
commit | 7171ce38d6b8e0540f7cecc828c1bbabf4bd8b91 (patch) | |
tree | 6e8b4cf5dea5a2e7c5007d546f868ea71d4c5287 | |
parent | 924b42e4f86a9f932249fba91be464afa82acf3c (diff) |
daemon: move two functions up
No semantic change.
https://bugs.freedesktop.org/show_bug.cgi?id=99862
-rw-r--r-- | src/up-daemon.c | 59 |
1 files changed, 27 insertions, 32 deletions
diff --git a/src/up-daemon.c b/src/up-daemon.c index d9bacdf..b6ad3f5 100644 --- a/src/up-daemon.c +++ b/src/up-daemon.c @@ -76,8 +76,6 @@ static gboolean up_daemon_get_on_battery_local (UpDaemon *daemon); static gboolean up_daemon_get_warning_level_local(UpDaemon *daemon); static gboolean up_daemon_get_on_ac_local (UpDaemon *daemon); -static guint calculate_timeout (UpDevice *device); - G_DEFINE_TYPE (UpDaemon, up_daemon, UP_TYPE_EXPORTED_DAEMON_SKELETON) #define UP_DAEMON_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), UP_TYPE_DAEMON, UpDaemonPrivate)) @@ -728,6 +726,33 @@ typedef struct { GSourceFunc callback; } TimeoutData; +static guint +calculate_timeout (UpDevice *device) +{ + UpDeviceLevel warning_level; + + g_object_get (G_OBJECT (device), "warning-level", &warning_level, NULL); + if (warning_level >= UP_DEVICE_LEVEL_DISCHARGING) + return 30; + return 120; +} + +static void +enable_poll_for_device (UpDevice *device, TimeoutData *data) +{ + guint timeout; + char *name; + + timeout = calculate_timeout (device); + data->timeout = timeout; + + data->id = g_timeout_add_seconds (timeout, fire_timeout_callback, device); + name = g_strdup_printf ("[upower] UpDevice::poll for %s (%u secs)", + up_device_get_object_path (device), timeout); + g_source_set_name_by_id (data->id, name); + g_free (name); +} + static void change_idle_timeout (UpDevice *device, GParamSpec *pspec, @@ -797,36 +822,6 @@ fire_timeout_callback (gpointer user_data) return G_SOURCE_CONTINUE; } -static guint -calculate_timeout (UpDevice *device) -{ - UpDeviceLevel warning_level; - - g_object_get (G_OBJECT (device), "warning-level", &warning_level, NULL); - if (warning_level >= UP_DEVICE_LEVEL_DISCHARGING) - return UP_DAEMON_SHORT_TIMEOUT; - return UP_DAEMON_LONG_TIMEOUT; -} - -static void -enable_poll_for_device (UpDevice *device, TimeoutData *data) -{ - const char *path; - guint timeout; - char *name; - - path = up_exported_device_get_native_path (UP_EXPORTED_DEVICE (device)); - - timeout = calculate_timeout (device); - data->timeout = timeout; - - data->id = g_timeout_add_seconds (timeout, fire_timeout_callback, device); - name = g_strdup_printf ("[upower] UpDevice::poll for %s (%u secs)", - path, timeout); - g_source_set_name_by_id (data->id, name); - g_free (name); -} - static void enable_warning_level_notifications (UpDaemon *daemon, UpDevice *device) { |