src/graph_instance.[ch]: Implement "inst_data_to_json".
[collection4.git] / src / graph_ident.h
1 /**
2  * collection4 - graph_ident.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_IDENT_H
25 #define GRAPH_IDENT_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
34 #define ANY_TOKEN "/any/"
35 #define ALL_TOKEN "/all/"
36
37 #define IS_ANY(str) (((str) != NULL) && (strcasecmp (ANY_TOKEN, (str)) == 0))
38 #define IS_ALL(str) (((str) != NULL) && (strcasecmp (ALL_TOKEN, (str)) == 0))
39
40 enum graph_ident_field_e
41 {
42   GIF_HOST,
43   GIF_PLUGIN,
44   GIF_PLUGIN_INSTANCE,
45   GIF_TYPE,
46   GIF_TYPE_INSTANCE,
47   _GIF_LAST
48 };
49 typedef enum graph_ident_field_e graph_ident_field_t;
50
51 graph_ident_t *ident_create (const char *host,
52     const char *plugin, const char *plugin_instance,
53     const char *type, const char *type_instance);
54 graph_ident_t *ident_clone (const graph_ident_t *ident);
55
56 #define IDENT_FLAG_REPLACE_ALL 0x01
57 #define IDENT_FLAG_REPLACE_ANY 0x02
58 graph_ident_t *ident_copy_with_selector (const graph_ident_t *selector,
59     const graph_ident_t *ident, unsigned int flags);
60
61 void ident_destroy (graph_ident_t *ident);
62
63 const char *ident_get_host (const graph_ident_t *ident);
64 const char *ident_get_plugin (const graph_ident_t *ident);
65 const char *ident_get_plugin_instance (const graph_ident_t *ident);
66 const char *ident_get_type (const graph_ident_t *ident);
67 const char *ident_get_type_instance (const graph_ident_t *ident);
68 const char *ident_get_field (const graph_ident_t *ident,
69     graph_ident_field_t field);
70
71 int ident_set_host (graph_ident_t *ident, const char *host);
72 int ident_set_plugin (graph_ident_t *ident, const char *plugin);
73 int ident_set_plugin_instance (graph_ident_t *ident,
74     const char *plugin_instance);
75 int ident_set_type (graph_ident_t *ident, const char *type);
76 int ident_set_type_instance (graph_ident_t *ident,
77     const char *type_instance);
78
79 int ident_compare (const graph_ident_t *i0,
80     const graph_ident_t *i1);
81
82 _Bool ident_matches (const graph_ident_t *selector,
83     const graph_ident_t *ident);
84
85 /* The "ident_intersect" function takes two selectors and returns true if a
86  * file may apply to both selectors. If the selectors contradict one another,
87  * for example one issuing "plugin = cpu" and the other "plugin = memory",
88  * then false is returned. */
89 _Bool ident_intersect (const graph_ident_t *s0, const graph_ident_t *s1);
90
91 char *ident_to_string (const graph_ident_t *ident);
92 char *ident_to_file (const graph_ident_t *ident);
93 int ident_to_json (const graph_ident_t *ident,
94     yajl_gen handler);
95 int ident_data_to_json (const graph_ident_t *ident,
96     dp_time_t begin, dp_time_t end,
97     yajl_gen handler);
98
99 int ident_describe (const graph_ident_t *ident, const graph_ident_t *selector,
100     char *buffer, size_t buffer_size);
101
102 time_t ident_get_mtime (const graph_ident_t *ident);
103
104 /* vim: set sw=2 sts=2 et fdm=marker : */
105 #endif /* GRAPH_IDENT_H */