Commit graph

156 commits

Author SHA1 Message Date
Bastien Nocera
a3c58db735 lib: Simplify resource destruction
Use g_clear_pointer() and g_clear_object() when possible.
2018-04-18 12:45:51 +02:00
Bastien Nocera
41bce28447 lib: Fix warnings when D-Bus related properties change
When UPower would appear, or disappear, we'd get warnings like:
g_object_notify: object class 'UpDevice' has no property named 'g-name-owner'
or:
g_object_notify: object class 'UpClient' has no property named 'g-name-owner'

This was caused by the property proxying added in 7531dbd and 28438a7
being too lax about which properties it tried to proxy, which included
ones that didn't apply to the object types in question.

See https://bugs.freedesktop.org/show_bug.cgi?id=43001

https://bugs.freedesktop.org/show_bug.cgi?id=102350
2018-03-02 17:47:14 +01:00
Bastien Nocera
b9aaa05bc6 docs: Better documentation for the BatteryLevel prop
https://bugs.freedesktop.org/show_bug.cgi?id=103361
2017-10-31 17:45:18 +01:00
Bastien Nocera
4753a8bc5a lib: Fix API docs for *-level properties
One was referencing a non-existent enum member, the other was
missing a link altogether.
2017-09-08 06:55:54 +02:00
Bastien Nocera
5ccd4fe959 lib: Add UP_DEVICE_KIND_GAMING_INPUT for gaming devices
Joypads, joysticks, dance mats, paddles, Wiimotes, steering wheels,
tractor cabin simulators, pedals, yokes, breathing controllers, and,
hmm, etc.

https://bugs.freedesktop.org/show_bug.cgi?id=102493
2017-08-31 16:21:18 +02:00
Bastien Nocera
eb6b1b62a2 lib: Simplify string checks
We don't need to protect against NULL values, we already do at the start
of the function.

Created with:
:%s,g_strcmp0\(.*\) == 0,g_str_equal \1,

Mentioned in:
https://bugs.freedesktop.org/show_bug.cgi?id=100359#c14
2017-04-10 10:37:32 +02:00
Bastien Nocera
499d05b837 all: Add BatteryLevel property
Export approximate battery levels that devices can use, exported by
the kernel as POWER_SUPPLY_CAPACITY_LEVEL_* values.

This avoids bizarrely accurate values showing up in UIs when we only
have ok/warning levels of accuracy in some cases.

https://bugs.freedesktop.org/show_bug.cgi?id=100359
2017-04-06 16:33:38 +02:00
Bastien Nocera
4f9230900b lib: Add more members to UpDeviceLevel struct
Those levels will not be used to cover warning levels, but approximate
battery levels that devices can use, exported by the kernel as
POWER_SUPPLY_CAPACITY_LEVEL_* values.

See linux/power_supply.h

https://bugs.freedesktop.org/show_bug.cgi?id=100359
2017-04-06 14:18:10 +02:00
Bastien Nocera
4b03777c54 build: Fix -Wformat-y2k compilation errors
The strings are user visible strings, so this isn't a y2k problem.
2016-06-08 14:14:24 +02:00
Martin Pitt
29c5c85f6b lib: Remove hidden singleton instance
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
2016-05-18 14:59:12 +02:00
Martin Pitt
932a6a39e3 lib: Add proper error and cancellable handling to UpClient constructor
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
2016-05-18 14:58:28 +02:00
Kalev Lember
0825c162d3 Support g_autoptr() for all libupower-glib object types
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>
2015-09-15 12:33:44 +01:00
Cosimo Cecchi
c108a8e8a4 Share generated code between daemon and library
Since we use the same GDBus code in libupower-glib and the daemon,
auto-generate a private library that can be used by both.
2015-07-29 13:38:13 +01:00
Bastien Nocera
fe37183fba lib: Fix memory leak in up_client_get_devices()
When up_client_get_devices() fails to contact the D-Bus daemon, don't
leak the newly created array.
2015-06-26 11:15:32 +02:00
Vlad Orlov
2510148b16 lib: Fix crash on uninitialized variant
Initialize the GVariant* pointers, so that they aren't uninitialized when
jumping to "out:" and unref'ing them.

https://bugs.freedesktop.org/show_bug.cgi?id=89476
https://bugs.debian.org/774546
https://bugs.launchpad.net/ubuntu-mate/+bug/1428337
2015-03-13 13:17:31 +01:00
Richard Hughes
969c97426a Do not print a critical warning when misusing up_device_set_object_path_sync() 2014-05-20 13:25:17 +01:00
Bastien Nocera
5ed25a7e5f all: Remove IsDocked property
Removes the deprecated (for not very long) property, before we do a 1.0
release.

https://bugs.freedesktop.org/show_bug.cgi?id=78380
2014-05-07 11:01:27 +02:00
Bastien Nocera
212b4397cc lib: Fix API doc for up_client_get_on_battery() 2014-05-07 09:46:49 +02:00
Bastien Nocera
54a030a38d lib: Hard-code the IsDocked value 2014-05-07 09:46:08 +02:00
Bastien Nocera
d650df8af8 lib: Fix typo in g-i annotation
Missing colon.
2014-04-23 15:48:48 +02:00
Martin Pitt
0d64bbddaa lib: Fix segfault on getting property when daemon is not running
This fixes "upower --version" when the daemon is not running, and thus the
client proxy is NULL.
2013-11-08 14:59:50 +01:00
Bastien Nocera
aa62f6a15c lib: Fix possible warning when type changes
UpDevice on the daemon side has a "type" property, but the
libupower-glib object has a "kind" type instead. Translate that.
2013-10-17 23:20:22 +02:00
Bastien Nocera
3063bdaf44 lib: Fix compile-time warning 2013-10-17 14:51:07 +02:00
Bastien Nocera
5f43bb78f7 lib: Remove up_client_enumerate_devices_sync()
And make device-removed send an object path, not a UpDevice.

