Add utility function config_get_loglevel_type_string
[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 <lttng/domain.h>
25 #include <lttng/event.h>
26 #include <stdint.h>
27
28 struct config_entry {
29 /* section is NULL if the entry is not in a section */
30 const char *section;
31 const char *name;
32 const char *value;
33 };
34
35 /* Instance of a configuration writer. */
36 struct config_writer;
37
38 /* Instance of a configuration document */
39 struct config_document;
40
41 struct config_element;
42
43 /*
44 * Return the config string representation of a kernel type.
45 */
46 LTTNG_HIDDEN
47 const char *config_get_domain_str(enum lttng_domain_type domain);
48
49 /*
50 * Return the config string representation of a loglevel type.
51 */
52 LTTNG_HIDDEN
53 const char *config_get_loglevel_type_string(
54 enum lttng_loglevel_type loglevel_type);
55
56 /*
57 * Return the event_type int value of lttng_event_type enumeration based on the
58 * passed string.
59 */
60 LTTNG_HIDDEN
61 int config_get_event_type(const char *event_type);
62
63 /*
64 * A config_entry_handler_cb receives config_entry structures belonging to the
65 * sections the handler has been registered to.
66 *
67 * The config_entry and its members are only valid for the duration of the call
68 * and must not be freed.
69 *
70 * config_entry_handler_cb may return negative value to indicate an error in
71 * the configuration file.
72 */
73 typedef int (*config_entry_handler_cb)(const struct config_entry *, void *);
74
75 /*
76 * Read a section's entries in an INI configuration file.
77 *
78 * path may be NULL, in which case the following paths will be tried:
79 * 1) $HOME/.lttng/lttng.conf
80 * 2) /etc/lttng/lttng.conf
81 *
82 * handler will only be called with entries belonging to the provided section.
83 * If section is NULL, all entries will be relayed to handler. If section is
84 * "", only the global entries are relayed.
85 *
86 * Returns 0 on success. Negative values are error codes. If the return value
87 * is positive, it represents the line number on which a parsing error occurred.
88 */
89 LTTNG_HIDDEN
90 int config_get_section_entries(const char *path, const char *section,
91 config_entry_handler_cb handler, void *user_data);
92
93 /*
94 * Parse a configuration value.
95 *
96 * This function expects either an unsigned integer or a boolean text option.
97 * The following strings are recognized: true, yes, on, false, no and off.
98 *
99 * Returns either the value of the parsed integer, or 0/1 if a boolean text
100 * string was recognized. Negative values indicate an error.
101 */
102 LTTNG_HIDDEN
103 int config_parse_value(const char *value);
104
105 /*
106 * Create an instance of a configuration writer.
107 *
108 * fd_output File to which the XML content must be written. The file will be
109 * closed once the config_writer has been destroyed.
110 *
111 * indent If other than 0 the XML will be pretty printed
112 * with indentation and newline.
113 *
114 * Returns an instance of a configuration writer on success, NULL on
115 * error.
116 */
117 LTTNG_HIDDEN
118 struct config_writer *config_writer_create(int fd_output, int indent);
119
120 /*
121 * Destroy an instance of a configuration writer.
122 *
123 * writer An instance of a configuration writer.
124 *
125 * Returns zero if the XML document could be closed cleanly. Negative values
126 * indicate an error.
127 */
128 LTTNG_HIDDEN
129 int config_writer_destroy(struct config_writer *writer);
130
131 /*
132 * Open an element tag.
133 *
134 * writer An instance of a configuration writer.
135 *
136 * element_name Element tag name.
137 *
138 * Returns zero if the XML element could be opened.
139 * Negative values indicate an error.
140 */
141 LTTNG_HIDDEN
142 int config_writer_open_element(struct config_writer *writer,
143 const char *element_name);
144
145 /*
146 * Write an element tag attribute.
147 *
148 * writer An instance of a configuration writer.
149 *
150 * name Attribute name.
151 *
152 * Returns zero if the XML element's attribute could be written.
153 * Negative values indicate an error.
154 */
155 LTTNG_HIDDEN
156 int config_writer_write_attribute(struct config_writer *writer,
157 const char *name, const char *value);
158
159 /*
160 * Close the current element tag.
161 *
162 * writer An instance of a configuration writer.
163 *
164 * Returns zero if the XML document could be closed cleanly.
165 * Negative values indicate an error.
166 */
167 LTTNG_HIDDEN
168 int config_writer_close_element(struct config_writer *writer);
169
170 /*
171 * Write an element of type unsigned int.
172 *
173 * writer An instance of a configuration writer.
174 *
175 * element_name Element name.
176 *
177 * value Unsigned int value of the element
178 *
179 * Returns zero if the element's value could be written.
180 * Negative values indicate an error.
181 */
182 LTTNG_HIDDEN
183 int config_writer_write_element_unsigned_int(struct config_writer *writer,
184 const char *element_name, uint64_t value);
185
186 /*
187 * Write an element of type signed int.
188 *
189 * writer An instance of a configuration writer.
190 *
191 * element_name Element name.
192 *
193 * value Signed int value of the element
194 *
195 * Returns zero if the element's value could be written.
196 * Negative values indicate an error.
197 */LTTNG_HIDDEN
198 int config_writer_write_element_signed_int(struct config_writer *writer,
199 const char *element_name, int64_t value);
200
201 /*
202 * Write an element of type boolean.
203 *
204 * writer An instance of a configuration writer.
205 *
206 * element_name Element name.
207 *
208 * value Boolean value of the element
209 *
210 * Returns zero if the element's value could be written.
211 * Negative values indicate an error.
212 */
213 LTTNG_HIDDEN
214 int config_writer_write_element_bool(struct config_writer *writer,
215 const char *element_name, int value);
216
217 /*
218 * Write an element of type string.
219 *
220 * writer An instance of a configuration writer.
221 *
222 * element_name Element name.
223 *
224 * value String value of the element
225 *
226 * Returns zero if the element's value could be written.
227 * Negative values indicate an error.
228 */
229 LTTNG_HIDDEN
230 int config_writer_write_element_string(struct config_writer *writer,
231 const char *element_name, const char *value);
232
233 /*
234 * Write an element of type config_element.
235 *
236 * writer An instance of a configuration writer.
237 *
238 * element The config_element instance.
239 *
240 * Returns zero if the element could be written.
241 * Negative values indicate an error.
242 */
243 LTTNG_HIDDEN
244 int config_writer_write_config_element(struct config_writer *writer,
245 const struct config_element *element);
246 /*
247 * Load session configurations from a file.
248 *
249 * path Path to an LTTng session configuration file. All *.lttng files
250 * will be loaded if path is a directory. If path is NULL, the default
251 * paths will be searched in the following order:
252 * 1) $HOME/.lttng/sessions
253 * 2) /etc/lttng/sessions
254 *
255 * session_name Name of the session to load. Will load all
256 * sessions from path if NULL.
257 *
258 * override Override current session configuration if it exists.
259 * autoload Tell to load the auto session(s).
260 *
261 * Returns zero if the session could be loaded successfully. Returns
262 * a negative LTTNG_ERR code on error.
263 */
264 LTTNG_HIDDEN
265 int config_load_session(const char *path, const char *session_name,
266 int override, unsigned int autoload);
267
268 /*
269 * Load session configuration from a document
270 *
271 * document The document to be loaded as a configuration
272 * session_name Name of the session to load. Will load all sessions from the
273 * passed document if NULL
274 *
275 * override Override current session configuration if it exists.
276 *
277 * Returns zero if the session could be loaded successfully. Returns
278 * a negative LTTNG_ERR code on error.
279 */
280 LTTNG_HIDDEN
281 int config_load_configuration_sessions(struct config_document *document,
282 const char *session_name, int override);
283
284 /*
285 * Get the document corresponding to the path.
286 *
287 * path Path to a configuration file.
288 * xsd_validation Whether or not to do a xsd validation
289 *
290 * Returns an new allocated config_document when successful.
291 * Returns NULL on error;
292 *
293 * The caller is responsible of freeing the document via config_document_free.
294 */
295 LTTNG_HIDDEN
296 struct config_document *config_document_get(const char *path);
297
298 /*
299 * Free an allocated document.
300 *
301 * document The document to free.
302 */
303 LTTNG_HIDDEN
304 void config_document_free(struct config_document *document);
305
306 /*
307 * Replace the value of a document element
308 *
309 * document The document containing the element to be modified.
310 * xpath The xpath string to the element.
311 * value The value to be placed inside the element.
312 *
313 * Returns zero if the session could be loaded successfully. Returns
314 * a negative LTTNG_ERR code on error.
315 * */
316 LTTNG_HIDDEN
317 int config_document_replace_element_value(struct config_document *document, const char *xpath, const char *value);
318
319 /*
320 * Swap a document node by the passed element.
321 *
322 * document The document containing the element to be modified.
323 * xpath The xpath string to the element.
324 * element The replacement element.
325 *
326 * Returns zero if the session could be loaded successfully. Returns
327 * a negative LTTNG_ERR code on error.
328 */
329 LTTNG_HIDDEN
330 int config_document_replace_element(struct config_document *document, const char *xpath, const struct config_element *element);
331
332 /*
333 * Get the value of a document element.
334 *
335 * document The document to be searched.
336 * xpath The xpath string to the element.
337 *
338 * Return null if multiple values exists or there is no
339 * value for the passed path.
340 */
341 LTTNG_HIDDEN
342 char *config_document_get_element_value(struct config_document *document, const char *xpath);
343
344 /*
345 * Check if an element exists inside a document.
346 *
347 * document The document to be searched.
348 * xpath The xpath string to the element.
349 *
350 * Returns 1 on success and 0 on failure.
351 */
352 LTTNG_HIDDEN
353 int config_document_element_exist(struct config_document *document, const char *xpath);
354
355 /*
356 *
357 */
358 LTTNG_HIDDEN
359 void config_element_free(struct config_element *element);
360
361 LTTNG_HIDDEN
362 struct config_element *config_element_create(const char *name, const char *value);
363
364 /*
365 * Add a child element to an element.
366 *
367 * parent The parent element.
368 * child The element to add as a child.
369 *
370 * Returns zero if the session could be loaded successfully. Returns
371 * a negative LTTNG_ERR code on error.
372 */
373 LTTNG_HIDDEN
374 int config_element_add_child(struct config_element *parent, const struct config_element *child);
375
376 /*
377 * Insert element to an existing document.
378 *
379 * document The document to be modified.
380 * xpath The xpath string to the insertion path.
381 * element The element to be inserted.
382 *
383 * Returns zero if the session could be loaded successfully. Returns
384 * a negative LTTNG_ERR code on error.
385 */
386 LTTNG_HIDDEN
387 int config_document_insert_element(struct config_document *document, const char *xpath, const struct config_element *element);
388
389
390 #endif /* _CONFIG_H */
This page took 0.055502 seconds and 5 git commands to generate.