2 * Copyright (C) 2010-2014 jeanfi@gmail.com
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 #define _(str) gettext(str)
25 #include <udisks/udisks.h>
28 #include <temperature.h>
30 const char *PROVIDER_NAME = "udisks2";
32 static GDBusObjectManager *manager;
34 static void udisks2_err(const char *msg)
36 log_err("%s: %s", PROVIDER_NAME, msg);
39 void udisks2_psensor_list_update(struct psensor **sensors)
43 UDisksDriveAta *drive_ata;
49 if (s->type & SENSOR_TYPE_UDISKS2) {
50 o = g_dbus_object_manager_get_object(manager,
56 g_object_get(o, "drive-ata", &drive_ata, NULL);
58 v = udisks_drive_ata_get_smart_temperature(drive_ata);
60 psensor_set_current_value(s, kelvin_to_celsius(v));
62 g_object_unref(G_OBJECT(o));
69 void udisks2_psensor_list_add(struct psensor ***sensors, int values_length)
74 UDisksDriveAta *drive_ata;
76 char *id, *name, *chip;
77 const char *path, *drive_id, *drive_model;
82 client = udisks_client_new_sync(NULL, NULL);
85 udisks2_err(_("Cannot get the udisks2 client"));
90 manager = udisks_client_get_object_manager(client);
92 objects = g_dbus_object_manager_get_objects(manager);
95 for (cur = objects; cur; cur = cur->next) {
96 path = g_dbus_object_get_object_path(cur->data);
98 g_object_get(cur->data,
100 "drive-ata", &drive_ata,
104 log_fct("Not a drive: %s", path);
109 log_fct("Not an ATA drive: %s", path);
113 if (!udisks_drive_ata_get_smart_enabled(drive_ata)) {
114 log_fct("SMART not enabled: %s", path);
118 if (!udisks_drive_ata_get_smart_temperature(drive_ata)) {
119 log_fct("No temperature available: %s", path);
123 drive_id = udisks_drive_get_id(drive);
125 id = g_strdup_printf("%s %s", PROVIDER_NAME, drive_id);
127 id = g_strdup_printf("%s %d", PROVIDER_NAME, i);
131 drive_model = udisks_drive_get_model(drive);
133 name = strdup(drive_model);
134 chip = strdup(drive_model);
136 name = strdup(_("Disk"));
137 chip = strdup(_("Disk"));
140 type = SENSOR_TYPE_TEMP | SENSOR_TYPE_UDISKS2 | SENSOR_TYPE_HDD;
142 s = psensor_create(id, name, chip, type, values_length);
143 s->udisks2_path = strdup(path);
145 psensor_list_append(sensors, s);
147 g_object_unref(G_OBJECT(cur->data));
150 g_list_free(objects);