mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-11-06 15:51:34 +00:00
Moved some library functions around, to put them in more logical files.
No external changes. git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@119 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
1 parent
a4940fe7c3
commit
faa996f454
9 files changed
+116
-88
No files matched your search
+1
-1
@@ -42,7 +42,7 @@ LIBCSOURCES := $(MODULE_DIR)/data.c $(MODULE_DIR)/general.c \
|
||||
LIBOTHEROBJECTS := $(MODULE_DIR)/conf-parse.o $(MODULE_DIR)/conf-lex.o
|
||||
LIBSHOBJECTS := $(LIBCSOURCES:.c=.lo) $(LIBOTHEROBJECTS:.o=.lo)
|
||||
LIBSTOBJECTS := $(LIBCSOURCES:.c=.ao) $(LIBOTHEROBJECTS:.o=.ao)
|
||||
LIBEXTRACLEAN := $(MODULE_DIR)/conf_parse.h
|
||||
LIBEXTRACLEAN := $(MODULE_DIR)/conf-parse.h
|
||||
|
||||
LIBHEADERFILES := $(MODULE_DIR)/error.h $(MODULE_DIR)/sensors.h
|
||||
|
||||
|
||||
@@ -279,4 +279,55 @@ const sensors_feature_data *sensors_get_all_features (sensors_chip_name name,
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int sensors_eval_expr(sensors_chip_name chipname, sensors_expr *expr,
|
||||
double val, double *result)
|
||||
{
|
||||
double res1,res2;
|
||||
int res;
|
||||
sensors_chip_feature *feature;
|
||||
|
||||
if (expr->kind == sensors_kind_val) {
|
||||
*result = expr->data.val;
|
||||
return 0;
|
||||
}
|
||||
if (expr->kind == sensors_kind_source) {
|
||||
*result = val;
|
||||
return 0;
|
||||
}
|
||||
if (expr->kind == sensors_kind_var) {
|
||||
if (! (feature = sensors_lookup_feature_name(chipname.prefix,
|
||||
expr->data.var)))
|
||||
return SENSORS_ERR_NO_ENTRY;
|
||||
if (! (res = sensors_get_feature(chipname,feature->number,result)))
|
||||
return res;
|
||||
return 0;
|
||||
}
|
||||
if ((res = sensors_eval_expr(chipname,expr->data.subexpr.sub1,val,&res1)))
|
||||
return res;
|
||||
if (expr->data.subexpr.sub2 &&
|
||||
(res = sensors_eval_expr(chipname,expr->data.subexpr.sub2,val,&res2)))
|
||||
return res;
|
||||
switch(expr->data.subexpr.op) {
|
||||
case sensors_add:
|
||||
*result = res1 + res2;
|
||||
return 0;
|
||||
case sensors_sub:
|
||||
*result = res1 - res2;
|
||||
return 0;
|
||||
case sensors_multiply:
|
||||
*result = res1 * res2;
|
||||
return 0;
|
||||
case sensors_divide:
|
||||
if (res2 == 0.0)
|
||||
return -SENSORS_ERR_DIV_ZERO;
|
||||
*result = res1 / res2;
|
||||
return 0;
|
||||
case sensors_negate:
|
||||
*result = -res1;
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+10
-18
@@ -23,24 +23,6 @@
|
||||
#include "sensors.h"
|
||||
#include "data.h"
|
||||
|
||||
typedef struct sensors_chip_feature {
|
||||
int number;
|
||||
const char *name;
|
||||
int logical_mapping;
|
||||
int compute_mapping;
|
||||
int mode;
|
||||
int sysctl;
|
||||
int offset;
|
||||
int scaling;
|
||||
} sensors_chip_feature;
|
||||
|
||||
typedef struct sensors_chip_features {
|
||||
const char *prefix;
|
||||
struct sensors_chip_feature *feature;
|
||||
} sensors_chip_features;
|
||||
|
||||
extern sensors_chip_features sensors_chip_features_list[];
|
||||
|
||||
/* Returns, one by one, a pointer to all sensor_chip structs of the
|
||||
config file which match with the given chip name. Last should be
|
||||
the value returned by the last call, or NULL if this is the first
|
||||
@@ -67,4 +49,14 @@ extern sensors_chip_feature *sensors_lookup_feature_name(const char *prefix,
|
||||
in the chips lists */
|
||||
extern int sensors_substitute_busses(void);
|
||||
|
||||
|
||||
/* Parse an i2c bus name into its components. Returns 0 on succes, a value from
|
||||
error.h on failure. */
|
||||
extern int sensors_parse_i2cbus_name(const char *name, int *res);
|
||||
|
||||
/* Evaluate an expression */
|
||||
extern int sensors_eval_expr(sensors_chip_name chipname, sensors_expr *expr,
|
||||
double val, double *result);
|
||||
|
||||
|
||||
#endif /* def LIB_SENSORS_ACCESS_H */
|
||||
+1
-1
@@ -18,7 +18,7 @@
|
||||
*/
|
||||
|
||||
#include "chips.h"
|
||||
#include "access.h"
|
||||
#include "data.h"
|
||||
#include "sensors.h"
|
||||
#include "src/sensors.h"
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "data.h"
|
||||
#include "general.h"
|
||||
#include "error.h"
|
||||
#include "conf.h"
|
||||
|
||||
/* These two functions are defined in conf-lex.l */
|
||||
extern int sensors_yylex(void);
|
||||
|
||||
+1
-53
@@ -23,7 +23,6 @@
|
||||
#include "error.h"
|
||||
#include "data.h"
|
||||
#include "sensors.h"
|
||||
#include "access.h"
|
||||
|
||||
sensors_chip *sensors_config_chips = NULL;
|
||||
int sensors_config_chips_count = 0;
|
||||
@@ -201,57 +200,6 @@ int sensors_parse_i2cbus_name(const char *name, int *res)
|
||||
}
|
||||
|
||||
|
||||
int sensors_eval_expr(sensors_chip_name chipname, sensors_expr *expr,
|
||||
double val, double *result)
|
||||
{
|
||||
double res1,res2;
|
||||
int res;
|
||||
sensors_chip_feature *feature;
|
||||
|
||||
if (expr->kind == sensors_kind_val) {
|
||||
*result = expr->data.val;
|
||||
return 0;
|
||||
}
|
||||
if (expr->kind == sensors_kind_source) {
|
||||
*result = val;
|
||||
return 0;
|
||||
}
|
||||
if (expr->kind == sensors_kind_var) {
|
||||
/* We should check the kind of variable here! */
|
||||
if (! (feature = sensors_lookup_feature_name(chipname.prefix,
|
||||
expr->data.var)))
|
||||
return SENSORS_ERR_NO_ENTRY;
|
||||
if (! (res = sensors_get_feature(chipname,feature->number,result)))
|
||||
return res;
|
||||
return 0;
|
||||
}
|
||||
if ((res = sensors_eval_expr(chipname,expr->data.subexpr.sub1,val,&res1)))
|
||||
return res;
|
||||
if (expr->data.subexpr.sub2 &&
|
||||
(res = sensors_eval_expr(chipname,expr->data.subexpr.sub2,val,&res2)))
|
||||
return res;
|
||||
switch(expr->data.subexpr.op) {
|
||||
case sensors_add:
|
||||
*result = res1 + res2;
|
||||
return 0;
|
||||
case sensors_sub:
|
||||
*result = res1 - res2;
|
||||
return 0;
|
||||
case sensors_multiply:
|
||||
*result = res1 * res2;
|
||||
return 0;
|
||||
case sensors_divide:
|
||||
if (res2 == 0.0)
|
||||
return -SENSORS_ERR_DIV_ZERO;
|
||||
*result = res1 / res2;
|
||||
return 0;
|
||||
case sensors_negate:
|
||||
*result = -res1;
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sensors_substitute_chip(sensors_chip_name *name,int lineno)
|
||||
{
|
||||
int i,j;
|
||||
@@ -273,7 +221,7 @@ int sensors_substitute_chip(sensors_chip_name *name,int lineno)
|
||||
break;
|
||||
}
|
||||
|
||||
/* Well, if we did not find anything, j - sensors_proc_bus_count; so if
|
||||
/* Well, if we did not find anything, j = sensors_proc_bus_count; so if
|
||||
we set this chip's bus number to j, it will never be matched. Good. */
|
||||
name->bus = j;
|
||||
return 0;
|
||||
|
||||
+49
-11
@@ -26,14 +26,18 @@
|
||||
for the representation of the config file data and the /proc/...
|
||||
data. */
|
||||
|
||||
/* Kinds of expression operators recognized */
|
||||
typedef enum sensors_operation {
|
||||
sensors_add, sensors_sub, sensors_multiply, sensors_divide,
|
||||
sensors_negate } sensors_operation;
|
||||
|
||||
/* An expression can have several forms */
|
||||
typedef enum sensors_expr_kind {
|
||||
sensors_kind_val, sensors_kind_source, sensors_kind_var,
|
||||
sensors_kind_sub } sensors_expr_kind;
|
||||
|
||||
/* An expression. It is either a floating point value, a variable name,
|
||||
an operation on subexpressions, or the special value 'sub' } */
|
||||
struct sensors_expr;
|
||||
|
||||
typedef struct sensors_subexpr {
|
||||
@@ -50,20 +54,24 @@ typedef struct sensors_expr {
|
||||
sensors_subexpr subexpr;
|
||||
} data;
|
||||
} sensors_expr;
|
||||
|
||||
|
||||
/* Config file label declaration: a feature name, combined with the label
|
||||
value */
|
||||
typedef struct sensors_label {
|
||||
char *name;
|
||||
char *value;
|
||||
int lineno;
|
||||
} sensors_label;
|
||||
|
||||
/* Config file set declaration: a feature name, combined with an expression */
|
||||
typedef struct sensors_set {
|
||||
char *name;
|
||||
sensors_expr *value;
|
||||
int lineno;
|
||||
} sensors_set;
|
||||
|
||||
/* Config file compute declaration: a feature name, combined with two
|
||||
expressions */
|
||||
typedef struct sensors_compute {
|
||||
char *name;
|
||||
sensors_expr *from_proc;
|
||||
@@ -71,12 +79,14 @@ typedef struct sensors_compute {
|
||||
int lineno;
|
||||
} sensors_compute;
|
||||
|
||||
/* A list of chip names, used to represent a config file chips declaration */
|
||||
typedef struct sensors_chip_name_list {
|
||||
sensors_chip_name *fits;
|
||||
int fits_count;
|
||||
int fits_max;
|
||||
} sensors_chip_name_list;
|
||||
|
||||
/* A config file chip block */
|
||||
typedef struct sensors_chip {
|
||||
sensors_chip_name_list chips;
|
||||
sensors_label *labels;
|
||||
@@ -91,9 +101,8 @@ typedef struct sensors_chip {
|
||||
int lineno;
|
||||
} sensors_chip;
|
||||
|
||||
typedef enum sensors_bus_type {sensors_i2c, sensors_isa,
|
||||
sensors_smbus } sensors_bus_type;
|
||||
|
||||
/* Config file bus declaration: the i2c bus number, combined with adapter
|
||||
and algorithm names */
|
||||
typedef struct sensors_bus {
|
||||
int number;
|
||||
char *adapter;
|
||||
@@ -101,11 +110,46 @@ typedef struct sensors_bus {
|
||||
int lineno;
|
||||
} sensors_bus;
|
||||
|
||||
/* /proc/sys/dev/sensors/chips line representation */
|
||||
typedef struct sensors_proc_chips_entry {
|
||||
int sysctl;
|
||||
sensors_chip_name name;
|
||||
} sensors_proc_chips_entry;
|
||||
|
||||
/* Internal data about a single chip feature.
|
||||
name is the string name used to refer to this feature (both in config
|
||||
files and through user functions);
|
||||
number is the internal feature number, used in many functions to refer
|
||||
to this feature
|
||||
logical_mapping is either SENSORS_NO_MAPPING is this is feature is the
|
||||
main element of category; or it is the number of a feature with which
|
||||
this feature is logically grouped (a group could be fan, fan_max and
|
||||
fan_div)
|
||||
compute_mapping is like logical_mapping, only it refers to another
|
||||
feature whose compute line will be inherited (a group could be fan and
|
||||
fan_max, but not fan_div)
|
||||
mode is SENSORS_MODE_NO_RW, SENSORS_MODE_R, SENSORS_MODE_W or
|
||||
SENSORS_MODE_RW, for unaccessible, readable, writable, and both readable
|
||||
and writable.
|
||||
sysctl is the SYSCTL id of the file the value can be found in;
|
||||
offset is the (byte) offset of the place this feature can be found;
|
||||
Divide the read value by 10**scaling to get the real value */
|
||||
typedef struct sensors_chip_feature {
|
||||
int number;
|
||||
const char *name;
|
||||
int logical_mapping;
|
||||
int compute_mapping;
|
||||
int mode;
|
||||
int sysctl;
|
||||
int offset;
|
||||
int scaling;
|
||||
} sensors_chip_feature;
|
||||
|
||||
/* Internal data about all features of a type of chip */
|
||||
typedef struct sensors_chip_features {
|
||||
const char *prefix;
|
||||
struct sensors_chip_feature *feature;
|
||||
} sensors_chip_features;
|
||||
|
||||
extern sensors_chip *sensors_config_chips;
|
||||
extern int sensors_config_chips_count;
|
||||
@@ -123,12 +167,6 @@ extern sensors_bus *sensors_proc_bus;
|
||||
extern int sensors_proc_bus_count;
|
||||
extern int sensors_proc_bus_max;
|
||||
|
||||
/* Parse an i2c bus name into its components. Returns 0 on succes, a value from
|
||||
error.h on failure. */
|
||||
extern int sensors_parse_i2cbus_name(const char *name, int *res);
|
||||
|
||||
extern int sensors_eval_expr(sensors_chip_name chipname, sensors_expr *expr,
|
||||
double val, double *result);
|
||||
|
||||
extern sensors_chip_features sensors_chip_features_list[];
|
||||
|
||||
#endif /* def LIB_SENSORS_DATA_H */
|
||||
+1
-1
@@ -43,7 +43,7 @@ extern void (*sensors_parse_error) (const char *err, int lineno);
|
||||
/* This function is called when an immediately fatal error (like no
|
||||
memory left) is detected. Give it a new value, and your own function
|
||||
is called instead of the default (which prints to stderr and ends
|
||||
the program). */
|
||||
the program). Never let it return! */
|
||||
extern void (*sensors_fatal_error) (const char *proc, const char *err);
|
||||
|
||||
|
||||
|
||||
+1
-3
@@ -24,9 +24,7 @@
|
||||
#include "proc.h"
|
||||
#include "error.h"
|
||||
#include "access.h"
|
||||
|
||||
extern int sensors_yyparse(void);
|
||||
extern FILE *sensors_yyin;
|
||||
#include "conf.h"
|
||||
|
||||
static void free_proc_chips_entry(sensors_proc_chips_entry entry);
|
||||
static void free_chip_name(sensors_chip_name name);
|
||||
|
||||
Reference in new issue
Block a user