This means that we don't keep all the remote devices as local
UpDevices object, getting woken up any time any of them have a
property changed, without anybody listening.

This should greatly cut down on the wakeups on the client side,
especially for applications that only use a small portion of the API
like the "on-battery" or "warning-level" properties.
2013-10-17 14:36:35 +02:00
Bastien Nocera
0010e93251 all: Remove *changed signals
Now that we send out PropertiesChanged signals (on the daemon side)
and "notify" signals (on the client side), there's no need for the
all encompassing DeviceChanged and Changed signals.

They would have woken up any client, even if they were not interested
in receiving the signals.
2013-10-17 14:25:25 +02:00
Bastien Nocera
595d72f6b6 lib: Proxy notify changes from UpDevice glue 2013-10-17 12:37:29 +02:00
Bastien Nocera
c33528da7a lib: Simplify proxying glue properties in UpClient 2013-10-17 12:36:44 +02:00
Bastien Nocera
db31456921 all: Add GetCriticalAction daemon method
This allows desktop front-ends to get which action will
actually be taken when we hit critical battery.

This is not a property as availability of actions might
change over the course of the run of the system, and
we didn't want to make unnecessary D-Bus calls on startup.
2013-10-17 09:04:03 +02:00
Bastien Nocera
b2f72dd69a all: Remove WarningLevel from the daemon properties
The WarningLevel property just replicated the warning level
on the display device, or at least should have. So we fix the latter
to remove the former.
2013-10-17 00:57:27 +02:00
Bastien Nocera
a76eaeddb9 lib: Trim properties when printing the display device 2013-10-17 00:45:26 +02:00
Bastien Nocera
45c4b37277 lib: Add up_client_get_display_device()
Add a helper to get to the display device.
2013-10-17 00:37:29 +02:00
Bastien Nocera
34951c91ff lib: Remove unneeded up_client_get_properties_sync()
It doesn't do anything, and we already broke the ABI by removing
some functions, so remove this as well.
2013-10-17 00:37:20 +02:00
Bastien Nocera
85ce906bf2 lib: Fix compilation 2013-10-15 16:04:21 +02:00
Bastien Nocera
677f2f4da7 lib: Use slices to allocate cached properties
Saves on memory fragmentation.
2013-10-15 15:51:55 +02:00
Bastien Nocera
4079ba8272 lib: Print property name when cached property doesn't exist 2013-10-15 15:51:00 +02:00
Bastien Nocera
d7d215a4b6 lib: Cache property values correctly
This is cleaner.
2013-10-15 15:50:31 +02:00
Bastien Nocera
b446cac8f6 daemon: Add new WarningLevel "Discharging"
When UPSes are discharging, we should have a warning already, as
it means that mains power has been lost to the UPS (though not
to the computer).
2013-10-14 14:38:32 +02:00
Bastien Nocera
d2484d4ec1 lib: Add support for the IconName property 2013-10-14 11:06:53 +02:00
Bastien Nocera
28438a7672 lib: Emit notify:: signals
In the UpClient object.

https://bugs.freedesktop.org/show_bug.cgi?id=43001
2013-10-14 11:06:53 +02:00
Bastien Nocera
e0fb5078bd lib: up_device_to_text() won't work for fake devices
For now, up_device_to_text() won't work for devices that aren't
backed by a UPower device.
2013-10-14 10:42:56 +02:00
Bastien Nocera
869050d699 lib: Make it possible to create local UpDevices
gnome-settings-daemon creates a composite UpDevice that's not
backed by any real D-Bus object in UPower, so we shouldn't
try and poke the inexistant proxy in this case.

We'll cache the properties that the caller sets in this case,
but will not support sending back default/unset values.
2013-10-14 10:42:56 +02:00
Bastien Nocera
858ab85f95 lib: Update for property removal and additions
Remove on-low-battery and add warning-level daemon properties.
2013-10-14 10:42:56 +02:00
Bastien Nocera
9c27c42a99 lib: Fix alignment of "online" in device dump 2013-10-14 10:42:56 +02:00
Bastien Nocera
493c2192a2 lib: Add warning-level device property 2013-10-14 10:42:56 +02:00
Bastien Nocera
5423adab89 lib: Add UpDeviceLevel enum 2013-10-14 10:42:56 +02:00
Bastien Nocera
8c83871f10 lib: Remove dbus-glib from the dependencies
libupower-glib now uses GDBus.
2013-10-14 10:42:56 +02:00
Bastien Nocera
5adf4c1e20 lib: Port UpWakeUps to GDBus
Using the new proxy.
2013-10-14 10:42:56 +02:00
Bastien Nocera
b989cad776 lib: Port UpDevice to GDBus
Using the new proxy.
2013-10-14 10:42:55 +02:00
Bastien Nocera
c590354d0a lib: No need to set private members to NULL
GObject already makes sure of that for us.
2013-10-14 10:42:55 +02:00
Bastien Nocera
65c84120f9 lib: Port UpClient to GDBus
Using the new proxy.
2013-10-14 10:42:55 +02:00