added udisks2 support
authorJean-Philippe Orsini <jeanfi@gmail.com>
Mon, 15 Sep 2014 23:03:19 +0000 (01:03 +0200)
committerJean-Philippe Orsini <jeanfi@gmail.com>
Mon, 15 Sep 2014 23:03:19 +0000 (01:03 +0200)
NEWS.html
src/lib/pudisks2.c [new file with mode: 0644]
src/lib/pudisks2.h [new file with mode: 0644]
src/main.c

index a3c7879..a1ac9ca 100644 (file)
--- a/NEWS.html
+++ b/NEWS.html
@@ -454,7 +454,7 @@ Added translator credits in the about dialog.
 </li>\r
 <li>\r
 <p>\r
-Added Crotian translation from LP (gogo).\r
+Added Croatian translation from LP (gogo).\r
 </p>\r
 </li>\r
 <li>\r
@@ -468,6 +468,11 @@ Included the full list of contributors from LP, available throw the
   about dialog.\r
 </p>\r
 </li>\r
+<li>\r
+<p>\r
+Support of disk temperature using udisks2.\r
+</p>\r
+</li>\r
 </ul></div>\r
 </div>\r
 </div>\r
@@ -2820,7 +2825,7 @@ Fixed BR1: crash when no temperature sensor is available
 <div id="footnotes"><hr /></div>\r
 <div id="footer">\r
 <div id="footer-text">\r
-Last updated 2014-09-11 20:10:44 CEST\r
+Last updated 2014-09-15 22:18:30 CEST\r
 </div>\r
 </div>\r
 </body>\r
diff --git a/src/lib/pudisks2.c b/src/lib/pudisks2.c
new file mode 100644 (file)
index 0000000..d4f4492
--- /dev/null
@@ -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 <locale.h>
+#include <libintl.h>
+#define _(str) gettext(str)
+
+#include <string.h>
+
+#include <udisks/udisks.h>
+
+#include <pudisks2.h>
+#include <temperature.h>
+
+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 (file)
index 0000000..8ff1854
--- /dev/null
@@ -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 <psensor.h>
+
+void udisks2_psensor_list_add(struct psensor ***sensors, int values_length);
+void udisks2_psensor_list_update(struct psensor **sensors);
+
+#endif
index 50c1bac..65549fb 100644 (file)
@@ -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);