device: Make it possible to remove devices from D-Bus

Add up_device_unregister() method to allow backends to hide particular
UpDevices from the D-Bus interface.

Also rename the private up_device_register_device() function, no need to
say "device" twice there, we're registering the only device passed as an
argument.
This commit is contained in:
Bastien Nocera 2022-09-05 16:11:14 +02:00
parent 6d78c4ab11
commit f035ab12a5
2 changed files with 15 additions and 2 deletions

View file

@ -424,7 +424,7 @@ up_device_compute_object_path (UpDevice *device)
}
static void
up_device_register_device (UpDevice *device)
up_device_register (UpDevice *device)
{
char *object_path = up_device_compute_object_path (device);
g_debug ("object path = %s", object_path);
@ -432,6 +432,18 @@ up_device_register_device (UpDevice *device)
g_free (object_path);
}
void
up_device_unregister (UpDevice *device)
{
g_autofree char *object_path = NULL;
object_path = g_strdup (g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (device)));
if (object_path != NULL) {
g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (device));
g_debug ("Unexported UpDevice with path %s", object_path);
}
}
/**
* up_device_refresh:
*
@ -492,7 +504,7 @@ up_device_initable_init (GInitable *initable,
register_device:
/* put on the bus */
up_device_register_device (device);
up_device_register (device);
return TRUE;
}

View file

@ -71,6 +71,7 @@ void up_device_sibling_discovered (UpDevice *device,
GObject *sibling);
gboolean up_device_refresh_internal (UpDevice *device,
UpRefreshReason reason);
void up_device_unregister (UpDevice *device);
G_END_DECLS