diff options
author | Richard Hughes <richard@hughsie.com> | 2011-03-03 14:02:27 +0000 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2011-03-03 14:02:27 +0000 |
commit | 38199e44ff1e87b586d51d30b69d1f70e40d27f1 (patch) | |
tree | dbd1202d6d4609350d8a7c1d09b26256a164ce7c | |
parent | 11301ae3d65bf28f97fb8c290b0f9e446658e824 (diff) |
Add an option for polling dock devices in UPower.conf, defaulting to false
-rw-r--r-- | etc/UPower.conf | 9 | ||||
-rw-r--r-- | src/linux/Makefile.am | 1 | ||||
-rw-r--r-- | src/linux/up-backend.c | 34 | ||||
-rw-r--r-- | src/linux/up-dock.c | 19 | ||||
-rw-r--r-- | src/linux/up-dock.h | 2 |
5 files changed, 62 insertions, 3 deletions
diff --git a/etc/UPower.conf b/etc/UPower.conf index 1b7f9c3..c82827a 100644 --- a/etc/UPower.conf +++ b/etc/UPower.conf @@ -20,3 +20,12 @@ SleepTimeout=1000 # default=true AllowHibernateEncryptedSwap=true + +# Poll the kernel for dock state changes. +# +# Some drivers are still broken, and do not send out uvents when the +# connected state changes. +# +# default=false +PollDockDevices=false + diff --git a/src/linux/Makefile.am b/src/linux/Makefile.am index d19b20d..c4646f7 100644 --- a/src/linux/Makefile.am +++ b/src/linux/Makefile.am @@ -5,6 +5,7 @@ INCLUDES = \ -DUP_COMPILATION \ -DG_UDEV_API_IS_SUBJECT_TO_CHANGE \ -DG_LOG_DOMAIN=\"UPower-Linux\" \ + -DPACKAGE_SYSCONF_DIR=\""$(sysconfdir)"\" \ -I$(top_srcdir)/libupower-glib \ $(USB_CFLAGS) \ $(GIO_CFLAGS) \ diff --git a/src/linux/up-backend.c b/src/linux/up-backend.c index c671d2d..069ca9b 100644 --- a/src/linux/up-backend.c +++ b/src/linux/up-backend.c @@ -284,6 +284,38 @@ up_backend_uevent_signal_handler_cb (GUdevClient *client, const gchar *action, } /** + * up_backend_should_poll_docks: + **/ +static gboolean +up_backend_should_poll_docks (void) +{ + gboolean ret; + GKeyFile *keyfile; + GError *error = NULL; + + /* get the settings from the config file */ + keyfile = g_key_file_new (); + ret = g_key_file_load_from_file (keyfile, + PACKAGE_SYSCONF_DIR "/UPower/UPower.conf", + G_KEY_FILE_NONE, + &error); + if (!ret) { + g_error ("Failed to get poll setting, assuming FALSE: %s", + error->message); + g_error_free (error); + goto out; + } + ret = g_key_file_get_boolean (keyfile, + "UPower", + "PollDockDevices", + NULL); + g_debug ("Polling docks: %s", ret ? "YES" : "NO"); +out: + g_key_file_free (keyfile); + return ret; +} + +/** * up_backend_coldplug: * @backend: The %UpBackend class instance * @daemon: The %UpDaemon controlling instance @@ -323,6 +355,8 @@ up_backend_coldplug (UpBackend *backend, UpDaemon *daemon) /* add dock update object */ backend->priv->dock = up_dock_new (); + ret = up_backend_should_poll_docks (); + up_dock_set_should_poll (backend->priv->dock, ret); ret = up_dock_coldplug (backend->priv->dock, daemon); if (!ret) g_warning ("failed to coldplug dock devices"); diff --git a/src/linux/up-dock.c b/src/linux/up-dock.c index 59475f7..78fb7d3 100644 --- a/src/linux/up-dock.c +++ b/src/linux/up-dock.c @@ -106,14 +106,27 @@ up_dock_poll_cb (UpDock *dock) /** * up_dock_coldplug: **/ +void +up_dock_set_should_poll (UpDock *dock, gboolean should_poll) +{ + if (should_poll && dock->priv->poll_id == 0) { + dock->priv->poll_id = g_timeout_add_seconds (UP_DOCK_POLL_TIMEOUT, + (GSourceFunc) up_dock_poll_cb, + dock); + } else if (dock->priv->poll_id > 0) { + g_source_remove (dock->priv->poll_id); + dock->priv->poll_id = 0; + } +} + +/** + * up_dock_coldplug: + **/ gboolean up_dock_coldplug (UpDock *dock, UpDaemon *daemon) { /* save daemon */ dock->priv->daemon = g_object_ref (daemon); - dock->priv->poll_id = g_timeout_add_seconds (UP_DOCK_POLL_TIMEOUT, - (GSourceFunc) up_dock_poll_cb, - dock); return up_dock_refresh (dock); } diff --git a/src/linux/up-dock.h b/src/linux/up-dock.h index 1f7c80a..0c79251 100644 --- a/src/linux/up-dock.h +++ b/src/linux/up-dock.h @@ -51,6 +51,8 @@ GType up_dock_get_type (void); UpDock *up_dock_new (void); gboolean up_dock_coldplug (UpDock *dock, UpDaemon *daemon); +void up_dock_set_should_poll (UpDock *dock, + gboolean should_poll); G_END_DECLS |