2 * Copyright (C) 2014 - Jonathan Rajotte <jonathan.r.julien@gmail.com>
3 * - Olivier Cotte <olivier.cotte@polymtl.ca>
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.
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
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.
24 #include <common/error.h>
25 #include <common/macros.h>
26 #include <common/config/config.h>
27 #include <lttng/lttng.h>
29 /* Instance of a machine interface writer. */
31 struct config_writer
*writer
;
32 enum lttng_mi_output_type type
;
36 * Version information for the machine interface.
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. */
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
;
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
;
65 * Create an instance of a machine interface writer.
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.
70 * Returns an instance of a machine interface writer on success, NULL on
73 struct mi_writer
*mi_lttng_writer_create(int fd_output
, int mi_output_type
);
76 * Destroy an instance of a machine interface writer.
78 * writer An instance of a machine interface writer.
80 * Returns zero if the XML document could be closed cleanly. Negative values
83 int mi_lttng_writer_destroy(struct mi_writer
*writer
);
86 * Open a command tag and add it's name node.
88 * writer An instance of a machine interface writer.
90 * command The command name.
92 * Returns zero if the XML document could be closed cleanly.
93 * Negative values indicate an error.
95 int mi_lttng_writer_command_open(struct mi_writer
*writer
, const char *command
);
98 * Close a command tag.
100 * writer An instance of a machine interface writer.
102 * Returns zero if the XML document could be closed cleanly.
103 * Negative values indicate an error.
105 int mi_lttng_writer_command_close(struct mi_writer
*writer
);
108 * Open an element tag.
110 * writer An instance of a machine interface writer.
112 * element_name Element tag name.
114 * Returns zero if the XML document could be closed cleanly.
115 * Negative values indicate an error.
117 int mi_lttng_writer_open_element(struct mi_writer
*writer
,
118 const char *element_name
);
121 * Close the current element tag.
123 * writer An instance of a machine interface writer.
125 * Returns zero if the XML document could be closed cleanly.
126 * Negative values indicate an error.
128 int mi_lttng_writer_close_element(struct mi_writer
*writer
);
131 * Write an element of type unsigned int.
133 * writer An instance of a machine interface writer.
135 * element_name Element name.
137 * value Unsigned int value of the element
139 * Returns zero if the element's value could be written.
140 * Negative values indicate an error.
142 int mi_lttng_writer_write_element_unsigned_int(struct mi_writer
*writer
,
143 const char *element_name
, uint64_t value
);
146 * Write an element of type signed int.
148 * writer An instance of a machine interface writer.
150 * element_name Element name.
152 * value Signed int value of the element
154 * Returns zero if the element's value could be written.
155 * Negative values indicate an error.
157 int mi_lttng_writer_write_element_signed_int(struct mi_writer
*writer
,
158 const char *element_name
, int64_t value
);
161 * Write an element of type boolean.
163 * writer An instance of a machine interface writer.
165 * element_name Element name.
167 * value Boolean value of the element
169 * Returns zero if the element's value could be written.
170 * Negative values indicate an error.
172 int mi_lttng_writer_write_element_bool(struct mi_writer
*writer
,
173 const char *element_name
, int value
);
176 * Write an element of type string.
178 * writer An instance of a machine interface writer.
180 * element_name Element name.
182 * value String value of the element
184 * Returns zero if the element's value could be written.
185 * Negative values indicate an error.
187 int mi_lttng_writer_write_element_string(struct mi_writer
*writer
,
188 const char *element_name
, const char *value
);
191 * Machine interface of struct version.
193 * writer An instance of a machine interface writer.
195 * version Version struct.
197 * lttng_description String value of the version description.
199 * lttng_license String value of the version license.
201 * Returns zero if the element's value could be written.
202 * Negative values indicate an error.
204 int mi_lttng_version(struct mi_writer
*writer
, struct mi_lttng_version
*version
,
205 const char *lttng_description
, const char *lttng_license
);
208 * Machine interface of struct session.
210 * writer An instance of a machine interface writer
212 * session An instance of a session
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.
222 * Returns zero if the element's value could be written.
223 * Negative values indicate an error.
225 int mi_lttng_session(struct mi_writer
*writer
,
226 struct lttng_session
*session
, int isOpen
);
228 #endif /* _MI_LTTNG_H */