]> arthur.barton.de Git - netdata.git/blob - src/eval.h
dns_query_time plugin: replace "." with "_" in dimensions
[netdata.git] / src / eval.h
1 #ifndef NETDATA_EVAL_H
2 #define NETDATA_EVAL_H
3
4 #define EVAL_MAX_VARIABLE_NAME_LENGTH 300
5
6 typedef struct eval_variable {
7     char *name;
8     uint32_t hash;
9     struct rrdvar *rrdvar;
10     struct eval_variable *next;
11 } EVAL_VARIABLE;
12
13 typedef struct eval_expression {
14     const char *source;
15     const char *parsed_as;
16
17     int *status;
18     calculated_number *this;
19     time_t *after;
20     time_t *before;
21
22     calculated_number result;
23
24     int error;
25     BUFFER *error_msg;
26
27     // hidden EVAL_NODE *
28     void *nodes;
29
30     // custom data to be used for looking up variables
31     struct rrdcalc *rrdcalc;
32 } EVAL_EXPRESSION;
33
34 #define EVAL_VALUE_INVALID    0
35 #define EVAL_VALUE_NUMBER     1
36 #define EVAL_VALUE_VARIABLE   2
37 #define EVAL_VALUE_EXPRESSION 3
38
39 // parsing and evaluation
40 #define EVAL_ERROR_OK                             0
41
42 // parsing errors
43 #define EVAL_ERROR_MISSING_CLOSE_SUBEXPRESSION    1
44 #define EVAL_ERROR_UNKNOWN_OPERAND                2
45 #define EVAL_ERROR_MISSING_OPERAND                3
46 #define EVAL_ERROR_MISSING_OPERATOR               4
47 #define EVAL_ERROR_REMAINING_GARBAGE              5
48 #define EVAL_ERROR_IF_THEN_ELSE_MISSING_ELSE      6
49
50 // evaluation errors
51 #define EVAL_ERROR_INVALID_VALUE                101
52 #define EVAL_ERROR_INVALID_NUMBER_OF_OPERANDS   102
53 #define EVAL_ERROR_VALUE_IS_NAN                 103
54 #define EVAL_ERROR_VALUE_IS_INFINITE            104
55 #define EVAL_ERROR_UNKNOWN_VARIABLE             105
56
57 // parse the given string as an expression and return:
58 //   a pointer to an expression if it parsed OK
59 //   NULL in which case the pointer to error has the error code
60 extern EVAL_EXPRESSION *expression_parse(const char *string, const char **failed_at, int *error);
61
62 // free all resources allocated for an expression
63 extern void expression_free(EVAL_EXPRESSION *op);
64
65 // convert an error code to a message
66 extern const char *expression_strerror(int error);
67
68 // evaluate an expression and return
69 // 1 = OK, the result is in: expression->result
70 // 2 = FAILED, the error message is in: buffer_tostring(expression->error_msg)
71 extern int expression_evaluate(EVAL_EXPRESSION *expression);
72
73 #endif //NETDATA_EVAL_H