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