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