55b8de3dc5fe0df2bc114b4f3ac709f0264b0eac
[lttng-tools.git] / src / common / config / session-config.h
1 /*
2 * Copyright (C) 2013 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License, version 2 only, as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 51
15 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17
18 #ifndef _CONFIG_H
19 #define _CONFIG_H
20
21 #include <common/config/ini.h>
22 #include <common/config/config-session-abi.h>
23 #include <common/macros.h>
24 #include <stdint.h>
25
26 struct config_entry {
27 /* section is NULL if the entry is not in a section */
28 const char *section;
29 const char *name;
30 const char *value;
31 };
32
33 struct config_load_session_override_attr {
34 char *path_url;
35 char *ctrl_url;
36 char *data_url;
37 };
38
39 /* Instance of a configuration writer. */
40 struct config_writer;
41
42 /*
43 * A config_entry_handler_cb receives config_entry structures belonging to the
44 * sections the handler has been registered to.
45 *
46 * The config_entry and its members are only valid for the duration of the call
47 * and must not be freed.
48 *
49 * config_entry_handler_cb may return negative value to indicate an error in
50 * the configuration file.
51 */
52 typedef int (*config_entry_handler_cb)(const struct config_entry *, void *);
53
54 /*
55 * Read a section's entries in an INI configuration file.
56 *
57 * path may be NULL, in which case the following paths will be tried:
58 * 1) $HOME/.lttng/lttng.conf
59 * 2) /etc/lttng/lttng.conf
60 *
61 * handler will only be called with entries belonging to the provided section.
62 * If section is NULL, all entries will be relayed to handler. If section is
63 * "", only the global entries are relayed.
64 *
65 * Returns 0 on success. Negative values are error codes. If the return value
66 * is positive, it represents the line number on which a parsing error occurred.
67 */
68 LTTNG_HIDDEN
69 int config_get_section_entries(const char *path, const char *section,
70 config_entry_handler_cb handler, void *user_data);
71
72 /*
73 * Parse a configuration value.
74 *
75 * This function expects either an unsigned integer or a boolean text option.
76 * The following strings are recognized: true, yes, on, false, no and off.
77 *
78 * Returns either the value of the parsed integer, or 0/1 if a boolean text
79 * string was recognized. Negative values indicate an error.
80 */
81 LTTNG_HIDDEN
82 int config_parse_value(const char *value);
83
84 /*
85 * Create an instance of a configuration writer.
86 *
87 * fd_output File to which the XML content must be written. The file will be
88 * closed once the config_writer has been destroyed.
89 *
90 * indent If other than 0 the XML will be pretty printed
91 * with indentation and newline.
92 *
93 * Returns an instance of a configuration writer on success, NULL on
94 * error.
95 */
96 LTTNG_HIDDEN
97 struct config_writer *config_writer_create(int fd_output, int indent);
98
99 /*
100 * Destroy an instance of a configuration writer.
101 *
102 * writer An instance of a configuration writer.
103 *
104 * Returns zero if the XML document could be closed cleanly. Negative values
105 * indicate an error.
106 */
107 LTTNG_HIDDEN
108 int config_writer_destroy(struct config_writer *writer);
109
110 /*
111 * Open an element tag.
112 *
113 * writer An instance of a configuration writer.
114 *
115 * element_name Element tag name.
116 *
117 * Returns zero if the XML element could be opened.
118 * Negative values indicate an error.
119 */
120 LTTNG_HIDDEN
121 int config_writer_open_element(struct config_writer *writer,
122 const char *element_name);
123
124 /*
125 * Write an element tag attribute.
126 *
127 * writer An instance of a configuration writer.
128 *
129 * name Attribute name.
130 *
131 * Returns zero if the XML element's attribute could be written.
132 * Negative values indicate an error.
133 */
134 LTTNG_HIDDEN
135 int config_writer_write_attribute(struct config_writer *writer,
136 const char *name, const char *value);
137
138 /*
139 * Close the current element tag.
140 *
141 * writer An instance of a configuration writer.
142 *
143 * Returns zero if the XML document could be closed cleanly.
144 * Negative values indicate an error.
145 */
146 LTTNG_HIDDEN
147 int config_writer_close_element(struct config_writer *writer);
148
149 /*
150 * Write an element of type unsigned int.
151 *
152 * writer An instance of a configuration writer.
153 *
154 * element_name Element name.
155 *
156 * value Unsigned int value of the element
157 *
158 * Returns zero if the element's value could be written.
159 * Negative values indicate an error.
160 */
161 LTTNG_HIDDEN
162 int config_writer_write_element_unsigned_int(struct config_writer *writer,
163 const char *element_name, uint64_t value);
164
165 /*
166 * Write an element of type signed int.
167 *
168 * writer An instance of a configuration writer.
169 *
170 * element_name Element name.
171 *
172 * value Signed int value of the element
173 *
174 * Returns zero if the element's value could be written.
175 * Negative values indicate an error.
176 */LTTNG_HIDDEN
177 int config_writer_write_element_signed_int(struct config_writer *writer,
178 const char *element_name, int64_t value);
179
180 /*
181 * Write an element of type boolean.
182 *
183 * writer An instance of a configuration writer.
184 *
185 * element_name Element name.
186 *
187 * value Boolean value of the element
188 *
189 * Returns zero if the element's value could be written.
190 * Negative values indicate an error.
191 */
192 LTTNG_HIDDEN
193 int config_writer_write_element_bool(struct config_writer *writer,
194 const char *element_name, int value);
195
196 /*
197 * Write an element of type string.
198 *
199 * writer An instance of a configuration writer.
200 *
201 * element_name Element name.
202 *
203 * value String value of the element
204 *
205 * Returns zero if the element's value could be written.
206 * Negative values indicate an error.
207 */
208 LTTNG_HIDDEN
209 int config_writer_write_element_string(struct config_writer *writer,
210 const char *element_name, const char *value);
211
212 /*
213 * Load session configurations from a file.
214 *
215 * path Path to an LTTng session configuration file. All *.lttng files
216 * will be loaded if path is a directory. If path is NULL, the default
217 * paths will be searched in the following order:
218 * 1) $HOME/.lttng/sessions
219 * 2) /etc/lttng/sessions
220 *
221 * session_name Name of the session to load. Will load all
222 * sessions from path if NULL.
223 *
224 * overwrite Overwrite current session configuration if it exists.
225 * autoload Tell to load the auto session(s).
226 * overrides The override attribute structure specifying override parameters.
227 *
228 * Returns zero if the session could be loaded successfully. Returns
229 * a negative LTTNG_ERR code on error.
230 */
231 LTTNG_HIDDEN
232 int config_load_session(const char *path, const char *session_name,
233 int overwrite, unsigned int autoload,
234 const struct config_load_session_override_attr *overrides);
235
236 #endif /* _CONFIG_H */
This page took 0.032887 seconds and 3 git commands to generate.