From 62b4d84cca7520ec939c8d3d13c6486f87eb4b77 Mon Sep 17 00:00:00 2001 From: David Zeuthen Date: Wed, 15 Apr 2009 11:16:58 -0400 Subject: [PATCH] add property device-detection-time --- src/devkit-disks-device-private.h | 1 + src/devkit-disks-device.c | 15 +++++++++++++++ src/org.freedesktop.DeviceKit.Disks.Device.xml | 6 ++++++ tools/devkit-disks.c | 14 +++++++++++--- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/devkit-disks-device-private.h b/src/devkit-disks-device-private.h index 2135ae1..a5ef43d 100644 --- a/src/devkit-disks-device-private.h +++ b/src/devkit-disks-device-private.h @@ -73,6 +73,7 @@ struct DevkitDisksDevicePrivate char *object_path; char *native_path; + guint64 device_detection_time; gboolean removed; diff --git a/src/devkit-disks-device.c b/src/devkit-disks-device.c index 873c3d9..fcd89b0 100644 --- a/src/devkit-disks-device.c +++ b/src/devkit-disks-device.c @@ -135,6 +135,7 @@ enum PROP_0, PROP_NATIVE_PATH, + PROP_DEVICE_DETECTION_TIME, PROP_DEVICE_MAJOR, PROP_DEVICE_MINOR, PROP_DEVICE_FILE, @@ -300,6 +301,9 @@ get_property (GObject *object, g_value_set_string (value, device->priv->native_path); break; + case PROP_DEVICE_DETECTION_TIME: + g_value_set_uint64 (value, device->priv->device_detection_time); + break; case PROP_DEVICE_MAJOR: g_value_set_int64 (value, major (device->priv->dev)); break; @@ -700,6 +704,10 @@ devkit_disks_device_class_init (DevkitDisksDeviceClass *klass) g_param_spec_string ("native-path", NULL, NULL, NULL, G_PARAM_READABLE)); g_object_class_install_property ( object_class, + PROP_DEVICE_DETECTION_TIME, + g_param_spec_uint64 ("device-detection-time", NULL, NULL, 0, G_MAXUINT64, 0, G_PARAM_READABLE)); + g_object_class_install_property ( + object_class, PROP_DEVICE_MAJOR, g_param_spec_int64 ("device-major", NULL, NULL, -G_MAXINT64, G_MAXINT64, 0, G_PARAM_READABLE)); g_object_class_install_property ( @@ -3404,6 +3412,13 @@ devkit_disks_device_new (DevkitDisksDaemon *daemon, DevkitDevice *d) device->priv->d = g_object_ref (d); device->priv->daemon = g_object_ref (daemon); device->priv->native_path = g_strdup (native_path); + + /* TODO: we might want to get this from udev or the kernel... to get the time when the device + * was initially detected... as opposed to this value which is when the device was detected + * by our daemon... but this will do for now... + */ + device->priv->device_detection_time = (guint64) time (NULL); + if (!update_info (device)) { g_object_unref (device); device = NULL; diff --git a/src/org.freedesktop.DeviceKit.Disks.Device.xml b/src/org.freedesktop.DeviceKit.Disks.Device.xml index 6fb05ee..b4f6237 100644 --- a/src/org.freedesktop.DeviceKit.Disks.Device.xml +++ b/src/org.freedesktop.DeviceKit.Disks.Device.xml @@ -1213,6 +1213,12 @@ OS specific native path of the device. On Linux this is the sysfs path, for example /sys/devices/pci0000:00/0000:00:1f.2/host2/target2:0:1/2:0:1:0/block/sda. + + + The point in time (seconds since the Epoch Jan 1, 1970 0:00 UTC) when the device + was detected by the daemon. + + Major for the device or -1 if not set. diff --git a/tools/devkit-disks.c b/tools/devkit-disks.c index e76094b..5e73a1c 100644 --- a/tools/devkit-disks.c +++ b/tools/devkit-disks.c @@ -363,6 +363,7 @@ typedef struct { char *native_path; + guint64 device_detection_time; gint64 device_major; gint64 device_minor; char *device_file; @@ -493,6 +494,8 @@ collect_props (const char *key, const GValue *value, DeviceProperties *props) if (strcmp (key, "native-path") == 0) props->native_path = g_strdup (g_value_get_string (value)); + else if (strcmp (key, "device-detection-time") == 0) + props->device_detection_time = g_value_get_uint64 (value); else if (strcmp (key, "device-major") == 0) props->device_major = g_value_get_int64 (value); else if (strcmp (key, "device-minor") == 0) @@ -989,11 +992,18 @@ do_show_info (const char *object_path) guint n; guint m; DeviceProperties *props; + struct tm *time_tm; + time_t time; + char time_buf[256]; props = device_properties_get (bus, object_path); if (props == NULL) return; + time = (time_t) props->device_detection_time; + time_tm = localtime (&time); + strftime (time_buf, sizeof time_buf, "%c", time_tm); + g_print ("Showing information for %s\n", object_path); g_print (" native-path: %s\n", props->native_path); g_print (" device: %" G_GINT64_MODIFIER "d:%" G_GINT64_MODIFIER "d\n", @@ -1004,6 +1014,7 @@ do_show_info (const char *object_path) g_print (" by-id: %s\n", (char *) props->device_file_by_id[n]); for (n = 0; props->device_file_by_path[n] != NULL; n++) g_print (" by-path: %s\n", (char *) props->device_file_by_path[n]); + g_print (" detected at: %s\n", time_buf); g_print (" system internal: %d\n", props->device_is_system_internal); g_print (" removable: %d\n", props->device_is_removable); g_print (" has media: %d\n", props->device_is_media_available); @@ -1143,9 +1154,6 @@ do_show_info (const char *object_path) } else if (props->drive_ata_smart_time_collected == 0) { g_print (" ATA SMART: Data not collected\n"); } else { - struct tm *time_tm; - time_t time; - char time_buf[256]; GPtrArray *p; time = (time_t) props->drive_ata_smart_time_collected; -- 2.7.4