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