From: Jonathan Rajotte Date: Thu, 4 Feb 2021 20:57:56 +0000 (-0500) Subject: MI: support double element X-Git-Tag: v2.13.0-rc3~38 X-Git-Url: http://git.lttng.org./?a=commitdiff_plain;h=7c9e11fd294074e94ba0531dab431f190e98cf56;p=lttng-tools.git MI: support double element Signed-off-by: Jonathan Rajotte Signed-off-by: Jérémie Galarneau Change-Id: I97411fea238d8b1275028d3d04a6f4f376624001 --- diff --git a/src/common/config/session-config.c b/src/common/config/session-config.c index b08f40a2e..2263d9478 100644 --- a/src/common/config/session-config.c +++ b/src/common/config/session-config.c @@ -639,6 +639,32 @@ int config_writer_write_element_bool(struct config_writer *writer, value ? config_xml_true : config_xml_false); } +LTTNG_HIDDEN +int config_writer_write_element_double(struct config_writer *writer, + const char *element_name, + double value) +{ + int ret; + xmlChar *encoded_element_name; + + if (!writer || !writer->writer || !element_name || !element_name[0]) { + ret = -1; + goto end; + } + + encoded_element_name = encode_string(element_name); + if (!encoded_element_name) { + ret = -1; + goto end; + } + + ret = xmlTextWriterWriteFormatElement( + writer->writer, encoded_element_name, "%f", value); + xmlFree(encoded_element_name); +end: + return ret >= 0 ? 0 : ret; +} + LTTNG_HIDDEN int config_writer_write_element_string(struct config_writer *writer, const char *element_name, const char *value) diff --git a/src/common/config/session-config.h b/src/common/config/session-config.h index 82400a5ae..1a6019fb1 100644 --- a/src/common/config/session-config.h +++ b/src/common/config/session-config.h @@ -200,6 +200,23 @@ LTTNG_HIDDEN int config_writer_write_element_string(struct config_writer *writer, const char *element_name, const char *value); +/* + * Write an element of type double. + * + * writer An instance of a configuration writer. + * + * element_name Element name. + * + * value Double value of the element + * + * Returns zero if the element's value could be written. + * Negative values indicate an error. + */ +LTTNG_HIDDEN +int config_writer_write_element_double(struct config_writer *writer, + const char *element_name, + double value); + /* * Load session configurations from a file. * diff --git a/src/common/mi-lttng.c b/src/common/mi-lttng.c index bdd6dcea1..9031677d7 100644 --- a/src/common/mi-lttng.c +++ b/src/common/mi-lttng.c @@ -721,6 +721,15 @@ int mi_lttng_writer_write_element_string(struct mi_writer *writer, element_name, value); } +LTTNG_HIDDEN +int mi_lttng_writer_write_element_double(struct mi_writer *writer, + const char *element_name, + double value) +{ + return config_writer_write_element_double( + writer->writer, element_name, value); +} + LTTNG_HIDDEN int mi_lttng_version(struct mi_writer *writer, struct mi_lttng_version *version, const char *lttng_description, const char *lttng_license) diff --git a/src/common/mi-lttng.h b/src/common/mi-lttng.h index 9c985f6bb..ad9283236 100644 --- a/src/common/mi-lttng.h +++ b/src/common/mi-lttng.h @@ -353,6 +353,20 @@ int mi_lttng_writer_write_element_bool(struct mi_writer *writer, int mi_lttng_writer_write_element_string(struct mi_writer *writer, const char *element_name, const char *value); +/* + * Write an element of type double. + * + * writer An instance of a machine interface writer. + * element_name Element name. + * value Double value of the element. + * + * Returns zero if the element's value could be written. + * Negative values indicate an error. + */ +int mi_lttng_writer_write_element_double(struct mi_writer *writer, + const char *element_name, + double value); + /* * Machine interface of struct version. *