Mi: mi backend + mi for command version
[lttng-tools.git] / src / common / mi-lttng.h
1 /*
2 * Copyright (C) 2014 - Jonathan Rajotte <jonathan.r.julien@gmail.com>
3 * - Olivier Cotte <olivier.cotte@polymtl.ca>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License, version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 51
16 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19 #ifndef _MI_LTTNG_H
20 #define _MI_LTTNG_H
21
22 #include <stdint.h>
23
24 #include <common/error.h>
25 #include <common/macros.h>
26 #include <common/config/config.h>
27 #include <lttng/lttng.h>
28
29 /* Instance of a machine interface writer. */
30 struct mi_writer {
31 struct config_writer *writer;
32 enum lttng_mi_output_type type;
33 };
34
35 /*
36 * Version information for the machine interface.
37 */
38 struct mi_lttng_version {
39 char version[NAME_MAX]; /* Version number of package */
40 uint32_t version_major; /* LTTng-Tools major version number */
41 uint32_t version_minor; /* LTTng-Tools minor version number */
42 uint32_t version_patchlevel; /* LTTng-Tools patchlevel version number */
43 char version_name[NAME_MAX];
44 char package_url[NAME_MAX]; /* Define to the home page for this package. */
45 };
46
47 /* Strings related to command */
48 const char * const mi_lttng_element_command;
49 const char * const mi_lttng_element_command_version;
50 const char * const mi_lttng_element_command_list;
51 const char * const mi_lttng_element_command_name;
52 const char * const mi_lttng_element_command_output;
53
54 /* Strings related to command: version */
55 const char * const mi_lttng_element_version;
56 const char * const mi_lttng_element_version_str;
57 const char * const mi_lttng_element_version_web;
58 const char * const mi_lttng_element_version_major;
59 const char * const mi_lttng_element_version_minor;
60 const char * const mi_lttng_element_version_license;
61 const char * const mi_lttng_element_version_patch_level;
62 const char * const mi_lttng_element_version_description;
63
64 /*
65 * Create an instance of a machine interface writer.
66 *
67 * fd_output File to which the XML content must be written. The file will be
68 * closed once the mi_writer has been destroyed.
69 *
70 * Returns an instance of a machine interface writer on success, NULL on
71 * error.
72 */
73 struct mi_writer *mi_lttng_writer_create(int fd_output, int mi_output_type);
74
75 /*
76 * Destroy an instance of a machine interface writer.
77 *
78 * writer An instance of a machine interface writer.
79 *
80 * Returns zero if the XML document could be closed cleanly. Negative values
81 * indicate an error.
82 */
83 int mi_lttng_writer_destroy(struct mi_writer *writer);
84
85 /*
86 * Open a command tag and add it's name node.
87 *
88 * writer An instance of a machine interface writer.
89 *
90 * command The command name.
91 *
92 * Returns zero if the XML document could be closed cleanly.
93 * Negative values indicate an error.
94 */
95 int mi_lttng_writer_command_open(struct mi_writer *writer, const char *command);
96
97 /*
98 * Close a command tag.
99 *
100 * writer An instance of a machine interface writer.
101 *
102 * Returns zero if the XML document could be closed cleanly.
103 * Negative values indicate an error.
104 */
105 int mi_lttng_writer_command_close(struct mi_writer *writer);
106
107 /*
108 * Open an element tag.
109 *
110 * writer An instance of a machine interface writer.
111 *
112 * element_name Element tag name.
113 *
114 * Returns zero if the XML document could be closed cleanly.
115 * Negative values indicate an error.
116 */
117 int mi_lttng_writer_open_element(struct mi_writer *writer,
118 const char *element_name);
119
120 /*
121 * Close the current element tag.
122 *
123 * writer An instance of a machine interface writer.
124 *
125 * Returns zero if the XML document could be closed cleanly.
126 * Negative values indicate an error.
127 */
128 int mi_lttng_writer_close_element(struct mi_writer *writer);
129
130 /*
131 * Write an element of type unsigned int.
132 *
133 * writer An instance of a machine interface writer.
134 *
135 * element_name Element name.
136 *
137 * value Unsigned int value of the element
138 *
139 * Returns zero if the element's value could be written.
140 * Negative values indicate an error.
141 */
142 int mi_lttng_writer_write_element_unsigned_int(struct mi_writer *writer,
143 const char *element_name, uint64_t value);
144
145 /*
146 * Write an element of type signed int.
147 *
148 * writer An instance of a machine interface writer.
149 *
150 * element_name Element name.
151 *
152 * value Signed int value of the element
153 *
154 * Returns zero if the element's value could be written.
155 * Negative values indicate an error.
156 */
157 int mi_lttng_writer_write_element_signed_int(struct mi_writer *writer,
158 const char *element_name, int64_t value);
159
160 /*
161 * Write an element of type boolean.
162 *
163 * writer An instance of a machine interface writer.
164 *
165 * element_name Element name.
166 *
167 * value Boolean value of the element
168 *
169 * Returns zero if the element's value could be written.
170 * Negative values indicate an error.
171 */
172 int mi_lttng_writer_write_element_bool(struct mi_writer *writer,
173 const char *element_name, int value);
174
175 /*
176 * Write an element of type string.
177 *
178 * writer An instance of a machine interface writer.
179 *
180 * element_name Element name.
181 *
182 * value String value of the element
183 *
184 * Returns zero if the element's value could be written.
185 * Negative values indicate an error.
186 */
187 int mi_lttng_writer_write_element_string(struct mi_writer *writer,
188 const char *element_name, const char *value);
189
190 /*
191 * Machine interface of struct version.
192 *
193 * writer An instance of a machine interface writer.
194 *
195 * version Version struct.
196 *
197 * lttng_description String value of the version description.
198 *
199 * lttng_license String value of the version license.
200 *
201 * Returns zero if the element's value could be written.
202 * Negative values indicate an error.
203 */
204 int mi_lttng_version(struct mi_writer *writer, struct mi_lttng_version *version,
205 const char *lttng_description, const char *lttng_license);
206
207 /*
208 * Machine interface of struct session.
209 *
210 * writer An instance of a machine interface writer
211 *
212 * session An instance of a session
213 *
214 * isOpen Define if we close the session element
215 * This should be use carefully and the client
216 * need to close the session element.
217 * Use case: nested addition information on a session
218 * ex: domain,channel event.
219 * 0-> False
220 * 1-> True
221 *
222 * Returns zero if the element's value could be written.
223 * Negative values indicate an error.
224 */
225 int mi_lttng_session(struct mi_writer *writer,
226 struct lttng_session *session, int isOpen);
227
228 #endif /* _MI_LTTNG_H */
This page took 0.034297 seconds and 5 git commands to generate.