1 /* -*- Mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
3 * Copyright (C) 2008 David Zeuthen <davidz@redhat.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
29 #include "gudevdevice.h"
30 #include "gudevprivate.h"
34 * @short_description: Get information about a device
36 * The #GUdevDevice class is used to get information about a specific
37 * device. Note that you cannot instantiate a #GUdevDevice object
38 * yourself. Instead you must use #GUdevClient to obtain #GUdevDevice
41 * To get basic information about a device, use
42 * g_udev_device_get_subsystem(), g_udev_device_get_devtype(),
43 * g_udev_device_get_name(), g_udev_device_get_number(),
44 * g_udev_device_get_sysfs_path(), g_udev_device_get_driver(),
45 * g_udev_device_get_action(), g_udev_device_get_seqnum(),
46 * g_udev_device_get_device_type(), g_udev_device_get_device_number(),
47 * g_udev_device_get_device_file(),
48 * g_udev_device_get_device_file_symlinks().
50 * To navigate the device tree, use g_udev_device_get_parent() and
51 * g_udev_device_get_parent_with_subsystem().
53 * To access udev properties for the device, use
54 * g_udev_device_get_property_keys(),
55 * g_udev_device_has_property(),
56 * g_udev_device_get_property(),
57 * g_udev_device_get_property_as_int(),
58 * g_udev_device_get_property_as_uint64(),
59 * g_udev_device_get_property_as_double(),
60 * g_udev_device_get_property_as_boolean() and
61 * g_udev_device_get_property_as_strv().
63 * To access sysfs attributes for the device, use
64 * g_udev_device_get_sysfs_attr(),
65 * g_udev_device_get_sysfs_attr_as_int(),
66 * g_udev_device_get_sysfs_attr_as_uint64(),
67 * g_udev_device_get_sysfs_attr_as_double(),
68 * g_udev_device_get_sysfs_attr_as_boolean() and
69 * g_udev_device_get_sysfs_attr_as_strv().
71 * Note that all getters on #GUdevDevice are non-reffing – returned
72 * values are owned by the object, should not be freed and are only
73 * valid as long as the object is alive.
75 * By design, #GUdevDevice will not react to changes for a device – it
76 * only contains a snapshot of information when the #GUdevDevice
77 * object was created. To work with changes, you typically connect to
78 * the #GUdevClient::uevent signal on a #GUdevClient and get a new
79 * #GUdevDevice whenever an event happens.
82 struct _GUdevDevicePrivate
84 struct udev_device *udevice;
86 /* computed ondemand and cached */
87 gchar **device_file_symlinks;
88 gchar **property_keys;
90 GHashTable *prop_strvs;
91 GHashTable *sysfs_attr_strvs;
94 G_DEFINE_TYPE (GUdevDevice, g_udev_device, G_TYPE_OBJECT)
97 g_udev_device_finalize (GObject *object)
99 GUdevDevice *device = G_UDEV_DEVICE (object);
101 g_strfreev (device->priv->device_file_symlinks);
102 g_strfreev (device->priv->property_keys);
103 g_strfreev (device->priv->tags);
105 if (device->priv->udevice != NULL)
106 udev_device_unref (device->priv->udevice);
108 if (device->priv->prop_strvs != NULL)
109 g_hash_table_unref (device->priv->prop_strvs);
111 if (device->priv->sysfs_attr_strvs != NULL)
112 g_hash_table_unref (device->priv->sysfs_attr_strvs);
114 if (G_OBJECT_CLASS (g_udev_device_parent_class)->finalize != NULL)
115 (* G_OBJECT_CLASS (g_udev_device_parent_class)->finalize) (object);
119 g_udev_device_class_init (GUdevDeviceClass *klass)
121 GObjectClass *gobject_class = (GObjectClass *) klass;
123 gobject_class->finalize = g_udev_device_finalize;
125 g_type_class_add_private (klass, sizeof (GUdevDevicePrivate));
129 g_udev_device_init (GUdevDevice *device)
131 device->priv = G_TYPE_INSTANCE_GET_PRIVATE (device,
138 _g_udev_device_new (struct udev_device *udevice)
142 device = G_UDEV_DEVICE (g_object_new (G_UDEV_TYPE_DEVICE, NULL));
143 device->priv->udevice = udev_device_ref (udevice);
149 * g_udev_device_get_subsystem:
150 * @device: A #GUdevDevice.
152 * Gets the subsystem for @device.
154 * Returns: The subsystem for @device.
157 g_udev_device_get_subsystem (GUdevDevice *device)
159 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
160 return udev_device_get_subsystem (device->priv->udevice);
164 * g_udev_device_get_devtype:
165 * @device: A #GUdevDevice.
167 * Gets the device type for @device.
169 * Returns: The devtype for @device.
172 g_udev_device_get_devtype (GUdevDevice *device)
174 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
175 return udev_device_get_devtype (device->priv->udevice);
179 * g_udev_device_get_name:
180 * @device: A #GUdevDevice.
182 * Gets the name of @device, e.g. "sda3".
184 * Returns: The name of @device.
187 g_udev_device_get_name (GUdevDevice *device)
189 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
190 return udev_device_get_sysname (device->priv->udevice);
194 * g_udev_device_get_number:
195 * @device: A #GUdevDevice.
197 * Gets the number of @device, e.g. "3" if g_udev_device_get_name() returns "sda3".
199 * Returns: The number of @device.
202 g_udev_device_get_number (GUdevDevice *device)
204 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
205 return udev_device_get_sysnum (device->priv->udevice);
209 * g_udev_device_get_sysfs_path:
210 * @device: A #GUdevDevice.
212 * Gets the sysfs path for @device.
214 * Returns: The sysfs path for @device.
217 g_udev_device_get_sysfs_path (GUdevDevice *device)
219 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
220 return udev_device_get_syspath (device->priv->udevice);
224 * g_udev_device_get_driver:
225 * @device: A #GUdevDevice.
227 * Gets the name of the driver used for @device.
229 * Returns: The name of the driver for @device or %NULL if unknown.
232 g_udev_device_get_driver (GUdevDevice *device)
234 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
235 return udev_device_get_driver (device->priv->udevice);
239 * g_udev_device_get_action:
240 * @device: A #GUdevDevice.
242 * Gets the most recent action (e.g. "add", "remove", "change", etc.) for @device.
244 * Returns: An action string.
247 g_udev_device_get_action (GUdevDevice *device)
249 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
250 return udev_device_get_action (device->priv->udevice);
254 * g_udev_device_get_seqnum:
255 * @device: A #GUdevDevice.
257 * Gets the most recent sequence number for @device.
259 * Returns: A sequence number.
262 g_udev_device_get_seqnum (GUdevDevice *device)
264 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), 0);
265 return udev_device_get_seqnum (device->priv->udevice);
269 * g_udev_device_get_device_type:
270 * @device: A #GUdevDevice.
272 * Gets the type of the device file, if any, for @device.
274 * Returns: The device number for @device or #G_UDEV_DEVICE_TYPE_NONE if the device does not have a device file.
277 g_udev_device_get_device_type (GUdevDevice *device)
279 struct stat stat_buf;
280 const gchar *device_file;
281 GUdevDeviceType type;
283 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), G_UDEV_DEVICE_TYPE_NONE);
285 type = G_UDEV_DEVICE_TYPE_NONE;
287 /* TODO: would be better to have support for this in libudev... */
289 device_file = g_udev_device_get_device_file (device);
290 if (device_file == NULL)
293 if (stat (device_file, &stat_buf) != 0)
296 if (S_ISBLK (stat_buf.st_mode))
297 type = G_UDEV_DEVICE_TYPE_BLOCK;
298 else if (S_ISCHR (stat_buf.st_mode))
299 type = G_UDEV_DEVICE_TYPE_CHAR;
306 * g_udev_device_get_device_number:
307 * @device: A #GUdevDevice.
309 * Gets the device number, if any, for @device.
311 * Returns: The device number for @device or 0 if unknown.
314 g_udev_device_get_device_number (GUdevDevice *device)
316 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), 0);
317 return udev_device_get_devnum (device->priv->udevice);
321 * g_udev_device_get_device_file:
322 * @device: A #GUdevDevice.
324 * Gets the device file for @device.
326 * Returns: The device file for @device or %NULL if no device file
330 g_udev_device_get_device_file (GUdevDevice *device)
332 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
333 return udev_device_get_devnode (device->priv->udevice);
337 * g_udev_device_get_device_file_symlinks:
338 * @device: A #GUdevDevice.
340 * Gets a list of symlinks (in <literal>/dev</literal>) that points to
341 * the device file for @device.
343 * Returns: (transfer none) (array zero-terminated=1) (element-type utf8): A %NULL terminated string array of symlinks. This array is owned by @device and should not be freed by the caller.
345 const gchar * const *
346 g_udev_device_get_device_file_symlinks (GUdevDevice *device)
348 struct udev_list_entry *l;
351 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
353 if (device->priv->device_file_symlinks != NULL)
356 p = g_ptr_array_new ();
357 for (l = udev_device_get_devlinks_list_entry (device->priv->udevice); l != NULL; l = udev_list_entry_get_next (l))
359 g_ptr_array_add (p, g_strdup (udev_list_entry_get_name (l)));
361 g_ptr_array_add (p, NULL);
362 device->priv->device_file_symlinks = (gchar **) g_ptr_array_free (p, FALSE);
365 return (const gchar * const *) device->priv->device_file_symlinks;
368 /* ---------------------------------------------------------------------------------------------------- */
371 * g_udev_device_get_parent:
372 * @device: A #GUdevDevice.
374 * Gets the immediate parent of @device, if any.
376 * Returns: (transfer full): A #GUdevDevice or %NULL if @device has no parent. Free with g_object_unref().
379 g_udev_device_get_parent (GUdevDevice *device)
382 struct udev_device *udevice;
384 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
388 udevice = udev_device_get_parent (device->priv->udevice);
392 ret = _g_udev_device_new (udevice);
399 * g_udev_device_get_parent_with_subsystem:
400 * @device: A #GUdevDevice.
401 * @subsystem: The subsystem of the parent to get.
402 * @devtype: (allow-none): The devtype of the parent to get or %NULL.
404 * Walks up the chain of parents of @device and returns the first
405 * device encountered where @subsystem and @devtype matches, if any.
407 * Returns: (transfer full): A #GUdevDevice or %NULL if @device has no parent with @subsystem and @devtype. Free with g_object_unref().
410 g_udev_device_get_parent_with_subsystem (GUdevDevice *device,
411 const gchar *subsystem,
412 const gchar *devtype)
415 struct udev_device *udevice;
417 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
418 g_return_val_if_fail (subsystem != NULL, NULL);
422 udevice = udev_device_get_parent_with_subsystem_devtype (device->priv->udevice,
428 ret = _g_udev_device_new (udevice);
434 /* ---------------------------------------------------------------------------------------------------- */
437 * g_udev_device_get_property_keys:
438 * @device: A #GUdevDevice.
440 * Gets all keys for properties on @device.
442 * Returns: (transfer none) (array zero-terminated=1) (element-type utf8): A %NULL terminated string array of property keys. This array is owned by @device and should not be freed by the caller.
445 g_udev_device_get_property_keys (GUdevDevice *device)
447 struct udev_list_entry *l;
450 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
452 if (device->priv->property_keys != NULL)
455 p = g_ptr_array_new ();
456 for (l = udev_device_get_properties_list_entry (device->priv->udevice); l != NULL; l = udev_list_entry_get_next (l))
458 g_ptr_array_add (p, g_strdup (udev_list_entry_get_name (l)));
460 g_ptr_array_add (p, NULL);
461 device->priv->property_keys = (gchar **) g_ptr_array_free (p, FALSE);
464 return (const gchar * const *) device->priv->property_keys;
469 * g_udev_device_has_property:
470 * @device: A #GUdevDevice.
471 * @key: Name of property.
473 * Check if a the property with the given key exists.
475 * Returns: %TRUE only if the value for @key exist.
478 g_udev_device_has_property (GUdevDevice *device,
481 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), FALSE);
482 g_return_val_if_fail (key != NULL, FALSE);
483 return udev_device_get_property_value (device->priv->udevice, key) != NULL;
487 * g_udev_device_get_property:
488 * @device: A #GUdevDevice.
489 * @key: Name of property.
491 * Look up the value for @key on @device.
493 * Returns: The value for @key or %NULL if @key doesn't exist on @device. Do not free this string, it is owned by @device.
496 g_udev_device_get_property (GUdevDevice *device,
499 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
500 g_return_val_if_fail (key != NULL, NULL);
501 return udev_device_get_property_value (device->priv->udevice, key);
505 * g_udev_device_get_property_as_int:
506 * @device: A #GUdevDevice.
507 * @key: Name of property.
509 * Look up the value for @key on @device and convert it to an integer
512 * Returns: The value for @key or 0 if @key doesn't exist or
516 g_udev_device_get_property_as_int (GUdevDevice *device,
522 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), 0);
523 g_return_val_if_fail (key != NULL, 0);
526 s = g_udev_device_get_property (device, key);
530 result = strtol (s, NULL, 0);
536 * g_udev_device_get_property_as_uint64:
537 * @device: A #GUdevDevice.
538 * @key: Name of property.
540 * Look up the value for @key on @device and convert it to an unsigned
541 * 64-bit integer using g_ascii_strtoull().
543 * Returns: The value for @key or 0 if @key doesn't exist or isn't a
547 g_udev_device_get_property_as_uint64 (GUdevDevice *device,
553 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), 0);
554 g_return_val_if_fail (key != NULL, 0);
557 s = g_udev_device_get_property (device, key);
561 result = g_ascii_strtoull (s, NULL, 0);
567 * g_udev_device_get_property_as_double:
568 * @device: A #GUdevDevice.
569 * @key: Name of property.
571 * Look up the value for @key on @device and convert it to a double
572 * precision floating point number using strtod().
574 * Returns: The value for @key or 0.0 if @key doesn't exist or isn't a
578 g_udev_device_get_property_as_double (GUdevDevice *device,
584 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), 0.0);
585 g_return_val_if_fail (key != NULL, 0.0);
588 s = g_udev_device_get_property (device, key);
592 result = strtod (s, NULL);
598 * g_udev_device_get_property_as_boolean:
599 * @device: A #GUdevDevice.
600 * @key: Name of property.
602 * Look up the value for @key on @device and convert it to an
603 * boolean. This is done by doing a case-insensitive string comparison
604 * on the string value against "1" and "true".
606 * Returns: The value for @key or %FALSE if @key doesn't exist or
610 g_udev_device_get_property_as_boolean (GUdevDevice *device,
616 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), FALSE);
617 g_return_val_if_fail (key != NULL, FALSE);
620 s = g_udev_device_get_property (device, key);
624 if (strcmp (s, "1") == 0 || g_ascii_strcasecmp (s, "true") == 0)
631 split_at_whitespace (const gchar *s)
637 result = g_strsplit_set (s, " \v\t\r\n", 0);
639 /* remove empty strings, thanks GLib */
640 for (n = 0; result[n] != NULL; n++)
642 if (strlen (result[n]) == 0)
645 for (m = n; result[m] != NULL; m++)
646 result[m] = result[m + 1];
655 * g_udev_device_get_property_as_strv:
656 * @device: A #GUdevDevice.
657 * @key: Name of property.
659 * Look up the value for @key on @device and return the result of
660 * splitting it into non-empty tokens split at white space (only space
661 * (' '), form-feed ('\f'), newline ('\n'), carriage return ('\r'),
662 * horizontal tab ('\t'), and vertical tab ('\v') are considered; the
663 * locale is not taken into account).
665 * Returns: (transfer none) (array zero-terminated=1) (element-type utf8): The value of @key on @device split into tokens or %NULL if @key doesn't exist. This array is owned by @device and should not be freed by the caller.
668 g_udev_device_get_property_as_strv (GUdevDevice *device,
674 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
675 g_return_val_if_fail (key != NULL, NULL);
677 if (device->priv->prop_strvs != NULL)
679 result = g_hash_table_lookup (device->priv->prop_strvs, key);
685 s = g_udev_device_get_property (device, key);
689 result = split_at_whitespace (s);
693 if (device->priv->prop_strvs == NULL)
694 device->priv->prop_strvs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_strfreev);
695 g_hash_table_insert (device->priv->prop_strvs, g_strdup (key), result);
698 return (const gchar* const *) result;
701 /* ---------------------------------------------------------------------------------------------------- */
704 * g_udev_device_get_sysfs_attr:
705 * @device: A #GUdevDevice.
706 * @name: Name of the sysfs attribute.
708 * Look up the sysfs attribute with @name on @device.
710 * Returns: The value of the sysfs attribute or %NULL if there is no
711 * such attribute. Do not free this string, it is owned by @device.
714 g_udev_device_get_sysfs_attr (GUdevDevice *device,
717 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
718 g_return_val_if_fail (name != NULL, NULL);
719 return udev_device_get_sysattr_value (device->priv->udevice, name);
723 * g_udev_device_get_sysfs_attr_as_int:
724 * @device: A #GUdevDevice.
725 * @name: Name of the sysfs attribute.
727 * Look up the sysfs attribute with @name on @device and convert it to an integer
730 * Returns: The value of the sysfs attribute or 0 if there is no such
734 g_udev_device_get_sysfs_attr_as_int (GUdevDevice *device,
740 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), 0);
741 g_return_val_if_fail (name != NULL, 0);
744 s = g_udev_device_get_sysfs_attr (device, name);
748 result = strtol (s, NULL, 0);
754 * g_udev_device_get_sysfs_attr_as_uint64:
755 * @device: A #GUdevDevice.
756 * @name: Name of the sysfs attribute.
758 * Look up the sysfs attribute with @name on @device and convert it to an unsigned
759 * 64-bit integer using g_ascii_strtoull().
761 * Returns: The value of the sysfs attribute or 0 if there is no such
765 g_udev_device_get_sysfs_attr_as_uint64 (GUdevDevice *device,
771 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), 0);
772 g_return_val_if_fail (name != NULL, 0);
775 s = g_udev_device_get_sysfs_attr (device, name);
779 result = g_ascii_strtoull (s, NULL, 0);
785 * g_udev_device_get_sysfs_attr_as_double:
786 * @device: A #GUdevDevice.
787 * @name: Name of the sysfs attribute.
789 * Look up the sysfs attribute with @name on @device and convert it to a double
790 * precision floating point number using strtod().
792 * Returns: The value of the sysfs attribute or 0.0 if there is no such
796 g_udev_device_get_sysfs_attr_as_double (GUdevDevice *device,
802 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), 0.0);
803 g_return_val_if_fail (name != NULL, 0.0);
806 s = g_udev_device_get_sysfs_attr (device, name);
810 result = strtod (s, NULL);
816 * g_udev_device_get_sysfs_attr_as_boolean:
817 * @device: A #GUdevDevice.
818 * @name: Name of the sysfs attribute.
820 * Look up the sysfs attribute with @name on @device and convert it to an
821 * boolean. This is done by doing a case-insensitive string comparison
822 * on the string value against "1" and "true".
824 * Returns: The value of the sysfs attribute or %FALSE if there is no such
828 g_udev_device_get_sysfs_attr_as_boolean (GUdevDevice *device,
834 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), FALSE);
835 g_return_val_if_fail (name != NULL, FALSE);
838 s = g_udev_device_get_sysfs_attr (device, name);
842 if (strcmp (s, "1") == 0 || g_ascii_strcasecmp (s, "true") == 0)
849 * g_udev_device_get_sysfs_attr_as_strv:
850 * @device: A #GUdevDevice.
851 * @name: Name of the sysfs attribute.
853 * Look up the sysfs attribute with @name on @device and return the result of
854 * splitting it into non-empty tokens split at white space (only space (' '),
855 * form-feed ('\f'), newline ('\n'), carriage return ('\r'), horizontal
856 * tab ('\t'), and vertical tab ('\v') are considered; the locale is
857 * not taken into account).
859 * Returns: (transfer none) (array zero-terminated=1) (element-type utf8): The value of the sysfs attribute split into tokens or %NULL if there is no such attribute. This array is owned by @device and should not be freed by the caller.
861 const gchar * const *
862 g_udev_device_get_sysfs_attr_as_strv (GUdevDevice *device,
868 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
869 g_return_val_if_fail (name != NULL, NULL);
871 if (device->priv->sysfs_attr_strvs != NULL)
873 result = g_hash_table_lookup (device->priv->sysfs_attr_strvs, name);
879 s = g_udev_device_get_sysfs_attr (device, name);
883 result = split_at_whitespace (s);
887 if (device->priv->sysfs_attr_strvs == NULL)
888 device->priv->sysfs_attr_strvs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_strfreev);
889 g_hash_table_insert (device->priv->sysfs_attr_strvs, g_strdup (name), result);
892 return (const gchar* const *) result;
896 * g_udev_device_get_tags:
897 * @device: A #GUdevDevice.
899 * Gets all tags for @device.
901 * Returns: (transfer none) (array zero-terminated=1) (element-type utf8): A %NULL terminated string array of tags. This array is owned by @device and should not be freed by the caller.
906 g_udev_device_get_tags (GUdevDevice *device)
908 struct udev_list_entry *l;
911 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
913 if (device->priv->tags != NULL)
916 p = g_ptr_array_new ();
917 for (l = udev_device_get_tags_list_entry (device->priv->udevice); l != NULL; l = udev_list_entry_get_next (l))
919 g_ptr_array_add (p, g_strdup (udev_list_entry_get_name (l)));
921 g_ptr_array_add (p, NULL);
922 device->priv->tags = (gchar **) g_ptr_array_free (p, FALSE);
925 return (const gchar * const *) device->priv->tags;
929 * g_udev_device_get_is_initialized:
930 * @device: A #GUdevDevice.
932 * Gets whether @device has been initalized.
934 * Returns: Whether @device has been initialized.
939 g_udev_device_get_is_initialized (GUdevDevice *device)
941 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), FALSE);
942 return udev_device_get_is_initialized (device->priv->udevice);
946 * g_udev_device_get_usec_since_initialized:
947 * @device: A #GUdevDevice.
949 * Gets number of micro-seconds since @device was initialized.
951 * This only works for devices with properties in the udev
952 * database. All other devices return 0.
954 * Returns: Number of micro-seconds since @device was initialized or 0 if unknown.
959 g_udev_device_get_usec_since_initialized (GUdevDevice *device)
961 g_return_val_if_fail (G_UDEV_IS_DEVICE (device), 0);
962 return udev_device_get_usec_since_initialized (device->priv->udevice);