normalize include
[psensor.git] / src / lib / psensor.h
1 /*
2  * Copyright (C) 2010-2014 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 <sensors/sensors.h>
23
24 #include <config.h>
25
26 #ifdef HAVE_ATASMART
27 #include <atasmart.h>
28 #endif
29
30 #include <bool.h>
31 #include <color.h>
32 #include <measure.h>
33 #include <plog.h>
34
35
36 enum psensor_type {
37         /* type of sensor values */
38         SENSOR_TYPE_TEMP = 0x00001,
39         SENSOR_TYPE_RPM = 0x00002,
40         SENSOR_TYPE_PERCENT = 0x00004,
41
42         /* Whether the sensor is remote */
43         SENSOR_TYPE_REMOTE = 0x00008,
44
45         /* Libraries used for retrieving sensor information */
46         SENSOR_TYPE_LMSENSOR = 0x00100,
47         SENSOR_TYPE_NVCTRL = 0x00200,
48         SENSOR_TYPE_GTOP = 0x00400,
49         SENSOR_TYPE_ATIADL = 0x00800,
50         SENSOR_TYPE_ATASMART = 0x01000,
51         SENSOR_TYPE_HDDTEMP = 0x02000,
52         SENSOR_TYPE_UDISKS2 = 0x800000,
53
54         /* Type of HW component */
55         SENSOR_TYPE_HDD = 0x04000,
56         SENSOR_TYPE_CPU = 0x08000,
57         SENSOR_TYPE_GPU = 0x10000,
58         SENSOR_TYPE_FAN = 0x20000,
59
60         SENSOR_TYPE_GRAPHICS = 0x40000,
61         SENSOR_TYPE_VIDEO = 0x80000,
62         SENSOR_TYPE_PCIE = 0x100000,
63         SENSOR_TYPE_MEMORY = 0x200000,
64         SENSOR_TYPE_AMBIENT = 0x400000,
65
66         /* Combinations */
67         SENSOR_TYPE_HDD_TEMP = (SENSOR_TYPE_HDD | SENSOR_TYPE_TEMP),
68         SENSOR_TYPE_CPU_USAGE = (SENSOR_TYPE_CPU | SENSOR_TYPE_PERCENT)
69 };
70
71 struct psensor {
72         /* Human readable name of the sensor.  It may not be uniq. */
73         char *name;
74
75         /* Uniq id of the sensor */
76         char *id;
77
78         /* Name of the chip. */
79         char *chip;
80
81         /* lm-sensor */
82         const sensors_chip_name *iname;
83
84         const sensors_feature *feature;
85
86         /* Maximum length of 'values' */
87         int values_max_length;
88
89         /* Last registered measures of the sensor.  Index 0 for the
90          * oldest measure.  */
91         struct measure *measures;
92
93         /* Color of the sensor used for the graph */
94         struct color *color;
95
96         /* Whether the graph sensor is displayed. */
97         bool graph_enabled;
98
99         /* see psensor_type */
100         unsigned int type;
101
102         /* The maximum detected value of the sensor */
103         double max;
104
105         /* The minimum detected value of the sensor */
106         double min;
107
108         /* Whether alarm alert is enabled for this sensor */
109         bool alarm_enabled;
110
111         int alarm_high_threshold;
112         int alarm_low_threshold;
113
114         /* Whether an alarm is raised for this sensor */
115         unsigned int alarm_raised;
116
117         void (*cb_alarm_raised)(struct psensor *, void *);
118         void *cb_alarm_raised_data;
119
120 #ifdef HAVE_LIBATIADL
121         /* AMD id for the aticonfig */
122         int amd_id;
123 #endif
124 #ifdef HAVE_ATASMART
125         SkDisk *disk;
126 #endif
127
128         void *provider_data;
129         void (*provider_data_free_fct)(void *);
130
131         char *url;
132
133         bool appindicator_enabled;
134 };
135
136 struct psensor *psensor_create(char *id,
137                                char *name,
138                                char *chip,
139                                unsigned int type,
140                                int values_max_length);
141
142 void psensor_values_resize(struct psensor *s, int new_size);
143
144 void psensor_free(struct psensor *sensor);
145
146 void psensor_list_free(struct psensor **sensors);
147 int psensor_list_size(struct psensor **sensors);
148
149 struct psensor **psensor_list_filter_graph_enabled(struct psensor **);
150
151 struct psensor *psensor_list_get_by_id(struct psensor **sensors,
152                                        const char *id);
153
154 int is_temp_type(unsigned int type);
155
156 double get_min_temp(struct psensor **sensors);
157 double get_max_temp(struct psensor **sensors);
158
159 double get_min_rpm(struct psensor **sensors);
160 double get_max_rpm(struct psensor **sensors);
161
162 /* Get the maximal current value of all sensors of a given type. */
163 double
164 psensor_get_max_current_value(struct psensor **sensors, unsigned int type);
165
166 /*
167  * Converts the value of a sensor to a string.
168  *
169  * parameter 'type' is SENSOR_TYPE_LMSENSOR_TEMP, SENSOR_TYPE_NVIDIA,
170  * or SENSOR_TYPE_LMSENSOR_FAN
171  */
172 char *psensor_value_to_str(unsigned int type,
173                            double value,
174                            int use_celsius);
175
176 char *psensor_measure_to_str(const struct measure *m,
177                              unsigned int type,
178                              unsigned int use_celsius);
179
180 struct psensor **get_all_sensors(int use_libatasmart, int values_max_length);
181
182 struct psensor **psensor_list_add(struct psensor **sensors,
183                                   struct psensor *sensor);
184
185 void psensor_list_append(struct psensor ***sensors, struct psensor *sensor);
186
187 struct psensor **psensor_list_copy(struct psensor **);
188
189 void psensor_set_current_value(struct psensor *sensor, double value);
190 void psensor_set_current_measure(struct psensor *sensor, double value,
191                                  struct timeval tv);
192
193 double psensor_get_current_value(const struct psensor *);
194
195 struct measure *psensor_get_current_measure(struct psensor *sensor);
196
197 /* Returns a string representation of a psensor type. */
198 const char *psensor_type_to_str(unsigned int type);
199
200 const char *psensor_type_to_unit_str(unsigned int type, int use_celsius);
201
202 double get_max_value(struct psensor **sensors, int type);
203
204 char *psensor_current_value_to_str(const struct psensor *, unsigned int);
205
206 void psensor_log_measures(struct psensor **sensors);
207
208 #endif