When starting up, we would try to connect to the iDevice repeatedly,
once a second. But the process takes between a quarter and half a
second, and is CPU heavy. Lower this timeout to once every 5 seconds to
reduce the initial CPU consumption.
When GetBrightness is called it's better to fetch the current value in the
sysfs attribute since many devices doesn't support the emission of brightness
changes to userland, and this could make settings daemons to handle
this value incorrectly.
Add static up_kbd_backlight_brightness_read that is now called during
initialization too, it returns -1 on errors, and use it everywhere we need
to read or check the current brightness.
https://bugs.freedesktop.org/show_bug.cgi?id=95457
GObject _new constructors should always return a new pointer and not do
anything else than g_{object,initable}_new(). Drop the internal
up_client_object singleton instance.
This simplifies the code and makes the code robust with multiple threads.
Side issue in https://bugs.freedesktop.org/show_bug.cgi?id=95350
This avoids spewing dozens of assertions like
libupower-glib-CRITICAL **: up_client_get_devices: assertion 'UP_IS_CLIENT (client)' failed
libupower-glib-CRITICAL **: up_device_get_object_path: assertion 'UP_IS_DEVICE (device)' failed
and useless default values and then exiting successfully (which might confuse
users or scripts trying to parse the output).
Use the new up_client_new_full() constructor so that we get a proper GError.
Side issue in https://bugs.freedesktop.org/show_bug.cgi?id=95350
A GObject's _init() should never fail or block, but this is currently the case
as up_client_init() connects to upowerd on D-Bus. Convert this to the GInitable
interface and provide a new constructor up_client_new_full() which accepts a
GCancellable and GError, so that clients can do proper error handling
and reporting.
This changes up_client_new() to return NULL when connecting to upowerd fails.
This provides a more well-defined behaviour in this case as clients can check
for this and our methods stop segfaulting as they have checks like
g_return_val_if_fail (UP_IS_CLIENT (client), ...)
Previously we returned a valid object, but trying to call any method on it
segfaulted due to the NULL D-Bus proxy, so client code had no chance to check
whether the UpClient object was really valid.
https://bugs.freedesktop.org/show_bug.cgi?id=95350
Include $(top_builddir) when building so that we can find the newly
generated D-Bus helper files. Note that, because we ship generated files
in the tarball, we'll also need to include $(top_srcdir).
This allows using e.g. g_autoptr(UpDevice) in other programs, but does
not make upower itself use g_autoptr, or require a new enough glib to
support it.
Signed-off-by: Richard Hughes <richard@hughsie.com>
The removal of dbus-glib and libdbus build dependencies has introduced
a build regression on upower, which fails to link with gobject
Signed-off-by: Richard Hughes <richard@hughsie.com>