2023-01-24 10:39:33 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#ifdef FF_HAVE_DBUS
|
|
|
|
|
#include <dbus/dbus.h>
|
|
|
|
|
|
2026-01-06 09:48:38 +08:00
|
|
|
#include "common/FFstrbuf.h"
|
|
|
|
|
#include "common/library.h"
|
2023-01-24 10:39:33 +01:00
|
|
|
|
|
|
|
|
typedef struct FFDBusLibrary
|
|
|
|
|
{
|
|
|
|
|
FF_LIBRARY_SYMBOL(dbus_bus_get)
|
|
|
|
|
FF_LIBRARY_SYMBOL(dbus_message_new_method_call)
|
2024-08-03 22:03:34 +08:00
|
|
|
FF_LIBRARY_SYMBOL(dbus_message_append_args)
|
2023-01-24 10:39:33 +01:00
|
|
|
FF_LIBRARY_SYMBOL(dbus_message_iter_init)
|
|
|
|
|
FF_LIBRARY_SYMBOL(dbus_message_iter_get_arg_type)
|
|
|
|
|
FF_LIBRARY_SYMBOL(dbus_message_iter_get_basic)
|
|
|
|
|
FF_LIBRARY_SYMBOL(dbus_message_iter_recurse)
|
|
|
|
|
FF_LIBRARY_SYMBOL(dbus_message_iter_has_next)
|
|
|
|
|
FF_LIBRARY_SYMBOL(dbus_message_iter_next)
|
|
|
|
|
FF_LIBRARY_SYMBOL(dbus_message_unref)
|
|
|
|
|
FF_LIBRARY_SYMBOL(dbus_connection_send_with_reply_and_block)
|
2026-02-26 09:47:18 +08:00
|
|
|
FF_LIBRARY_SYMBOL(dbus_connection_unref)
|
2023-01-24 10:39:33 +01:00
|
|
|
} FFDBusLibrary;
|
|
|
|
|
|
|
|
|
|
typedef struct FFDBusData
|
|
|
|
|
{
|
|
|
|
|
const FFDBusLibrary* lib;
|
|
|
|
|
DBusConnection* connection;
|
|
|
|
|
} FFDBusData;
|
|
|
|
|
|
2023-06-24 10:59:53 +08:00
|
|
|
const char* ffDBusLoadData(DBusBusType busType, FFDBusData* data); //Returns an error message or NULL on success
|
2024-07-28 10:54:26 +08:00
|
|
|
bool ffDBusGetString(FFDBusData* dbus, DBusMessageIter* iter, FFstrbuf* result);
|
2023-01-24 10:39:33 +01:00
|
|
|
bool ffDBusGetBool(FFDBusData* dbus, DBusMessageIter* iter, bool* result);
|
2024-08-03 22:03:34 +08:00
|
|
|
bool ffDBusGetUint(FFDBusData* dbus, DBusMessageIter* iter, uint32_t* result);
|
2025-09-03 16:42:16 +08:00
|
|
|
DBusMessage* ffDBusGetMethodReply(FFDBusData* dbus, const char* busName, const char* objectPath, const char* interface, const char* method, const char* arg1, const char* arg2);
|
2023-01-24 10:39:33 +01:00
|
|
|
DBusMessage* ffDBusGetProperty(FFDBusData* dbus, const char* busName, const char* objectPath, const char* interface, const char* property);
|
2024-04-17 19:00:45 +08:00
|
|
|
bool ffDBusGetPropertyString(FFDBusData* dbus, const char* busName, const char* objectPath, const char* interface, const char* property, FFstrbuf* result);
|
2025-09-04 09:35:52 +08:00
|
|
|
bool ffDBusGetInt(FFDBusData* dbus, DBusMessageIter* iter, int32_t* result);
|
2024-08-03 22:03:34 +08:00
|
|
|
bool ffDBusGetPropertyUint(FFDBusData* dbus, const char* busName, const char* objectPath, const char* interface, const char* property, uint32_t* result);
|
2026-02-26 09:47:18 +08:00
|
|
|
void ffDBusDestroyData(FFDBusData* data);
|
2023-01-24 10:39:33 +01:00
|
|
|
|
2024-11-19 15:07:20 +08:00
|
|
|
static inline DBusMessage* ffDBusGetAllProperties(FFDBusData* dbus, const char* busName, const char* objectPath, const char* interface)
|
|
|
|
|
{
|
2025-09-03 16:42:16 +08:00
|
|
|
return ffDBusGetMethodReply(dbus, busName, objectPath, "org.freedesktop.DBus.Properties", "GetAll", interface, NULL);
|
2024-11-19 15:07:20 +08:00
|
|
|
}
|
|
|
|
|
|
2026-02-26 09:47:18 +08:00
|
|
|
#define FF_DBUS_AUTO_DESTROY_DATA __attribute__((__cleanup__(ffDBusDestroyData)))
|
|
|
|
|
|
2023-01-24 10:39:33 +01:00
|
|
|
#endif // FF_HAVE_DBUS
|