diff options
| -rw-r--r-- | plugins/libsensors/libsensors-plugin.c | 740 | ||||
| -rw-r--r-- | plugins/mbmon/mbmon-plugin.c | 291 | ||||
| -rw-r--r-- | plugins/nvidia/nvidia-plugin.c | 309 | ||||
| -rw-r--r-- | plugins/omnibook/omnibook-plugin.c | 93 | 
4 files changed, 693 insertions, 740 deletions
| diff --git a/plugins/libsensors/libsensors-plugin.c b/plugins/libsensors/libsensors-plugin.c index 6050b7b..2dd18ae 100644 --- a/plugins/libsensors/libsensors-plugin.c +++ b/plugins/libsensors/libsensors-plugin.c @@ -47,13 +47,13 @@ const gchar *plugin_name = "libsensors";  GHashTable *hash_table = NULL;  enum { -	LIBSENSORS_CHIP_PARSE_ERROR, -	LIBSENSORS_MISSING_FEATURE_ERROR, -	LIBSENSORS_REGEX_URL_COMPILE_ERROR, -	LIBSENSORS_CHIP_NOT_FOUND_ERROR +    LIBSENSORS_CHIP_PARSE_ERROR, +    LIBSENSORS_MISSING_FEATURE_ERROR, +    LIBSENSORS_REGEX_URL_COMPILE_ERROR, +    LIBSENSORS_CHIP_NOT_FOUND_ERROR  }; -#if SENSORS_API_VERSION < 0x400  +#if SENSORS_API_VERSION < 0x400  #define LIBSENSORS_CONFIG_FILE "/etc/sensors.conf"  #define LIBSENSORS_ALTERNATIVE_CONFIG_FILE "/usr/local/etc/sensors.conf"  #endif @@ -61,455 +61,405 @@ enum {  regex_t uri_re;  static char *get_chip_name_string(const sensors_chip_name *chip) { -	char *name; +    char *name;  #if SENSORS_API_VERSION < 0x400 -	// taken from lm-sensors:prog/sensors/main.c:sprintf_chip_name -	switch (chip->bus) { -	case SENSORS_CHIP_NAME_BUS_ISA: -		name = g_strdup_printf ("%s-isa-%04x", chip->prefix, chip->addr); -		break; -	case SENSORS_CHIP_NAME_BUS_DUMMY: -		name = g_strdup_printf ("%s-%s-%04x", chip->prefix, chip->busname, chip->addr); -		break; -        case SENSORS_CHIP_NAME_BUS_PCI: -                name = g_strdup_printf ("%s-pci-%04x", chip->prefix, chip->addr); -                break; -	default: -		name = g_strdup_printf ("%s-i2c-%d-%02x", chip->prefix, chip->bus, chip->addr); -		break; -	} +    /* taken from lm-sensors:prog/sensors/main.c:sprintf_chip_name */ +    switch (chip->bus) { +        case SENSORS_CHIP_NAME_BUS_ISA: +            name = g_strdup_printf ("%s-isa-%04x", chip->prefix, chip->addr); +            break; +        case SENSORS_CHIP_NAME_BUS_DUMMY: +            name = g_strdup_printf ("%s-%s-%04x", chip->prefix, chip->busname, chip->addr); +            break; +            case SENSORS_CHIP_NAME_BUS_PCI: +                    name = g_strdup_printf ("%s-pci-%04x", chip->prefix, chip->addr); +                    break; +        default: +            name = g_strdup_printf ("%s-i2c-%d-%02x", chip->prefix, chip->bus, chip->addr); +            break; +    } +  #else -	// adapted from lm-sensors:prog/sensors/main.c:sprintf_chip_name  -        // in lm-sensors-3.0 +/* adapted from lm-sensors:prog/sensors/main.c:sprintf_chip_name in lm-sensors-3.0 */  #define BUF_SIZE 200 -	name = g_malloc0(BUF_SIZE); -	if (sensors_snprintf_chip_name(name, BUF_SIZE, chip) < 0) { -		g_free(name); -                name = NULL; -        } -         +    name = g_malloc0(BUF_SIZE); +    if (sensors_snprintf_chip_name(name, BUF_SIZE, chip) < 0) { +        g_free(name); +        name = NULL; +    }  #endif -	return name; +    return name;  }  #if SENSORS_API_VERSION < 0x400  static SensorType get_sensor_type (const char *name) { -        SensorType type = CURRENT_SENSOR; - -	if (g_strrstr(name, "in")) { -                type = VOLTAGE_SENSOR; -	} -        else if (g_strrstr(name, "fan")) { -                type = FAN_SENSOR; -	} -        else if (g_strrstr(name, "temp")) { -                type = TEMP_SENSOR; -	} else { -                g_debug("sensor %s not recognised as either voltage, fan or temp sensor - assuming is a current sensor", name); -                type = CURRENT_SENSOR; -        } -        return type; +    SensorType type = CURRENT_SENSOR; + +    if (g_strrstr(name, "in")) { +        type = VOLTAGE_SENSOR; +    } +    else if (g_strrstr(name, "fan")) { +        type = FAN_SENSOR; +    } +    else if (g_strrstr(name, "temp")) { +        type = TEMP_SENSOR; +    } else { +        g_debug("sensor %s not recognised as either voltage, fan or temp sensor - assuming is a current sensor", name); +        type = CURRENT_SENSOR; +    } +    return type;  } -  /* If a sensor is 'interesting' to us then return its label, otherwise NULL. */  static char *get_sensor_interesting_label (sensors_chip_name chip, int feature) { -	char *label; - -	if (sensors_get_ignored(chip, feature) &&  -            (sensors_get_label(chip, feature, &label) == 0)) { -                if (! (strcmp ("alarms", label) == 0 || strncmp ("sensor", label, 6) == 0)) { -                        return label; -                } else { -                        free (label); -                } +    char *label; + +    if (sensors_get_ignored(chip, feature) && (sensors_get_label(chip, feature, &label) == 0)) { +        if (! (strcmp ("alarms", label) == 0 || strncmp ("sensor", label, 6) == 0)) { +            return label; +        } else { +            free (label);          } -         +    } -	return NULL; +    return NULL;  } -static const sensors_feature_data * get_sensor_min_max(const sensors_chip_name *chip,  -                               int *n1, int *n2, -                               int number,  -                               gdouble *low_value, -                               gdouble *high_value) { -	const sensors_feature_data *data; -	double value; -	 -	/* The sub features are returned directly after the main feature by -	   sensors_get_all_features(), so no need to iterate over all features */ -	while ((data = sensors_get_all_features (*chip, n1, n2)) != NULL && -			data->mapping == number) { -		if ((data->mode & SENSORS_MODE_R) &&  -		    (sensors_get_feature(*chip, data->number, &value) == 0) && -                    data->name != NULL) { -			if (g_str_has_suffix(data->name, "_min")) { -                                 -				*low_value = value; -                                 -                                g_debug("overriding low value of sensor %s with value %f", data->name, value); -                                 -                        } else if (g_str_has_suffix(data->name, "_max")) { -                                 -				*high_value = value; -                                g_debug("overriding high value of sensor %s with value %f", data->name, value); -                                 -                        } -                         -		} -	} -        return data; +static const sensors_feature_data * get_sensor_min_max(const sensors_chip_name *chip, +                                                        int *n1, int *n2, +                                                        int number, +                                                        gdouble *low_value, +                                                        gdouble *high_value) { + +    const sensors_feature_data *data; +    double value; + +    /* The sub features are returned directly after the main feature by +       sensors_get_all_features(), so no need to iterate over all features */ +    while ((data = sensors_get_all_features (*chip, n1, n2)) != NULL && data->mapping == number) { +        if ((data->mode & SENSORS_MODE_R) && (sensors_get_feature(*chip, data->number, &value) == 0) && data->name != NULL) { + +            if (g_str_has_suffix(data->name, "_min")) { +                *low_value = value; +                g_debug("overriding low value of sensor %s with value %f", data->name, value); +            } else if (g_str_has_suffix(data->name, "_max")) { +                *high_value = value; +                g_debug("overriding high value of sensor %s with value %f", data->name, value); +            } +        } +    } +    return data;  }  #endif  static IconType get_sensor_icon (SensorType type) { -	switch (type) { -	case TEMP_SENSOR: -		return CPU_ICON; -	case FAN_SENSOR: -		return FAN_ICON; -	default: -		return GENERIC_ICON; -	} +    switch (type) { +        case TEMP_SENSOR: +            return CPU_ICON; +        case FAN_SENSOR: +            return FAN_ICON; +        default: +            return GENERIC_ICON; +        }  } -  #if SENSORS_API_VERSION < 0x400  static void check_sensor_with_data(GList **sensors,                                     const char * const chip_name,                                     const sensors_chip_name *chip,                                     int *n1, int *n2, -                                   const sensors_feature_data *data)  -{ -        char *label; -	double value; -        SensorsAppletSensorInfo *sensor_info = NULL; -         -        /* ... some of which are boring ... */ -        if ((label = get_sensor_interesting_label (*chip, data->number))) { -                /* ... and some of which are actually sensors */ -                if ((data->mode & SENSORS_MODE_R) &&  -                    (data->mapping == SENSORS_NO_MAPPING) &&  -                    (sensors_get_feature(*chip, data->number, &value) == 0) // make sure we can actually get a value for it -                        ) { -                        SensorType type; -                        gboolean visible; -                        IconType icon; -                        gdouble low_value, high_value; -			 -                        gchar *url; -			 -                        type = get_sensor_type (data->name); -                        visible = (type == TEMP_SENSOR ? TRUE : FALSE); -                        icon = get_sensor_icon(type); -                         -                        // the 'path' contains all the information we need to -                        // identify this sensor later -                        url = g_strdup_printf ("sensor://%s/%d", chip_name, data->number); -                         -                        // get low and high values -                        sensors_applet_plugin_default_sensor_limits(type,  -                                                                    &low_value, -                                                                    &high_value); -                         -                        data = get_sensor_min_max(chip, n1, n2, data->number, -                                                  &low_value, &high_value);                         -                        if (data != NULL) { -                                // try adding this one -                                                        // at this point we have called sensors_get_all_features() and stopped when we have a potential new sensor, so make sure we try this as well - do a recursive call -                                check_sensor_with_data(sensors, chip_name, chip, n1, n2, data); -                                         -                        } - -                        g_hash_table_insert(hash_table, g_strdup(url), (void *)chip); -                        // the id identifies a particular sensor for the user; -                        // we default to the label returned by libsensors -                        sensors_applet_plugin_add_sensor_with_limits(sensors, -                                                                     url, -                                                                     label,  -                                                                     label, -                                                                     type,  -                                                                     visible, -                                                                     low_value,  -                                                                     high_value,  -                                                                     icon, -                                                                     DEFAULT_GRAPH_COLOR);                         -                        g_free(url); -                } -                free (label); +                                   const sensors_feature_data *data) { + +    char *label; +    double value; +    SensorsAppletSensorInfo *sensor_info = NULL; + +    /* ... some of which are boring ... */ +    if ((label = get_sensor_interesting_label (*chip, data->number))) { +        /* ... and some of which are actually sensors */ +        if ((data->mode & SENSORS_MODE_R) && +            (data->mapping == SENSORS_NO_MAPPING) && +            (sensors_get_feature(*chip, data->number, &value) == 0)) {    /* make sure we can actually get a value for it */ + +            SensorType type; +            gboolean visible; +            IconType icon; +            gdouble low_value, high_value; + +            gchar *url; + +            type = get_sensor_type (data->name); +            visible = (type == TEMP_SENSOR ? TRUE : FALSE); +            icon = get_sensor_icon(type); + +            /* the 'path' contains all the information we need to identify this sensor later */ +            url = g_strdup_printf ("sensor://%s/%d", chip_name, data->number); + +            /* get low and high values */ +            sensors_applet_plugin_default_sensor_limits(type, &low_value, &high_value); + +            data = get_sensor_min_max(chip, n1, n2, data->number, &low_value, &high_value); +            if (data != NULL) { +                /* try adding this one */ +                /* at this point we have called sensors_get_all_features() and stopped when we have a potential new sensor, so make sure we try this as well - do a recursive call */ +                check_sensor_with_data(sensors, chip_name, chip, n1, n2, data); +            } + +            g_hash_table_insert(hash_table, g_strdup(url), (void *)chip); +            /* the id identifies a particular sensor for the user; */ +            /* we default to the label returned by libsensors */ +            sensors_applet_plugin_add_sensor_with_limits(sensors, +                                                         url, +                                                         label, +                                                         label, +                                                         type, +                                                         visible, +                                                         low_value, +                                                         high_value, +                                                         icon, +                                                         DEFAULT_GRAPH_COLOR); +            g_free(url);          } -         +        free (label); +    } +  }  #endif -  static GList *libsensors_plugin_get_sensors(void) { -	const sensors_chip_name *chip_name; -	int i; -        GList *sensors = NULL; - -#if SENSORS_API_VERSION < 0x400         -	FILE *file; -        g_debug("%s: using libsensors version < 4", __FUNCTION__); - -	/* try to open config file, otherwise try alternate config -	 * file - if neither succeed, exit */ -	if ((file = fopen (LIBSENSORS_CONFIG_FILE, "r")) == NULL) { -		if ((file = fopen (LIBSENSORS_ALTERNATIVE_CONFIG_FILE, "r")) == NULL) { -                        g_debug("%s: error opening libsensors config file... ", __FUNCTION__); -			return sensors; -		} -	} -	 -	/* at this point should have an open config file, if is not -	 * valid, close file and return */ -	if (sensors_init(file) != 0) { -		fclose(file); -                g_debug("%s: error initing libsensors from config file...", __FUNCTION__); -		return sensors; -	} -	fclose(file); - -	/* libsensors exposes a number of chips -  ... */ -	i = 0; -	while ((chip_name = sensors_get_detected_chips (&i)) != NULL) { -		char *chip_name_string; -		const sensors_feature_data *data; -		int n1 = 0, n2 = 0; -                 -		chip_name_string = get_chip_name_string(chip_name); -		 -		/* ... each of which has one or more 'features' ... */ -		while ((data = sensors_get_all_features (*chip_name, &n1, &n2)) != NULL) { // error -                        // fill in list for us -                        check_sensor_with_data(&sensors, chip_name_string,  -                                               chip_name, &n1, &n2, data); -                } -		g_free (chip_name_string); -	} +    const sensors_chip_name *chip_name; +    int i; +    GList *sensors = NULL; + +#if SENSORS_API_VERSION < 0x400 +    FILE *file; +    g_debug("%s: using libsensors version < 4", __FUNCTION__); + +    /* try to open config file, otherwise try alternate config +     * file - if neither succeed, exit */ +    if ((file = fopen (LIBSENSORS_CONFIG_FILE, "r")) == NULL) { +        if ((file = fopen (LIBSENSORS_ALTERNATIVE_CONFIG_FILE, "r")) == NULL) { +            g_debug("%s: error opening libsensors config file... ", __FUNCTION__); +            return sensors; +        } +    } + +    /* at this point should have an open config file, if is not +     * valid, close file and return */ +    if (sensors_init(file) != 0) { +        fclose(file); +        g_debug("%s: error initing libsensors from config file...", __FUNCTION__); +        return sensors; +    } +    fclose(file); + +    /* libsensors exposes a number of chips -  ... */ +    i = 0; +    while ((chip_name = sensors_get_detected_chips (&i)) != NULL) { +        char *chip_name_string; +        const sensors_feature_data *data; +        int n1 = 0, n2 = 0; + +        chip_name_string = get_chip_name_string(chip_name); + +        /* ... each of which has one or more 'features' ... */ +        while ((data = sensors_get_all_features (*chip_name, &n1, &n2)) != NULL) { /* error */ +            /* fill in list for us */ +            check_sensor_with_data(&sensors, chip_name_string, chip_name, &n1, &n2, data); +        } +        g_free (chip_name_string); +    }  #else -        g_debug("%s: using libsensors version >= 4", __FUNCTION__); -         -        int nr = 0; -        if (sensors_init(NULL) != 0) { -                g_debug("%s: error initing libsensors", __FUNCTION__); -                return sensors; +    g_debug("%s: using libsensors version >= 4", __FUNCTION__); + +    int nr = 0; +    if (sensors_init(NULL) != 0) { +        g_debug("%s: error initing libsensors", __FUNCTION__); +        return sensors; +    } + +    i = 0; +    while ((chip_name = sensors_get_detected_chips(NULL, &nr))) { + +        char *chip_name_string, *label; +        const sensors_subfeature *input_feature; +        const sensors_subfeature *low_feature; +        const sensors_subfeature *high_feature; +        const sensors_feature *main_feature; +        SensorType type; +        gint nr1 = 0; +        gdouble value, low, high; +        gchar *path; +        gboolean visible; +        IconType icon; + +        chip_name_string = get_chip_name_string(chip_name); +        if (chip_name_string == NULL) { +            g_debug("%s: %d: error getting name string for sensor: %s\n", __FILE__, __LINE__, chip_name->path); +            continue;          } -	i = 0; -	while ((chip_name = sensors_get_detected_chips(NULL, &nr))) -        { -                char *chip_name_string, *label;                 -                const sensors_subfeature *input_feature; -                const sensors_subfeature *low_feature; -                const sensors_subfeature *high_feature; -		const sensors_feature *main_feature; -                SensorType type; -		gint nr1 = 0; -                gdouble value, low, high; -                gchar *path; -                gboolean visible; -                IconType icon; -                 -		chip_name_string = get_chip_name_string(chip_name); -                if (chip_name_string == NULL) { -                        g_debug("%s: %d: error getting name string for sensor: %s\n", -                                        __FILE__, __LINE__, chip_name->path); -                        continue; -                } -                 -		while ((main_feature = sensors_get_features(chip_name, &nr1))) -                { -			switch (main_feature->type) -                        { -                        case SENSORS_FEATURE_IN: -				type = VOLTAGE_SENSOR; -				input_feature = sensors_get_subfeature(chip_name,  -                                                                    main_feature,  -                                                                    SENSORS_SUBFEATURE_IN_INPUT); -				low_feature = sensors_get_subfeature(chip_name,  -                                                                     main_feature,  -                                                                     SENSORS_SUBFEATURE_IN_MIN); -				high_feature = sensors_get_subfeature(chip_name,  -                                                                      main_feature,  -                                                                      SENSORS_SUBFEATURE_IN_MAX); -			  	break; -                        case SENSORS_FEATURE_FAN: -				type = FAN_SENSOR; -				input_feature = sensors_get_subfeature(chip_name,  -                                                                    main_feature,  -                                                                    SENSORS_SUBFEATURE_FAN_INPUT); -				low_feature = sensors_get_subfeature(chip_name,  -                                                                     main_feature,  -                                                                     SENSORS_SUBFEATURE_FAN_MIN); -                                // no fan max feature -				high_feature = NULL; -				break; -                        case SENSORS_FEATURE_TEMP: -				type = TEMP_SENSOR; -				input_feature = sensors_get_subfeature(chip_name,  -                                                                    main_feature,  -                                                                    SENSORS_SUBFEATURE_TEMP_INPUT); -				low_feature = sensors_get_subfeature(chip_name,  -                                                                     main_feature,  -                                                                     SENSORS_SUBFEATURE_TEMP_MIN); -				high_feature = sensors_get_subfeature(chip_name,  -                                                                      main_feature,  -                                                                      SENSORS_SUBFEATURE_TEMP_MAX); -				if (!high_feature) -					high_feature = sensors_get_subfeature(chip_name,  -									      main_feature,  -									      SENSORS_SUBFEATURE_TEMP_CRIT); -				break; -                        default: -                                g_debug("%s: %d: error determining type for: %s\n", -                                        __FILE__, __LINE__, chip_name_string); -				continue; -                        } -                         -			if (!input_feature) -                        { -                                g_debug("%s: %d: could not get input subfeature for: %s\n", -                                        __FILE__, __LINE__, chip_name_string); -				continue; -                        } -                        // if still here we got input feature so get label -                        label = sensors_get_label(chip_name, main_feature); -                        if (!label)  -                        { -                                g_debug("%s: %d: error: could not get label for: %s\n", -                                        __FILE__, __LINE__, chip_name_string); -                                continue; -                        } - -                        g_assert(chip_name_string && label); -                         -                        icon = get_sensor_icon(type); -                        visible = (type == TEMP_SENSOR ? TRUE : FALSE); -                        sensors_applet_plugin_default_sensor_limits(type,  -                                                                    &low,  -                                                                    &high);                         -                        if (low_feature) { -                                sensors_get_value(chip_name, low_feature->number, &low); -                        } - -                        if (high_feature) { -                                sensors_get_value(chip_name, high_feature->number, &high); -                        } -                         -                                 -                        if (sensors_get_value(chip_name, input_feature->number, &value) < 0) { -                                g_debug("%s: %d: error: could not get value for input feature of sensor: %s\n", -                                        __FILE__, __LINE__, chip_name_string); -                                free(label); -                                continue; -                        } - -                        g_debug("for chip %s (type %s) got label %s and value %f", chip_name_string,  -                                (type == TEMP_SENSOR ? "temp" : -                                 (type == FAN_SENSOR ? "fan" : -                                  (type == VOLTAGE_SENSOR ? "voltage" : "error"))), label, value); - -                        path = g_strdup_printf ("sensor://%s/%d", chip_name_string, input_feature->number); -			g_hash_table_insert(hash_table, g_strdup(path), (void *)chip_name); -                        sensors_applet_plugin_add_sensor_with_limits(&sensors, -                                                                     path, -                                                                     label, -                                                                     label, -                                                                     type,  -                                                                     visible, -                                                                     low,  -                                                                     high, -                                                                     icon, -                                                                     DEFAULT_GRAPH_COLOR); -                } -                g_free(chip_name_string); -                 -                 + +        while ((main_feature = sensors_get_features(chip_name, &nr1))) { +            switch (main_feature->type) { +                case SENSORS_FEATURE_IN: +                    type = VOLTAGE_SENSOR; +                    input_feature = sensors_get_subfeature(chip_name, main_feature, SENSORS_SUBFEATURE_IN_INPUT); +                    low_feature = sensors_get_subfeature(chip_name, main_feature, SENSORS_SUBFEATURE_IN_MIN); +                    high_feature = sensors_get_subfeature(chip_name, main_feature, SENSORS_SUBFEATURE_IN_MAX); +                    break; + +                case SENSORS_FEATURE_FAN: +                    type = FAN_SENSOR; +                    input_feature = sensors_get_subfeature(chip_name, main_feature, SENSORS_SUBFEATURE_FAN_INPUT); +                    low_feature = sensors_get_subfeature(chip_name, main_feature, SENSORS_SUBFEATURE_FAN_MIN); +                    /* no fan max feature */ +                    high_feature = NULL; +                    break; + +                case SENSORS_FEATURE_TEMP: +                    type = TEMP_SENSOR; +                    input_feature = sensors_get_subfeature(chip_name, main_feature, SENSORS_SUBFEATURE_TEMP_INPUT); +                    low_feature = sensors_get_subfeature(chip_name, main_feature, SENSORS_SUBFEATURE_TEMP_MIN); +                    high_feature = sensors_get_subfeature(chip_name, main_feature, SENSORS_SUBFEATURE_TEMP_MAX); +                    if (!high_feature) +                        high_feature = sensors_get_subfeature(chip_name, main_feature, SENSORS_SUBFEATURE_TEMP_CRIT); +                    break; + +                default: +                    g_debug("%s: %d: error determining type for: %s\n", __FILE__, __LINE__, chip_name_string); +                    continue; +            } + +            if (!input_feature) { +                g_debug("%s: %d: could not get input subfeature for: %s\n", __FILE__, __LINE__, chip_name_string); +                continue; +            } + +            /* if still here we got input feature so get label */ +            label = sensors_get_label(chip_name, main_feature); +            if (!label) { +                g_debug("%s: %d: error: could not get label for: %s\n", __FILE__, __LINE__, chip_name_string); +                continue; +            } + +            g_assert(chip_name_string && label); + +            icon = get_sensor_icon(type); +            visible = (type == TEMP_SENSOR ? TRUE : FALSE); +            sensors_applet_plugin_default_sensor_limits(type, &low, &high); +            if (low_feature) { +                sensors_get_value(chip_name, low_feature->number, &low); +            } + +            if (high_feature) { +                sensors_get_value(chip_name, high_feature->number, &high); +            } + +            if (sensors_get_value(chip_name, input_feature->number, &value) < 0) { +                g_debug("%s: %d: error: could not get value for input feature of sensor: %s\n", __FILE__, __LINE__, chip_name_string); +                free(label); +                continue; +            } + +            g_debug("for chip %s (type %s) got label %s and value %f", chip_name_string, +                (type == TEMP_SENSOR ? "temp" : (type == FAN_SENSOR ? "fan" : (type == VOLTAGE_SENSOR ? "voltage" : "error"))), label, value); + +            path = g_strdup_printf ("sensor://%s/%d", chip_name_string, input_feature->number); +            g_hash_table_insert(hash_table, g_strdup(path), (void *)chip_name); + +            sensors_applet_plugin_add_sensor_with_limits(&sensors, +                                                         path, +                                                         label, +                                                         label, +                                                         type, +                                                         visible, +                                                         low, +                                                         high, +                                                         icon, +                                                         DEFAULT_GRAPH_COLOR);          } +        g_free(chip_name_string); + +    }  #endif -        return sensors; +    return sensors;  } -static gdouble libsensors_plugin_get_sensor_value(const gchar *path,  -						  const gchar *id,  -						  SensorType type, -						  GError **error) { -	gdouble result = 0; -	regmatch_t m[3]; - -	/* parse the uri into a (chip, feature) tuplet */ -	if (regexec (&uri_re, path, 3, m, 0) == 0) { -		const sensors_chip_name *found_chip; -		int feature; -		int i; - -		if ((found_chip = g_hash_table_lookup(hash_table, -						     path)) != NULL) -		{ -			gdouble value; -			feature = atoi(path + m[2].rm_so); +static gdouble libsensors_plugin_get_sensor_value(const gchar *path, +                                                    const gchar *id, +                                                    SensorType type, +                                                    GError **error) { +    gdouble result = 0; +    regmatch_t m[3]; + +    /* parse the uri into a (chip, feature) tuplet */ +    if (regexec (&uri_re, path, 3, m, 0) == 0) { +        const sensors_chip_name *found_chip; +        int feature; +        int i; + +        if ((found_chip = g_hash_table_lookup(hash_table, path)) != NULL) { +            gdouble value; +            feature = atoi(path + m[2].rm_so); +  #if SENSORS_API_VERSION < 0x400 -			/* retrieve the value of the feature */ -			if (sensors_get_feature (*found_chip, feature, &value) == 0) { -				result = value; -			} else { -				g_set_error (error, SENSORS_APPLET_PLUGIN_ERROR, LIBSENSORS_MISSING_FEATURE_ERROR, "Error retrieving sensor value"); -			} +            /* retrieve the value of the feature */ +            if (sensors_get_feature (*found_chip, feature, &value) == 0) { +                result = value; +            } else { +                g_set_error (error, SENSORS_APPLET_PLUGIN_ERROR, LIBSENSORS_MISSING_FEATURE_ERROR, "Error retrieving sensor value"); +            }  #else -			if (sensors_get_value(found_chip, feature, &value) >= 0) { -				result = value; -			} else { -				g_set_error (error, SENSORS_APPLET_PLUGIN_ERROR, LIBSENSORS_MISSING_FEATURE_ERROR, "Error retrieving sensor value"); -			} +            if (sensors_get_value(found_chip, feature, &value) >= 0) { +                result = value; +            } else { +                g_set_error (error, SENSORS_APPLET_PLUGIN_ERROR, LIBSENSORS_MISSING_FEATURE_ERROR, "Error retrieving sensor value"); +            }  #endif -		} else { -			g_set_error (error, SENSORS_APPLET_PLUGIN_ERROR, LIBSENSORS_CHIP_NOT_FOUND_ERROR, "Chip not found"); -		} -	} else { -		g_set_error (error, SENSORS_APPLET_PLUGIN_ERROR, LIBSENSORS_REGEX_URL_COMPILE_ERROR, "Error compiling URL regex"); -	} -	return result; + +        } else { +            g_set_error (error, SENSORS_APPLET_PLUGIN_ERROR, LIBSENSORS_CHIP_NOT_FOUND_ERROR, "Chip not found"); +        } +    } else { +        g_set_error (error, SENSORS_APPLET_PLUGIN_ERROR, LIBSENSORS_REGEX_URL_COMPILE_ERROR, "Error compiling URL regex"); +    } +    return result;  }  static GList *libsensors_plugin_init() { -	/* compile the regular expressions */ -	if (regcomp(&uri_re, "^sensor://([a-z0-9_-]+)/([0-9]+)$", -                    REG_EXTENDED | REG_ICASE) != 0) { -		g_debug("Error compiling regexp...not initing libsensors sensors interface"); -		return NULL; -	} - -	/* create hash table to associate path strings with sensors_chip_name -	 * pointers - make sure it free's the keys strings on destroy */ -	hash_table = g_hash_table_new_full(g_str_hash, -					   g_str_equal, -					   g_free, -					   NULL); -	return libsensors_plugin_get_sensors(); +    /* compile the regular expressions */ +    if (regcomp(&uri_re, "^sensor://([a-z0-9_-]+)/([0-9]+)$", REG_EXTENDED | REG_ICASE) != 0) { +        g_debug("Error compiling regexp...not initing libsensors sensors interface"); +        return NULL; +    } + +    /* create hash table to associate path strings with sensors_chip_name +     * pointers - make sure it free's the keys strings on destroy */ +    hash_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); +    return libsensors_plugin_get_sensors();  } - -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 libsensors_plugin_init(); +    return libsensors_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 libsensors_plugin_get_sensor_value(path, id, type, error); + +    return libsensors_plugin_get_sensor_value(path, id, type, error);  } diff --git a/plugins/mbmon/mbmon-plugin.c b/plugins/mbmon/mbmon-plugin.c index fc7b854..9f25777 100644 --- a/plugins/mbmon/mbmon-plugin.c +++ b/plugins/mbmon/mbmon-plugin.c @@ -46,146 +46,144 @@ const gchar *plugin_name = "mbmon";  #define MBMON_OUTPUT_BUFFER_LENGTH 1024  enum { -	MBMON_SOCKET_OPEN_ERROR, -	MBMON_SOCKET_CONNECT_ERROR, -	MBMON_GIOCHANNEL_ERROR, -	MBMON_GIOCHANNEL_READ_ERROR - +    MBMON_SOCKET_OPEN_ERROR, +    MBMON_SOCKET_CONNECT_ERROR, +    MBMON_GIOCHANNEL_ERROR, +    MBMON_GIOCHANNEL_READ_ERROR  };  static const gchar *mbmon_plugin_query_mbmon_daemon(GError **error) { -	int sockfd; -	ssize_t n = 1; -	gboolean first_run = FALSE; -	gint output_length = 0; -	gchar *pc; - -	struct sockaddr_in address; -	static char* buffer = NULL; -	static GTimeVal previous_query_time; -	GTimeVal current_query_time; - -	if (NULL == buffer) { -		// initialise buffer and current time -		buffer = g_new0(char, MBMON_OUTPUT_BUFFER_LENGTH); -		g_get_current_time(&previous_query_time); -		first_run = TRUE; -	} -	g_get_current_time(¤t_query_time); - -	/* only query if more than 2 seconds has elapsed, -	mbmon daemon will send a new value every 2 seconds */ -	if (first_run || current_query_time.tv_sec - previous_query_time.tv_sec > 2) { -		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, MBMON_SOCKET_OPEN_ERROR, "Error opening socket for mbmon"); -			return NULL; -		} - -		address.sin_family = AF_INET; -		address.sin_addr.s_addr = inet_addr(MBMON_SERVER_IP_ADDRESS); -		address.sin_port = htons(MBMON_PORT_NUMBER); - -		if (connect(sockfd, (struct sockaddr *)&address, (socklen_t)sizeof(address)) == -1) { -			g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, MBMON_SOCKET_CONNECT_ERROR, "Error connecting to mbmon daemon on port %i on %s", htons(MBMON_PORT_NUMBER), MBMON_SERVER_IP_ADDRESS); -			return NULL; -		} - -		pc = buffer; -		while ((n = read(sockfd, pc, MBMON_OUTPUT_BUFFER_LENGTH - output_length)) > 0) { -			output_length += n; -			pc = &pc[n]; -		} -		/* always null terminate the end of the buffer -		 * regardless of how much stuff is in it already */ -		buffer[output_length] = '\0'; -		close(sockfd); -	} - -	return buffer; +    int sockfd; +    ssize_t n = 1; +    gboolean first_run = FALSE; +    gint output_length = 0; +    gchar *pc; + +    struct sockaddr_in address; +    static char* buffer = NULL; +    static GTimeVal previous_query_time; +    GTimeVal current_query_time; + +    if (NULL == buffer) { +        /* initialise buffer and current time */ +        buffer = g_new0(char, MBMON_OUTPUT_BUFFER_LENGTH); +        g_get_current_time(&previous_query_time); +        first_run = TRUE; +    } +    g_get_current_time(¤t_query_time); + +    /* only query if more than 2 seconds has elapsed, +    mbmon daemon will send a new value every 2 seconds */ +    if (first_run || current_query_time.tv_sec - previous_query_time.tv_sec > 2) { +        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, MBMON_SOCKET_OPEN_ERROR, "Error opening socket for mbmon"); +            return NULL; +        } + +        address.sin_family = AF_INET; +        address.sin_addr.s_addr = inet_addr(MBMON_SERVER_IP_ADDRESS); +        address.sin_port = htons(MBMON_PORT_NUMBER); + +        if (connect(sockfd, (struct sockaddr *)&address, (socklen_t)sizeof(address)) == -1) { +            g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, MBMON_SOCKET_CONNECT_ERROR, "Error connecting to mbmon daemon on port %i on %s", htons(MBMON_PORT_NUMBER), MBMON_SERVER_IP_ADDRESS); +            return NULL; +        } + +        pc = buffer; +        while ((n = read(sockfd, pc, MBMON_OUTPUT_BUFFER_LENGTH - output_length)) > 0) { +            output_length += n; +            pc = &pc[n]; +        } +        /* always null terminate the end of the buffer +         * regardless of how much stuff is in it already */ +        buffer[output_length] = '\0'; +        close(sockfd); +    } + +    return buffer;  }  static SensorType get_sensor_type (const char *name) { -        SensorType type = CURRENT_SENSOR; +    SensorType type = CURRENT_SENSOR; -	if (g_strrstr(name, "FAN")) { +    if (g_strrstr(name, "FAN")) {          type = FAN_SENSOR; -	} -    else if (g_strrstr(name, "TEMP")) { +    } else if (g_strrstr(name, "TEMP")) {          type = TEMP_SENSOR; -	} else { +    } else {          type = VOLTAGE_SENSOR;      } -        return type; +    return type;  }  static IconType get_sensor_icon (SensorType type) { -	switch (type) { -	case TEMP_SENSOR: -		return CPU_ICON; -	case FAN_SENSOR: -		return FAN_ICON; -	default: -		return GENERIC_ICON; -	} +    switch (type) { +        case TEMP_SENSOR: +            return CPU_ICON; +        case FAN_SENSOR: +            return FAN_ICON; +        default: +            return GENERIC_ICON; +    }  }  static void mbmon_plugin_get_sensors(GList **sensors) { -	GError *error = NULL; -	const gchar *mbmon_output; -	gchar **output_vector = NULL, **pv, **pv2; +    GError *error = NULL; +    const gchar *mbmon_output; +    gchar **output_vector = NULL, **pv, **pv2; -	mbmon_output = mbmon_plugin_query_mbmon_daemon(&error); +    mbmon_output = mbmon_plugin_query_mbmon_daemon(&error); -	if (error) { -		g_error_free(error); -		return; -	} +    if (error) { +        g_error_free(error); +        return; +    } -	pv = output_vector = g_strsplit(mbmon_output, "\n", -1); +    pv = output_vector = g_strsplit(mbmon_output, "\n", -1); -	while(pv[0] != NULL) { -		pv2 = g_strsplit(pv[0], ":", -1); -		gchar *name, *label; -		SensorType type; +    while(pv[0] != NULL) { +        pv2 = g_strsplit(pv[0], ":", -1); +        gchar *name, *label; +        SensorType type;          gboolean visible;          IconType icon;          gdouble low_value, high_value; -		type = get_sensor_type(pv2[0]); -		icon = get_sensor_icon(type); -		name = g_strstrip(pv2[0]); -		label = NULL; -		visible = (type == TEMP_SENSOR ? TRUE : FALSE); - -		if(type == VOLTAGE_SENSOR) { -		    if(g_strrstr(name, "VC0")) { -		        label = g_strdup("Core Voltage 1"); -		    } else if(g_strrstr(name, "VC1")) { -		        label = g_strdup("Core Voltage 2"); -		    } else if(g_strrstr(name, "V33")) { -		        label = g_strdup("+3.3v Voltage"); -		    } else if(g_strrstr(name, "V50P")) { -		        label = g_strdup("+5v Voltage"); -		    } else if(g_strrstr(name, "V12P")) { -		        label = g_strdup("+12v Voltage"); -		    } else if(g_strrstr(name, "V12N")) { -		        label = g_strdup("-12v Voltage"); -		    } else if(g_strrstr(name, "V50N")) { -		        label = g_strdup("-5v Voltage"); -		    } -		} - -		label = (label == NULL ? name : label); - -		sensors_applet_plugin_default_sensor_limits(type, &low_value, &high_value); - -		sensors_applet_plugin_add_sensor_with_limits(sensors, -		                                             name, -		                                             name, +        type = get_sensor_type(pv2[0]); +        icon = get_sensor_icon(type); +        name = g_strstrip(pv2[0]); +        label = NULL; +        visible = (type == TEMP_SENSOR ? TRUE : FALSE); + +        if(type == VOLTAGE_SENSOR) { +            if(g_strrstr(name, "VC0")) { +                label = g_strdup("Core Voltage 1"); +            } else if(g_strrstr(name, "VC1")) { +                label = g_strdup("Core Voltage 2"); +            } else if(g_strrstr(name, "V33")) { +                label = g_strdup("+3.3v Voltage"); +            } else if(g_strrstr(name, "V50P")) { +                label = g_strdup("+5v Voltage"); +            } else if(g_strrstr(name, "V12P")) { +                label = g_strdup("+12v Voltage"); +            } else if(g_strrstr(name, "V12N")) { +                label = g_strdup("-12v Voltage"); +            } else if(g_strrstr(name, "V50N")) { +                label = g_strdup("-5v Voltage"); +            } +        } + +        label = (label == NULL ? name : label); + +        sensors_applet_plugin_default_sensor_limits(type, &low_value, &high_value); + +        sensors_applet_plugin_add_sensor_with_limits(sensors, +                                                     name, +                                                     name,                                                       label,                                                       type,                                                       visible, @@ -194,69 +192,70 @@ static void mbmon_plugin_get_sensors(GList **sensors) {                                                       icon,                                                       DEFAULT_GRAPH_COLOR); -	    g_strfreev(pv2); -		pv++; -	} -	g_strfreev(output_vector); +        g_strfreev(pv2); +        pv++; +    } +    g_strfreev(output_vector);  }  /* to be called to setup for mbmon sensors */  static GList *mbmon_plugin_init(void) { -	GList *sensors = NULL; -	mbmon_plugin_get_sensors(&sensors); -        return sensors; +    GList *sensors = NULL; +    mbmon_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 mbmon_plugin_get_sensor_value(const gchar *path, -						  const gchar *id, -						  SensorType type, -						  GError **error) { +                                            const gchar *id, +                                            SensorType type, +                                            GError **error) { -	const gchar *mbmon_output; -	gchar **output_vector = NULL, **pv, **pv2; +    const gchar *mbmon_output; +    gchar **output_vector = NULL, **pv, **pv2; -	gfloat sensor_value = -1.0f; +    gfloat sensor_value = -1.0f; -	mbmon_output = mbmon_plugin_query_mbmon_daemon(error); +    mbmon_output = mbmon_plugin_query_mbmon_daemon(error); -	if (*error) { -		return sensor_value; -	} +    if (*error) { +        return sensor_value; +    } -	pv = output_vector = g_strsplit(mbmon_output, "\n", -1); +    pv = output_vector = g_strsplit(mbmon_output, "\n", -1); -	while(pv[0] != NULL) { -		if (g_strrstr(pv[0], path) != NULL) { +    while(pv[0] != NULL) { +        if (g_strrstr(pv[0], path) != NULL) { -		    pv2 = g_strsplit(pv[0], ":", -1); -			sensor_value = (gfloat)(g_ascii_strtod(pv2[1], NULL)); -	        g_strfreev(pv2); -			break; -		} -		pv++; -	} -	g_strfreev(output_vector); +            pv2 = g_strsplit(pv[0], ":", -1); +            sensor_value = (gfloat)(g_ascii_strtod(pv2[1], NULL)); +            g_strfreev(pv2); +            break; +        } +        pv++; +    } +    g_strfreev(output_vector); -	return (gdouble)sensor_value; +    return (gdouble)sensor_value;  }  const gchar *sensors_applet_plugin_name(void)  { -        return plugin_name; +    return plugin_name;  }  GList *sensors_applet_plugin_init(void)  { -        return mbmon_plugin_init(); +    return mbmon_plugin_init();  }  gdouble sensors_applet_plugin_get_sensor_value(const gchar *path,                                                  const gchar *id,                                                  SensorType type,                                                  GError **error) { -        return mbmon_plugin_get_sensor_value(path, id, type, error); + +    return mbmon_plugin_get_sensor_value(path, id, type, error);  } diff --git a/plugins/nvidia/nvidia-plugin.c b/plugins/nvidia/nvidia-plugin.c index 46a7b32..4a30e34 100644 --- a/plugins/nvidia/nvidia-plugin.c +++ b/plugins/nvidia/nvidia-plugin.c @@ -40,178 +40,183 @@ const gchar *plugin_name = "nvidia";  Display *nvidia_sensors_dpy; /* the connection to the X server */  /* returns the value of the sensor */ -static gdouble nvidia_plugin_get_sensor_value(const gchar *path,  -                                              const gchar *id,  +static gdouble nvidia_plugin_get_sensor_value(const gchar *path, +                                              const gchar *id,                                                SensorType type, -                                              GError **error) -{ -	Bool res; -	int temp; -	int i; - -	i = g_ascii_strtoll(id + strlen("GPU"), NULL, 10); -        if (g_ascii_strcasecmp(path, THERMAL_SENSOR_TEMP) == 0) { -		res = XNVCTRLQueryTargetAttribute(nvidia_sensors_dpy, -						  NV_CTRL_TARGET_TYPE_THERMAL_SENSOR, -						  i, -						  0, -						  NV_CTRL_THERMAL_SENSOR_READING, -						  &temp); -        } else if (g_ascii_strcasecmp(path, THERMAL_COOLER_LEVEL) == 0) { -		res = XNVCTRLQueryTargetAttribute(nvidia_sensors_dpy, -						  NV_CTRL_TARGET_TYPE_COOLER, -						  i, -						  0, -						  NV_CTRL_THERMAL_COOLER_LEVEL, -						  &temp); -        } else if (g_ascii_strcasecmp(path, GPU_CORE_TEMP) == 0) { -		res = XNVCTRLQueryTargetAttribute(nvidia_sensors_dpy, -						  NV_CTRL_TARGET_TYPE_GPU, -						  i, -						  0, -						  NV_CTRL_GPU_CORE_TEMPERATURE, -						  &temp); -        } else if (g_ascii_strcasecmp(path, AMBIENT_TEMP) == 0) { -		res = XNVCTRLQueryTargetAttribute(nvidia_sensors_dpy, -						  NV_CTRL_TARGET_TYPE_GPU, -						  i, -						  0, -						  NV_CTRL_AMBIENT_TEMPERATURE, -						  &temp); -        } else { -                g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, 0, "Invalid path string passed to nvidia_plugin_get_sensor_value"); -                return 0; -        } -                 - -        if (res != True) { -                /* when res isn't true something went wrong */ -                g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, 0, "XNVCTRLQueryAttribute returned false"); -                return 0; -        } -         -        /* convert the int to gdouble and return it */ -        return (gdouble)temp; +                                              GError **error) { + +    Bool res; +    int temp; +    int i; + +    i = g_ascii_strtoll(id + strlen("GPU"), NULL, 10); +    if (g_ascii_strcasecmp(path, THERMAL_SENSOR_TEMP) == 0) { +        res = XNVCTRLQueryTargetAttribute(nvidia_sensors_dpy, +                          NV_CTRL_TARGET_TYPE_THERMAL_SENSOR, +                          i, +                          0, +                          NV_CTRL_THERMAL_SENSOR_READING, +                          &temp); + +    } else if (g_ascii_strcasecmp(path, THERMAL_COOLER_LEVEL) == 0) { +        res = XNVCTRLQueryTargetAttribute(nvidia_sensors_dpy, +                          NV_CTRL_TARGET_TYPE_COOLER, +                          i, +                          0, +                          NV_CTRL_THERMAL_COOLER_LEVEL, +                          &temp); + +    } else if (g_ascii_strcasecmp(path, GPU_CORE_TEMP) == 0) { +        res = XNVCTRLQueryTargetAttribute(nvidia_sensors_dpy, +                          NV_CTRL_TARGET_TYPE_GPU, +                          i, +                          0, +                          NV_CTRL_GPU_CORE_TEMPERATURE, +                          &temp); + +    } else if (g_ascii_strcasecmp(path, AMBIENT_TEMP) == 0) { +        res = XNVCTRLQueryTargetAttribute(nvidia_sensors_dpy, +                          NV_CTRL_TARGET_TYPE_GPU, +                          i, +                          0, +                          NV_CTRL_AMBIENT_TEMPERATURE, +                          &temp); + +    } else { +        g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, 0, "Invalid path string passed to nvidia_plugin_get_sensor_value"); +        return 0; +    } + +    if (res != True) { +        /* when res isn't true something went wrong */ +        g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, 0, "XNVCTRLQueryAttribute returned false"); +        return 0; +    } + +    /* convert the int to gdouble and return it */ +    return (gdouble)temp;  }  /* creates the connection to the X server and checks whether the   * NV-CONTROL extension is loaded */ -static GList *nvidia_plugin_init(void) -{ -	int dummy; -	int event_base, error_base; -        GList *sensors = NULL; - -	/* create the connection to the X server */ -	if (!(nvidia_sensors_dpy = XOpenDisplay(NULL))) { -		/* no connection to the X server avaible */ -		return sensors; -	} +static GList *nvidia_plugin_init(void) { +    int dummy; +    int event_base, error_base; +    GList *sensors = NULL; + +    /* create the connection to the X server */ +    if (!(nvidia_sensors_dpy = XOpenDisplay(NULL))) { +        /* no connection to the X server avaible */ +        return sensors; +    } -	/* check if the NV-CONTROL extension is available on this X +    /* check if the NV-CONTROL extension is available on this X           * server - if so add the two sensors if they exist */ -	if (XNVCTRLQueryExtension(nvidia_sensors_dpy, &event_base, &error_base)) { -		int i, cnt; - -		if (XNVCTRLQueryTargetCount(nvidia_sensors_dpy, -					    NV_CTRL_TARGET_TYPE_THERMAL_SENSOR, -					    &cnt)) { -			for (i = 0; i < cnt; i++) { -				gchar *id = g_strdup_printf("GPU%d%s", i, THERMAL_SENSOR_TEMP); - -				sensors_applet_plugin_add_sensor(&sensors, -								 THERMAL_SENSOR_TEMP, -								 id, -								 _("GPU"), -								 TEMP_SENSOR, -								 TRUE, -								 GPU_ICON, -								 DEFAULT_GRAPH_COLOR); - -				g_free(id); -			} -		} - -		if (XNVCTRLQueryTargetCount(nvidia_sensors_dpy, -					    NV_CTRL_TARGET_TYPE_COOLER, -					    &cnt)) { - -			for (i = 0; i < cnt; i++) { -				gchar *id = g_strdup_printf("GPU%d%s", i, THERMAL_COOLER_LEVEL); - -				sensors_applet_plugin_add_sensor(&sensors, -								 THERMAL_COOLER_LEVEL, -								 id, -								 _("GPU"), -								 FAN_SENSOR, -								 TRUE, -								 FAN_ICON, -								 DEFAULT_GRAPH_COLOR); - -				g_free(id); -			} -		} - -		if (XNVCTRLQueryTargetCount(nvidia_sensors_dpy, -					    NV_CTRL_TARGET_TYPE_GPU, -					    &cnt)) -		{ -			for (i = 0; i < cnt; i++) -			{ -				if (XNVCTRLQueryTargetAttribute(nvidia_sensors_dpy, -								NV_CTRL_TARGET_TYPE_GPU, -								i, -							       	0, NV_CTRL_GPU_CORE_TEMPERATURE, &dummy)) { -					gchar *id = g_strdup_printf("GPU%d%s", 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); -				} -				if (XNVCTRLQueryTargetAttribute(nvidia_sensors_dpy, -								NV_CTRL_TARGET_TYPE_GPU, -								i, -							       	0, NV_CTRL_AMBIENT_TEMPERATURE, &dummy)) { -					gchar *id = g_strdup_printf("GPU%d%s", i, AMBIENT_TEMP); - -					sensors_applet_plugin_add_sensor(&sensors, -                                                         AMBIENT_TEMP, -							 id, -                                                         _("Ambient"), -                                                         TEMP_SENSOR, -                                                         FALSE, -                                                         GENERIC_ICON, -                                                         DEFAULT_GRAPH_COLOR); -					g_free(id); -				} -			} +    if (XNVCTRLQueryExtension(nvidia_sensors_dpy, &event_base, &error_base)) { +        int i, cnt; + +        if (XNVCTRLQueryTargetCount(nvidia_sensors_dpy, +                        NV_CTRL_TARGET_TYPE_THERMAL_SENSOR, +                        &cnt)) { + +            for (i = 0; i < cnt; i++) { +                gchar *id = g_strdup_printf("GPU%d%s", i, THERMAL_SENSOR_TEMP); + +                sensors_applet_plugin_add_sensor(&sensors, +                                                 THERMAL_SENSOR_TEMP, +                                                 id, +                                                 _("GPU"), +                                                 TEMP_SENSOR, +                                                 TRUE, +                                                 GPU_ICON, +                                                 DEFAULT_GRAPH_COLOR); + +                g_free(id); +            } +        } + +        if (XNVCTRLQueryTargetCount(nvidia_sensors_dpy, +                        NV_CTRL_TARGET_TYPE_COOLER, +                        &cnt)) { + +            for (i = 0; i < cnt; i++) { +                gchar *id = g_strdup_printf("GPU%d%s", i, THERMAL_COOLER_LEVEL); + +                sensors_applet_plugin_add_sensor(&sensors, +                                                 THERMAL_COOLER_LEVEL, +                                                 id, +                                                 _("GPU"), +                                                 FAN_SENSOR, +                                                 TRUE, +                                                 FAN_ICON, +                                                 DEFAULT_GRAPH_COLOR); + +                g_free(id); +            } +        } + +        if (XNVCTRLQueryTargetCount(nvidia_sensors_dpy, +                        NV_CTRL_TARGET_TYPE_GPU, +                        &cnt)) { + +            for (i = 0; i < cnt; i++) { +                if (XNVCTRLQueryTargetAttribute(nvidia_sensors_dpy, +                                NV_CTRL_TARGET_TYPE_GPU, +                                i, +                                       0, NV_CTRL_GPU_CORE_TEMPERATURE, &dummy)) { + +                    gchar *id = g_strdup_printf("GPU%d%s", 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);                  } +                if (XNVCTRLQueryTargetAttribute(nvidia_sensors_dpy, +                                NV_CTRL_TARGET_TYPE_GPU, +                                i, +                                       0, NV_CTRL_AMBIENT_TEMPERATURE, &dummy)) { +                    gchar *id = g_strdup_printf("GPU%d%s", i, AMBIENT_TEMP); + +                    sensors_applet_plugin_add_sensor(&sensors, +                                                     AMBIENT_TEMP, +                                                     id, +                                                     _("Ambient"), +                                                     TEMP_SENSOR, +                                                     FALSE, +                                                     GENERIC_ICON, +                                                     DEFAULT_GRAPH_COLOR); +                    g_free(id); +                } +            }          } -        return sensors; + +    } +    return sensors;  } -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 nvidia_plugin_init(); +    return nvidia_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 nvidia_plugin_get_sensor_value(path, id, type, error); + +    return nvidia_plugin_get_sensor_value(path, id, type, error);  } diff --git a/plugins/omnibook/omnibook-plugin.c b/plugins/omnibook/omnibook-plugin.c index 7906d21..386511c 100644 --- a/plugins/omnibook/omnibook-plugin.c +++ b/plugins/omnibook/omnibook-plugin.c @@ -33,75 +33,74 @@ const gchar *plugin_name = "omnibook";  #define OMNIBOOK_DEVICE_FILE "/proc/omnibook/temperature"  enum { -	OMNIBOOK_DEVICE_FILE_OPEN_ERROR, -	OMNIBOOK_DEVICE_FILE_READ_ERROR +    OMNIBOOK_DEVICE_FILE_OPEN_ERROR, +    OMNIBOOK_DEVICE_FILE_READ_ERROR  };  static void omnibook_plugin_setup_manually(GList **sensors) { -	/* omnibook only has the one device file with one temp in it */ -	if (g_file_test(OMNIBOOK_DEVICE_FILE, G_FILE_TEST_EXISTS)) { - -		sensors_applet_plugin_add_sensor(sensors, -                                                 OMNIBOOK_DEVICE_FILE, -                                                 _("temperature"), -                                                 _("CPU"), -                                                 TEMP_SENSOR, -                                                 TRUE, -                                                 CPU_ICON, -                                                 DEFAULT_GRAPH_COLOR); -	} -}	 +    /* omnibook only has the one device file with one temp in it */ +    if (g_file_test(OMNIBOOK_DEVICE_FILE, G_FILE_TEST_EXISTS)) { + +        sensors_applet_plugin_add_sensor(sensors, +                                         OMNIBOOK_DEVICE_FILE, +                                         _("temperature"), +                                         _("CPU"), +                                         TEMP_SENSOR, +                                         TRUE, +                                         CPU_ICON, +                                         DEFAULT_GRAPH_COLOR); +    } +}  /* to be called to setup for sys sensors */  static GList *omnibook_plugin_init(void) { -        GList *sensors = NULL; -        /* call function to recursively look for sensors -	   starting at the defined base directory */ -	omnibook_plugin_setup_manually(&sensors); -        return sensors; -		 -} +    GList *sensors = NULL; +    /* call function to recursively look for sensors starting at the defined base directory */ +    omnibook_plugin_setup_manually(&sensors); +    return sensors; +} -static gdouble omnibook_plugin_get_sensor_value(const gchar *path,  -						  const gchar *id,  -						  SensorType type, -						  GError **error) { +static gdouble omnibook_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; +    /* 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, OMNIBOOK_DEVICE_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, OMNIBOOK_DEVICE_FILE_OPEN_ERROR, "Error opening sensor device file %s", path); +        return -1.0; +    } -	if (fscanf(fp, "CPU temperature: %f", &sensor_value) != 1) { -		g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, OMNIBOOK_DEVICE_FILE_READ_ERROR, "Error reading from sensor device file %s", path); -		fclose(fp); -		return -1.0; -	} +    if (fscanf(fp, "CPU temperature: %f", &sensor_value) != 1) { +        g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, OMNIBOOK_DEVICE_FILE_READ_ERROR, "Error reading from sensor device file %s", path); +        fclose(fp); +        return -1.0; +    } -	fclose(fp); +    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 omnibook_plugin_init(); +    return omnibook_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 omnibook_plugin_get_sensor_value(path, id, type, error); + +    return omnibook_plugin_get_sensor_value(path, id, type, error);  } | 
