X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Ftracker.c;h=7c97d561c982139283afde068394da7703a161c6;hp=afc253def71f990f77bb50923adde56bf481880e;hb=546c03fe47b33fa4490f94a3e441fb51e78bd3b0;hpb=e283e4a062cc16b5839a8a479e12498789320b5e diff --git a/src/common/tracker.c b/src/common/tracker.c index afc253def..7c97d561c 100644 --- a/src/common/tracker.c +++ b/src/common/tracker.c @@ -1,18 +1,8 @@ /* - * Copyright (C) 2019 - Jonathan Rajotte-Julien + * Copyright (C) 2019 Jonathan Rajotte-Julien * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License, version 2.1 only, - * as published by the Free Software Foundation. + * SPDX-License-Identifier: LGPL-2.1-only * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include @@ -277,13 +267,13 @@ const struct lttng_tracker_id *lttng_tracker_ids_get_at_index( return lttng_tracker_ids_get_pointer_of_index(ids, index); } -int lttng_tracker_ids_get_count(const struct lttng_tracker_ids *ids, unsigned int *count) +enum lttng_tracker_id_status lttng_tracker_ids_get_count(const struct lttng_tracker_ids *ids, unsigned int *count) { - enum lttng_tracker_id_status status = LTTNG_ROTATION_STATUS_OK; + enum lttng_tracker_id_status status = LTTNG_TRACKER_ID_STATUS_OK; if (!ids || !count) { - status = LTTNG_ROTATION_STATUS_INVALID; + status = LTTNG_TRACKER_ID_STATUS_INVALID; goto end; } @@ -294,13 +284,87 @@ end: void lttng_tracker_ids_destroy(struct lttng_tracker_ids *ids) { + int i; + if (!ids) { return; } - for (int i = 0; i < ids->count; i++) { + for (i = 0; i < ids->count; i++) { lttng_tracker_id_reset(&ids->id_array[i]); } free(ids->id_array); free(ids); } + +int lttng_tracker_ids_serialize(const struct lttng_tracker_ids *ids, + struct lttng_dynamic_buffer *buffer) +{ + int ret = 0; + int value; + const char *string = NULL; + unsigned int count; + enum lttng_tracker_id_status status; + const struct lttng_tracker_id *id; + unsigned int i; + + status = lttng_tracker_ids_get_count(ids, &count); + if (status != LTTNG_TRACKER_ID_STATUS_OK) { + ret = LTTNG_ERR_INVALID; + goto error; + } + + for (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; +}