Merge pull request #1 from wshallum/master
[collection4.git] / src / graph_instance.h
1 /**
2  * collection4 - graph_instance.h
3  * Copyright (C) 2010  Florian octo Forster
4  * 
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * 
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  * 
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA  02110-1301  USA
19  *
20  * Authors:
21  *   Florian octo Forster <ff at octo.it>
22  **/
23
24 #ifndef GRAPH_INSTANCE_H
25 #define GRAPH_INSTANCE_H 1
26
27 #include <time.h>
28
29 #include <yajl/yajl_gen.h>
30
31 #include "graph_types.h"
32 #include "data_provider.h"
33 #include "graph_ident.h"
34 #include "rrd_args.h"
35 #include "utils_array.h"
36
37 /*
38  * Methods
39  */
40 graph_instance_t *inst_create (graph_config_t *cfg,
41                 const graph_ident_t *ident);
42
43 void inst_destroy (graph_instance_t *inst);
44
45 int inst_add_file (graph_instance_t *inst, const graph_ident_t *file);
46
47 graph_instance_t *inst_get_selected (graph_config_t *cfg);
48
49 int inst_get_all_selected (graph_config_t *cfg,
50     graph_inst_callback_t callback, void *user_data);
51
52 int inst_get_params (graph_config_t *cfg, graph_instance_t *inst,
53     char *buffer, size_t buffer_size);
54
55 int inst_get_rrdargs (graph_config_t *cfg, graph_instance_t *inst,
56     rrd_args_t *args);
57
58 graph_def_t *inst_get_default_defs (graph_config_t *cfg,
59     graph_instance_t *inst);
60
61 /* Returns a copy of the selector which must be freed by the caller. */
62 graph_ident_t *inst_get_selector (graph_instance_t *inst);
63
64 int inst_compare (const graph_instance_t *i0, const graph_instance_t *i1);
65
66 int inst_compare_ident (graph_instance_t *inst, const graph_ident_t *ident);
67
68 /* Returns true if "ident" matches the instance's selector. */
69 _Bool inst_ident_matches (graph_instance_t *inst, const graph_ident_t *ident);
70
71 /* Returns true if the instance's selector matches the (more general)
72  * "selector" ident. */
73 _Bool inst_matches_ident (graph_instance_t *inst,
74     const graph_ident_t *selector);
75
76 _Bool inst_matches_string (graph_config_t *cfg, graph_instance_t *inst,
77     const char *term);
78
79 /* Compares the given string with the appropriate field of the selector or, if
80  * the selector field is "/all/", iterates over all the files of the instance
81  * and checks the appropriate field. Returns true if the field of the selector
82  * or of one of the files matches. The string must match entirely but
83  * comparison is done case-insensitive. */
84 _Bool inst_matches_field (graph_instance_t *inst,
85     graph_ident_field_t field, const char *field_value);
86
87 int inst_to_json (const graph_instance_t *inst, yajl_gen handler);
88 int inst_data_to_json (const graph_instance_t *inst,
89     dp_time_t begin, dp_time_t end,
90     yajl_gen handler);
91
92 int inst_describe (graph_config_t *cfg, graph_instance_t *inst,
93     char *buffer, size_t buffer_size);
94
95 time_t inst_get_mtime (graph_instance_t *inst);
96
97 #endif /* GRAPH_INSTANCE_H */
98 /* vim: set sw=2 sts=2 et fdm=marker : */