ff74eb0992bfd8c7e76729d15602c5e0dcd604b2
[lttng-tools.git] / src / common / config / session-config.h
1 /*
2 * Copyright (C) 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
8 #ifndef _CONFIG_H
9 #define _CONFIG_H
10
11 #include <common/config/ini.h>
12 #include <common/config/config-session-abi.h>
13 #include <common/macros.h>
14 #include <stdint.h>
15
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19
20 struct config_entry {
21 /* section is NULL if the entry is not in a section */
22 const char *section;
23 const char *name;
24 const char *value;
25 };
26
27 struct config_load_session_override_attr {
28 char *path_url;
29 char *ctrl_url;
30 char *data_url;
31 char *session_name;
32 };
33
34 /* Instance of a configuration writer. */
35 struct config_writer;
36
37 /*
38 * A config_entry_handler_cb receives config_entry structures belonging to the
39 * sections the handler has been registered to.
40 *
41 * The config_entry and its members are only valid for the duration of the call
42 * and must not be freed.
43 *
44 * config_entry_handler_cb may return negative value to indicate an error in
45 * the configuration file.
46 */
47 typedef int (*config_entry_handler_cb)(const struct config_entry *, void *);
48
49 /*
50 * Read a section's entries in an INI configuration file.
51 *
52 * path may be NULL, in which case the following paths will be tried:
53 * 1) $HOME/.lttng/lttng.conf
54 * 2) /etc/lttng/lttng.conf
55 *
56 * handler will only be called with entries belonging to the provided section.
57 * If section is NULL, all entries will be relayed to handler. If section is
58 * "", only the global entries are relayed.
59 *
60 * Returns 0 on success. Negative values are error codes. If the return value
61 * is positive, it represents the line number on which a parsing error occurred.
62 */
63 int 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 */
75 int config_parse_value(const char *value);
76
77 /*
78 * Create an instance of a configuration writer.
79 *
80 * fd_output File to which the XML content must be written. fd_output is
81 * owned by the caller.
82 *
83 * indent If other than 0 the XML will be pretty printed
84 * with indentation and newline.
85 *
86 * Returns an instance of a configuration writer on success, NULL on
87 * error.
88 */
89 struct config_writer *config_writer_create(int fd_output, int indent);
90
91 /*
92 * Destroy an instance of a configuration writer.
93 *
94 * writer An instance of a configuration writer.
95 *
96 * Returns zero if the XML document could be closed cleanly. Negative values
97 * indicate an error.
98 */
99 int config_writer_destroy(struct config_writer *writer);
100
101 /*
102 * Open an element tag.
103 *
104 * writer An instance of a configuration writer.
105 *
106 * element_name Element tag name.
107 *
108 * Returns zero if the XML element could be opened.
109 * Negative values indicate an error.
110 */
111 int config_writer_open_element(struct config_writer *writer,
112 const char *element_name);
113
114 /*
115 * Write an element tag attribute.
116 *
117 * writer An instance of a configuration writer.
118 *
119 * name Attribute name.
120 *
121 * Returns zero if the XML element's attribute could be written.
122 * Negative values indicate an error.
123 */
124 int config_writer_write_attribute(struct config_writer *writer,
125 const char *name, const char *value);
126
127 /*
128 * Close the current element tag.
129 *
130 * writer An instance of a configuration writer.
131 *
132 * Returns zero if the XML document could be closed cleanly.
133 * Negative values indicate an error.
134 */
135 int config_writer_close_element(struct config_writer *writer);
136
137 /*
138 * Write an element of type unsigned int.
139 *
140 * writer An instance of a configuration writer.
141 *
142 * element_name Element name.
143 *
144 * value Unsigned int value of the element
145 *
146 * Returns zero if the element's value could be written.
147 * Negative values indicate an error.
148 */
149 int config_writer_write_element_unsigned_int(struct config_writer *writer,
150 const char *element_name, uint64_t value);
151
152 /*
153 * Write an element of type signed int.
154 *
155 * writer An instance of a configuration writer.
156 *
157 * element_name Element name.
158 *
159 * value Signed int value of the element
160 *
161 * Returns zero if the element's value could be written.
162 * Negative values indicate an error.
163 */
164 int config_writer_write_element_signed_int(struct config_writer *writer,
165 const char *element_name, int64_t value);
166
167 /*
168 * Write an element of type boolean.
169 *
170 * writer An instance of a configuration writer.
171 *
172 * element_name Element name.
173 *
174 * value Boolean value of the element
175 *
176 * Returns zero if the element's value could be written.
177 * Negative values indicate an error.
178 */
179 int config_writer_write_element_bool(struct config_writer *writer,
180 const char *element_name, int value);
181
182 /*
183 * Write an element of type string.
184 *
185 * writer An instance of a configuration writer.
186 *
187 * element_name Element name.
188 *
189 * value String value of the element
190 *
191 * Returns zero if the element's value could be written.
192 * Negative values indicate an error.
193 */
194 int config_writer_write_element_string(struct config_writer *writer,
195 const char *element_name, const char *value);
196
197 /*
198 * Write an element of type double.
199 *
200 * writer An instance of a configuration writer.
201 *
202 * element_name Element name.
203 *
204 * value Double value of the element
205 *
206 * Returns zero if the element's value could be written.
207 * Negative values indicate an error.
208 */
209 int config_writer_write_element_double(struct config_writer *writer,
210 const char *element_name,
211 double value);
212
213 /*
214 * Load session configurations from a file.
215 *
216 * path Path to an LTTng session configuration file. All *.lttng files
217 * will be loaded if path is a directory. If path is NULL, the default
218 * paths will be searched in the following order:
219 * 1) $HOME/.lttng/sessions
220 * 2) /etc/lttng/sessions
221 *
222 * session_name Name of the session to load. Will load all
223 * sessions from path if NULL.
224 *
225 * overwrite Overwrite current session configuration if it exists.
226 * autoload Tell to load the auto session(s).
227 * overrides The override attribute structure specifying override parameters.
228 *
229 * Returns zero if the session could be loaded successfully. Returns
230 * a negative LTTNG_ERR code on error.
231 */
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 #ifdef __cplusplus
237 }
238 #endif
239
240 #endif /* _CONFIG_H */
This page took 0.032687 seconds and 3 git commands to generate.