#include <hdd.h>
#include <psensor.h>
-#include <lmsensor.h>
#include <temperature.h>
-#ifdef HAVE_GTOP
-#include <cpu.h>
-#include <pmem.h>
-#endif
-
struct psensor *psensor_create(char *id,
char *name,
char *chip,
psensor->graph_enabled = 1;
psensor->appindicator_enabled = 0;
+ psensor->provider_data = NULL;
+ psensor->provider_data_free_fct = &free;
+
return psensor;
}
if (cur_ms) {
int i;
+
for (i = 0; i < new_size - 1 && i < cur_size - 1; i++)
measure_copy(&cur_ms[cur_size - i - 1],
&new_ms[new_size - i - 1]);
s->measures = new_ms;
}
-void psensor_free(struct psensor *sensor)
+void psensor_free(struct psensor *s)
{
- if (sensor) {
- log_debug("Cleanup %s", sensor->id);
+ if (!s)
+ return;
- free(sensor->name);
- free(sensor->id);
+ log_debug("Cleanup %s", s->id);
- if (sensor->chip)
- free(sensor->chip);
+ free(s->name);
+ free(s->id);
- if (sensor->color)
- free(sensor->color);
+ if (s->chip)
+ free(s->chip);
- measures_free(sensor->measures);
+ if (s->color)
+ free(s->color);
- free(sensor->url);
+ measures_free(s->measures);
- free(sensor);
- }
+ free(s->url);
+
+ if (s->provider_data && s->provider_data_free_fct)
+ s->provider_data_free_fct(s->provider_data);
+
+ free(s);
}
void psensor_list_free(struct psensor **sensors)
return size;
}
-int psensor_list_contains_type(struct psensor **sensors, unsigned int type)
-{
- struct psensor **s;
-
- if (!sensors)
- return 0;
-
- s = sensors;
- while (*s) {
- if ((*s)->type & type)
- return 1;
- s++;
- }
-
- return 0;
-}
-
struct psensor **psensor_list_add(struct psensor **sensors,
struct psensor *sensor)
{
struct psensor **tmp;
if (!sensor)
- return ;
+ return;
tmp = psensor_list_add(*sensors, sensor);
return type & SENSOR_TYPE_TEMP;
}
-int is_fan_type(unsigned int type)
-{
- return type & SENSOR_TYPE_FAN;
-}
-
char *
psensor_value_to_str(unsigned int type, double value, int use_celsius)
{
if (sensor->type & type) {
int i;
double t;
+
for (i = 0; i < sensor->values_max_length; i++) {
t = sensor->measures[i].value;
return get_max_value(sensors, SENSOR_TYPE_TEMP);
}
-struct psensor **get_all_sensors(int use_libatasmart, int values_max_length)
-{
- struct psensor **psensors;
- struct psensor **tmp_psensors;
-
- psensors = lmsensor_psensor_list_add(NULL, values_max_length);
-
- if (!use_libatasmart) {
- tmp_psensors = hddtemp_psensor_list_add(psensors,
- values_max_length);
- if (tmp_psensors != psensors) {
- free(psensors);
- psensors = tmp_psensors;
- }
- }
-#ifdef HAVE_ATASMART
- else {
- tmp_psensors = hdd_psensor_list_add(psensors,
- values_max_length);
- if (tmp_psensors != psensors) {
- free(psensors);
- psensors = tmp_psensors;
- }
- }
-#endif
-
-#ifdef HAVE_GTOP
- mem_psensor_list_add(&psensors, values_max_length);
-#endif
-
- if (!psensors) { /* there is no detected sensors */
- psensors = malloc(sizeof(struct psensor *));
- *psensors = NULL;
- }
-
- return psensors;
-}
-
const char *psensor_type_to_str(unsigned int type)
{
if (type & SENSOR_TYPE_NVCTRL) {
return "Memory usage";
else if (type & SENSOR_TYPE_PCIE)
return "PCIe usage";
- else
- return "NVIDIA GPU";
+
+ return "NVIDIA GPU";
}
if (type & SENSOR_TYPE_ATIADL) {
return "AMD GPU Temperature";
else if (type & SENSOR_TYPE_RPM)
return "AMD GPU Fan Speed";
- else /* type & SENSOR_TYPE_USAGE */
- return "AMD GPU Usage";
+ /*else type & SENSOR_TYPE_USAGE */
+ return "AMD GPU Usage";
}
if ((type & SENSOR_TYPE_HDD_TEMP) == SENSOR_TYPE_HDD_TEMP)
if (is_temp_type(type)) {
if (use_celsius)
return "\302\260C";
- else
- return "\302\260F";
- } else if (is_fan_type(type)) {
+ return "\302\260F";
+ } else if (type & SENSOR_TYPE_RPM) {
return _("RPM");
- } else if (type & SENSOR_TYPE_CPU_USAGE) {
+ } else if (type & SENSOR_TYPE_PERCENT) {
return _("%");
- } else {
- return _("N/A");
}
-}
-
-void psensor_list_update_measures(struct psensor **sensors)
-{
- lmsensor_psensor_list_update(sensors);
-
-#ifdef HAVE_GTOP
- cpu_psensor_list_update(sensors);
- mem_psensor_list_update(sensors);
-#endif
-
- if (psensor_list_contains_type(sensors, SENSOR_TYPE_HDDTEMP))
- hddtemp_psensor_list_update(sensors);
-
-#ifdef HAVE_ATASMART
- if (psensor_list_contains_type(sensors, SENSOR_TYPE_ATASMART))
- hdd_psensor_list_update(sensors);
-#endif
+ return _("N/A");
}
void psensor_log_measures(struct psensor **sensors)
}
}
-void psensor_init()
-{
- lmsensor_init();
-}
-
-void psensor_cleanup()
-{
- lmsensor_cleanup();
-}
-
struct psensor **psensor_list_copy(struct psensor **sensors)
{
struct psensor **result;