spa: bluez: add send_with_reply() dbus helper

This function sends a DBusMessage on a DBusConnection
and sets the reply callback of the resulting DBusPendingCall,
as well as properly cancelling the pending call if anything fails.
This commit is contained in:
Barnabás Pőcze 2023-07-11 19:57:23 +02:00
parent 6e581deb91
commit b52d590936
7 changed files with 64 additions and 96 deletions

View file

@ -44,4 +44,25 @@ static inline bool reply_with_error(DBusConnection *conn,
return reply && dbus_connection_send(conn, reply, NULL);
}
static inline DBusPendingCall *send_with_reply(DBusConnection *conn,
DBusMessage *m,
DBusPendingCallNotifyFunction callback, void *user_data)
{
DBusPendingCall *pending_call;
if (!dbus_connection_send_with_reply(conn, m, &pending_call, DBUS_TIMEOUT_USE_DEFAULT))
return NULL;
if (!pending_call)
return NULL;
if (!dbus_pending_call_set_notify(pending_call, callback, user_data, NULL)) {
dbus_pending_call_cancel(pending_call);
dbus_pending_call_unref(pending_call);
return NULL;
}
return pending_call;
}
#endif /* SPA_BLUEZ5_DBUS_HELPERS_H */