This patch introduces a feature whereby rrdcached will disallow updates
[rrdtool.git] / src / rrd_rpncalc.h
1 /****************************************************************************
2  * RRDtool 1.3.2  Copyright by Tobi Oetiker, 1997-2008
3  ****************************************************************************
4  * rrd_rpncalc.h  RPN calculator functions
5  ****************************************************************************/
6 #ifndef _RRD_RPNCALC_H
7 #define _RRD_RPNCALC_H
8
9 /* WARNING: if new operators are added, they MUST be added at the very end of the list.
10  * This is because COMPUTE (CDEF) DS store OP nodes by number (name is not
11  * an option due to limited par array size). OP nodes must have the same
12  * numeric values, otherwise the stored numbers will mean something different. */
13 enum op_en { OP_NUMBER = 0, OP_VARIABLE, OP_INF, OP_PREV, OP_NEGINF,
14     OP_UNKN, OP_NOW, OP_TIME, OP_ADD, OP_MOD, OP_SUB, OP_MUL,
15     OP_DIV, OP_SIN, OP_DUP, OP_EXC, OP_POP,
16     OP_COS, OP_LOG, OP_EXP, OP_LT, OP_LE, OP_GT, OP_GE, OP_EQ, OP_IF,
17     OP_MIN, OP_MAX, OP_LIMIT, OP_FLOOR, OP_CEIL,
18     OP_UN, OP_END, OP_LTIME, OP_NE, OP_ISINF, OP_PREV_OTHER, OP_COUNT,
19     OP_ATAN, OP_SQRT, OP_SORT, OP_REV, OP_TREND, OP_TRENDNAN,
20     OP_ATAN2, OP_RAD2DEG, OP_DEG2RAD,
21     OP_AVG, OP_ABS, OP_ADDNAN
22 };
23
24 typedef struct rpnp_t {
25     enum op_en op;
26     double    val;      /* value for a OP_NUMBER */
27     long      ptr;      /* pointer into the gdes array for OP_VAR */
28     double   *data;     /* pointer to the current value from OP_VAR DAS */
29     long      ds_cnt;   /* data source count for data pointer */
30     long      step;     /* time step for OP_VAR das */
31 } rpnp_t;
32
33 /* a compact representation of rpnp_t for computed data sources */
34 typedef struct rpn_cdefds_t {
35     char      op;       /* rpn operator type */
36     short     val;      /* used by OP_NUMBER and OP_VARIABLE */
37 } rpn_cdefds_t;
38
39 #define MAX_VNAME_LEN 255
40 #define DEF_NAM_FMT "%255[-_A-Za-z0-9]"
41
42 /* limit imposed by sizeof(rpn_cdefs_t) and rrd.ds_def.par */
43 #define DS_CDEF_MAX_RPN_NODES 26
44
45 typedef struct rpnstack_t {
46     double   *s;
47     long      dc_stacksize;
48     long      dc_stackblock;
49 } rpnstack_t;
50
51 void      rpnstack_init(
52     rpnstack_t *rpnstack);
53 void      rpnstack_free(
54     rpnstack_t *rpnstack);
55
56 void      parseCDEF_DS(
57     const char *def,
58     rrd_t *rrd,
59     int ds_idx);
60 long      lookup_DS(
61     void *rrd_vptr,
62     char *ds_name);
63
64 short     rpn_compact(
65     rpnp_t *rpnp,
66     rpn_cdefds_t **rpnc,
67     short *count);
68 rpnp_t   *rpn_expand(
69     rpn_cdefds_t *rpnc);
70 void      rpn_compact2str(
71     rpn_cdefds_t *rpnc,
72     ds_def_t *ds_def,
73     char **str);
74 rpnp_t   *rpn_parse(
75     void *key_hash,
76     const char *const expr,
77     long      (*lookup) (void *,
78                          char *));
79 short     rpn_calc(
80     rpnp_t *rpnp,
81     rpnstack_t *rpnstack,
82     long data_idx,
83     rrd_value_t *output,
84     int output_idx);
85
86 #endif