diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/i2c-proc/i2c-proc-plugin.c | 302 | ||||
-rw-r--r-- | plugins/i2c-sys/i2c-sys-plugin.c | 257 | ||||
-rw-r--r-- | plugins/i8k/i8k-plugin.c | 214 | ||||
-rw-r--r-- | plugins/ibm-acpi/ibm-acpi-plugin.c | 283 |
4 files changed, 533 insertions, 523 deletions
diff --git a/plugins/i2c-proc/i2c-proc-plugin.c b/plugins/i2c-proc/i2c-proc-plugin.c index 06ed2af..3b2ae5a 100644 --- a/plugins/i2c-proc/i2c-proc-plugin.c +++ b/plugins/i2c-proc/i2c-proc-plugin.c @@ -37,58 +37,57 @@ const gchar *plugin_name = "i2c-proc"; #define I2C_PROC_BASE_DIR "/proc/sys/dev/sensors" enum { - I2C_PROC_DEVICE_FILE_OPEN_ERROR, - I2C_PROC_DEVICE_FILE_READ_ERROR + I2C_PROC_DEVICE_FILE_OPEN_ERROR, + I2C_PROC_DEVICE_FILE_READ_ERROR }; -static void i2c_proc_plugin_add_sensor(GList **sensors, - const gchar *path) { - gchar *filename; - gchar *label; - gboolean enable; - SensorType sensor_type; - IconType icon_type = GENERIC_ICON; - - filename = g_path_get_basename(path); - - /* setup temp2 as CPU sensor and enable it */ - if (g_ascii_strcasecmp(filename, "temp2") == 0) { - sensor_type = TEMP_SENSOR; - label = g_strdup(_("CPU")); - enable = TRUE; - icon_type = CPU_ICON; - } else { - label = g_strdup(filename); - - switch(filename[0]) { - case 'c': /* currents are "curr?" */ - sensor_type = CURRENT_SENSOR; - break; - case 'f': /* fans are "fan?" */ - sensor_type = FAN_SENSOR; - icon_type = FAN_ICON; - break; - case 'i': /* voltages are "in?" */ - sensor_type = VOLTAGE_SENSOR; - break; - case 't': /* temps are "temp?" */ - sensor_type = TEMP_SENSOR; - break; - case 'v': /* vids are just vid */ - sensor_type = VOLTAGE_SENSOR; - break; - default: - /* SHOULDN'T BE ABLE - * TO GET HERE!! */ - g_debug("error in i2c-proc sensor detection code - unhandled sensor filename %s", filename); - g_free(filename); - g_free(label); - return; - } - /* disable all other sensors */ - enable = FALSE; - } - sensors_applet_plugin_add_sensor(sensors, +static void i2c_proc_plugin_add_sensor(GList **sensors, const gchar *path) { + gchar *filename; + gchar *label; + gboolean enable; + SensorType sensor_type; + IconType icon_type = GENERIC_ICON; + + filename = g_path_get_basename(path); + + /* setup temp2 as CPU sensor and enable it */ + if (g_ascii_strcasecmp(filename, "temp2") == 0) { + sensor_type = TEMP_SENSOR; + label = g_strdup(_("CPU")); + enable = TRUE; + icon_type = CPU_ICON; + } else { + label = g_strdup(filename); + + switch(filename[0]) { + case 'c': /* currents are "curr?" */ + sensor_type = CURRENT_SENSOR; + break; + case 'f': /* fans are "fan?" */ + sensor_type = FAN_SENSOR; + icon_type = FAN_ICON; + break; + case 'i': /* voltages are "in?" */ + sensor_type = VOLTAGE_SENSOR; + break; + case 't': /* temps are "temp?" */ + sensor_type = TEMP_SENSOR; + break; + case 'v': /* vids are just vid */ + sensor_type = VOLTAGE_SENSOR; + break; + default: + /* SHOULDN'T BE ABLE TO GET HERE!! */ + g_debug("error in i2c-proc sensor detection code - unhandled sensor filename %s", filename); + g_free(filename); + g_free(label); + return; + } + /* disable all other sensors */ + enable = FALSE; + } + + sensors_applet_plugin_add_sensor(sensors, path, filename, label, @@ -97,138 +96,135 @@ static void i2c_proc_plugin_add_sensor(GList **sensors, icon_type, DEFAULT_GRAPH_COLOR); - - g_free(filename); - g_free(label); -} + g_free(filename); + g_free(label); +} static void i2c_proc_plugin_test_sensor(GList **sensors, const gchar *path) { - gchar *filename; - - filename = g_path_get_basename(path); - /* see if filename starts with any of the sensor - prefixes */ - if (g_str_has_prefix(filename, "curr") || - (g_str_has_prefix(filename, "fan") && - !g_str_has_prefix(filename, "fan_div")) || - g_str_has_prefix(filename, "in") || - g_str_has_prefix(filename, "temp") || - g_str_has_prefix(filename, "vid")) { - i2c_proc_plugin_add_sensor(sensors, path); - } - g_free(filename); - + gchar *filename; + + filename = g_path_get_basename(path); + /* see if filename starts with any of the sensor prefixes */ + if (g_str_has_prefix(filename, "curr") || + (g_str_has_prefix(filename, "fan") && + !g_str_has_prefix(filename, "fan_div")) || + g_str_has_prefix(filename, "in") || + g_str_has_prefix(filename, "temp") || + g_str_has_prefix(filename, "vid")) { + + i2c_proc_plugin_add_sensor(sensors, path); + } + g_free(filename); + } /* to be called to setup for proc sensors */ static GList *i2c_proc_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, I2C_PROC_BASE_DIR, i2c_proc_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, I2C_PROC_BASE_DIR, i2c_proc_plugin_test_sensor); + return sensors; } -static gdouble i2c_proc_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 float1, float2, float3; - gint int1, int2; +static gdouble i2c_proc_plugin_get_sensor_value(const gchar *path, + const gchar *id, + SensorType type, + GError **error) { - gfloat sensor_value = -1.0; + /* to open and access the value of each sensor */ + FILE *fp; + gfloat float1, float2, float3; + gint int1, int2; - gchar *old_locale = NULL; + gfloat sensor_value = -1.0; + + gchar *old_locale = NULL; /* always use C locale */ - if (NULL == (old_locale = setlocale(LC_NUMERIC, "C"))) { - g_warning("Could not change locale to C locale for reading i2c-proc device files.. will try regardless"); - } - - if (NULL == (fp = fopen(path, "r"))) { - g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, I2C_PROC_DEVICE_FILE_OPEN_ERROR, "Error opening sensor device file %s", path); - - } else { - - switch (type) { - case CURRENT_SENSOR: - + if (NULL == (old_locale = setlocale(LC_NUMERIC, "C"))) { + g_warning("Could not change locale to C locale for reading i2c-proc device files.. will try regardless"); + } + + if (NULL == (fp = fopen(path, "r"))) { + g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, I2C_PROC_DEVICE_FILE_OPEN_ERROR, "Error opening sensor device file %s", path); + } else { + switch (type) { + case CURRENT_SENSOR: + if (fscanf(fp, "%f %f %f", &float1, &float2, &float3) != 3) { + g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, I2C_PROC_DEVICE_FILE_READ_ERROR, "Error reading from sensor device file %s", path); + } else { + sensor_value = float3; + } + break; + + case FAN_SENSOR: + if (fscanf(fp, "%d %d", &int1, &int2) != 2) { + g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, I2C_PROC_DEVICE_FILE_READ_ERROR, "Error reading from sensor device file %s", path); + } else { + sensor_value = (gfloat)int2; + } + break; + + case VOLTAGE_SENSOR: + /* is it CPU_VID or IN */ + switch(id[0]) { + case 'i': if (fscanf(fp, "%f %f %f", &float1, &float2, &float3) != 3) { - g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, I2C_PROC_DEVICE_FILE_READ_ERROR, "Error reading from sensor device file %s", path); + g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, I2C_PROC_DEVICE_FILE_READ_ERROR, "Error reading from sensor device file %s", path); } else { - sensor_value = float3; - } - break; - - case FAN_SENSOR: - if (fscanf(fp, "%d %d", &int1, &int2) != 2) { - g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, I2C_PROC_DEVICE_FILE_READ_ERROR, "Error reading from sensor device file %s", path); - - } else { - sensor_value = (gfloat)int2; - } - break; - - case VOLTAGE_SENSOR: - /* is it CPU_VID or IN */ - switch(id[0]) { - case 'i': - if (fscanf(fp, "%f %f %f", &float1, &float2, &float3) != 3) { - g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, I2C_PROC_DEVICE_FILE_READ_ERROR, "Error reading from sensor device file %s", path); - } else { - sensor_value = float3; - } - break; - - case 'v': - /* want first value in file as float */ - if (fscanf(fp, "%f", &float1) != 1) { - g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, I2C_PROC_DEVICE_FILE_READ_ERROR, "Error reading from sensor device file %s", path); - } else { - sensor_value = float1; - } - break; - default: - g_debug("error in i2c-proc sensor read value function code - unhandled sensor id %s", id); - g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, I2C_PROC_DEVICE_FILE_READ_ERROR, "Error reading from sensor device file %s", path); + sensor_value = float3; } break; - case TEMP_SENSOR: - if (fscanf(fp, "%f %f %f", &float1, &float2, &float3) != 3) { - g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, I2C_PROC_DEVICE_FILE_READ_ERROR, "Error reading from sensor device file %s", path); + case 'v': + /* want first value in file as float */ + if (fscanf(fp, "%f", &float1) != 1) { + g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, I2C_PROC_DEVICE_FILE_READ_ERROR, "Error reading from sensor device file %s", path); } else { - sensor_value = float3; + sensor_value = float1; } break; - } /* end switch */ - fclose(fp); - } - if (NULL != old_locale) { - setlocale(LC_NUMERIC, old_locale); - } - - return (gdouble)sensor_value; + default: + g_debug("error in i2c-proc sensor read value function code - unhandled sensor id %s", id); + g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, I2C_PROC_DEVICE_FILE_READ_ERROR, "Error reading from sensor device file %s", path); + } + break; + + case TEMP_SENSOR: + if (fscanf(fp, "%f %f %f", &float1, &float2, &float3) != 3) { + g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, I2C_PROC_DEVICE_FILE_READ_ERROR, "Error reading from sensor device file %s", path); + } else { + sensor_value = float3; + } + break; + } /* end switch */ + fclose(fp); + } + + if (NULL != old_locale) { + setlocale(LC_NUMERIC, old_locale); + } + + 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 i2c_proc_plugin_init(); + return i2c_proc_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 i2c_proc_plugin_get_sensor_value(path, id, type, error); + + return i2c_proc_plugin_get_sensor_value(path, id, type, error); } diff --git a/plugins/i2c-sys/i2c-sys-plugin.c b/plugins/i2c-sys/i2c-sys-plugin.c index b1be6b2..3e86fa5 100644 --- a/plugins/i2c-sys/i2c-sys-plugin.c +++ b/plugins/i2c-sys/i2c-sys-plugin.c @@ -33,159 +33,162 @@ const gchar *plugin_name = "i2c-sys"; #define I2C_SYS_BASE_DIR "/sys" enum { - I2C_SYS_DEVICE_FILE_OPEN_ERROR, - I2C_SYS_DEVICE_FILE_READ_ERROR + I2C_SYS_DEVICE_FILE_OPEN_ERROR, + I2C_SYS_DEVICE_FILE_READ_ERROR }; static void i2c_sys_plugin_add_sensor(GList **sensors, const gchar *path) { - gchar *filename; - gchar *id; - gchar *label; - gboolean enable; - guint sensor_type; - IconType icon_type = GENERIC_ICON; - - filename = g_path_get_basename(path); - - /* setup temp2 as CPU sensor and enable it */ - if (g_ascii_strcasecmp(filename, "temp2_input") == 0) { - id = g_strndup(filename, 5); - label = g_strdup(_("CPU")); - sensor_type = TEMP_SENSOR; - enable = TRUE; - icon_type = CPU_ICON; - } else { - switch(filename[0]) { - case 'c': - /* either current or cpu?_vid sensor */ - if (filename[1] == 'u') { /* currents are curr?_input */ - id = g_strndup(filename, 5); - label = g_strndup(filename, 5); - sensor_type = CURRENT_SENSOR; - } - else { /* cpu_vid is cpu?_vid */ - id = g_strdup(filename); - label = g_strdup(filename); - sensor_type = VOLTAGE_SENSOR; - } - break; - case 'f': /* fans are "fan?_input" */ - id = g_strndup(filename, 4); - label = g_strndup(filename, 4); - sensor_type = FAN_SENSOR; - icon_type = FAN_ICON; - break; - case 't': /* temps are "temp?_input" */ - id = g_strndup(filename, 5); - label = g_strndup(filename, 5); - sensor_type = TEMP_SENSOR; - break; - case 'i': /* voltages are "in?_input" */ - id = g_strndup(filename, 3); - label = g_strndup(filename, 3); - sensor_type = VOLTAGE_SENSOR; - break; - default: - /* SHOULDN'T BE ABLE - * TO GET HERE!! */ - g_warning("filename:\"%s\" begins with a charater that is not covered by this switch statement... not adding sensor", filename); - g_free(filename); - g_free(id); - g_free(label); - - return; - - } - /* disable all other sensors */ - enable = FALSE; - } - sensors_applet_plugin_add_sensor(sensors, + gchar *filename; + gchar *id; + gchar *label; + gboolean enable; + guint sensor_type; + IconType icon_type = GENERIC_ICON; + + filename = g_path_get_basename(path); + + /* setup temp2 as CPU sensor and enable it */ + if (g_ascii_strcasecmp(filename, "temp2_input") == 0) { + id = g_strndup(filename, 5); + label = g_strdup(_("CPU")); + sensor_type = TEMP_SENSOR; + enable = TRUE; + icon_type = CPU_ICON; + } else { + switch(filename[0]) { + case 'c': /* either current or cpu?_vid sensor */ + if (filename[1] == 'u') { /* currents are curr?_input */ + id = g_strndup(filename, 5); + label = g_strndup(filename, 5); + sensor_type = CURRENT_SENSOR; + } else { /* cpu_vid is cpu?_vid */ + id = g_strdup(filename); + label = g_strdup(filename); + sensor_type = VOLTAGE_SENSOR; + } + break; + + case 'f': /* fans are "fan?_input" */ + id = g_strndup(filename, 4); + label = g_strndup(filename, 4); + sensor_type = FAN_SENSOR; + icon_type = FAN_ICON; + break; + + case 't': /* temps are "temp?_input" */ + id = g_strndup(filename, 5); + label = g_strndup(filename, 5); + sensor_type = TEMP_SENSOR; + break; + + case 'i': /* voltages are "in?_input" */ + id = g_strndup(filename, 3); + label = g_strndup(filename, 3); + sensor_type = VOLTAGE_SENSOR; + break; + + default: + /* SHOULDN'T BE ABLE * TO GET HERE!! */ + g_warning("filename:\"%s\" begins with a charater that is not covered by this switch statement... not adding sensor", filename); + g_free(filename); + g_free(id); + g_free(label); + + return; + } + + /* disable all other sensors */ + enable = FALSE; + } + + sensors_applet_plugin_add_sensor(sensors, path, id, - label, + label, sensor_type, enable, icon_type, DEFAULT_GRAPH_COLOR); - g_free(filename); - g_free(id); - g_free(label); -} - - -static void i2c_sys_plugin_test_sensor(GList **sensors, - const gchar *path) { - gchar *filename; - - filename = g_path_get_basename(path); - - if ((g_str_has_suffix(filename, "_input") && - (g_str_has_prefix(filename, "temp") || - g_str_has_prefix(filename, "fan") || - g_str_has_prefix(filename, "curr") || - g_str_has_prefix(filename, "in"))) || - (g_str_has_prefix(filename, "cpu") && - (g_str_has_suffix(filename, "_vid")))) { - i2c_sys_plugin_add_sensor(sensors, path); - - } - g_free(filename); + + g_free(filename); + g_free(id); + g_free(label); +} + +static void i2c_sys_plugin_test_sensor(GList **sensors, const gchar *path) { +gchar *filename; + +filename = g_path_get_basename(path); + +if ((g_str_has_suffix(filename, "_input") && + (g_str_has_prefix(filename, "temp") || + g_str_has_prefix(filename, "fan") || + g_str_has_prefix(filename, "curr") || + g_str_has_prefix(filename, "in"))) || + (g_str_has_prefix(filename, "cpu") && + (g_str_has_suffix(filename, "_vid")))) { + + i2c_sys_plugin_add_sensor(sensors, path); +} + + g_free(filename); } /* to be called to setup for sys sensors */ static GList *i2c_sys_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, - I2C_SYS_BASE_DIR, - i2c_sys_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, + I2C_SYS_BASE_DIR, + i2c_sys_plugin_test_sensor); + return sensors; } - -static gdouble i2c_sys_plugin_get_sensor_value(const gchar *path, - const gchar *id, +static gdouble i2c_sys_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; - - if (NULL == (fp = fopen(path, "r"))) { - g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, I2C_SYS_DEVICE_FILE_OPEN_ERROR, "Error opening sensor device file %s", path); - return -1.0; - } - - if (fscanf(fp, "%f", &sensor_value) != 1) { - g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, I2C_SYS_DEVICE_FILE_READ_ERROR, "Error reading from sensor device file %s", path); - fclose(fp); - return -1.0; - } - fclose(fp); - - if (type != FAN_SENSOR) { - sensor_value /= 1000.0; - } - - return (gdouble)sensor_value; + + /* to open and access the value of each sensor */ + FILE *fp; + gfloat sensor_value; + + if (NULL == (fp = fopen(path, "r"))) { + g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, I2C_SYS_DEVICE_FILE_OPEN_ERROR, "Error opening sensor device file %s", path); + return -1.0; + } + + if (fscanf(fp, "%f", &sensor_value) != 1) { + g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, I2C_SYS_DEVICE_FILE_READ_ERROR, "Error reading from sensor device file %s", path); + fclose(fp); + return -1.0; + } + fclose(fp); + + if (type != FAN_SENSOR) { + sensor_value /= 1000.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 i2c_sys_plugin_init(); + return i2c_sys_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 i2c_sys_plugin_get_sensor_value(path, id, type, error); + + return i2c_sys_plugin_get_sensor_value(path, id, type, error); } diff --git a/plugins/i8k/i8k-plugin.c b/plugins/i8k/i8k-plugin.c index 201f8ef..5fc8741 100644 --- a/plugins/i8k/i8k-plugin.c +++ b/plugins/i8k/i8k-plugin.c @@ -34,128 +34,134 @@ const gchar *plugin_name = "i8k"; #define I8K_DEVICE_FILE "i8k" enum { - I8K_DEVICE_FILE_OPEN_ERROR, - I8K_DEVICE_FILE_READ_ERROR + I8K_DEVICE_FILE_OPEN_ERROR, + I8K_DEVICE_FILE_READ_ERROR }; static void i8k_plugin_setup_manually(GList **sensors) { - if (g_file_test(I8K_DEVICE_PATH, G_FILE_TEST_EXISTS)) { - /* with i8k have only 3 fixed sensors, all accessed - from the I8K_DEVICE_PATH */ - sensors_applet_plugin_add_sensor(sensors, - I8K_DEVICE_PATH, - "temp1", - _("CPU"), - TEMP_SENSOR, - TRUE, - CPU_ICON, - DEFAULT_GRAPH_COLOR); - sensors_applet_plugin_add_sensor(sensors, - I8K_DEVICE_PATH, - "fan1", - _("FAN1"), - FAN_SENSOR, - FALSE, - FAN_ICON, - DEFAULT_GRAPH_COLOR); - sensors_applet_plugin_add_sensor(sensors, - I8K_DEVICE_PATH, - "fan2", - _("FAN2"), - FAN_SENSOR, - FALSE, - FAN_ICON, - DEFAULT_GRAPH_COLOR); - } + if (g_file_test(I8K_DEVICE_PATH, G_FILE_TEST_EXISTS)) { + /* with i8k have only 3 fixed sensors, all accessed + from the I8K_DEVICE_PATH */ + sensors_applet_plugin_add_sensor(sensors, + I8K_DEVICE_PATH, + "temp1", + _("CPU"), + TEMP_SENSOR, + TRUE, + CPU_ICON, + DEFAULT_GRAPH_COLOR); + + sensors_applet_plugin_add_sensor(sensors, + I8K_DEVICE_PATH, + "fan1", + _("FAN1"), + FAN_SENSOR, + FALSE, + FAN_ICON, + DEFAULT_GRAPH_COLOR); + + sensors_applet_plugin_add_sensor(sensors, + I8K_DEVICE_PATH, + "fan2", + _("FAN2"), + FAN_SENSOR, + FALSE, + FAN_ICON, + DEFAULT_GRAPH_COLOR); + } } + /* to be called externally to setup for i8k sensors */ static GList *i8k_plugin_init(void) { - GList *sensors = NULL; - - i8k_plugin_setup_manually(&sensors); + GList *sensors = NULL; + + i8k_plugin_setup_manually(&sensors); - return sensors; - + return sensors; } -gdouble i8k_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; - gint cpu_temp, fan1_status, fan2_status, fan1_rpm, fan2_rpm; - gint sensor_value; - gint space_count, file_length; - - if (NULL == (fp = fopen(path, "r"))) { - g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, I8K_DEVICE_FILE_OPEN_ERROR, "Error opening sensor device file %s", path); - return -1.0; - } - - space_count = 0; - file_length = 0; - - /* count spaces but stop if have counted 100 characters and - still not found a space (to avoid infinite loop if file - format error) */ - while (file_length < 100 && space_count < 3) { - if (fgetc(fp) == ' ') { - space_count++; - } - file_length++; - } - - if (fscanf(fp, "%d %d %d %d %d", &cpu_temp, &fan1_status, &fan2_status, &fan1_rpm, &fan2_rpm) != 5) { - g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, I8K_DEVICE_FILE_READ_ERROR, "Error reading from sensor device file %s", path); - fclose(fp); - return -1.0; - } - fclose(fp); - - switch (type) { - case TEMP_SENSOR: - sensor_value = cpu_temp; - break; - case FAN_SENSOR: - switch (id[3]) { - case '1': - sensor_value = fan1_rpm; - break; - case '2': - sensor_value = fan2_rpm; - break; - default: - g_error("Error in i8k sensor get value function code for id %s", id); - g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, I8K_DEVICE_FILE_READ_ERROR, "Error reading from sensor device file %s", path); - return -1.0; - } - break; - - default: - g_error("Unknown sensor type passed as parameter to i8k sensor interface, cannot get value for this sensor"); - g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, I8K_DEVICE_FILE_READ_ERROR, "Error reading from sensor device file %s", path); - return -1.0; - } // end switch (sensor_type) - - return (gdouble)sensor_value; +gdouble i8k_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; + gint cpu_temp, fan1_status, fan2_status, fan1_rpm, fan2_rpm; + gint sensor_value; + gint space_count, file_length; + + if (NULL == (fp = fopen(path, "r"))) { + g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, I8K_DEVICE_FILE_OPEN_ERROR, "Error opening sensor device file %s", path); + return -1.0; + } + + space_count = 0; + file_length = 0; + + /* count spaces but stop if have counted 100 characters and + still not found a space (to avoid infinite loop if file + format error) */ + while (file_length < 100 && space_count < 3) { + if (fgetc(fp) == ' ') { + space_count++; + } + file_length++; + } + + if (fscanf(fp, "%d %d %d %d %d", &cpu_temp, &fan1_status, &fan2_status, &fan1_rpm, &fan2_rpm) != 5) { + g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, I8K_DEVICE_FILE_READ_ERROR, "Error reading from sensor device file %s", path); + fclose(fp); + return -1.0; + } + fclose(fp); + + switch (type) { + case TEMP_SENSOR: + sensor_value = cpu_temp; + break; + + case FAN_SENSOR: + switch (id[3]) { + case '1': + sensor_value = fan1_rpm; + break; + + case '2': + sensor_value = fan2_rpm; + break; + + default: + g_error("Error in i8k sensor get value function code for id %s", id); + g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, I8K_DEVICE_FILE_READ_ERROR, "Error reading from sensor device file %s", path); + return -1.0; + } + break; + + default: + g_error("Unknown sensor type passed as parameter to i8k sensor interface, cannot get value for this sensor"); + g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, I8K_DEVICE_FILE_READ_ERROR, "Error reading from sensor device file %s", path); + return -1.0; + } // end switch (sensor_type) + + 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 i8k_plugin_init(); + return i8k_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 i8k_plugin_get_sensor_value(path, id, type, error); + + return i8k_plugin_get_sensor_value(path, id, type, error); } diff --git a/plugins/ibm-acpi/ibm-acpi-plugin.c b/plugins/ibm-acpi/ibm-acpi-plugin.c index 94a3a36..0f6c8c5 100644 --- a/plugins/ibm-acpi/ibm-acpi-plugin.c +++ b/plugins/ibm-acpi/ibm-acpi-plugin.c @@ -44,176 +44,181 @@ const gchar *plugin_name = "ibm-acpi"; enum { - IBM_ACPI_FILE_OPEN_ERROR, - IBM_ACPI_FILE_READ_ERROR + IBM_ACPI_FILE_OPEN_ERROR, + IBM_ACPI_FILE_READ_ERROR }; static void ibm_acpi_plugin_setup_manually(GList **sensors) { - gchar *label; - - if (g_file_test(IBM_ACPI_TEMPERATURE_FILE, G_FILE_TEST_EXISTS)) { - /* with Ibm_Acpi have 8 fixed sensors, all accessed - from the IBM_ACPI_TEMPERATURE_FILE */ - sensors_applet_plugin_add_sensor(sensors, - IBM_ACPI_TEMPERATURE_FILE, - CPU, - _(CPU), - TEMP_SENSOR, - TRUE, - CPU_ICON, - DEFAULT_GRAPH_COLOR); - sensors_applet_plugin_add_sensor(sensors, - IBM_ACPI_TEMPERATURE_FILE, - MPCI, - _("MiniPCI"), - TEMP_SENSOR, - FALSE, - GENERIC_ICON, - DEFAULT_GRAPH_COLOR); - - sensors_applet_plugin_add_sensor(sensors, - IBM_ACPI_TEMPERATURE_FILE, - HDD, - _(HDD), - TEMP_SENSOR, - FALSE, - HDD_ICON, - DEFAULT_GRAPH_COLOR); - - sensors_applet_plugin_add_sensor(sensors, - IBM_ACPI_TEMPERATURE_FILE, - GPU, - _(GPU), - TEMP_SENSOR, - FALSE, - GPU_ICON, - DEFAULT_GRAPH_COLOR); - - label = g_strdup_printf("%s %d", _("Battery"), 0); - sensors_applet_plugin_add_sensor(sensors, - IBM_ACPI_TEMPERATURE_FILE, - BAT0, - label, - TEMP_SENSOR, - FALSE, - BATTERY_ICON, - DEFAULT_GRAPH_COLOR); - - g_free(label); - label = g_strdup_printf("%s %d", _("Battery"), 0); - sensors_applet_plugin_add_sensor(sensors, - IBM_ACPI_TEMPERATURE_FILE, - BAT1, - label, - TEMP_SENSOR, - FALSE, - BATTERY_ICON, - DEFAULT_GRAPH_COLOR); - - g_free(label); - } - - if (g_file_test(IBM_ACPI_FAN_FILE, G_FILE_TEST_EXISTS)) { - sensors_applet_plugin_add_sensor(sensors, - IBM_ACPI_FAN_FILE, - FAN, - _("Fan"), - FAN_SENSOR, - FALSE, - FAN_ICON, - DEFAULT_GRAPH_COLOR); - - } + gchar *label; + + if (g_file_test(IBM_ACPI_TEMPERATURE_FILE, G_FILE_TEST_EXISTS)) { + + /* with Ibm_Acpi have 8 fixed sensors, all accessed + from the IBM_ACPI_TEMPERATURE_FILE */ + sensors_applet_plugin_add_sensor(sensors, + IBM_ACPI_TEMPERATURE_FILE, + CPU, + _(CPU), + TEMP_SENSOR, + TRUE, + CPU_ICON, + DEFAULT_GRAPH_COLOR); + + sensors_applet_plugin_add_sensor(sensors, + IBM_ACPI_TEMPERATURE_FILE, + MPCI, + _("MiniPCI"), + TEMP_SENSOR, + FALSE, + GENERIC_ICON, + DEFAULT_GRAPH_COLOR); + + sensors_applet_plugin_add_sensor(sensors, + IBM_ACPI_TEMPERATURE_FILE, + HDD, + _(HDD), + TEMP_SENSOR, + FALSE, + HDD_ICON, + DEFAULT_GRAPH_COLOR); + + sensors_applet_plugin_add_sensor(sensors, + IBM_ACPI_TEMPERATURE_FILE, + GPU, + _(GPU), + TEMP_SENSOR, + FALSE, + GPU_ICON, + DEFAULT_GRAPH_COLOR); + + label = g_strdup_printf("%s %d", _("Battery"), 0); + sensors_applet_plugin_add_sensor(sensors, + IBM_ACPI_TEMPERATURE_FILE, + BAT0, + label, + TEMP_SENSOR, + FALSE, + BATTERY_ICON, + DEFAULT_GRAPH_COLOR); + + g_free(label); + + label = g_strdup_printf("%s %d", _("Battery"), 0); + sensors_applet_plugin_add_sensor(sensors, + IBM_ACPI_TEMPERATURE_FILE, + BAT1, + label, + TEMP_SENSOR, + FALSE, + BATTERY_ICON, + DEFAULT_GRAPH_COLOR); + + g_free(label); + } + + if (g_file_test(IBM_ACPI_FAN_FILE, G_FILE_TEST_EXISTS)) { + sensors_applet_plugin_add_sensor(sensors, + IBM_ACPI_FAN_FILE, + FAN, + _("Fan"), + FAN_SENSOR, + FALSE, + FAN_ICON, + DEFAULT_GRAPH_COLOR); + + } } + /* to be called externally to setup for ibm_acpi sensors */ GList *ibm_acpi_plugin_init(void) { - GList *sensors = NULL; - - ibm_acpi_plugin_setup_manually(&sensors); + GList *sensors = NULL; + + ibm_acpi_plugin_setup_manually(&sensors); - return sensors; - + return sensors; } -gdouble ibm_acpi_plugin_get_sensor_value(const gchar *path, - const gchar *id, +gdouble ibm_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; - gint sensor_value; - gint cpu_temp, minipci_temp, hdd_temp, gpu_temp, bat0_temp, bat1_temp, unknown0, unknown1; - gint fan_speed; + /* to open and access the value of each sensor */ + FILE *fp; + gint sensor_value; + gint cpu_temp, minipci_temp, hdd_temp, gpu_temp, bat0_temp, bat1_temp, unknown0, unknown1; + gint fan_speed; - if (NULL == (fp = fopen(path, "r"))) { - g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, IBM_ACPI_FILE_OPEN_ERROR, "Error opening sensor device file %s", path); - return -1.0; - } + if (NULL == (fp = fopen(path, "r"))) { + g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, IBM_ACPI_FILE_OPEN_ERROR, "Error opening sensor device file %s", path); + return -1.0; + } - switch (type) { + switch (type) { case TEMP_SENSOR: - if (fscanf(fp, "temperatures: %d %d %d %d %d %d %d %d", &cpu_temp, &minipci_temp, &hdd_temp, &gpu_temp, &bat0_temp, &unknown0, &bat1_temp, &unknown1) != 8) { - g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, IBM_ACPI_FILE_READ_ERROR, "Error reading from sensor device file %s", path); - fclose(fp); - return -1.0; - } - - if (g_ascii_strcasecmp(id, CPU) == 0) { - sensor_value = cpu_temp; - } else if (g_ascii_strcasecmp(id, MPCI) == 0) { - sensor_value = minipci_temp; - } else if (g_ascii_strcasecmp(id, HDD) == 0) { - sensor_value = hdd_temp; - } else if (g_ascii_strcasecmp(id, GPU) == 0) { - sensor_value = gpu_temp; - } else if (g_ascii_strcasecmp(id, BAT0) == 0) { - sensor_value = bat0_temp; - } else if (g_ascii_strcasecmp(id, BAT1) == 0) { - sensor_value = bat1_temp; - } - break; - case FAN_SENSOR: - fscanf(fp, "%*[^\n]"); /* Skip to the End of the Line */ - fscanf(fp, "%*1[\n]"); /* Skip One Newline */ - if (fscanf(fp, "speed: %d", &fan_speed) != 1) { - g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, IBM_ACPI_FILE_READ_ERROR, "Error reading from sensor device file %s", path); - fclose(fp); - return -1.0; - } - - if (g_ascii_strcasecmp(id, "FAN") == 0) { - sensor_value = fan_speed; - } - break; + if (fscanf(fp, "temperatures: %d %d %d %d %d %d %d %d", &cpu_temp, &minipci_temp, &hdd_temp, &gpu_temp, &bat0_temp, &unknown0, &bat1_temp, &unknown1) != 8) { + g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, IBM_ACPI_FILE_READ_ERROR, "Error reading from sensor device file %s", path); + fclose(fp); + return -1.0; + } + + if (g_ascii_strcasecmp(id, CPU) == 0) { + sensor_value = cpu_temp; + } else if (g_ascii_strcasecmp(id, MPCI) == 0) { + sensor_value = minipci_temp; + } else if (g_ascii_strcasecmp(id, HDD) == 0) { + sensor_value = hdd_temp; + } else if (g_ascii_strcasecmp(id, GPU) == 0) { + sensor_value = gpu_temp; + } else if (g_ascii_strcasecmp(id, BAT0) == 0) { + sensor_value = bat0_temp; + } else if (g_ascii_strcasecmp(id, BAT1) == 0) { + sensor_value = bat1_temp; + } + break; - default: - g_error("Unknown sensor type passed as parameter to ibm-acpi sensor interface, cannot get value for this sensor"); + case FAN_SENSOR: + fscanf(fp, "%*[^\n]"); /* Skip to the End of the Line */ + fscanf(fp, "%*1[\n]"); /* Skip One Newline */ + if (fscanf(fp, "speed: %d", &fan_speed) != 1) { g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, IBM_ACPI_FILE_READ_ERROR, "Error reading from sensor device file %s", path); fclose(fp); return -1.0; - } + } + + if (g_ascii_strcasecmp(id, "FAN") == 0) { + sensor_value = fan_speed; + } + break; - fclose(fp); + default: + g_error("Unknown sensor type passed as parameter to ibm-acpi sensor interface, cannot get value for this sensor"); + g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, IBM_ACPI_FILE_READ_ERROR, "Error reading from sensor device file %s", path); + fclose(fp); + return -1.0; + } + + fclose(fp); - return (gdouble)sensor_value; + 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 ibm_acpi_plugin_init(); + return ibm_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 ibm_acpi_plugin_get_sensor_value(path, id, type, error); + + return ibm_acpi_plugin_get_sensor_value(path, id, type, error); } |