Hi Stefan,
I like the idea of adding more registry keys for hardware components. I want some registry keys for usb devices so I had a look at your patch. I don't like the mess with the added goto serial. If in future there will be support for usb and the whole source will be quite hard to follow. The usb registry keys are needed e.g. for this [1]. So i like to propose my idea how it could look like.
In function new_device( LibHalContext *ctx, const char *udi ) we could readout the info.subsystem setting of the newly added device and add a if for info.subsystem strings like block - block devices tty - serial usb_devices/usb - usb
could look like
/* HAL callback for new device */ static void new_device( LibHalContext *ctx, const char *udi ) { DBusError error; char *subsystem = NULL;
p_dbus_error_init( &error );
if (!(subsystem = p_libhal_device_get_property_string( ctx, udi, "info.subsystem", &error ))) goto done;
if (strcmp(subsystem == "block") == 0) block_device( ctx, udi, &error ); else if (strcmp(subsystem == "usb_device") == 0) usb_device( ctx, udi, &error ); else if (strcmp(subsystem == "tty") == 0) serial_device( ctx, udi, &error );
p_dbus_error_free( &error ); }
Now we have a ability to handle each device type with an own function, like
static void block_device( LibHalContext *ctx, const char *udi, DBusError *error ) { char *device = NULL; char *mount_point = NULL; char *parent = NULL; char *uuid_str = NULL; char *type = NULL; GUID guid, *guid_ptr = NULL; enum device_type drive_type;
if (!(device = p_libhal_device_get_property_string( ctx, udi, "block.device", error ))) goto done;
if (!(mount_point = p_libhal_device_get_property_string( ctx, udi, "volume.mount_point", error ))) goto done;
if (!(parent = p_libhal_device_get_property_string( ctx, udi, "info.parent", error ))) goto done;
if (!(uuid_str = p_libhal_device_get_property_string( ctx, udi, "volume.uuid", error ))) p_dbus_error_free( &error ); /* ignore error */ else guid_ptr = parse_uuid( &guid, uuid_str );
if (!(type = p_libhal_device_get_property_string( ctx, parent, "storage.drive_type", error ))) p_dbus_error_free( &error ); /* ignore error */
if (type && !strcmp( type, "cdrom" )) drive_type = DEVICE_CDROM; else if (type && !strcmp( type, "floppy" )) drive_type = DEVICE_FLOPPY; else drive_type = DEVICE_UNKNOWN;
if (p_libhal_device_get_property_bool( ctx, parent, "storage.removable", error )) { add_dos_device( -1, udi, device, mount_point, drive_type, guid_ptr ); /* add property watch for mount point */ p_libhal_device_add_property_watch( ctx, udi, error ); } else if (guid_ptr) add_volume( udi, device, mount_point, DEVICE_HARDDISK_VOL, guid_ptr );
done: if (type) p_libhal_free_string( type ); if (parent) p_libhal_free_string( parent ); if (device) p_libhal_free_string( device ); if (uuid_str) p_libhal_free_string( uuid_str ); if (mount_point) p_libhal_free_string( mount_point ); }
Keep in mind that i am not sure if this source samples compile - was a quick copy & paste action.
What do you think about it?
[1] http://wiki.winehq.org/USB