mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
spa: bluez: use spa_autoptr for DBusMessage
This commit is contained in:
parent
c6c3259a08
commit
6e581deb91
8 changed files with 205 additions and 360 deletions
|
|
@ -43,40 +43,36 @@ static DBusHandlerResult upower_parse_percentage(struct impl *this, DBusMessageI
|
|||
static void upower_get_percentage_properties_reply(DBusPendingCall *pending, void *user_data)
|
||||
{
|
||||
struct impl *backend = user_data;
|
||||
DBusMessage *r;
|
||||
DBusMessageIter i, variant_i;
|
||||
|
||||
spa_assert(backend->pending_get_call == pending);
|
||||
r = steal_reply_and_unref(&backend->pending_get_call);
|
||||
spa_autoptr(DBusMessage) r = steal_reply_and_unref(&backend->pending_get_call);
|
||||
if (r == NULL)
|
||||
return;
|
||||
|
||||
if (dbus_message_get_type(r) == DBUS_MESSAGE_TYPE_ERROR) {
|
||||
spa_log_error(backend->log, "Failed to get percentage from UPower: %s",
|
||||
dbus_message_get_error_name(r));
|
||||
goto finish;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!dbus_message_iter_init(r, &i) || !spa_streq(dbus_message_get_signature(r), "v")) {
|
||||
spa_log_error(backend->log, "Invalid arguments in Get() reply");
|
||||
goto finish;
|
||||
return;
|
||||
}
|
||||
|
||||
dbus_message_iter_recurse(&i, &variant_i);
|
||||
upower_parse_percentage(backend, &variant_i);
|
||||
|
||||
finish:
|
||||
dbus_message_unref(r);
|
||||
}
|
||||
|
||||
static int update_battery_percentage(struct impl *this)
|
||||
{
|
||||
cancel_and_unref(&this->pending_get_call);
|
||||
|
||||
DBusMessage *m = dbus_message_new_method_call(UPOWER_SERVICE,
|
||||
UPOWER_DISPLAY_DEVICE_OBJECT,
|
||||
DBUS_INTERFACE_PROPERTIES,
|
||||
"Get");
|
||||
spa_autoptr(DBusMessage) m = dbus_message_new_method_call(UPOWER_SERVICE,
|
||||
UPOWER_DISPLAY_DEVICE_OBJECT,
|
||||
DBUS_INTERFACE_PROPERTIES,
|
||||
"Get");
|
||||
if (!m)
|
||||
return -ENOMEM;
|
||||
|
||||
|
|
@ -89,8 +85,6 @@ static int update_battery_percentage(struct impl *this)
|
|||
dbus_connection_send_with_reply(this->conn, m, &this->pending_get_call, -1);
|
||||
dbus_pending_call_set_notify(this->pending_get_call, upower_get_percentage_properties_reply, this, NULL);
|
||||
|
||||
dbus_message_unref(m);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue