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 void udisks2_psensor_list_update(struct psensor **sensors)
38 UDisksDriveAta *drive_ata;
42 for (; *sensors; sensors++) {
45 if (s->type & SENSOR_TYPE_UDISKS2) {
46 o = g_dbus_object_manager_get_object(manager,
52 g_object_get(o, "drive-ata", &drive_ata, NULL);
54 variant = g_variant_new_parsed
56 g_variant_new_boolean(TRUE));
58 udisks_drive_ata_call_smart_update_sync(drive_ata,
63 v = udisks_drive_ata_get_smart_temperature(drive_ata);
65 psensor_set_current_value(s, kelvin_to_celsius(v));
67 g_object_unref(G_OBJECT(o));
72 void udisks2_psensor_list_add(struct psensor ***sensors, int values_length)
77 UDisksDriveAta *drive_ata;
79 char *id, *name, *chip;
80 const char *path, *drive_id, *drive_model;
85 client = udisks_client_new_sync(NULL, NULL);
88 log_err(_("%s: cannot get the udisks2 client"), PROVIDER_NAME);
93 manager = udisks_client_get_object_manager(client);
95 objects = g_dbus_object_manager_get_objects(manager);
98 for (cur = objects; cur; cur = cur->next) {
99 path = g_dbus_object_get_object_path(cur->data);
101 g_object_get(cur->data,
103 "drive-ata", &drive_ata,
107 log_fct("Not a drive: %s", path);
112 log_fct("Not an ATA drive: %s", path);
116 if (!udisks_drive_ata_get_smart_enabled(drive_ata)) {
117 log_fct("SMART not enabled: %s", path);
121 if (!udisks_drive_ata_get_smart_temperature(drive_ata)) {
122 log_fct("No temperature available: %s", path);
126 drive_id = udisks_drive_get_id(drive);
128 id = g_strdup_printf("%s %s", PROVIDER_NAME, drive_id);
130 id = g_strdup_printf("%s %d", PROVIDER_NAME, i);
134 drive_model = udisks_drive_get_model(drive);
136 name = strdup(drive_model);
137 chip = strdup(drive_model);
139 name = strdup(_("Disk"));
140 chip = strdup(_("Disk"));
143 type = SENSOR_TYPE_TEMP | SENSOR_TYPE_UDISKS2 | SENSOR_TYPE_HDD;
145 s = psensor_create(id, name, chip, type, values_length);
146 s->udisks2_path = strdup(path);
148 psensor_list_append(sensors, s);
150 g_object_unref(G_OBJECT(cur->data));
153 g_list_free(objects);