forked from drath/libratbag
ratbagd: add DBus methods to retrieve object paths
Add two new helpers to query ratbagd for the object-paths of a specific object: GetDeviceByName: Return device given a device name GetProfileByIndex: Return a profile given a profile index Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
This commit is contained in:
@@ -221,6 +221,27 @@ static int ratbagd_device_get_default_profile(sd_bus *bus,
|
||||
return sd_bus_message_append(reply, "o", "/");
|
||||
}
|
||||
|
||||
static int ratbagd_device_get_profile_by_index(sd_bus_message *m,
|
||||
void *userdata,
|
||||
sd_bus_error *error)
|
||||
{
|
||||
struct ratbagd_device *device = userdata;
|
||||
struct ratbagd_profile *profile;
|
||||
unsigned int index;
|
||||
int r;
|
||||
|
||||
r = sd_bus_message_read(m, "u", &index);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (index >= device->n_profiles || !device->profiles[index])
|
||||
return -ENXIO;
|
||||
|
||||
profile = device->profiles[index];
|
||||
return sd_bus_reply_method_return(m, "o",
|
||||
ratbagd_profile_get_path(profile));
|
||||
}
|
||||
|
||||
const sd_bus_vtable ratbagd_device_vtable[] = {
|
||||
SD_BUS_VTABLE_START(0),
|
||||
SD_BUS_PROPERTY("Id", "s", NULL, offsetof(struct ratbagd_device, name), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
@@ -228,6 +249,7 @@ const sd_bus_vtable ratbagd_device_vtable[] = {
|
||||
SD_BUS_PROPERTY("Profiles", "ao", ratbagd_device_get_profiles, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("ActiveProfile", "o", ratbagd_device_get_active_profile, 0, 0),
|
||||
SD_BUS_PROPERTY("DefaultProfile", "o", ratbagd_device_get_default_profile, 0, 0),
|
||||
SD_BUS_METHOD("GetProfileByIndex", "u", "o", ratbagd_device_get_profile_by_index, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
SD_BUS_VTABLE_END,
|
||||
};
|
||||
|
||||
|
||||
@@ -121,11 +121,33 @@ static int ratbagd_get_devices(sd_bus *bus,
|
||||
return sd_bus_message_close_container(reply);
|
||||
}
|
||||
|
||||
static int ratbagd_get_device_by_name(sd_bus_message *m,
|
||||
void *userdata,
|
||||
sd_bus_error *error)
|
||||
{
|
||||
struct ratbagd *ctx = userdata;
|
||||
struct ratbagd_device *device;
|
||||
const char *name;
|
||||
int r;
|
||||
|
||||
r = sd_bus_message_read(m, "s", &name);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
device = ratbagd_device_lookup(ctx, name);
|
||||
if (!device)
|
||||
return -ENXIO;
|
||||
|
||||
return sd_bus_reply_method_return(m, "o",
|
||||
ratbagd_device_get_path(device));
|
||||
}
|
||||
|
||||
static const sd_bus_vtable ratbagd_vtable[] = {
|
||||
SD_BUS_VTABLE_START(0),
|
||||
SD_BUS_PROPERTY("Devices", "ao", ratbagd_get_devices, 0, 0),
|
||||
SD_BUS_SIGNAL("DeviceNew", "o", 0),
|
||||
SD_BUS_SIGNAL("DeviceRemoved", "o", 0),
|
||||
SD_BUS_METHOD("GetDeviceByName", "s", "o", ratbagd_get_device_by_name, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
SD_BUS_VTABLE_END,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user