#ifndef LTTNG_TRACKER_INTERNAL_H
#define LTTNG_TRACKER_INTERNAL_H
-#include <lttng/constant.h>
#include <common/macros.h>
+#include <common/dynamic-buffer.h>
+#include <lttng/constant.h>
#include <lttng/tracker.h>
#include <stdbool.h>
struct lttng_tracker_id *lttng_tracker_ids_get_pointer_of_index(
const struct lttng_tracker_ids *list, unsigned int index);
+/*
+ * Serialize a ids collection to a lttng_dynamic_buffer.
+ * Return LTTNG_OK on success, negative lttng error code on error.
+ */
+LTTNG_HIDDEN
+int lttng_tracker_ids_serialize(const struct lttng_tracker_ids *ids,
+ struct lttng_dynamic_buffer *buffer);
+
#endif /* LTTNG_TRACKER_INTERNAL_H */
#include <lttng/event-internal.h>
#include <lttng/session-internal.h>
#include <lttng/session-descriptor-internal.h>
+#include <lttng/tracker-internal.h>
#include "client.h"
#include "lttng-sessiond.h"
struct lttcomm_tracker_command_header cmd_header;
struct lttng_tracker_ids *ids = NULL;
enum lttng_tracker_id_status status;
- unsigned int nr_ids, i;
+ unsigned int nr_ids;
struct lttng_dynamic_buffer buf;
ret = cmd_list_tracker_ids(
goto error;
}
+ lttng_dynamic_buffer_init(&buf);
+
status = lttng_tracker_ids_get_count(ids, &nr_ids);
if (status != LTTNG_TRACKER_ID_STATUS_OK) {
- ret = LTTNG_ERR_INVALID;
+ ret = -LTTNG_ERR_INVALID;
goto error_list_tracker;
}
- lttng_dynamic_buffer_init(&buf);
- for (i = 0; i < nr_ids; i++) {
- const struct lttng_tracker_id *id;
- struct lttcomm_tracker_id_header id_hdr;
- size_t var_data_len = 0;
- enum lttng_tracker_id_status status;
- const char *string;
- int value;
-
- id = lttng_tracker_ids_get_at_index(ids, i);
- if (!id) {
- ret = LTTNG_ERR_INVALID;
- goto error_list_tracker;
- }
-
- memset(&id_hdr, 0, sizeof(id_hdr));
- id_hdr.type = lttng_tracker_id_get_type(id);
- switch (id_hdr.type) {
- case LTTNG_ID_ALL:
- break;
- case LTTNG_ID_VALUE:
- status = lttng_tracker_id_get_value(id, &value);
- id_hdr.u.value = value;
- if (status != LTTNG_TRACKER_ID_STATUS_OK) {
- ret = LTTNG_ERR_INVALID;
- goto error_list_tracker;
- }
- break;
- case LTTNG_ID_STRING:
- status = lttng_tracker_id_get_string(
- id, &string);
- if (status != LTTNG_TRACKER_ID_STATUS_OK) {
- ret = LTTNG_ERR_INVALID;
- goto error_list_tracker;
- }
+ cmd_header.nb_tracker_id = nr_ids;
- id_hdr.u.var_data_len = var_data_len =
- strlen(string) + 1;
- break;
- default:
- ret = LTTNG_ERR_INVALID;
- goto error_list_tracker;
- }
- ret = lttng_dynamic_buffer_append(
- &buf, &id_hdr, sizeof(id_hdr));
- if (ret) {
- ret = LTTNG_ERR_NOMEM;
- goto error_list_tracker;
- }
- ret = lttng_dynamic_buffer_append(
- &buf, string, var_data_len);
- if (ret) {
- ret = LTTNG_ERR_NOMEM;
- goto error_list_tracker;
- }
+ ret = lttng_tracker_ids_serialize(ids, &buf);
+ if (ret < 0) {
+ goto error_list_tracker;
}
- cmd_header.nb_tracker_id = nr_ids;
ret = setup_lttng_msg(cmd_ctx, buf.data, buf.size, &cmd_header,
sizeof(cmd_header));
error_list_tracker:
lttng_tracker_ids_destroy(ids);
lttng_dynamic_buffer_reset(&buf);
if (ret < 0) {
- goto setup_error;
+ goto error;
}
ret = LTTNG_OK;
free(ids->id_array);
free(ids);
}
+
+int lttng_tracker_ids_serialize(const struct lttng_tracker_ids *ids,
+ struct lttng_dynamic_buffer *buffer)
+{
+ int ret;
+ int value;
+ const char *string;
+ unsigned int count;
+ enum lttng_tracker_id_status status;
+ const struct lttng_tracker_id *id;
+
+ status = lttng_tracker_ids_get_count(ids, &count);
+ if (status != LTTNG_TRACKER_ID_STATUS_OK) {
+ ret = LTTNG_ERR_INVALID;
+ goto error;
+ }
+
+ for (unsigned int i = 0; i < count; i++) {
+ struct lttcomm_tracker_id_header id_hdr;
+ size_t var_data_len = 0;
+
+ id = lttng_tracker_ids_get_at_index(ids, i);
+ if (!id) {
+ ret = -LTTNG_ERR_INVALID;
+ goto error;
+ }
+
+ memset(&id_hdr, 0, sizeof(id_hdr));
+ id_hdr.type = lttng_tracker_id_get_type(id);
+ switch (id_hdr.type) {
+ case LTTNG_ID_ALL:
+ break;
+ case LTTNG_ID_VALUE:
+ status = lttng_tracker_id_get_value(id, &value);
+ id_hdr.u.value = value;
+ if (status != LTTNG_TRACKER_ID_STATUS_OK) {
+ ret = -LTTNG_ERR_INVALID;
+ goto error;
+ }
+ break;
+ case LTTNG_ID_STRING:
+ status = lttng_tracker_id_get_string(
+ id, &string);
+ if (status != LTTNG_TRACKER_ID_STATUS_OK) {
+ ret = -LTTNG_ERR_INVALID;
+ goto error;
+ }
+
+ id_hdr.u.var_data_len = var_data_len =
+ strlen(string) + 1;
+ break;
+ default:
+ ret = -LTTNG_ERR_INVALID;
+ goto error;
+ }
+ ret = lttng_dynamic_buffer_append(
+ buffer, &id_hdr, sizeof(id_hdr));
+ if (ret) {
+ ret = -LTTNG_ERR_NOMEM;
+ goto error;
+ }
+ ret = lttng_dynamic_buffer_append(
+ buffer, string, var_data_len);
+ if (ret) {
+ ret = -LTTNG_ERR_NOMEM;
+ goto error;
+ }
+ }
+error:
+ return ret;
+}