diff options
-rw-r--r-- | discover/device-handler.c | 22 | ||||
-rw-r--r-- | discover/udev.c | 1 | ||||
-rw-r--r-- | ui/test/discover-test.c | 16 |
3 files changed, 39 insertions, 0 deletions
diff --git a/discover/device-handler.c b/discover/device-handler.c index a06dafc..11fb115 100644 --- a/discover/device-handler.c +++ b/discover/device-handler.c @@ -304,6 +304,27 @@ static struct discover_device *find_device(struct device_handler *handler, return NULL; } +static enum device_type event_device_type(struct device *device, + struct event *event) +{ + const char *param; + + param = event_get_param(event, "type"); + if (!param) { + pb_log("%s: empty type\n", device->id); + return DEVICE_TYPE_UNKNOWN; + } + + if (!strcmp(param, "disk") || !strcmp(param, "partition")) + return DEVICE_TYPE_DISK; + + if (!strcmp(param, "net")) + return DEVICE_TYPE_NETWORK; + + pb_log("%s: unknown type '%s'\n", device->id, param); + return DEVICE_TYPE_UNKNOWN; +} + static struct discover_device *discover_device_create( struct device_handler *handler, struct discover_context *ctx, @@ -325,6 +346,7 @@ static struct discover_device *discover_device_create( dev->device_path = talloc_strdup(dev, devname); dev->device->id = talloc_strdup(dev, event->device); + dev->device->type = event_device_type(dev->device, event); talloc_set_destructor(dev, destroy_device); diff --git a/discover/udev.c b/discover/udev.c index 309a749..d13ced7 100644 --- a/discover/udev.c +++ b/discover/udev.c @@ -126,6 +126,7 @@ static int udev_handle_dev_action(struct udev_device *dev, const char *action) event->n_params = 0; event->params = NULL; event_set_param(event, "DEVNAME", devnode); + event_set_param(event, "type", devtype); udev_setup_event_params(dev, event); diff --git a/ui/test/discover-test.c b/ui/test/discover-test.c index 45a4c74..faf1d89 100644 --- a/ui/test/discover-test.c +++ b/ui/test/discover-test.c @@ -3,6 +3,21 @@ #include "ui/common/discover-client.h" +static const char *device_type_string(enum device_type type) +{ + switch (type) { + case DEVICE_TYPE_DISK: + return "disk"; + case DEVICE_TYPE_NETWORK: + return "network"; + case DEVICE_TYPE_OPTICAL: + return "optical"; + case DEVICE_TYPE_UNKNOWN: + return "unknown"; + } + return "invalid"; +} + static int print_device_add(struct device *device, void __attribute__((unused)) *arg) { @@ -10,6 +25,7 @@ static int print_device_add(struct device *device, printf("new device:\n"); printf("\tid: %s\n", device->id); + printf("\ttype: %s\n", device_type_string(device->type)); printf("\tname: %s\n", device->name); printf("\tdesc: %s\n", device->description); printf("\ticon: %s\n", device->icon_file); |