spa: bluez: use spa_autoptr for DBusMessage

This commit is contained in:
Barnabás Pőcze 2023-07-11 19:24:46 +02:00
parent c6c3259a08
commit 6e581deb91
8 changed files with 205 additions and 360 deletions

View file

@ -5,6 +5,8 @@
#ifndef SPA_BLUEZ5_DBUS_HELPERS_H
#define SPA_BLUEZ5_DBUS_HELPERS_H
#include <stdbool.h>
#include <dbus/dbus.h>
#include <spa/utils/cleanup.h>
@ -29,4 +31,17 @@ static inline DBusMessage *steal_reply_and_unref(DBusPendingCall **pp)
return reply;
}
SPA_DEFINE_AUTOPTR_CLEANUP(DBusMessage, DBusMessage, {
spa_clear_ptr(*thing, dbus_message_unref);
})
static inline bool reply_with_error(DBusConnection *conn,
DBusMessage *reply_to,
const char *error_name, const char *error_message)
{
spa_autoptr(DBusMessage) reply = dbus_message_new_error(reply_to, error_name, error_message);
return reply && dbus_connection_send(conn, reply, NULL);
}
#endif /* SPA_BLUEZ5_DBUS_HELPERS_H */