chiark / gitweb /
libudev: pass udev_device in enumerate
authorKay Sievers <kay.sievers@vrfy.org>
Thu, 18 Sep 2008 06:32:43 +0000 (23:32 -0700)
committerKay Sievers <kay.sievers@vrfy.org>
Thu, 18 Sep 2008 06:32:43 +0000 (23:32 -0700)
udev/lib/exported_symbols
udev/lib/libudev-enumerate.c
udev/lib/libudev.h
udev/lib/test-libudev.c
udev/udevadm-info.c
udev/udevadm-trigger.c

index 2711f0b00a03bf506ed2e0a2ee6fe6b5251ef4e2..c06148b25403398f802fc16933a432e601c873b9 100644 (file)
@@ -15,6 +15,7 @@ udev_device_get_udev
 udev_device_get_syspath
 udev_device_get_devpath
 udev_device_get_devname
+udev_device_get_sysname
 udev_device_get_subsystem
 udev_device_get_devlinks
 udev_device_get_properties
index 458be5861a527569d12a697e042ce3baa0e7c62b..b8e4807c478cffd79f7607a286cfd94270e4a713 100644 (file)
@@ -109,43 +109,17 @@ static int devices_delay(struct udev *udev, const char *syspath)
        return 0;
 }
 
-static int devices_call(struct udev *udev, const char *syspath,
-                       int (*cb)(struct udev *udev,
-                                 const char *syspath, const char *subsystem, const char *name,
-                                 void *data),
-                       void *data,
-                       int *cb_rc)
-{
-       char subsystem[UTIL_PATH_SIZE];
-       const char *name;
-
-       name = strrchr(syspath, '/');
-       if (name == NULL)
-               return -1;
-       name++;
-
-       if (util_get_sys_subsystem(udev, syspath, subsystem, sizeof(subsystem)) < 2)
-               return -1;
-       *cb_rc = cb(udev, syspath, subsystem, name, data);
-       return 0;
-}
-
 /**
  * udev_enumerate_devices:
- * @udev_device: udev device
- * @cb: function to be called for every property found
+ * @udev: udev library context
+ * @subsystem: the subsystem to enumerate
+ * @cb: function to be called for every device found
  * @data: data to be passed to the function
  *
- * Retrieve the property key/value pairs belonging to the
- * udev device. For every key/value pair, the passed function will be
- * called. If the function returns 1, remaning properties will be
- * ignored.
- *
- * Returns: the number of properties passed to the caller, or a negative value on error
+ * Returns: the number of devices passed to the caller, or a negative value on error
  **/
 int udev_enumerate_devices(struct udev *udev, const char *subsystem,
-                          int (*cb)(struct udev *udev,
-                                    const char *syspath, const char *subsystem, const char *name, void *data),
+                          int (*cb)(struct udev_device *udev_device, void *data),
                           void *data)
 {
        char base[UTIL_PATH_SIZE];
@@ -171,9 +145,16 @@ int udev_enumerate_devices(struct udev *udev, const char *subsystem,
        list_for_each_entry_safe(loop_device, tmp_device, &device_list, node) {
                if (devices_delay(udev, loop_device->name))
                        continue;
-               if (cb_rc == 0)
-                       if (devices_call(udev, loop_device->name, cb, data, &cb_rc) == 0)
+               if (cb_rc == 0) {
+                       struct udev_device *device;
+
+                       device = udev_device_new_from_syspath(udev, loop_device->name);
+                       if (device != NULL) {
+                               cb_rc = cb(device, data);
                                count++;
+                               udev_device_unref(device);
+                       }
+               }
                list_del(&loop_device->node);
                free(loop_device->name);
                free(loop_device);
@@ -181,9 +162,16 @@ int udev_enumerate_devices(struct udev *udev, const char *subsystem,
 
        /* handle remaining delayed devices */
        list_for_each_entry_safe(loop_device, tmp_device, &device_list, node) {
-               if (cb_rc == 0)
-                       if (devices_call(udev, loop_device->name, cb, data, &cb_rc) == 0)
+               if (cb_rc == 0) {
+                       struct udev_device *device;
+
+                       device = udev_device_new_from_syspath(udev, loop_device->name);
+                       if (device != NULL) {
+                               cb_rc = cb(device, data);
                                count++;
+                               udev_device_unref(device);
+                       }
+               }
                list_del(&loop_device->node);
                free(loop_device->name);
                free(loop_device);
index 6996b47fa3f8eb12c0ba4928d9fe67f4e5bd350a..78fc137c1205dedca0c6895f5ef0567ad06f1e49 100644 (file)
@@ -70,8 +70,7 @@ extern unsigned long long int udev_device_get_seqnum(struct udev_device *udev_de
 extern const char *udev_device_get_attr_value(struct udev_device *udev_device, const char *attr);
 
 extern int udev_enumerate_devices(struct udev *udev, const char *subsystem,
-                                 int (*cb)(struct udev *udev,
-                                           const char *syspath, const char *subsystem, const char *name, void *data),
+                                 int (*cb)(struct udev_device *udev_device, void *data),
                                  void *data);
 
 struct udev_monitor;
index 929fd667301e344acd1023b945deae910a420964..50123f6ec7eb38613c53ec945a6e4ef5d5480f28 100644 (file)
@@ -116,11 +116,12 @@ static int test_device_parents(struct udev *udev, const char *syspath)
        return 0;
 }
 
-static int devices_enum_cb(struct udev *udev,
-                          const char *devpath, const char *subsystem, const char *name,
-                          void *data)
+static int devices_enum_cb(struct udev_device *device, void *data)
 {
-       printf("device:    '%s' (%s) '%s'\n", devpath, subsystem, name);
+       printf("device:    '%s' (%s) '%s'\n",
+              udev_device_get_syspath(device),
+              udev_device_get_subsystem(device),
+              udev_device_get_sysname(device));
        return 0;
 }
 
index 9ce83aabd884abecd04ab769b08b86180141504c..abb424bfea4895596d3d7c2cdf105dca7b8562e8 100644 (file)
@@ -165,18 +165,10 @@ static void print_record(struct udev_device *device)
        printf("\n");
 }
 
-static int export_all_cb(struct udev *udev,
-                        const char *syspath, const char *subsystem, const char *name,
-                        void *data)
+static int export_all_cb(struct udev_device *device, void *data)
 {
-       struct udev_device *device;
-
-       device = udev_device_new_from_syspath(udev, syspath);
-       if (device == NULL)
-               return 0;
        if (udev_device_get_devname(device) != NULL)
                print_record(device);
-       udev_device_unref(device);
        return 0;
 }
 
index 13736378df12ec80df18d440811cee95d3fd9064..e7940ef92d608a6274690e75f6d8cb1571645c69 100644 (file)
@@ -126,7 +126,7 @@ static int pass_to_socket(struct udev *udev, const char *syspath, const char *ac
        int fd;
        char link_target[UTIL_PATH_SIZE];
        int len;
-       const char *devpath = syspath[strlen(udev_get_sys_path(udev))];
+       const char *devpath = &syspath[strlen(udev_get_sys_path(udev))];
        int err = 0;
 
        if (verbose)