diff options
author | Bastien Nocera <hadess@hadess.net> | 2013-10-11 11:57:24 +0200 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2013-10-14 10:42:56 +0200 |
commit | 68aca3a7e7dbbbeab9d6728b1c3d42fa2fdb1538 (patch) | |
tree | 35ba66ec1d74345007f2e8f5915eab58ff543e78 /src | |
parent | 3bf0b7adafa71ef44085189132c209848f21da81 (diff) | |
download | upower-68aca3a7e7dbbbeab9d6728b1c3d42fa2fdb1538.tar.gz |
daemon: Load level policy configuration
Diffstat (limited to 'src')
-rw-r--r-- | src/up-daemon.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/up-daemon.c b/src/up-daemon.c index 243fd8a..c57c797 100644 --- a/src/up-daemon.c +++ b/src/up-daemon.c @@ -81,6 +81,14 @@ struct UpDaemonPrivate gboolean during_coldplug; guint battery_poll_id; guint battery_poll_count; + + gboolean use_percentage_for_policy; + guint low_percentage; + guint critical_percentage; + guint action_percentage; + guint low_time; + guint critical_time; + guint action_time; }; static void up_daemon_finalize (GObject *object); @@ -616,6 +624,48 @@ up_daemon_properties_changed_cb (GObject *object, GParamSpec *pspec, UpDaemon *d } } +#define LOAD_OR_DEFAULT(val, str, def) val = (load_default ? def : up_config_get_uint (daemon->priv->config, str)) + +static void +load_percentage_policy (UpDaemon *daemon, + gboolean load_default) +{ + LOAD_OR_DEFAULT (daemon->priv->low_percentage, "PercentageLow", 10); + LOAD_OR_DEFAULT (daemon->priv->critical_percentage, "PercentageCritical", 3); + LOAD_OR_DEFAULT (daemon->priv->action_percentage, "PercentageAction", 2); +} + +static void +load_time_policy (UpDaemon *daemon, + gboolean load_default) +{ + LOAD_OR_DEFAULT (daemon->priv->low_time, "TimeLow", 1200); + LOAD_OR_DEFAULT (daemon->priv->critical_time, "TimeCritical", 300); + LOAD_OR_DEFAULT (daemon->priv->action_time, "TimeAction", 120); +} + +#define IS_DESCENDING(x, y, z) (x > y && y > z) + +static void +policy_config_validate (UpDaemon *daemon) +{ + if (daemon->priv->low_percentage >= 100 || + daemon->priv->critical_percentage >= 100 || + daemon->priv->action_percentage >= 100) { + load_percentage_policy (daemon, TRUE); + } else if (!IS_DESCENDING (daemon->priv->low_percentage, + daemon->priv->critical_percentage, + daemon->priv->action_percentage)) { + load_percentage_policy (daemon, TRUE); + } + + if (!IS_DESCENDING (daemon->priv->low_time, + daemon->priv->critical_time, + daemon->priv->action_time)) { + load_time_policy (daemon, TRUE); + } +} + /** * up_daemon_init: **/ @@ -627,6 +677,11 @@ up_daemon_init (UpDaemon *daemon) daemon->priv->config = up_config_new (); daemon->priv->power_devices = up_device_list_new (); + daemon->priv->use_percentage_for_policy = up_config_get_boolean (daemon->priv->config, "UsePercentageForPolicy"); + load_percentage_policy (daemon, FALSE); + load_time_policy (daemon, FALSE); + policy_config_validate (daemon); + daemon->priv->backend = up_backend_new (); g_signal_connect (daemon->priv->backend, "device-added", G_CALLBACK (up_daemon_device_added_cb), daemon); |