import psensor trunk from private svn
[psensor.git] / src / lib / psensor.h
1 /*
2     Copyright (C) 2010-2011 wpitchoune@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 "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_TEMP = 0x0100 | SENSOR_TYPE_TEMP,
35         SENSOR_TYPE_NVIDIA = 0x0200 | SENSOR_TYPE_TEMP,
36         SENSOR_TYPE_HDD_TEMP = 0x0300 | SENSOR_TYPE_TEMP,
37         SENSOR_TYPE_LMSENSOR_FAN = 0x0400 | SENSOR_TYPE_FAN
38 };
39
40 struct psensor {
41         /* Human readable name of the sensor.  It may not be uniq. */
42         char *name;
43
44         /* Uniq id of the sensor */
45         char *id;
46
47         /* lm-sensor */
48         const sensors_chip_name *iname;
49         const sensors_feature *feature;
50
51         /* Maximum length of 'values' */
52         int values_max_length;
53
54         /* Last registered measures of the sensor.  Index 0 for the
55            oldest measure.  */
56         struct measure *measures;
57
58         /* Color of the sensor used for the graph */
59         struct color *color;
60
61         /* Whether the sensor is displayed in the graph */
62         int enabled;
63
64         /* see psensor_type */
65         unsigned int type;
66
67         /* The maximum detected value of the sensor */
68         double max;
69
70         /* The minimum detected value of the sensor */
71         double min;
72
73         /*
74            Whether alarm alerts is enabled for this sensor
75          */
76         int alarm_enabled;
77
78         /*
79            An alarm is raised if the current sensor value is bigger. 0
80            means no limit
81          */
82         double alarm_limit;
83
84         /* Whether the current value is bigger than 'alarm_limit'.  */
85         int alarm_raised;
86
87         void (*cb_alarm_raised) (struct psensor *, void *);
88         void *cb_alarm_raised_data;
89
90 #ifdef HAVE_NVIDIA
91         /* Nvidia id for the nvctrl */
92         int nvidia_id;
93 #endif
94
95         char *url;
96
97 };
98
99 struct psensor *psensor_create(char *id,
100                                char *name, unsigned int type,
101                                int values_max_length);
102
103 void psensor_values_resize(struct psensor *s, int new_size);
104
105 void psensor_free(struct psensor *sensor);
106
107 void psensor_list_free(struct psensor **sensors);
108 int psensor_list_size(struct psensor **sensors);
109
110 struct psensor *psensor_list_get_by_id(struct psensor **sensors,
111                                        const char *id);
112
113 /*
114   Return 1 if there is at least one sensor of a given type, else
115   returns 0 */
116 int psensor_list_contains_type(struct psensor **sensors, unsigned int type);
117
118 int is_temp_type(unsigned int type);
119 int is_fan_type(unsigned int type);
120
121 double get_min_temp(struct psensor **sensors);
122 double get_max_temp(struct psensor **sensors);
123
124 double get_min_rpm(struct psensor **sensors);
125 double get_max_rpm(struct psensor **sensors);
126
127 /*
128   Converts the value of a sensor to a string.
129
130   parameter 'type' is SENSOR_TYPE_LMSENSOR_TEMP, SENSOR_TYPE_NVIDIA,
131   or SENSOR_TYPE_LMSENSOR_FAN
132 */
133 char *psensor_value_to_string(unsigned int type, double value);
134
135 struct psensor **get_all_sensors(int values_max_length);
136
137 struct psensor **psensor_list_add(struct psensor **sensors,
138                                   struct psensor *sensor);
139
140 void psensor_set_current_value(struct psensor *sensor, double value);
141 void psensor_set_current_measure(struct psensor *sensor, double value,
142                                  struct timeval tv);
143
144 double psensor_get_current_value(struct psensor *sensor);
145
146 struct measure *psensor_get_current_measure(struct psensor *sensor);
147
148 /*
149   Returns a string representation of a psensor type.
150 */
151 const char *psensor_type_to_str(unsigned int type);
152
153 void psensor_list_update_measures(struct psensor **sensors);
154
155 #endif