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