Typo: occured -> occurred
[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>
36f2332b 24#include <stdint.h>
1501a7f3
JG
25
26struct 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
36f2332b
JG
33/* Instance of a configuration writer. */
34struct config_writer;
35
1501a7f3
JG
36/*
37 * A config_entry_handler_cb receives config_entry structures belonging to the
38 * sections the handler has been registered to.
39 *
40 * The config_entry and its members are only valid for the duration of the call
41 * and must not be freed.
42 *
43 * config_entry_handler_cb may return negative value to indicate an error in
44 * the configuration file.
45 */
46typedef int (*config_entry_handler_cb)(const struct config_entry *, void *);
47
48/*
49 * Read a section's entries in an INI configuration file.
50 *
51 * path may be NULL, in which case the following paths will be tried:
52 * 1) $HOME/.lttng/lttng.conf
53 * 2) /etc/lttng/lttng.conf
54 *
55 * handler will only be called with entries belonging to the provided section.
56 * If section is NULL, all entries will be relayed to handler. If section is
57 * "", only the global entries are relayed.
58 *
59 * Returns 0 on success. Negative values are error codes. If the return value
83f4233d 60 * is positive, it represents the line number on which a parsing error occurred.
1501a7f3
JG
61 */
62LTTNG_HIDDEN
63int config_get_section_entries(const char *path, const char *section,
64 config_entry_handler_cb handler, void *user_data);
65
66/*
67 * Parse a configuration value.
68 *
69 * This function expects either an unsigned integer or a boolean text option.
70 * The following strings are recognized: true, yes, on, false, no and off.
71 *
72 * Returns either the value of the parsed integer, or 0/1 if a boolean text
73 * string was recognized. Negative values indicate an error.
74 */
75LTTNG_HIDDEN
76int config_parse_value(const char *value);
77
36f2332b
JG
78/*
79 * Create an instance of a configuration writer.
80 *
81 * fd_output File to which the XML content must be written. The file will be
82 * closed once the config_writer has been destroyed.
83 *
705bb62f
JRJ
84 * indent If other than 0 the XML will be pretty printed
85 * with indentation and newline.
86 *
36f2332b
JG
87 * Returns an instance of a configuration writer on success, NULL on
88 * error.
89 */
90LTTNG_HIDDEN
705bb62f 91struct config_writer *config_writer_create(int fd_output, int indent);
36f2332b
JG
92
93/*
94 * Destroy an instance of a configuration writer.
95 *
96 * writer An instance of a configuration writer.
97 *
98 * Returns zero if the XML document could be closed cleanly. Negative values
99 * indicate an error.
100 */
101LTTNG_HIDDEN
102int config_writer_destroy(struct config_writer *writer);
103
104/*
105 * Open an element tag.
106 *
107 * writer An instance of a configuration writer.
108 *
109 * element_name Element tag name.
110 *
e10b6a1c 111 * Returns zero if the XML element could be opened.
36f2332b
JG
112 * Negative values indicate an error.
113 */
114LTTNG_HIDDEN
115int config_writer_open_element(struct config_writer *writer,
116 const char *element_name);
117
e10b6a1c
JG
118/*
119 * Write an element tag attribute.
120 *
121 * writer An instance of a configuration writer.
122 *
123 * name Attribute name.
124 *
125 * Returns zero if the XML element's attribute could be written.
126 * Negative values indicate an error.
127 */
128LTTNG_HIDDEN
129int config_writer_write_attribute(struct config_writer *writer,
130 const char *name, const char *value);
131
36f2332b
JG
132/*
133 * Close the current element tag.
134 *
135 * writer An instance of a configuration writer.
136 *
137 * Returns zero if the XML document could be closed cleanly.
138 * Negative values indicate an error.
139 */
140LTTNG_HIDDEN
141int config_writer_close_element(struct config_writer *writer);
142
143/*
144 * Write an element of type unsigned int.
145 *
146 * writer An instance of a configuration writer.
147 *
148 * element_name Element name.
149 *
150 * value Unsigned int value of the element
151 *
152 * Returns zero if the element's value could be written.
153 * Negative values indicate an error.
154 */
155LTTNG_HIDDEN
156int config_writer_write_element_unsigned_int(struct config_writer *writer,
157 const char *element_name, uint64_t value);
158
159/*
160 * Write an element of type signed int.
161 *
162 * writer An instance of a configuration writer.
163 *
164 * element_name Element name.
165 *
166 * value Signed int value of the element
167 *
168 * Returns zero if the element's value could be written.
169 * Negative values indicate an error.
170 */LTTNG_HIDDEN
171int config_writer_write_element_signed_int(struct config_writer *writer,
172 const char *element_name, int64_t value);
173
174/*
175 * Write an element of type boolean.
176 *
177 * writer An instance of a configuration writer.
178 *
179 * element_name Element name.
180 *
181 * value Boolean value of the element
182 *
183 * Returns zero if the element's value could be written.
184 * Negative values indicate an error.
185 */
186LTTNG_HIDDEN
187int config_writer_write_element_bool(struct config_writer *writer,
188 const char *element_name, int value);
189
190/*
191 * Write an element of type string.
192 *
193 * writer An instance of a configuration writer.
194 *
195 * element_name Element name.
196 *
197 * value String value of the element
198 *
199 * Returns zero if the element's value could be written.
200 * Negative values indicate an error.
201 */
202LTTNG_HIDDEN
203int config_writer_write_element_string(struct config_writer *writer,
204 const char *element_name, const char *value);
205
dcf266c0
JG
206/*
207 * Load session configurations from a file.
208 *
209 * path Path to an LTTng session configuration file. All *.lttng files
210 * will be loaded if path is a directory. If path is NULL, the default
211 * paths will be searched in the following order:
212 * 1) $HOME/.lttng/sessions
213 * 2) /etc/lttng/sessions
214 *
215 * session_name Name of the session to load. Will load all
216 * sessions from path if NULL.
217 *
218 * override Override current session configuration if it exists.
ab38c13f 219 * autoload Tell to load the auto session(s).
dcf266c0
JG
220 *
221 * Returns zero if the session could be loaded successfully. Returns
222 * a negative LTTNG_ERR code on error.
223 */
224LTTNG_HIDDEN
225int config_load_session(const char *path, const char *session_name,
ab38c13f 226 int override, unsigned int autoload);
dcf266c0 227
1501a7f3 228#endif /* _CONFIG_H */
This page took 0.045937 seconds and 5 git commands to generate.