check target call cppcheck if it is installed
[psensor.git] / src / lib / psensor.h
1 /*
2  * Copyright (C) 2010-2012 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 #ifdef HAVE_ATASMART
26 #include <atasmart.h>
27 #endif
28
29 #include "bool.h"
30 #include "color.h"
31 #include "log.h"
32 #include "measure.h"
33
34 enum psensor_type {
35         SENSOR_TYPE_TEMP = 0x0001,
36         SENSOR_TYPE_FAN = 0x0002,
37         SENSOR_TYPE_REMOTE = 0x0004,
38
39         SENSOR_TYPE_LMSENSOR = 0x0100,
40         SENSOR_TYPE_NVIDIA_TEMP = (0x0200 | SENSOR_TYPE_TEMP),
41         SENSOR_TYPE_HDD_TEMP = (0x0400 | SENSOR_TYPE_TEMP),
42         SENSOR_TYPE_CPU_USAGE = 0x0800,
43         SENSOR_TYPE_AMD = 0x1000,
44
45         SENSOR_TYPE_HDD_TEMP_ATASMART = (0x2000 | SENSOR_TYPE_HDD_TEMP),
46         SENSOR_TYPE_HDD_TEMP_HDDTEMP = (0x4000 | SENSOR_TYPE_HDD_TEMP),
47
48         SENSOR_TYPE_AMD_TEMP = (SENSOR_TYPE_AMD | SENSOR_TYPE_TEMP),
49         SENSOR_TYPE_AMD_FAN = (SENSOR_TYPE_AMD | SENSOR_TYPE_FAN),
50
51         SENSOR_TYPE_LMSENSOR_TEMP = (SENSOR_TYPE_LMSENSOR | SENSOR_TYPE_TEMP),
52         SENSOR_TYPE_LMSENSOR_FAN = (SENSOR_TYPE_LMSENSOR | SENSOR_TYPE_FAN)
53 };
54
55 struct psensor {
56         /* Human readable name of the sensor.  It may not be uniq. */
57         char *name;
58
59         /* Uniq id of the sensor */
60         char *id;
61
62         /* Name of the chip. */
63         char *chip;
64
65         /* lm-sensor */
66         const sensors_chip_name *iname;
67         const sensors_feature *feature;
68
69         /* Maximum length of 'values' */
70         int values_max_length;
71
72         /* Last registered measures of the sensor.  Index 0 for the
73            oldest measure.  */
74         struct measure *measures;
75
76         /* Color of the sensor used for the graph */
77         struct color *color;
78
79         /* Whether the graph sensor is displayed. */
80         bool enabled;
81
82         /* see psensor_type */
83         unsigned int type;
84
85         /* The maximum detected value of the sensor */
86         double max;
87
88         /* The minimum detected value of the sensor */
89         double min;
90
91         /* Whether alarm alert is enabled for this sensor */
92         bool alarm_enabled;
93
94         int alarm_high_threshold;
95         int alarm_low_threshold;
96
97         /* Whether an alarm is raised for this sensor */
98         unsigned int alarm_raised;
99
100         void (*cb_alarm_raised) (struct psensor *, void *);
101         void *cb_alarm_raised_data;
102
103 #ifdef HAVE_NVIDIA
104         /* Nvidia id for the nvctrl */
105         int nvidia_id;
106 #endif
107 #ifdef HAVE_LIBATIADL
108         /* AMD id for the aticonfig */
109         int amd_id;
110 #endif
111 #ifdef HAVE_ATASMART
112         SkDisk *disk;
113 #endif
114
115         char *url;
116
117         bool appindicator_enabled;
118 };
119
120 struct psensor *psensor_create(char *id,
121                                char *name,
122                                char *chip,
123                                unsigned int type,
124                                int values_max_length);
125
126 void psensor_values_resize(struct psensor *s, int new_size);
127
128 void psensor_free(struct psensor *sensor);
129
130 void psensor_list_free(struct psensor **sensors);
131 int psensor_list_size(struct psensor **sensors);
132
133 struct psensor *psensor_list_get_by_id(struct psensor **sensors,
134                                        const char *id);
135
136 /*
137   Return 1 if there is at least one sensor of a given type, else
138   returns 0 */
139 int psensor_list_contains_type(struct psensor **sensors, unsigned int type);
140
141 int is_temp_type(unsigned int type);
142 int is_fan_type(unsigned int type);
143
144 double get_min_temp(struct psensor **sensors);
145 double get_max_temp(struct psensor **sensors);
146
147 double get_min_rpm(struct psensor **sensors);
148 double get_max_rpm(struct psensor **sensors);
149
150 /*
151   Get the maximal current value of all sensors of a given type.
152 */
153 double
154 psensor_get_max_current_value(struct psensor **sensors, unsigned int type);
155
156 /*
157   Converts the value of a sensor to a string.
158
159   parameter 'type' is SENSOR_TYPE_LMSENSOR_TEMP, SENSOR_TYPE_NVIDIA,
160   or SENSOR_TYPE_LMSENSOR_FAN
161 */
162 char *psensor_value_to_str(unsigned int type,
163                            double value,
164                            int use_celcius);
165
166 char *psensor_measure_to_str(const struct measure *m,
167                              unsigned int type,
168                              unsigned int use_celcius);
169
170 struct psensor **get_all_sensors(int use_libatasmart, int values_max_length);
171
172 struct psensor **psensor_list_add(struct psensor **sensors,
173                                   struct psensor *sensor);
174
175 void psensor_set_current_value(struct psensor *sensor, double value);
176 void psensor_set_current_measure(struct psensor *sensor, double value,
177                                  struct timeval tv);
178
179 double psensor_get_current_value(struct psensor *sensor);
180
181 struct measure *psensor_get_current_measure(struct psensor *sensor);
182
183 /*
184   Returns a string representation of a psensor type.
185 */
186 const char *psensor_type_to_str(unsigned int type);
187
188 const char *psensor_type_to_unit_str(unsigned int type, int use_celcius);
189
190 void psensor_list_update_measures(struct psensor **sensors);
191
192 void psensor_init();
193
194 void psensor_cleanup();
195
196 double get_max_value(struct psensor **sensors, int type);
197
198 double celcius_to_fahrenheit(double c);
199 double fahrenheit_to_celcius(double c);
200
201
202 void psensor_log_measures(struct psensor **sensors);
203
204 #endif