summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/acpi/acpi-plugin.c149
-rw-r--r--plugins/aticonfig/aticonfig-plugin.c145
-rw-r--r--plugins/eee/eee-plugin.c112
-rw-r--r--plugins/hddtemp/hddtemp-plugin.c338
4 files changed, 367 insertions, 377 deletions
diff --git a/plugins/acpi/acpi-plugin.c b/plugins/acpi/acpi-plugin.c
index 16749e2..93ee53e 100644
--- a/plugins/acpi/acpi-plugin.c
+++ b/plugins/acpi/acpi-plugin.c
@@ -34,104 +34,97 @@ const gchar *plugin_name = "acpi";
#define ACPI_THERMAL_BASE_DIR "/proc/acpi/thermal"
enum {
- ACPI_DEVICE_FILE_OPEN_ERROR,
- ACPI_DEVICE_FILE_READ_ERROR
+ ACPI_DEVICE_FILE_OPEN_ERROR,
+ ACPI_DEVICE_FILE_READ_ERROR
};
static void acpi_plugin_add_sensor(GList **sensors, const gchar *path) {
- gchar *dirname;
- gchar *id;
- gchar *label;
-
-
- dirname = g_path_get_dirname(path);
- id = g_path_get_basename(dirname);
- g_free(dirname);
-
- sensors_applet_plugin_add_sensor(sensors,
- path,
- id,
- _("CPU"),
- TEMP_SENSOR,
- TRUE,
- CPU_ICON,
- DEFAULT_GRAPH_COLOR);
- g_free(id);
-}
-
-static void acpi_plugin_test_sensor(GList **sensors,
- const gchar *path) {
- gchar *filename;
-
- filename = g_path_get_basename(path);
-
- if (g_ascii_strcasecmp(filename, "temperature") == 0 ||
- g_ascii_strcasecmp(filename, "status") == 0) {
- acpi_plugin_add_sensor(sensors, path);
-
- }
- g_free(filename);
-
+ gchar *dirname;
+ gchar *id;
+ gchar *label;
+
+
+ dirname = g_path_get_dirname(path);
+ id = g_path_get_basename(dirname);
+ g_free(dirname);
+
+ sensors_applet_plugin_add_sensor(sensors,
+ path,
+ id,
+ _("CPU"),
+ TEMP_SENSOR,
+ TRUE,
+ CPU_ICON,
+ DEFAULT_GRAPH_COLOR);
+ g_free(id);
}
+static void acpi_plugin_test_sensor(GList **sensors, const gchar *path) {
+ gchar *filename;
+ filename = g_path_get_basename(path);
+ if (g_ascii_strcasecmp(filename, "temperature") == 0 ||
+ g_ascii_strcasecmp(filename, "status") == 0) {
+ acpi_plugin_add_sensor(sensors, path);
+ }
+ g_free(filename);
+}
-/* to be called to setup for acpi sensors and returns the list of found
- * sensors */
+/* to be called to setup for acpi sensors and returns the list of found sensors */
static GList *acpi_plugin_init(void) {
- GList *sensors = NULL;
-
- /* call function to recursively look for sensors
- starting at the defined base directory */
- sensors_applet_plugin_find_sensors(&sensors, ACPI_THERMAL_ZONE_BASE_DIR, acpi_plugin_test_sensor);
- sensors_applet_plugin_find_sensors(&sensors, ACPI_THERMAL_BASE_DIR, acpi_plugin_test_sensor);
- return sensors;
-}
+ GList *sensors = NULL;
+ /* call function to recursively look for sensors
+ starting at the defined base directory */
+ sensors_applet_plugin_find_sensors(&sensors, ACPI_THERMAL_ZONE_BASE_DIR, acpi_plugin_test_sensor);
+ sensors_applet_plugin_find_sensors(&sensors, ACPI_THERMAL_BASE_DIR, acpi_plugin_test_sensor);
+ return sensors;
+}
-static gdouble acpi_plugin_get_sensor_value(const gchar *path,
- const gchar *id,
+static gdouble acpi_plugin_get_sensor_value(const gchar *path,
+ const gchar *id,
SensorType type,
GError **error) {
-
- /* to open and access the value of each sensor */
- FILE *fp;
- gfloat sensor_value = -1.0f;
- gchar units[32];
-
- if (NULL == (fp = fopen(path, "r"))) {
- g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, ACPI_DEVICE_FILE_OPEN_ERROR, "Error opening sensor device file %s", path);
- return sensor_value;
- }
-
- if (fscanf(fp, "temperature: %f %31s", &sensor_value, units) < 1) {
- g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, ACPI_DEVICE_FILE_READ_ERROR, "Error reading from sensor device file %s", path);
- fclose(fp);
- return sensor_value;
- }
- fclose(fp);
-
- /* need to convert if units are deciKelvin */
- if (g_ascii_strcasecmp(units, "dK") == 0) {
- sensor_value = (sensor_value / 10.0) - 273.0;
- }
-
- return (gdouble)sensor_value;
+
+ /* to open and access the value of each sensor */
+ FILE *fp;
+ gfloat sensor_value = -1.0f;
+ gchar units[32];
+
+ if (NULL == (fp = fopen(path, "r"))) {
+ g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, ACPI_DEVICE_FILE_OPEN_ERROR, "Error opening sensor device file %s", path);
+ return sensor_value;
+ }
+
+ if (fscanf(fp, "temperature: %f %31s", &sensor_value, units) < 1) {
+ g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, ACPI_DEVICE_FILE_READ_ERROR, "Error reading from sensor device file %s", path);
+ fclose(fp);
+ return sensor_value;
+ }
+ fclose(fp);
+
+ /* need to convert if units are deciKelvin */
+ if (g_ascii_strcasecmp(units, "dK") == 0) {
+ sensor_value = (sensor_value / 10.0) - 273.0;
+ }
+
+ return (gdouble)sensor_value;
}
-const gchar *sensors_applet_plugin_name(void)
+const gchar *sensors_applet_plugin_name(void)
{
- return plugin_name;
+ return plugin_name;
}
-GList *sensors_applet_plugin_init(void)
+GList *sensors_applet_plugin_init(void)
{
- return acpi_plugin_init();
+ return acpi_plugin_init();
}
-gdouble sensors_applet_plugin_get_sensor_value(const gchar *path,
- const gchar *id,
+gdouble sensors_applet_plugin_get_sensor_value(const gchar *path,
+ const gchar *id,
SensorType type,
GError **error) {
- return acpi_plugin_get_sensor_value(path, id, type, error);
+
+ return acpi_plugin_get_sensor_value(path, id, type, error);
}
diff --git a/plugins/aticonfig/aticonfig-plugin.c b/plugins/aticonfig/aticonfig-plugin.c
index 9d6f554..d716065 100644
--- a/plugins/aticonfig/aticonfig-plugin.c
+++ b/plugins/aticonfig/aticonfig-plugin.c
@@ -47,106 +47,109 @@ static int num_gpus = 0;
static int ati_get_temps(gdouble temps[], int max_temps)
{
- double temp;
- int read_count;
- int gpu_no = 0;
+ double temp;
+ int read_count;
+ int gpu_no = 0;
+
#ifdef HAVE_STDIO_H
- FILE *aticonfig = popen(ATICONFIG_EXE
+ FILE *aticonfig = popen(ATICONFIG_EXE
" --adapter=all --od-gettemperature", "r");
- if (aticonfig == NULL) {
- return 0;
- }
- while ((read_count = fscanf(aticonfig, "Temperature - %lf", &temp)) != EOF) {
- if (read_count < 1) {
- getc(aticonfig);
- }
- else {
- temps[gpu_no] = (gdouble)temp;
- if (++gpu_no >= max_temps)
- break;
+ if (aticonfig == NULL) {
+ return 0;
+ }
+ while ((read_count = fscanf(aticonfig, "Temperature - %lf", &temp)) != EOF) {
+ if (read_count < 1) {
+ getc(aticonfig);
+ }
+ else {
+ temps[gpu_no] = (gdouble)temp;
+ if (++gpu_no >= max_temps)
+ break;
+ }
}
- }
- pclose(aticonfig);
+ pclose(aticonfig);
#endif
- return gpu_no;
+
+ return gpu_no;
}
static void ati_update_temps(void)
{
#ifdef HAVE_TIME_H
- static time_t last = 0;
- time_t now = time(NULL);
- /* Only update when more than two seconds have passed since last update */
- if (timediff(now, last) > 2) {
+ static time_t last = 0;
+ time_t now = time(NULL);
+ /* Only update when more than two seconds have passed since last update */
+ if (timediff(now, last) > 2) {
#endif
- num_gpus = ati_get_temps(&gpu_temps, MAX_GPUS);
+ num_gpus = ati_get_temps(&gpu_temps, MAX_GPUS);
#ifdef HAVE_TIME_H
- last = now;
- }
+ last = now;
+ }
#endif
}
-static GList *aticonfig_plugin_init(void)
+static GList *aticonfig_plugin_init(void)
{
- GList *sensors = NULL;
-
- g_debug("Initializing aticonfig plugin\n");
-
- int sensor_count = ati_get_temps(&gpu_temps, MAX_GPUS);
-
- int i;
- for (i = 0; i < sensor_count; i++) {
- gchar *id = g_strdup_printf("%s%d%s", SENSOR_ID_PREFIX, i, GPU_CORE_TEMP);
- sensors_applet_plugin_add_sensor(&sensors,
- GPU_CORE_TEMP,
- id,
- _("GPU"),
- TEMP_SENSOR,
- TRUE,
- GPU_ICON,
- DEFAULT_GRAPH_COLOR);
- g_free(id);
- }
- return sensors;
+ GList *sensors = NULL;
+
+ g_debug("Initializing aticonfig plugin\n");
+
+ int sensor_count = ati_get_temps(&gpu_temps, MAX_GPUS);
+
+ int i;
+ for (i = 0; i < sensor_count; i++) {
+ gchar *id = g_strdup_printf("%s%d%s", SENSOR_ID_PREFIX, i, GPU_CORE_TEMP);
+ sensors_applet_plugin_add_sensor(&sensors,
+ GPU_CORE_TEMP,
+ id,
+ _("GPU"),
+ TEMP_SENSOR,
+ TRUE,
+ GPU_ICON,
+ DEFAULT_GRAPH_COLOR);
+ g_free(id);
+ }
+
+ return sensors;
}
-static gdouble aticonfig_plugin_get_sensor_value(const gchar *path,
- const gchar *id,
+static gdouble aticonfig_plugin_get_sensor_value(const gchar *path,
+ const gchar *id,
SensorType type,
- GError **error)
+ GError **error)
{
- if (g_ascii_strcasecmp(path, GPU_CORE_TEMP) != 0 || type != TEMP_SENSOR) {
- g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR,
- 0, "Invalid sensor value request to aticonfig plugin");
- return 0;
- }
- ati_update_temps();
-
- int i = g_ascii_strtoll(id + strlen(SENSOR_ID_PREFIX), NULL, 10);
- if (i < 0 || i >= num_gpus) {
- g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR,
- 0, "Sensor index out of range in aticonfig plugin");
- return 0;
- }
- return gpu_temps[i];
+ if (g_ascii_strcasecmp(path, GPU_CORE_TEMP) != 0 || type != TEMP_SENSOR) {
+ g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR,
+ 0, "Invalid sensor value request to aticonfig plugin");
+ return 0;
+ }
+ ati_update_temps();
+
+ int i = g_ascii_strtoll(id + strlen(SENSOR_ID_PREFIX), NULL, 10);
+ if (i < 0 || i >= num_gpus) {
+ g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR,
+ 0, "Sensor index out of range in aticonfig plugin");
+ return 0;
+ }
+ return gpu_temps[i];
}
-const gchar *sensors_applet_plugin_name(void)
+const gchar *sensors_applet_plugin_name(void)
{
- return plugin_name;
+ return plugin_name;
}
-GList *sensors_applet_plugin_init(void)
+GList *sensors_applet_plugin_init(void)
{
- return aticonfig_plugin_init();
+ return aticonfig_plugin_init();
}
-gdouble sensors_applet_plugin_get_sensor_value(const gchar *path,
- const gchar *id,
+gdouble sensors_applet_plugin_get_sensor_value(const gchar *path,
+ const gchar *id,
SensorType type,
- GError **error)
+ GError **error)
{
- return aticonfig_plugin_get_sensor_value(path, id, type, error);
+ return aticonfig_plugin_get_sensor_value(path, id, type, error);
}
diff --git a/plugins/eee/eee-plugin.c b/plugins/eee/eee-plugin.c
index 7000f1c..a1867f1 100644
--- a/plugins/eee/eee-plugin.c
+++ b/plugins/eee/eee-plugin.c
@@ -33,85 +33,85 @@ const gchar *plugin_name = "eee";
#define EEE_FAN_FILE "/proc/eee/fan_rpm"
enum {
- EEE_DEVICE_FILE_OPEN_ERROR,
- EEE_DEVICE_FILE_READ_ERROR
+ EEE_DEVICE_FILE_OPEN_ERROR,
+ EEE_DEVICE_FILE_READ_ERROR
};
static void eee_plugin_add_sensor(GList **sensors, const gchar *path) {
- gchar *dirname;
- gchar *id;
- gchar *label;
-
- dirname = g_path_get_dirname(path);
- id = g_path_get_basename(dirname);
- g_free(dirname);
-
- sensors_applet_plugin_add_sensor(sensors,
- path,
- id,
- _("FAN"),
- FAN_SENSOR,
- TRUE,
- FAN_ICON,
- DEFAULT_GRAPH_COLOR);
- g_free(id);
+ gchar *dirname;
+ gchar *id;
+ gchar *label;
+
+ dirname = g_path_get_dirname(path);
+ id = g_path_get_basename(dirname);
+ g_free(dirname);
+
+ sensors_applet_plugin_add_sensor(sensors,
+ path,
+ id,
+ _("FAN"),
+ FAN_SENSOR,
+ TRUE,
+ FAN_ICON,
+ DEFAULT_GRAPH_COLOR);
+ g_free(id);
}
static void eee_plugin_test_sensor(GList **sensors,
- const gchar *path) {
- gchar *filename;
- filename = g_path_get_basename(path);
- eee_plugin_add_sensor(sensors, path);
- g_free(filename);
+ const gchar *path) {
+ gchar *filename;
+ filename = g_path_get_basename(path);
+ eee_plugin_add_sensor(sensors, path);
+ g_free(filename);
}
+
static GList *eee_plugin_init(void) {
- GList *sensors = NULL;
+ GList *sensors = NULL;
- sensors_applet_plugin_find_sensors(&sensors, EEE_FAN_FILE,
- eee_plugin_test_sensor);
- return sensors;
+ sensors_applet_plugin_find_sensors(&sensors, EEE_FAN_FILE,
+ eee_plugin_test_sensor);
+ return sensors;
}
-
static gdouble eee_plugin_get_sensor_value(const gchar *path,
- const gchar *id,
- SensorType type,
- GError **error) {
-
- FILE *fp;
- gfloat sensor_value = 0;
- gchar units[32];
-
- if (NULL == (fp = fopen(path, "r"))) {
- g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, EEE_DEVICE_FILE_OPEN_ERROR, "Error opening sensor device file %s", path);
- return sensor_value;
- }
-
- if (fscanf(fp, "%f", &sensor_value, units) < 1) {
- g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, EEE_DEVICE_FILE_READ_ERROR, "Error reading from sensor device file %s", path);
- fclose(fp);
- return sensor_value;
- }
- fclose(fp);
-
- return (gdouble)sensor_value;
+ const gchar *id,
+ SensorType type,
+ GError **error) {
+
+ FILE *fp;
+ gfloat sensor_value = 0;
+ gchar units[32];
+
+ if (NULL == (fp = fopen(path, "r"))) {
+ g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, EEE_DEVICE_FILE_OPEN_ERROR, "Error opening sensor device file %s", path);
+ return sensor_value;
+ }
+
+ if (fscanf(fp, "%f", &sensor_value, units) < 1) {
+ g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, EEE_DEVICE_FILE_READ_ERROR, "Error reading from sensor device file %s", path);
+ fclose(fp);
+ return sensor_value;
+ }
+ fclose(fp);
+
+ return (gdouble)sensor_value;
}
const gchar *sensors_applet_plugin_name(void)
{
- return plugin_name;
+ return plugin_name;
}
GList *sensors_applet_plugin_init(void)
{
- return eee_plugin_init();
+ return eee_plugin_init();
}
gdouble sensors_applet_plugin_get_sensor_value(const gchar *path,
- const gchar *id,
- SensorType type,
- GError **error) {
- return eee_plugin_get_sensor_value(path, id, type, error);
+ const gchar *id,
+ SensorType type,
+ GError **error) {
+ return eee_plugin_get_sensor_value(path, id, type, error);
}
diff --git a/plugins/hddtemp/hddtemp-plugin.c b/plugins/hddtemp/hddtemp-plugin.c
index e045d2d..506491d 100644
--- a/plugins/hddtemp/hddtemp-plugin.c
+++ b/plugins/hddtemp/hddtemp-plugin.c
@@ -51,201 +51,195 @@ const gchar *plugin_name = "hddtemp";
#define HDDTEMP_OUTPUT_BUFFER_LENGTH 1024
enum {
- HDDTEMP_SOCKET_OPEN_ERROR,
- HDDTEMP_SOCKET_CONNECT_ERROR,
- HDDTEMP_GIOCHANNEL_ERROR,
- HDDTEMP_GIOCHANNEL_READ_ERROR
-
+ HDDTEMP_SOCKET_OPEN_ERROR,
+ HDDTEMP_SOCKET_CONNECT_ERROR,
+ HDDTEMP_GIOCHANNEL_ERROR,
+ HDDTEMP_GIOCHANNEL_READ_ERROR
};
static gchar buffer[HDDTEMP_OUTPUT_BUFFER_LENGTH];
static const gchar *hddtemp_plugin_query_hddtemp_daemon(GError **error) {
- int sockfd;
- ssize_t n = 1;
- guint output_length = 0;
- static gboolean first_run = TRUE;
- gchar *pc;
-
- struct sockaddr_in address;
- static GTimeVal previous_query_time;
- GTimeVal current_query_time;
-
- if (first_run) {
- // initialise previous time
- g_get_current_time(&previous_query_time);
- }
- g_get_current_time(&current_query_time);
-
- /* only actually query if more than 60 seconds has elapsed as
- hddtemp daemon will only actually send a new value if is > 60
- seconds */
- if (first_run || current_query_time.tv_sec - previous_query_time.tv_sec > 60) {
- previous_query_time = current_query_time;
-
- if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
- // couldn't open socket
- g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, HDDTEMP_SOCKET_OPEN_ERROR, "Error opening socket for hddtemp");
- return NULL;
- }
-
- address.sin_family = AF_INET;
- address.sin_addr.s_addr = inet_addr(HDDTEMP_SERVER_IP_ADDRESS);
- address.sin_port = htons(HDDTEMP_PORT_NUMBER);
-
- if (connect(sockfd, (struct sockaddr *)&address,
- (socklen_t)sizeof(address)) == -1) {
- g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, HDDTEMP_SOCKET_CONNECT_ERROR, "Error connecting to hddtemp daemon on port %i on %s", htons(HDDTEMP_PORT_NUMBER), HDDTEMP_SERVER_IP_ADDRESS);
- close(sockfd);
- return NULL;
- }
- memset(buffer, 0, sizeof(buffer));
- pc = buffer;
- while ((n = read(sockfd, pc,
- sizeof(buffer) - output_length)) > 0) {
- output_length += n;
- pc += n;
- }
- /* always null terminate the end of the buffer */
- buffer[MIN(output_length, sizeof(buffer) - 1)] = '\0';
- close(sockfd);
- first_run = FALSE;
- }
-
- return buffer;
+ int sockfd;
+ ssize_t n = 1;
+ guint output_length = 0;
+ static gboolean first_run = TRUE;
+ gchar *pc;
+
+ struct sockaddr_in address;
+ static GTimeVal previous_query_time;
+ GTimeVal current_query_time;
+
+ if (first_run) {
+ // initialise previous time
+ g_get_current_time(&previous_query_time);
+ }
+ g_get_current_time(&current_query_time);
+
+ /* only actually query if more than 60 seconds has elapsed as
+ hddtemp daemon will only actually send a new value if is > 60
+ seconds */
+ if (first_run || current_query_time.tv_sec - previous_query_time.tv_sec > 60) {
+ previous_query_time = current_query_time;
+
+ if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
+ // couldn't open socket
+ g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, HDDTEMP_SOCKET_OPEN_ERROR, "Error opening socket for hddtemp");
+ return NULL;
+ }
+
+ address.sin_family = AF_INET;
+ address.sin_addr.s_addr = inet_addr(HDDTEMP_SERVER_IP_ADDRESS);
+ address.sin_port = htons(HDDTEMP_PORT_NUMBER);
+
+ if (connect(sockfd, (struct sockaddr *)&address, (socklen_t)sizeof(address)) == -1) {
+ g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, HDDTEMP_SOCKET_CONNECT_ERROR, "Error connecting to hddtemp daemon on port %i on %s", htons(HDDTEMP_PORT_NUMBER), HDDTEMP_SERVER_IP_ADDRESS);
+ close(sockfd);
+ return NULL;
+ }
+ memset(buffer, 0, sizeof(buffer));
+ pc = buffer;
+ while ((n = read(sockfd, pc, sizeof(buffer) - output_length)) > 0) {
+ output_length += n;
+ pc += n;
+ }
+ /* always null terminate the end of the buffer */
+ buffer[MIN(output_length, sizeof(buffer) - 1)] = '\0';
+ close(sockfd);
+ first_run = FALSE;
+ }
+
+ return buffer;
}
-
+
static void hddtemp_plugin_get_sensors(GList **sensors) {
- GError *error = NULL;
- const gchar *hddtemp_output;
- gchar **output_vector = NULL, **pv;
-
- hddtemp_output = hddtemp_plugin_query_hddtemp_daemon(&error);
-
- if (error) {
- g_error_free(error);
- return;
- }
-
- if (hddtemp_output[0] != '|') {
- g_debug("Error in format of string returned from hddtemp daemon: char at [0] should be \"|\", instead whole output is: \"%s\"", hddtemp_output);
- return;
- }
-
- /* for each sensor the output will contain four strings ie
- |/dev/hda|WDC WD800JB-00ETA0|32|C||/dev/hdb|???|ERR|*|
- note the repetition -----^ */
-
- /*
-
- pv[0 + 5*n] empty
- pv[1 + 5*n] device name
- pv[2 + 5*n] disk label
- pv[3 + 5*n] temperature
- pv[4 + 5*n] unit
- pv[5 + 5*n] empty
-
- */
-
- pv = output_vector = g_strsplit(hddtemp_output, "|", -1);
-
- while(pv[1] != NULL) {
- if (g_strcmp0(pv[2], "") != 0 &&
- g_strcmp0(pv[3], "") != 0 &&
- g_strcmp0(pv[4], "") != 0 &&
- (!(g_ascii_strcasecmp(pv[2], "???") == 0 ||
- g_ascii_strcasecmp(pv[3], "ERR") == 0 ||
- g_ascii_strcasecmp(pv[4], "*") == 0))) {
- sensors_applet_plugin_add_sensor(sensors,
- pv[1], // must be dynamically allocated
- pv[1], // must be dynamically allocated
- pv[2], // must be dynamically allocated
- TEMP_SENSOR,
- FALSE,
- HDD_ICON,
- DEFAULT_GRAPH_COLOR);
- }
- pv += 5;
- }
- g_strfreev(output_vector);
+ GError *error = NULL;
+ const gchar *hddtemp_output;
+ gchar **output_vector = NULL, **pv;
+
+ hddtemp_output = hddtemp_plugin_query_hddtemp_daemon(&error);
+
+ if (error) {
+ g_error_free(error);
+ return;
+ }
+
+ if (hddtemp_output[0] != '|') {
+ g_debug("Error in format of string returned from hddtemp daemon: char at [0] should be \"|\", instead whole output is: \"%s\"", hddtemp_output);
+ return;
+ }
+
+ /* for each sensor the output will contain four strings ie
+ |/dev/hda|WDC WD800JB-00ETA0|32|C||/dev/hdb|???|ERR|*|
+ note the repetition -----^ */
+
+ /*
+ pv[0 + 5*n] empty
+ pv[1 + 5*n] device name
+ pv[2 + 5*n] disk label
+ pv[3 + 5*n] temperature
+ pv[4 + 5*n] unit
+ pv[5 + 5*n] empty
+ */
+
+ pv = output_vector = g_strsplit(hddtemp_output, "|", -1);
+
+ while(pv[1] != NULL) {
+ if (g_strcmp0(pv[2], "") != 0 &&
+ g_strcmp0(pv[3], "") != 0 &&
+ g_strcmp0(pv[4], "") != 0 &&
+ (!(g_ascii_strcasecmp(pv[2], "???") == 0 ||
+ g_ascii_strcasecmp(pv[3], "ERR") == 0 ||
+ g_ascii_strcasecmp(pv[4], "*") == 0))) {
+
+ sensors_applet_plugin_add_sensor(sensors,
+ pv[1], // must be dynamically allocated
+ pv[1], // must be dynamically allocated
+ pv[2], // must be dynamically allocated
+ TEMP_SENSOR,
+ FALSE,
+ HDD_ICON,
+ DEFAULT_GRAPH_COLOR);
+ }
+ pv += 5;
+ }
+ g_strfreev(output_vector);
}
/* to be called to setup for hddtemp sensors */
static GList *hddtemp_plugin_init(void) {
- GList *sensors = NULL;
- hddtemp_plugin_get_sensors(&sensors);
- return sensors;
+ GList *sensors = NULL;
+ hddtemp_plugin_get_sensors(&sensors);
+ return sensors;
}
-
/* returns the value of the sensor_list at the given iter, or if an
error occurs, instatiates error with an error message */
-static gdouble hddtemp_plugin_get_sensor_value(const gchar *path,
- const gchar *id,
- SensorType type,
- GError **error) {
-
- const gchar *hddtemp_output;
- gchar **output_vector = NULL, **pv;
-
- gfloat sensor_value = -1.0f;
-
- hddtemp_output = hddtemp_plugin_query_hddtemp_daemon(error);
-
- if (*error) {
- return sensor_value;
- }
-
- if (hddtemp_output[0] != '|') {
- g_debug("Error in format of string returned from hddtemp daemon: char at [0] should be \"|\", instead whole output is: \"%s\"", hddtemp_output);
- return sensor_value;
- }
-
- /* for each sensor the output will contain four strings ie
- |/dev/hda|WDC WD800JB-00ETA0|32|C||/dev/hdb|???|ERR|*|
- note the repetition -----^
-
- pv[0 + 5*n] empty
- pv[1 + 5*n] device name
- pv[2 + 5*n] disk label
- pv[3 + 5*n] temperature
- pv[4 + 5*n] unit
- pv[5 + 5*n] empty
-
- */
-
- pv = output_vector = g_strsplit(hddtemp_output, "|", -1);
-
- while(pv[1] != NULL) {
- if (g_ascii_strcasecmp(pv[1], path) == 0) {
- sensor_value = (gfloat)(g_ascii_strtod(pv[3], NULL));
-
- /* always return sensor values in celsius */
- if (pv[4][0] == 'F') {
- sensor_value = (sensor_value - 32.0) * 5.0 / 9.0;
- }
- break;
- }
- pv += 5;
- }
- g_strfreev(output_vector);
-
- return (gdouble)sensor_value;
+static gdouble hddtemp_plugin_get_sensor_value(const gchar *path,
+ const gchar *id,
+ SensorType type,
+ GError **error) {
+
+ const gchar *hddtemp_output;
+ gchar **output_vector = NULL, **pv;
+
+ gfloat sensor_value = -1.0f;
+
+ hddtemp_output = hddtemp_plugin_query_hddtemp_daemon(error);
+
+ if (*error) {
+ return sensor_value;
+ }
+
+ if (hddtemp_output[0] != '|') {
+ g_debug("Error in format of string returned from hddtemp daemon: char at [0] should be \"|\", instead whole output is: \"%s\"", hddtemp_output);
+ return sensor_value;
+ }
+
+ /* for each sensor the output will contain four strings ie
+ |/dev/hda|WDC WD800JB-00ETA0|32|C||/dev/hdb|???|ERR|*|
+ note the repetition -----^
+
+ pv[0 + 5*n] empty
+ pv[1 + 5*n] device name
+ pv[2 + 5*n] disk label
+ pv[3 + 5*n] temperature
+ pv[4 + 5*n] unit
+ pv[5 + 5*n] empty
+ */
+
+ pv = output_vector = g_strsplit(hddtemp_output, "|", -1);
+
+ while(pv[1] != NULL) {
+ if (g_ascii_strcasecmp(pv[1], path) == 0) {
+ sensor_value = (gfloat)(g_ascii_strtod(pv[3], NULL));
+
+ /* always return sensor values in celsius */
+ if (pv[4][0] == 'F') {
+ sensor_value = (sensor_value - 32.0) * 5.0 / 9.0;
+ }
+ break;
+ }
+ pv += 5;
+ }
+ g_strfreev(output_vector);
+
+ return (gdouble)sensor_value;
}
-const gchar *sensors_applet_plugin_name(void)
+const gchar *sensors_applet_plugin_name(void)
{
- return plugin_name;
+ return plugin_name;
}
-GList *sensors_applet_plugin_init(void)
+GList *sensors_applet_plugin_init(void)
{
- return hddtemp_plugin_init();
+ return hddtemp_plugin_init();
}
-gdouble sensors_applet_plugin_get_sensor_value(const gchar *path,
- const gchar *id,
+gdouble sensors_applet_plugin_get_sensor_value(const gchar *path,
+ const gchar *id,
SensorType type,
GError **error) {
- return hddtemp_plugin_get_sensor_value(path, id, type, error);
+ return hddtemp_plugin_get_sensor_value(path, id, type, error);
}