work on libata support
[psensor.git] / src / lib / psensor.h
1 /*
2  * Copyright (C) 2010-2011 jeanfi@gmail.com
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301 USA
18  */
19 #ifndef _PSENSOR_PSENSOR_H_
20 #define _PSENSOR_PSENSOR_H_
21
22 #include "config.h"
23 #include <sensors/sensors.h>
24
25 #ifdef HAVE_ATASMART
26 #include <atasmart.h>
27 #endif
28
29 #include "color.h"
30 #include "log.h"
31 #include "measure.h"
32
33 enum psensor_type {
34         SENSOR_TYPE_TEMP = 0x0001,
35         SENSOR_TYPE_FAN = 0x0002,
36         SENSOR_TYPE_REMOTE = 0x0004,
37
38         SENSOR_TYPE_LMSENSOR = 0x0100,
39         SENSOR_TYPE_NVIDIA_TEMP = 0x0200 | SENSOR_TYPE_TEMP,
40         SENSOR_TYPE_HDD_TEMP = 0x0400 | SENSOR_TYPE_TEMP,
41         SENSOR_TYPE_CPU_USAGE = 0x0800,
42         SENSOR_TYPE_AMD = 0x1000,
43
44         SENSOR_TYPE_AMD_TEMP = SENSOR_TYPE_AMD | SENSOR_TYPE_TEMP,
45         SENSOR_TYPE_AMD_FAN = SENSOR_TYPE_AMD | SENSOR_TYPE_FAN,
46
47         SENSOR_TYPE_LMSENSOR_TEMP = SENSOR_TYPE_LMSENSOR | SENSOR_TYPE_TEMP,
48         SENSOR_TYPE_LMSENSOR_FAN = SENSOR_TYPE_LMSENSOR | SENSOR_TYPE_FAN
49 };
50
51 struct psensor {
52         /* Human readable name of the sensor.  It may not be uniq. */
53         char *name;
54
55         /* Uniq id of the sensor */
56         char *id;
57
58         /* lm-sensor */
59         const sensors_chip_name *iname;
60         const sensors_feature *feature;
61
62         /* Maximum length of 'values' */
63         int values_max_length;
64
65         /* Last registered measures of the sensor.  Index 0 for the
66            oldest measure.  */
67         struct measure *measures;
68
69         /* Color of the sensor used for the graph */
70         struct color *color;
71
72         /* Whether the sensor is displayed in the graph */
73         int enabled;
74
75         /* see psensor_type */
76         unsigned int type;
77
78         /* The maximum detected value of the sensor */
79         double max;
80
81         /* The minimum detected value of the sensor */
82         double min;
83
84         /*
85            Whether alarm alerts is enabled for this sensor
86          */
87         int alarm_enabled;
88
89         /*
90            An alarm is raised if the current sensor value is bigger. 0
91            means no limit
92          */
93         double alarm_limit;
94
95         /* Whether the current value is bigger than 'alarm_limit'.  */
96         int alarm_raised;
97
98         void (*cb_alarm_raised) (struct psensor *, void *);
99         void *cb_alarm_raised_data;
100
101 #ifdef HAVE_NVIDIA
102         /* Nvidia id for the nvctrl */
103         int nvidia_id;
104 #endif
105 #ifdef HAVE_LIBATIADL
106         /* AMD id for the aticonfig */
107         int amd_id;
108 #endif
109 #ifdef HAVE_ATASMART
110         SkDisk *disk;
111 #endif
112
113         char *url;
114 };
115
116 struct psensor *psensor_create(char *id,
117                                char *name, unsigned int type,
118                                int values_max_length);
119
120 void psensor_values_resize(struct psensor *s, int new_size);
121
122 void psensor_free(struct psensor *sensor);
123
124 void psensor_list_free(struct psensor **sensors);
125 int psensor_list_size(struct psensor **sensors);
126
127 struct psensor *psensor_list_get_by_id(struct psensor **sensors,
128                                        const char *id);
129
130 /*
131   Return 1 if there is at least one sensor of a given type, else
132   returns 0 */
133 int psensor_list_contains_type(struct psensor **sensors, unsigned int type);
134
135 int is_temp_type(unsigned int type);
136 int is_fan_type(unsigned int type);
137
138 double get_min_temp(struct psensor **sensors);
139 double get_max_temp(struct psensor **sensors);
140
141 double get_min_rpm(struct psensor **sensors);
142 double get_max_rpm(struct psensor **sensors);
143
144 /*
145   Get the maximal current value of all sensors of a given type.
146 */
147 double
148 psensor_get_max_current_value(struct psensor **sensors, unsigned int type);
149
150 /*
151   Converts the value of a sensor to a string.
152
153   parameter 'type' is SENSOR_TYPE_LMSENSOR_TEMP, SENSOR_TYPE_NVIDIA,
154   or SENSOR_TYPE_LMSENSOR_FAN
155 */
156 char *psensor_value_to_string(unsigned int type, double value);
157
158 struct psensor **get_all_sensors(int values_max_length);
159
160 struct psensor **psensor_list_add(struct psensor **sensors,
161                                   struct psensor *sensor);
162
163 void psensor_set_current_value(struct psensor *sensor, double value);
164 void psensor_set_current_measure(struct psensor *sensor, double value,
165                                  struct timeval tv);
166
167 double psensor_get_current_value(struct psensor *sensor);
168
169 struct measure *psensor_get_current_measure(struct psensor *sensor);
170
171 /*
172   Returns a string representation of a psensor type.
173 */
174 const char *psensor_type_to_str(unsigned int type);
175
176 const char *psensor_type_to_unit_str(unsigned int type);
177
178 void psensor_list_update_measures(struct psensor **sensors);
179
180 void psensor_init();
181
182 void psensor_cleanup();
183
184 double get_max_value(struct psensor **sensors, int type);
185
186 #endif