X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Ftracker.c;h=312d7bce07601ee26a87ae82a5cd6821d8d16285;hp=afc253def71f990f77bb50923adde56bf481880e;hb=ab5be9fa2eb5ba9600a82cd18fd3cfcbac69169a;hpb=e283e4a062cc16b5839a8a479e12498789320b5e diff --git a/src/common/tracker.c b/src/common/tracker.c index afc253def..312d7bce0 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; } @@ -304,3 +294,74 @@ void lttng_tracker_ids_destroy(struct lttng_tracker_ids *ids) 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; +}