Merge pull request #2796 from jimklimov/fix-docs-markup
[networkupstools.git] / include / state.h
blob9857e4d5842263f97c2d1018940b02672a0365c5
1 /* state.h - Network UPS Tools common state management functions
3 Copyright (C)
4 2003 Russell Kroll <rkroll@exploits.org>
5 2012 Arnaud Quette <arnaud.quette@free.fr>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #ifndef NUT_STATE_H_SEEN
23 #define NUT_STATE_H_SEEN 1
25 #include "extstate.h"
27 #ifdef __cplusplus
28 /* *INDENT-OFF* */
29 extern "C" {
30 /* *INDENT-ON* */
31 #endif
33 #define ST_SOCK_BUF_LEN 512
35 #include "timehead.h"
37 #if defined(HAVE_CLOCK_GETTIME) && defined(HAVE_CLOCK_MONOTONIC) && HAVE_CLOCK_GETTIME && HAVE_CLOCK_MONOTONIC
38 typedef struct timespec st_tree_timespec_t;
39 #else
40 typedef struct timeval st_tree_timespec_t;
41 #endif
43 typedef struct st_tree_s {
44 char *var;
45 char *val; /* points to raw or safe */
47 char *raw; /* raw data from caller */
48 size_t rawsize;
50 char *safe; /* safe data from pconf_encode */
51 size_t safesize;
53 int flags;
54 long aux;
56 /* When was this entry last written (meaning that
57 * val/raw/safe, flags, aux, enum or range value
58 * was added, changed or deleted)?
60 st_tree_timespec_t lastset;
62 struct enum_s *enum_list;
63 struct range_s *range_list;
65 struct st_tree_s *left;
66 struct st_tree_s *right;
67 } st_tree_t;
69 int state_get_timestamp(st_tree_timespec_t *now);
70 int st_tree_node_compare_timestamp(const st_tree_t *node, const st_tree_timespec_t *cutoff);
71 int state_setinfo(st_tree_t **nptr, const char *var, const char *val);
72 int state_addenum(st_tree_t *root, const char *var, const char *val);
73 int state_addrange(st_tree_t *root, const char *var, const int min, const int max);
74 int state_setaux(st_tree_t *root, const char *var, const char *auxs);
75 const char *state_getinfo(st_tree_t *root, const char *var);
76 int state_getflags(st_tree_t *root, const char *var);
77 long state_getaux(st_tree_t *root, const char *var);
78 const enum_t *state_getenumlist(st_tree_t *root, const char *var);
79 const range_t *state_getrangelist(st_tree_t *root, const char *var);
80 void state_setflags(st_tree_t *root, const char *var, size_t numflags, char **flags);
81 int state_addcmd(cmdlist_t **list, const char *cmd);
82 void state_infofree(st_tree_t *node);
83 void state_cmdfree(cmdlist_t *list);
84 int state_delcmd(cmdlist_t **list, const char *cmd);
85 int state_delinfo(st_tree_t **root, const char *var);
86 int state_delinfo_olderthan(st_tree_t **root, const char *var, const st_tree_timespec_t *cutoff);
87 int state_delenum(st_tree_t *root, const char *var, const char *val);
88 int state_delrange(st_tree_t *root, const char *var, const int min, const int max);
89 st_tree_t *state_tree_find(st_tree_t *node, const char *var);
91 #ifdef __cplusplus
92 /* *INDENT-OFF* */
94 /* *INDENT-ON* */
95 #endif
97 #endif /* NUT_STATE_H_SEEN */