diff options
author | David Zeuthen <david@fubar.dk> | 2004-04-10 13:57:39 +0000 |
---|---|---|
committer | David Zeuthen <david@fubar.dk> | 2004-04-10 13:57:39 +0000 |
commit | 794c13c2e598629b7c81ac086afefc5c771578b5 (patch) | |
tree | 1ce0fd9a3ee67520d5ccb7d5c3a21941da20a402 | |
parent | 31a6e466229dfe945d899beb6d02fe376291fdbd (diff) |
add got_udi() method
move add/merge of class device to a single function
add got_udi() method
call got_udi() before adding (bus_device_got_udi): new function
new function (block_class_post_process): set block.storage_device to the
physical device, e.g. USB etc., backing the block device; simplify a
bit
-rw-r--r-- | ChangeLog | 17 | ||||
-rw-r--r-- | hald/linux/block_class_device.c | 421 | ||||
-rw-r--r-- | hald/linux/bus_device.c | 10 | ||||
-rw-r--r-- | hald/linux/bus_device.h | 18 | ||||
-rw-r--r-- | hald/linux/class_device.c | 110 | ||||
-rw-r--r-- | hald/linux/class_device.h | 19 | ||||
-rw-r--r-- | hald/linux/ide_bus_device.c | 5 | ||||
-rw-r--r-- | hald/linux/ide_host_bus_device.c | 1 | ||||
-rw-r--r-- | hald/linux/input_class_device.c | 1 | ||||
-rw-r--r-- | hald/linux/pci_bus_device.c | 1 | ||||
-rw-r--r-- | hald/linux/printer_class_device.c | 1 | ||||
-rw-r--r-- | hald/linux/scsi_device_class_device.c | 1 | ||||
-rw-r--r-- | hald/linux/scsi_host_class_device.c | 1 | ||||
-rw-r--r-- | hald/linux/usb_bus_device.c | 1 | ||||
-rw-r--r-- | hald/linux/usbif_bus_device.c | 1 |
15 files changed, 374 insertions, 234 deletions
@@ -1,3 +1,20 @@ +2004-04-10 David Zeuthen <david@fubar.dk> + + * hald/linux/class_device.h: add got_udi() method + + * hald/linux/class_device.c (class_device_final): move add/merge of + class device to a single function + + * hald/linux/bus_device.h: add got_udi() method + + * hald/linux/bus_device.c (bus_device_got_parent): call got_udi() + before adding + (bus_device_got_udi): new function + + * hald/linux/block_class_device.c (block_class_got_udi): new function + (block_class_post_process): set block.storage_device to the physical + device, e.g. USB etc., backing the block device; simplify a bit + 2004-04-08 Joe Shaw <joe@ximian.com> * hald/linux/printer_class_device.c (printer_class_device_accept): diff --git a/hald/linux/block_class_device.c b/hald/linux/block_class_device.c index 860d44b8..3363b205 100644 --- a/hald/linux/block_class_device.c +++ b/hald/linux/block_class_device.c @@ -559,6 +559,26 @@ detect_media (HalDevice * d) return FALSE; } +static void +block_class_got_udi (ClassDeviceHandler *self, + HalDevice *d, + const char *udi) +{ + const char *stordev_udi; + char temp_prefix[] = "/org/freedesktop/Hal/devices/temp"; + + /* fixup from setting block.storage_device below to a temporary + * device */ + stordev_udi = hal_device_property_get_string (d, + "block.storage_device"); + + if (strncmp (stordev_udi, temp_prefix, strlen(temp_prefix)) == 0) { + hal_device_property_set_string (d, + "block.storage_device", + udi); + } +} + static void block_class_post_process (ClassDeviceHandler *self, HalDevice *d, @@ -567,10 +587,12 @@ block_class_post_process (ClassDeviceHandler *self, { int major, minor; HalDevice *parent; - HalDevice *stordev; - char *stordev_udi; + HalDevice *stordev = NULL; + const char *stordev_udi; const char *device_file; - + dbus_bool_t has_removable_media = FALSE; + dbus_bool_t is_hotplugable = FALSE; + parent = hal_device_store_find (hald_get_gdl (), hal_device_property_get_string (d, "info.parent")); assert (parent != NULL); @@ -587,11 +609,53 @@ block_class_post_process (ClassDeviceHandler *self, /* Determine physical device that is backing this block device */ if (hal_device_property_get_bool (d, "block.is_volume")) { - stordev_udi = parent->udi; - stordev = parent; + /* Take the block parent */ + stordev_udi = hal_device_property_get_string ( + parent, "block.storage_device"); + stordev = hal_device_store_find (hald_get_gdl (), stordev_udi); } else { - stordev_udi = d->udi; - stordev = d; + const char *udi_it; + + stordev_udi = NULL; + + /* walk up the device chain, start with our parent */ + udi_it = parent->udi; + + while (udi_it != NULL) { + HalDevice *d_it; + const char *bus; + + /* Find device */ + d_it = hal_device_store_find (hald_get_gdl (), udi_it); + assert (d_it != NULL); + + /* Check info.bus */ + bus = hal_device_property_get_string (d_it,"info.bus"); + if (strcmp (bus, "usb") == 0) { + stordev_udi = udi_it; + stordev = d_it; + break; + } else if (strcmp (bus, "ide") == 0) { + stordev_udi = udi_it; + stordev = d_it; + break; + } + + /* Go to parent */ + udi_it = hal_device_property_get_string (d_it, + "info.parent"); + } + + if (stordev_udi == NULL) { + /* We couldn't find a storage device, use our own udi + * + * Ayeii, note - this is a temporary UDI but we will + * remedy such a situation in _got_udi() above + */ + stordev_udi = d->udi; + stordev = d; + } + } hal_device_property_set_string (d, "block.storage_device", @@ -609,201 +673,201 @@ block_class_post_process (ClassDeviceHandler *self, /** @todo Guestimate product name; use volume label */ hal_device_property_set_string (d, "info.product", "Volume"); - } else { - dbus_bool_t removable_media = FALSE; + /* Not much to do for volumes; our parent already set the + * appropriate values for the storage device backing us */ + return; + } - /* be pessimistic */ - hal_device_property_set_bool (stordev, "storage.cdr", FALSE); - hal_device_property_set_bool (stordev, "storage.cdrw", FALSE); - hal_device_property_set_bool (stordev, "storage.dvd", FALSE); - hal_device_property_set_bool (stordev, "storage.dvdr", FALSE); - hal_device_property_set_bool (stordev, "storage.dvdram", FALSE); + /* be pessimistic */ + hal_device_property_set_bool (stordev, "storage.cdr", FALSE); + hal_device_property_set_bool (stordev, "storage.cdrw", FALSE); + hal_device_property_set_bool (stordev, "storage.dvd", FALSE); + hal_device_property_set_bool (stordev, "storage.dvdr", FALSE); + hal_device_property_set_bool (stordev, "storage.dvdram", FALSE); - /* We are a disk or cdrom drive; maybe we even offer - * removable media - */ - hal_device_property_set_string (d, "info.category", "block"); + /* We are a disk or cdrom drive; maybe we even offer + * removable media + */ + hal_device_property_set_string (d, "info.category", "block"); - HAL_INFO (("Bus type is %s!", - hal_device_property_get_string (parent, "info.bus"))); + HAL_INFO (("Bus type is %s!", + hal_device_property_get_string (parent, "info.bus"))); - if (strcmp (hal_device_property_get_string (parent, "info.bus"), + if (strcmp (hal_device_property_get_string (parent, "info.bus"), "ide") == 0) { - const char *ide_name; - char *model; - char *media; - - ide_name = get_last_element (hal_device_property_get_string - (d, "linux.sysfs_path")); - - model = read_single_line ("/proc/ide/%s/model", - ide_name); - if (model != NULL) { - hal_device_property_set_string (stordev, "storage.model", model); - hal_device_property_set_string (d, "info.product", - model); - } + const char *ide_name; + char *model; + char *media; + ide_name = get_last_element (hal_device_property_get_string + (d, "linux.sysfs_path")); - /* According to the function proc_ide_read_media() in - * drivers/ide/ide-proc.c in the Linux sources, media - * can only assume "disk", "cdrom", "tape", "floppy", - * "UNKNOWN" - */ + model = read_single_line ("/proc/ide/%s/model", ide_name); + if (model != NULL) { + hal_device_property_set_string (stordev, + "storage.model", + model); + hal_device_property_set_string (d, + "info.product", + model); + } - /** @todo Given floppy how - * do we determine it's LS120? - */ + + /* According to the function proc_ide_read_media() in + * drivers/ide/ide-proc.c in the Linux sources, media + * can only assume "disk", "cdrom", "tape", "floppy", + * "UNKNOWN" + */ + + /** @todo Given floppy how + * do we determine it's LS120? + */ - media = read_single_line ("/proc/ide/%s/media", - ide_name); - if (media != NULL) { - hal_device_property_set_string (stordev, "storage.media", + media = read_single_line ("/proc/ide/%s/media", + ide_name); + if (media != NULL) { + hal_device_property_set_string (stordev, "storage.media", media); - - /* Set for removable media */ - if (strcmp (media, "disk") == 0) { - hal_device_add_capability (stordev, "storage"); - hal_device_property_set_string (stordev, - "info.category", - "storage"); - } else if (strcmp (media, "cdrom") == 0) { - - hal_device_add_capability (stordev, "storage"); - hal_device_add_capability (stordev, - "storage.removable"); - hal_device_property_set_string (stordev, - "info.category", - "storage.removable"); - - removable_media = TRUE; - } else if (strcmp (media, "floppy") == 0) { - hal_device_add_capability (stordev, "storage"); - hal_device_add_capability (stordev, - "storage.removable"); - hal_device_property_set_string (stordev, - "info.category", - "storage.removable"); - removable_media = TRUE; - } else if (strcmp (media, "tape") == 0) { - hal_device_add_capability (stordev, "storage"); - hal_device_add_capability (stordev, - "storage.removable"); - hal_device_property_set_string (stordev, - "info.category", - "storage.removable"); - removable_media = TRUE; - } - - } - - } - else if (strcmp (hal_device_property_get_string (parent, "info.bus"), - "scsi_device") == 0) { - const char *sysfs_path; - char attr_path[SYSFS_PATH_MAX]; - struct sysfs_attribute *attr; - sysfs_path = hal_device_property_get_string ( - d, - "linux.sysfs_path"); - - snprintf (attr_path, SYSFS_PATH_MAX, - "%s/device/vendor", sysfs_path); - attr = sysfs_open_attribute (attr_path); - if (sysfs_read_attribute (attr) >= 0) { - hal_device_property_set_string (d, "info.vendor", - strip_space (attr-> - value)); - sysfs_close_attribute (attr); + /* Set for removable media */ + if (strcmp (media, "disk") == 0) { + /* left blank */ + } else if (strcmp (media, "cdrom") == 0) { + has_removable_media = TRUE; + } else if (strcmp (media, "floppy") == 0) { + has_removable_media = TRUE; + } else if (strcmp (media, "tape") == 0) { + has_removable_media = TRUE; } - - snprintf (attr_path, SYSFS_PATH_MAX, - "%s/device/model", sysfs_path); - attr = sysfs_open_attribute (attr_path); - if (sysfs_read_attribute (attr) >= 0) { - hal_device_property_set_string (d, "info.product", + + } + + } else if (strcmp (hal_device_property_get_string (parent, + "info.bus"), + "scsi_device") == 0) { + const char *sysfs_path; + char attr_path[SYSFS_PATH_MAX]; + struct sysfs_attribute *attr; + + sysfs_path = hal_device_property_get_string ( + d, "linux.sysfs_path"); + + snprintf (attr_path, SYSFS_PATH_MAX, + "%s/device/vendor", sysfs_path); + attr = sysfs_open_attribute (attr_path); + if (sysfs_read_attribute (attr) >= 0) { + hal_device_property_set_string (d, "info.vendor", strip_space (attr-> value)); - sysfs_close_attribute (attr); - } - - snprintf (attr_path, SYSFS_PATH_MAX, - "%s/device/type", sysfs_path); - attr = sysfs_open_attribute (attr_path); - if (sysfs_read_attribute (attr) >= 0) { - int type = parse_dec (attr->value); - switch (type) { - case 0: /* Disk */ - hal_device_add_capability (stordev, "storage"); - hal_device_property_set_string ( - stordev, "info.category", "storage"); - hal_device_property_set_string ( - stordev, "storage.media", "disk"); - break; - case 1: /* Tape */ - hal_device_add_capability (stordev, "storage"); - hal_device_add_capability ( - stordev, "storage.removable"); - hal_device_property_set_string ( - stordev, "info.category", - "storage.removable"); - hal_device_property_set_string ( - stordev, - "storage.media", "tape"); - removable_media = TRUE; - break; - case 5: /* CD-ROM */ - hal_device_add_capability (stordev, "storage"); - hal_device_add_capability ( - stordev, "storage.removable"); - hal_device_property_set_string ( - stordev, "storage.media", "cdrom"); - hal_device_property_set_string ( - stordev, "info.category", - "storage.removable"); - - removable_media = TRUE; - break; - default: - /** @todo add more SCSI types */ - HAL_WARNING (("Don't know how to " - "handle SCSI type %d", - type)); - } + sysfs_close_attribute (attr); + } + + snprintf (attr_path, SYSFS_PATH_MAX, + "%s/device/model", sysfs_path); + attr = sysfs_open_attribute (attr_path); + if (sysfs_read_attribute (attr) >= 0) { + strip_space (attr->value); + hal_device_property_set_string (d, + "info.product", + attr->value); + hal_device_property_set_string (stordev, + "storage.model", + attr->value); + sysfs_close_attribute (attr); + } + + snprintf (attr_path, SYSFS_PATH_MAX, + "%s/device/type", sysfs_path); + attr = sysfs_open_attribute (attr_path); + if (sysfs_read_attribute (attr) >= 0) { + int type = parse_dec (attr->value); + switch (type) { + case 0: /* Disk */ + hal_device_property_set_string ( + stordev, + "storage.media", + "disk"); + break; + case 1: /* Tape */ + has_removable_media = TRUE; + hal_device_property_set_string ( + stordev, + "storage.media", + "tape"); + has_removable_media = TRUE; + break; + case 5: /* CD-ROM */ + hal_device_property_set_string ( + stordev, + "storage.media", + "cdrom"); + has_removable_media = TRUE; + break; + default: + /** @todo add more SCSI types */ + HAL_WARNING (("Don't know how to " + "handle SCSI type %d", + type)); } - } else { - /** @todo block device on non-IDE and non-SCSI device; - * how to find the name and the media-type? Right now - * we just assume that the disk is fixed and of type - * flash. - * - */ - - hal_device_property_set_string (stordev, "storage.media", - "flash"); - - hal_device_add_capability (stordev, "storage"); - hal_device_property_set_string (stordev, "info.category", - "storage"); - - /* guestimate product name */ - hal_device_property_set_string (d, "info.product", "Disk"); - } - - hal_device_property_set_bool (stordev, "storage.removable", removable_media); + } else { + /** @todo block device on non-IDE and non-SCSI device; + * how to find the name and the media-type? Right now + * we just assume that the disk is fixed and of type + * flash. + */ + + hal_device_property_set_string ( + stordev, + "storage.media", + "flash"); + + /* guestimate product name */ + hal_device_property_set_string (d, "info.product", "Disk"); + + } + + + hal_device_property_set_bool ( + stordev, + "storage.removable", + has_removable_media); + + if (has_removable_media) { + hal_device_add_capability ( + stordev, + "storage.removable"); } if (hal_device_has_property (stordev, "storage.media") && - strcmp (hal_device_property_get_string (stordev, "storage.media"), "cdrom") == 0) { + strcmp (hal_device_property_get_string (stordev, "storage.media"), + "cdrom") == 0) { cdrom_check (stordev, device_file); } + + hal_device_property_set_string (stordev, "info.category", "storage"); + hal_device_add_capability (stordev, "storage"); + + + + if (hal_device_has_property (stordev, "info.bus") && + ( strcmp (hal_device_property_get_string (stordev, "info.bus"), + "usb") == 0 || + strcmp (hal_device_property_get_string (stordev, "info.bus"), + "ieee1394") == 0) ) { + is_hotplugable = TRUE; + } + + hal_device_property_set_bool (stordev, "storage.hotplugable", + is_hotplugable); + if (is_hotplugable) { + hal_device_add_capability (stordev, "storage.hotplugable"); + } + /* check for media on the device */ detect_media (d); - } static char * @@ -826,8 +890,6 @@ block_class_compute_udi (HalDevice * d, int append_num) - - #define MOUNT_POINT_MAX 256 #define MOUNT_POINT_STRING_SIZE 128 @@ -1228,6 +1290,7 @@ ClassDeviceHandler block_class_handler = { class_device_udev_event, /**< handle udev event */ class_device_get_device_file_target,/**< where to store devfile name */ block_class_post_process, /**< add more properties */ + block_class_got_udi, /**< got UDI */ block_class_compute_udi, /**< UDI computation */ "block", /**< sysfs class name */ "block", /**< hal class name */ diff --git a/hald/linux/bus_device.c b/hald/linux/bus_device.c index 317c6c7b..5902d8b1 100644 --- a/hald/linux/bus_device.c +++ b/hald/linux/bus_device.c @@ -173,6 +173,9 @@ bus_device_got_parent (HalDeviceStore *store, HalDevice *parent, new_udi = rename_and_merge (d, self->compute_udi, self->hal_bus_name); if (new_udi != NULL) { new_d = hal_device_store_find (hald_get_gdl (), new_udi); + + self->got_udi (self, new_d != NULL ? new_d : d, new_udi); + hal_device_store_add (hald_get_gdl (), new_d != NULL ? new_d : d); } @@ -253,5 +256,12 @@ bus_device_post_process (BusDeviceHandler *self, { } +void +bus_device_got_udi (BusDeviceHandler *self, + HalDevice *d, + const char *udi) +{ +} + /** @} */ diff --git a/hald/linux/bus_device.h b/hald/linux/bus_device.h index b06bd084..e0d8767d 100644 --- a/hald/linux/bus_device.h +++ b/hald/linux/bus_device.h @@ -138,7 +138,19 @@ struct BusDeviceHandler_s { void (*post_process) (BusDeviceHandler *self, HalDevice *d, const char *sysfs_path, - struct sysfs_device *device); + struct sysfs_device *device); + + /** Called when the UDI has been determined, but before the device + * is added to the GDL. + * + * @param self Pointer to class members + * @param d The HalDevice object + * @param udi UDI of device + */ + void (*got_udi) (BusDeviceHandler *self, + HalDevice *d, + const char *udi); + /** name of bus the instance handles (name mentioned in /sys/bus) */ const char *sysfs_bus_name; @@ -171,4 +183,8 @@ void bus_device_post_process (BusDeviceHandler *self, const char *sysfs_path, struct sysfs_device *device); +void bus_device_got_udi (BusDeviceHandler *self, + HalDevice *d, + const char *udi); + #endif /* BUS_DEVICE_H */ diff --git a/hald/linux/class_device.c b/hald/linux/class_device.c index 7e6e9103..3a485363 100644 --- a/hald/linux/class_device.c +++ b/hald/linux/class_device.c @@ -60,6 +60,9 @@ static void class_device_got_device_file (HalDevice *d, gpointer user_data, gboolean prop_exists); +static void +class_device_final (ClassDeviceHandler* self, HalDevice *d); + /** Generic accept function that accepts the device if and only if * the class name from sysfs equals the class name in the class @@ -80,9 +83,6 @@ class_device_accept (ClassDeviceHandler *self, /* only care about given sysfs class name */ if (strcmp (class_device->classname, self->sysfs_class_name) == 0) { - HAL_INFO (("########################################")); - HAL_INFO (("########################################")); - HAL_INFO (("########################################")); return TRUE; } @@ -127,12 +127,13 @@ class_device_visit (ClassDeviceHandler *self, class_device->sysdevice->path); } + /* Temporary property used for _udev_event() */ + hal_device_property_set_string (d, ".udev.sysfs_path", path); + hal_device_property_set_string (d, ".udev.class_name", + self->sysfs_class_name); + /* We may require a device file */ if (self->require_device_file) { - /* Temporary property used for _udev_event() */ - hal_device_property_set_string (d, ".udev.sysfs_path", path); - hal_device_property_set_string (d, ".udev.class_name", - self->sysfs_class_name); /* Find the property name we should store the device file in */ self->get_device_file_target (self, d, path, class_device, @@ -248,13 +249,8 @@ class_device_got_parent_device (HalDeviceStore *store, HalDevice *parent, gpointer user_data) { AsyncInfo *ai = user_data; - const char *target_dev = NULL; - const char *sysfs_path = NULL; - char *new_udi = NULL; - HalDevice *new_d = NULL; HalDevice *d = (HalDevice *) ai->device; ClassDeviceHandler *self = ai->handler; - struct sysfs_class_device *class_device; g_free (ai); @@ -270,19 +266,9 @@ class_device_got_parent_device (HalDeviceStore *store, HalDevice *parent, /* set parent */ hal_device_property_set_string (d, "info.parent", parent->udi); - /* get more information about the device from the specialised - * function */ - sysfs_path = hal_device_property_get_string (d, "linux.sysfs_path"); - assert (sysfs_path != NULL); - class_device = sysfs_open_class_device (sysfs_path); - if (class_device == NULL) - DIE (("Coulnd't get sysfs class device object for path %s", - sysfs_path)); - self->post_process (self, d, sysfs_path, class_device); - sysfs_close_class_device (class_device); - - /** @todo handle merge_or_add==FALSE && require_device_file==TRUE */ - if (self->require_device_file) { + /* wait for the appropriate property for the device file */ + if (self->require_device_file ) { + const char *target_dev; target_dev = hal_device_property_get_string (d, ".target_dev"); assert (target_dev != NULL); @@ -292,18 +278,7 @@ class_device_got_parent_device (HalDeviceStore *store, HalDevice *parent, (gpointer) self, is_probing ? 0 : HAL_LINUX_HOTPLUG_TIMEOUT); } else { - /* Compute a proper UDI (unique device id) and try to locate a - * persistent unplugged device or simple add this new device... - */ - new_udi = rename_and_merge (d, self->compute_udi, self->hal_class_name); - if (new_udi != NULL) { - new_d = hal_device_store_find (hald_get_gdl (), - new_udi); - hal_device_store_add (hald_get_gdl (), - new_d != NULL ? new_d : d); - } - hal_device_store_remove (hald_get_tdl (), d); - g_object_unref (d); + class_device_final (self, d); } } @@ -322,7 +297,6 @@ class_device_got_sysdevice (HalDeviceStore *store, gpointer user_data) { AsyncInfo *ai = user_data; - const char *target_dev; const char *parent_udi; HalDevice *parent_device; HalDevice *d = (HalDevice *) ai->device; @@ -356,6 +330,7 @@ class_device_got_sysdevice (HalDeviceStore *store, /* wait for the appropriate property for the device file */ if (self->require_device_file ) { + const char *target_dev; target_dev = hal_device_property_get_string (d, ".target_dev"); assert (target_dev != NULL); @@ -365,8 +340,7 @@ class_device_got_sysdevice (HalDeviceStore *store, (gpointer) self, is_probing ? 0 : HAL_LINUX_HOTPLUG_TIMEOUT); } else { - /** @todo FIXME */ - DIE (("fix me here")); + class_device_final (self, d); } } @@ -374,9 +348,10 @@ static void class_device_got_device_file (HalDevice *d, gpointer user_data, gboolean prop_exists) { - HalDevice *sysdevice; ClassDeviceHandler *self = (ClassDeviceHandler *) user_data; + HAL_INFO (("entering")); + if (!prop_exists) { HAL_WARNING (("Never got device file for class device at %s", hal_device_property_get_string (d, ".udev.sysfs_path"))); @@ -385,28 +360,43 @@ class_device_got_device_file (HalDevice *d, gpointer user_data, return; } - /* remove the property for the device file name target */ - hal_device_property_remove (d, ".target_dev"); + class_device_final (self, d); +} + +static void +class_device_final (ClassDeviceHandler* self, HalDevice *d) +{ + const char *sysfs_path = NULL; + struct sysfs_class_device *class_device; - /* remove properties for udev reception */ - hal_device_property_remove (d, ".udev.sysfs_path"); - hal_device_property_remove (d, ".udev.class_name"); + /* get more information about the device from the specialised + * function */ + sysfs_path = hal_device_property_get_string (d, ".udev.sysfs_path"); + assert (sysfs_path != NULL); + class_device = sysfs_open_class_device (sysfs_path); + if (class_device == NULL) + DIE (("Coulnd't get sysfs class device object for path %s", + sysfs_path)); + self->post_process (self, d, sysfs_path, class_device); + sysfs_close_class_device (class_device); if (self->merge_or_add) { const char *sysdevice_udi; + HalDevice *sysdevice; + /* get the sysdevice from the temporary cookie */ sysdevice_udi = hal_device_property_get_string (d, ".sysdevice"); assert (sysdevice_udi != NULL); sysdevice = hal_device_store_find (hald_get_gdl (), sysdevice_udi); assert (sysdevice != NULL); - hal_device_property_remove (d, ".sysdevice"); - - /* now, do some post-processing */ - self->post_process (self, d, - hal_device_property_get_string (d, ".udev.sysfs_path"), - NULL /** @todo FIXME */ ); + /* remove various temporary properties */ + hal_device_property_remove (d, ".udev.sysfs_path"); + hal_device_property_remove (d, ".udev.class_name"); + hal_device_property_remove (d, ".sysdevice"); + hal_device_property_remove (d, ".target_dev"); + /* merge information from temporary device onto the physical * device */ hal_device_merge (sysdevice, d); @@ -418,6 +408,13 @@ class_device_got_device_file (HalDevice *d, gpointer user_data, } else { char *new_udi; HalDevice *new_d; + + /* remove various temporary properties */ + hal_device_property_remove (d, ".udev.sysfs_path"); + hal_device_property_remove (d, ".udev.class_name"); + hal_device_property_remove (d, ".sysdevice"); + hal_device_property_remove (d, ".target_dev"); + /* Compute a proper UDI (unique device id) and try to locate a * persistent unplugged device or simply add this new device... */ @@ -425,6 +422,9 @@ class_device_got_device_file (HalDevice *d, gpointer user_data, if (new_udi != NULL) { new_d = hal_device_store_find (hald_get_gdl (), new_udi); + + self->got_udi (self, new_d!=NULL ? new_d : d, new_udi); + hal_device_store_add (hald_get_gdl (), new_d != NULL ? new_d : d); } @@ -519,5 +519,11 @@ class_device_get_device_file_target (ClassDeviceHandler *self, "%s.device", self->hal_class_name); } +void +class_device_got_udi (ClassDeviceHandler *self, + HalDevice *d, + const char *udi) +{ +} /** @} */ diff --git a/hald/linux/class_device.h b/hald/linux/class_device.h index a833e16a..f026d091 100644 --- a/hald/linux/class_device.h +++ b/hald/linux/class_device.h @@ -154,6 +154,8 @@ struct ClassDeviceHandler_s { * through e.g. ioctl's using the device file property and also * for setting info.category|capability. * + * Note that the UDI is not yet valid, use function got_udi to + * * @param self Pointer to class members * @param d The HalDevice object of the instance of * this device class @@ -167,6 +169,18 @@ struct ClassDeviceHandler_s { const char *sysfs_path, struct sysfs_class_device *class_device); + /** Called when the UDI has been determined, but before the device + * is added to the GDL. Note that this is only invoked if + * merge_or_add is FALSE. + * + * @param self Pointer to class members + * @param d The HalDevice object, see above + * @param udi UDI of device + */ + void (*got_udi) (ClassDeviceHandler *self, + HalDevice *d, + const char *udi); + /** This function will compute the device udi based on other properties * of the device. * @@ -239,6 +253,11 @@ void class_device_post_process (ClassDeviceHandler *self, const char *sysfs_path, struct sysfs_class_device *class_device); +void class_device_got_udi (ClassDeviceHandler *self, + HalDevice *d, + const char *udi); + + void class_device_tick (ClassDeviceHandler *self); void class_device_get_device_file_target (ClassDeviceHandler *self, diff --git a/hald/linux/ide_bus_device.c b/hald/linux/ide_bus_device.c index d638af96..c3acc6a2 100644 --- a/hald/linux/ide_bus_device.c +++ b/hald/linux/ide_bus_device.c @@ -81,10 +81,10 @@ ide_device_post_process (BusDeviceHandler *self, if (channel == 0) { hal_device_property_set_string (d, "info.product", - "IDE channel (master)"); + "IDE device (master)"); } else { hal_device_property_set_string (d, "info.product", - "IDE channel (slave)"); + "IDE device (slave)"); } hal_device_property_set_bool (d, "info.virtual", TRUE); @@ -102,6 +102,7 @@ BusDeviceHandler ide_bus_handler = { bus_device_removed, /**< device is removed */ ide_device_compute_udi, /**< UDI computing function */ ide_device_post_process, /**< add more properties */ + bus_device_got_udi, /**< got UDI */ "ide", /**< sysfs bus name */ "ide" /**< namespace */ }; diff --git a/hald/linux/ide_host_bus_device.c b/hald/linux/ide_host_bus_device.c index 02359a6e..8b1ef8c4 100644 --- a/hald/linux/ide_host_bus_device.c +++ b/hald/linux/ide_host_bus_device.c @@ -108,6 +108,7 @@ BusDeviceHandler ide_host_bus_handler = { bus_device_removed, /**< device is removed */ ide_host_device_compute_udi, /**< UDI computing function */ ide_host_device_post_process, /**< add more properties */ + bus_device_got_udi, /**< got UDI */ "ide_host", /**< sysfs bus name */ "ide_host" /**< namespace */ }; diff --git a/hald/linux/input_class_device.c b/hald/linux/input_class_device.c index 42eedf23..96a4d4c9 100644 --- a/hald/linux/input_class_device.c +++ b/hald/linux/input_class_device.c @@ -134,6 +134,7 @@ ClassDeviceHandler input_class_handler = { class_device_udev_event, /**< handle udev event */ input_class_get_device_file_target, /**< where to store devfile name */ input_class_post_process, /**< add more properties */ + class_device_got_udi, /**< got UDI */ NULL, /**< No UDI computation */ "input", /**< sysfs class name */ "input", /**< hal class name */ diff --git a/hald/linux/pci_bus_device.c b/hald/linux/pci_bus_device.c index ab653009..c2549d5f 100644 --- a/hald/linux/pci_bus_device.c +++ b/hald/linux/pci_bus_device.c @@ -769,6 +769,7 @@ BusDeviceHandler pci_bus_handler = { bus_device_removed, /**< device is removed */ pci_device_compute_udi, /**< UDI computing function */ pci_device_post_process, /**< add more properties */ + bus_device_got_udi, /**< got UDI */ "pci", /**< sysfs bus name */ "pci" /**< namespace */ }; diff --git a/hald/linux/printer_class_device.c b/hald/linux/printer_class_device.c index 2f4501fb..a72ae72d 100644 --- a/hald/linux/printer_class_device.c +++ b/hald/linux/printer_class_device.c @@ -174,6 +174,7 @@ ClassDeviceHandler printer_class_handler = { class_device_udev_event, /**< handle udev event */ class_device_get_device_file_target,/**< where to store devfile name */ printer_class_post_process, /**< add more properties */ + class_device_got_udi, /**< got UDI */ NULL, /**< No UDI computation */ "usb", /**< sysfs class name */ "printer", /**< hal class name */ diff --git a/hald/linux/scsi_device_class_device.c b/hald/linux/scsi_device_class_device.c index 211654e4..c9839fc0 100644 --- a/hald/linux/scsi_device_class_device.c +++ b/hald/linux/scsi_device_class_device.c @@ -112,6 +112,7 @@ ClassDeviceHandler scsi_device_class_handler = { class_device_udev_event, /**< handle udev event */ class_device_get_device_file_target,/**< where to store devfile name */ scsi_device_class_post_process, /**< add more properties */ + class_device_got_udi, /**< got UDI */ scsi_device_class_compute_udi, /**< No UDI computation */ "scsi_device", /**< sysfs class name */ "scsi_device", /**< hal class name */ diff --git a/hald/linux/scsi_host_class_device.c b/hald/linux/scsi_host_class_device.c index 2d8ca871..6ea0e4ce 100644 --- a/hald/linux/scsi_host_class_device.c +++ b/hald/linux/scsi_host_class_device.c @@ -101,6 +101,7 @@ ClassDeviceHandler scsi_host_class_handler = { class_device_udev_event, /**< handle udev event */ class_device_get_device_file_target,/**< where to store devfile name */ scsi_host_class_post_process, /**< add more properties */ + class_device_got_udi, /**< got UDI */ scsi_host_class_compute_udi, /**< No UDI computation */ "scsi_host", /**< sysfs class name */ "scsi_host", /**< hal class name */ diff --git a/hald/linux/usb_bus_device.c b/hald/linux/usb_bus_device.c index 1a163229..1f43df7d 100644 --- a/hald/linux/usb_bus_device.c +++ b/hald/linux/usb_bus_device.c @@ -998,6 +998,7 @@ BusDeviceHandler usb_bus_handler = { bus_device_removed, /**< device is removed */ usb_device_compute_udi, /**< UDI computing function */ usb_device_post_process, /**< add more properties */ + bus_device_got_udi, /**< got UDI */ "usb", /**< sysfs bus name */ "usb" /**< namespace */ }; diff --git a/hald/linux/usbif_bus_device.c b/hald/linux/usbif_bus_device.c index fc50c7b7..9578fe25 100644 --- a/hald/linux/usbif_bus_device.c +++ b/hald/linux/usbif_bus_device.c @@ -158,6 +158,7 @@ BusDeviceHandler usbif_bus_handler = { bus_device_removed, /**< device is removed */ usbif_device_compute_udi, /**< UDI computing function */ usbif_device_post_process, /**< add more properties */ + bus_device_got_udi, /**< got UDI */ "usb", /**< sysfs bus name */ "usbif" /**< namespace */ }; |