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