Imported Upstream version 0.6.2.17
[psensor-pkg-debian.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 "config.h"
23 #include <sensors/sensors.h>
24
25 #include "color.h"
26 #include "log.h"
27 #include "measure.h"
28
29 enum psensor_type {
30         SENSOR_TYPE_TEMP = 0x0001,
31         SENSOR_TYPE_FAN = 0x0002,
32         SENSOR_TYPE_REMOTE = 0x0004,
33
34         SENSOR_TYPE_LMSENSOR = 0x0100,
35         SENSOR_TYPE_NVIDIA_TEMP = 0x0200 | SENSOR_TYPE_TEMP,
36         SENSOR_TYPE_HDD_TEMP = 0x0400 | SENSOR_TYPE_TEMP,
37         SENSOR_TYPE_CPU_USAGE = 0x0800,
38         SENSOR_TYPE_AMD = 0x1000,
39
40         SENSOR_TYPE_AMD_TEMP = SENSOR_TYPE_AMD | SENSOR_TYPE_TEMP,
41         SENSOR_TYPE_AMD_FAN = SENSOR_TYPE_AMD | SENSOR_TYPE_FAN,
42
43         SENSOR_TYPE_LMSENSOR_TEMP = SENSOR_TYPE_LMSENSOR | SENSOR_TYPE_TEMP,
44         SENSOR_TYPE_LMSENSOR_FAN = SENSOR_TYPE_LMSENSOR | SENSOR_TYPE_FAN
45 };
46
47 struct psensor {
48         /* Human readable name of the sensor.  It may not be uniq. */
49         char *name;
50
51         /* Uniq id of the sensor */
52         char *id;
53
54         /* lm-sensor */
55         const sensors_chip_name *iname;
56         const sensors_feature *feature;
57
58         /* Maximum length of 'values' */
59         int values_max_length;
60
61         /* Last registered measures of the sensor.  Index 0 for the
62            oldest measure.  */
63         struct measure *measures;
64
65         /* Color of the sensor used for the graph */
66         struct color *color;
67
68         /* Whether the sensor is displayed in the graph */
69         int enabled;
70
71         /* see psensor_type */
72         unsigned int type;
73
74         /* The maximum detected value of the sensor */
75         double max;
76
77         /* The minimum detected value of the sensor */
78         double min;
79
80         /*
81            Whether alarm alerts is enabled for this sensor
82          */
83         int alarm_enabled;
84
85         /*
86            An alarm is raised if the current sensor value is bigger. 0
87            means no limit
88          */
89         double alarm_limit;
90
91         /* Whether the current value is bigger than 'alarm_limit'.  */
92         int alarm_raised;
93
94         void (*cb_alarm_raised) (struct psensor *, void *);
95         void *cb_alarm_raised_data;
96
97 #ifdef HAVE_NVIDIA
98         /* Nvidia id for the nvctrl */
99         int nvidia_id;
100 #endif
101 #ifdef HAVE_LIBATIADL
102         /* AMD id for the aticonfig */
103         int amd_id;
104 #endif
105
106         char *url;
107 };
108
109 struct psensor *psensor_create(char *id,
110                                char *name, unsigned int type,
111                                int values_max_length);
112
113 void psensor_values_resize(struct psensor *s, int new_size);
114
115 void psensor_free(struct psensor *sensor);
116
117 void psensor_list_free(struct psensor **sensors);
118 int psensor_list_size(struct psensor **sensors);
119
120 struct psensor *psensor_list_get_by_id(struct psensor **sensors,
121                                        const char *id);
122
123 /*
124   Return 1 if there is at least one sensor of a given type, else
125   returns 0 */
126 int psensor_list_contains_type(struct psensor **sensors, unsigned int type);
127
128 int is_temp_type(unsigned int type);
129 int is_fan_type(unsigned int type);
130
131 double get_min_temp(struct psensor **sensors);
132 double get_max_temp(struct psensor **sensors);
133
134 double get_min_rpm(struct psensor **sensors);
135 double get_max_rpm(struct psensor **sensors);
136
137 /*
138   Get the maximal current value of all sensors of a given type.
139 */
140 double
141 psensor_get_max_current_value(struct psensor **sensors, unsigned int type);
142
143 /*
144   Converts the value of a sensor to a string.
145
146   parameter 'type' is SENSOR_TYPE_LMSENSOR_TEMP, SENSOR_TYPE_NVIDIA,
147   or SENSOR_TYPE_LMSENSOR_FAN
148 */
149 char *psensor_value_to_string(unsigned int type, double value);
150
151 struct psensor **get_all_sensors(int values_max_length);
152
153 struct psensor **psensor_list_add(struct psensor **sensors,
154                                   struct psensor *sensor);
155
156 void psensor_set_current_value(struct psensor *sensor, double value);
157 void psensor_set_current_measure(struct psensor *sensor, double value,
158                                  struct timeval tv);
159
160 double psensor_get_current_value(struct psensor *sensor);
161
162 struct measure *psensor_get_current_measure(struct psensor *sensor);
163
164 /*
165   Returns a string representation of a psensor type.
166 */
167 const char *psensor_type_to_str(unsigned int type);
168
169 const char *psensor_type_to_unit_str(unsigned int type);
170
171 void psensor_list_update_measures(struct psensor **sensors);
172
173 void psensor_init();
174
175 void psensor_cleanup();
176
177 double get_max_value(struct psensor **sensors, int type);
178
179 #endif