| 1 | /* |
|---|
| 2 | data.h - Part of libsensors, a Linux library for reading sensor data. |
|---|
| 3 | Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl> |
|---|
| 4 | Copyright (C) 2007 Jean Delvare <khali@linux-fr.org> |
|---|
| 5 | |
|---|
| 6 | This program is free software; you can redistribute it and/or modify |
|---|
| 7 | it under the terms of the GNU General Public License as published by |
|---|
| 8 | the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | (at your option) any later version. |
|---|
| 10 | |
|---|
| 11 | This program is distributed in the hope that it will be useful, |
|---|
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | GNU General Public License for more details. |
|---|
| 15 | |
|---|
| 16 | You should have received a copy of the GNU General Public License |
|---|
| 17 | along with this program; if not, write to the Free Software |
|---|
| 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|---|
| 19 | MA 02110-1301 USA. |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | #ifndef LIB_SENSORS_DATA_H |
|---|
| 23 | #define LIB_SENSORS_DATA_H |
|---|
| 24 | |
|---|
| 25 | #include "sensors.h" |
|---|
| 26 | |
|---|
| 27 | /* This header file contains all kinds of data structures which are used |
|---|
| 28 | for the representation of the config file data and the /proc/... |
|---|
| 29 | data. */ |
|---|
| 30 | |
|---|
| 31 | /* Kinds of expression operators recognized */ |
|---|
| 32 | typedef enum sensors_operation { |
|---|
| 33 | sensors_add, sensors_sub, sensors_multiply, sensors_divide, |
|---|
| 34 | sensors_negate, sensors_exp, sensors_log, |
|---|
| 35 | } sensors_operation; |
|---|
| 36 | |
|---|
| 37 | /* An expression can have several forms */ |
|---|
| 38 | typedef enum sensors_expr_kind { |
|---|
| 39 | sensors_kind_val, sensors_kind_source, sensors_kind_var, |
|---|
| 40 | sensors_kind_sub |
|---|
| 41 | } sensors_expr_kind; |
|---|
| 42 | |
|---|
| 43 | /* An expression. It is either a floating point value, a variable name, |
|---|
| 44 | an operation on subexpressions, or the special value 'sub' } */ |
|---|
| 45 | struct sensors_expr; |
|---|
| 46 | |
|---|
| 47 | typedef struct sensors_subexpr { |
|---|
| 48 | sensors_operation op; |
|---|
| 49 | struct sensors_expr *sub1; |
|---|
| 50 | struct sensors_expr *sub2; |
|---|
| 51 | } sensors_subexpr; |
|---|
| 52 | |
|---|
| 53 | typedef struct sensors_expr { |
|---|
| 54 | sensors_expr_kind kind; |
|---|
| 55 | union { |
|---|
| 56 | double val; |
|---|
| 57 | char *var; |
|---|
| 58 | sensors_subexpr subexpr; |
|---|
| 59 | } data; |
|---|
| 60 | } sensors_expr; |
|---|
| 61 | |
|---|
| 62 | /* Config file label declaration: a feature name, combined with the label |
|---|
| 63 | value */ |
|---|
| 64 | typedef struct sensors_label { |
|---|
| 65 | char *name; |
|---|
| 66 | char *value; |
|---|
| 67 | int lineno; |
|---|
| 68 | } sensors_label; |
|---|
| 69 | |
|---|
| 70 | /* Config file set declaration: a subfeature name, combined with an |
|---|
| 71 | expression */ |
|---|
| 72 | typedef struct sensors_set { |
|---|
| 73 | char *name; |
|---|
| 74 | sensors_expr *value; |
|---|
| 75 | int lineno; |
|---|
| 76 | } sensors_set; |
|---|
| 77 | |
|---|
| 78 | /* Config file compute declaration: a feature name, combined with two |
|---|
| 79 | expressions */ |
|---|
| 80 | typedef struct sensors_compute { |
|---|
| 81 | char *name; |
|---|
| 82 | sensors_expr *from_proc; |
|---|
| 83 | sensors_expr *to_proc; |
|---|
| 84 | int lineno; |
|---|
| 85 | } sensors_compute; |
|---|
| 86 | |
|---|
| 87 | /* Config file ignore declaration: a feature name */ |
|---|
| 88 | typedef struct sensors_ignore { |
|---|
| 89 | char *name; |
|---|
| 90 | int lineno; |
|---|
| 91 | } sensors_ignore; |
|---|
| 92 | |
|---|
| 93 | /* A list of chip names, used to represent a config file chips declaration */ |
|---|
| 94 | typedef struct sensors_chip_name_list { |
|---|
| 95 | sensors_chip_name *fits; |
|---|
| 96 | int fits_count; |
|---|
| 97 | int fits_max; |
|---|
| 98 | } sensors_chip_name_list; |
|---|
| 99 | |
|---|
| 100 | /* A config file chip block */ |
|---|
| 101 | typedef struct sensors_chip { |
|---|
| 102 | sensors_chip_name_list chips; |
|---|
| 103 | sensors_label *labels; |
|---|
| 104 | int labels_count; |
|---|
| 105 | int labels_max; |
|---|
| 106 | sensors_set *sets; |
|---|
| 107 | int sets_count; |
|---|
| 108 | int sets_max; |
|---|
| 109 | sensors_compute *computes; |
|---|
| 110 | int computes_count; |
|---|
| 111 | int computes_max; |
|---|
| 112 | sensors_ignore *ignores; |
|---|
| 113 | int ignores_count; |
|---|
| 114 | int ignores_max; |
|---|
| 115 | int lineno; |
|---|
| 116 | } sensors_chip; |
|---|
| 117 | |
|---|
| 118 | /* Config file bus declaration: the bus type and number, combined with adapter |
|---|
| 119 | name */ |
|---|
| 120 | typedef struct sensors_bus { |
|---|
| 121 | char *adapter; |
|---|
| 122 | sensors_bus_id bus; |
|---|
| 123 | int lineno; |
|---|
| 124 | } sensors_bus; |
|---|
| 125 | |
|---|
| 126 | /* Internal data about all features and subfeatures of a chip */ |
|---|
| 127 | typedef struct sensors_chip_features { |
|---|
| 128 | struct sensors_chip_name chip; |
|---|
| 129 | struct sensors_feature *feature; |
|---|
| 130 | struct sensors_subfeature *subfeature; |
|---|
| 131 | int feature_count; |
|---|
| 132 | int subfeature_count; |
|---|
| 133 | } sensors_chip_features; |
|---|
| 134 | |
|---|
| 135 | extern sensors_chip *sensors_config_chips; |
|---|
| 136 | extern int sensors_config_chips_count; |
|---|
| 137 | extern int sensors_config_chips_max; |
|---|
| 138 | |
|---|
| 139 | extern sensors_bus *sensors_config_busses; |
|---|
| 140 | extern int sensors_config_busses_count; |
|---|
| 141 | extern int sensors_config_busses_max; |
|---|
| 142 | |
|---|
| 143 | extern sensors_chip_features *sensors_proc_chips; |
|---|
| 144 | extern int sensors_proc_chips_count; |
|---|
| 145 | extern int sensors_proc_chips_max; |
|---|
| 146 | |
|---|
| 147 | #define sensors_add_proc_chips(el) sensors_add_array_el( \ |
|---|
| 148 | (el), &sensors_proc_chips, &sensors_proc_chips_count,\ |
|---|
| 149 | &sensors_proc_chips_max, sizeof(struct sensors_chip_features)) |
|---|
| 150 | |
|---|
| 151 | extern sensors_bus *sensors_proc_bus; |
|---|
| 152 | extern int sensors_proc_bus_count; |
|---|
| 153 | extern int sensors_proc_bus_max; |
|---|
| 154 | |
|---|
| 155 | #define sensors_add_proc_bus(el) sensors_add_array_el( \ |
|---|
| 156 | (el), &sensors_proc_bus, &sensors_proc_bus_count,\ |
|---|
| 157 | &sensors_proc_bus_max, sizeof(struct sensors_bus)) |
|---|
| 158 | |
|---|
| 159 | /* Substitute configuration bus numbers with real-world /proc bus numbers |
|---|
| 160 | in the chips lists */ |
|---|
| 161 | int sensors_substitute_busses(void); |
|---|
| 162 | |
|---|
| 163 | |
|---|
| 164 | /* Parse a bus id into its components. Returns 0 on succes, a value from |
|---|
| 165 | error.h on failure. */ |
|---|
| 166 | int sensors_parse_bus_id(const char *name, sensors_bus_id *bus); |
|---|
| 167 | |
|---|
| 168 | #endif /* def LIB_SENSORS_DATA_H */ |
|---|