From 15d844f17741d30f4f1bc3154c6d74c9a6c5a3b2 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Tue, 16 Sep 2014 01:03:19 +0200 Subject: [PATCH] added udisks2 support --- NEWS.html | 9 +++- src/lib/pudisks2.c | 153 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/lib/pudisks2.h | 27 ++++++++++ src/main.c | 3 ++ 4 files changed, 190 insertions(+), 2 deletions(-) create mode 100644 src/lib/pudisks2.c create mode 100644 src/lib/pudisks2.h diff --git a/NEWS.html b/NEWS.html index a3c7879..a1ac9ca 100644 --- a/NEWS.html +++ b/NEWS.html @@ -454,7 +454,7 @@ Added translator credits in the about dialog.
  • -Added Crotian translation from LP (gogo). +Added Croatian translation from LP (gogo).

  • @@ -468,6 +468,11 @@ Included the full list of contributors from LP, available throw the about dialog.

  • +
  • +

    +Support of disk temperature using udisks2. +

    +
  • @@ -2820,7 +2825,7 @@ Fixed BR1: crash when no temperature sensor is available

    diff --git a/src/lib/pudisks2.c b/src/lib/pudisks2.c new file mode 100644 index 0000000..d4f4492 --- /dev/null +++ b/src/lib/pudisks2.c @@ -0,0 +1,153 @@ +/* + * Copyright (C) 2010-2014 jeanfi@gmail.com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#include +#include +#define _(str) gettext(str) + +#include + +#include + +#include +#include + +const char *PROVIDER_NAME = "udisks2"; + +static GDBusObjectManager *manager; + +static void udisks2_err(const char *msg) +{ + log_err("%s: %s", PROVIDER_NAME, msg); +} + +void udisks2_psensor_list_update(struct psensor **sensors) +{ + struct psensor *s; + GDBusObject *o; + UDisksDriveAta *drive_ata; + double v; + + while (*sensors) { + s = *sensors; + + if (s->type & SENSOR_TYPE_UDISKS2) { + o = g_dbus_object_manager_get_object(manager, + s->udisks2_path); + + if (!o) + continue; + + g_object_get(o, "drive-ata", &drive_ata, NULL); + + v = udisks_drive_ata_get_smart_temperature(drive_ata); + + psensor_set_current_value(s, kelvin_to_celsius(v)); + + g_object_unref(G_OBJECT(o)); + } + + sensors++; + } +} + +void udisks2_psensor_list_add(struct psensor ***sensors, int values_length) +{ + UDisksClient *client; + GList *objects, *cur; + UDisksDrive *drive; + UDisksDriveAta *drive_ata; + int i, type; + char *id, *name, *chip; + const char *path, *drive_id, *drive_model; + struct psensor *s; + + log_fct_enter(); + + client = udisks_client_new_sync(NULL, NULL); + + if (!client) { + udisks2_err(_("Cannot get the udisks2 client")); + log_fct_exit(); + return; + } + + manager = udisks_client_get_object_manager(client); + + objects = g_dbus_object_manager_get_objects(manager); + + i = 0; + for (cur = objects; cur; cur = cur->next) { + path = g_dbus_object_get_object_path(cur->data); + + g_object_get(cur->data, + "drive", &drive, + "drive-ata", &drive_ata, + NULL); + + if (!drive) { + log_fct("Not a drive: %s", path); + continue; + } + + if (!drive_ata) { + log_fct("Not an ATA drive: %s", path); + continue; + } + + if (!udisks_drive_ata_get_smart_enabled(drive_ata)) { + log_fct("SMART not enabled: %s", path); + continue; + } + + if (!udisks_drive_ata_get_smart_temperature(drive_ata)) { + log_fct("No temperature available: %s", path); + continue; + } + + drive_id = udisks_drive_get_id(drive); + if (drive_id) { + id = g_strdup_printf("%s %s", PROVIDER_NAME, drive_id); + } else { + id = g_strdup_printf("%s %d", PROVIDER_NAME, i); + i++; + } + + drive_model = udisks_drive_get_model(drive); + if (drive_model) { + name = strdup(drive_model); + chip = strdup(drive_model); + } else { + name = strdup(_("Disk")); + chip = strdup(_("Disk")); + } + + type = SENSOR_TYPE_TEMP | SENSOR_TYPE_UDISKS2 | SENSOR_TYPE_HDD; + + s = psensor_create(id, name, chip, type, values_length); + s->udisks2_path = strdup(path); + + psensor_list_append(sensors, s); + + g_object_unref(G_OBJECT(cur->data)); + } + + g_list_free(objects); + + log_fct_exit(); +} diff --git a/src/lib/pudisks2.h b/src/lib/pudisks2.h new file mode 100644 index 0000000..8ff1854 --- /dev/null +++ b/src/lib/pudisks2.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2010-2014 jeanfi@gmail.com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#ifndef _PSENSOR_UDISKS2_H_ +#define _PSENSOR_UDISKS2_H_ + +#include + +void udisks2_psensor_list_add(struct psensor ***sensors, int values_length); +void udisks2_psensor_list_update(struct psensor **sensors); + +#endif diff --git a/src/main.c b/src/main.c index 50c1bac..65549fb 100644 --- a/src/main.c +++ b/src/main.c @@ -166,6 +166,9 @@ static void *update_measures(void *data) #ifdef HAVE_LIBATIADL amd_psensor_list_update(sensors); #endif +#ifdef HAVE_LIBUDISKS2 + udisks2_psensor_list_update(sensors); +#endif psensor_log_measures(sensors); -- 2.7.4