From 06706a6d2ee8fb3673993acec5d194cced440792 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Jos=C3=A9=20Carracedo=20Carballal?= Date: Tue, 3 Sep 2024 17:37:15 +0200 Subject: [PATCH] Remove explicit references to estimator / spectrum objects in messages --- analyzer/insp-server.c | 23 +++++++++++------------ analyzer/msg.c | 41 ++++++++++++++++++----------------------- analyzer/msg.h | 4 ++-- 3 files changed, 31 insertions(+), 37 deletions(-) diff --git a/analyzer/insp-server.c b/analyzer/insp-server.c index 6bd3205..84ec666 100644 --- a/analyzer/insp-server.c +++ b/analyzer/insp-server.c @@ -220,6 +220,7 @@ DEF_MSGCB(OPEN) SUFREQ ft; struct suscan_inspector_sampling_info samp_info; suscan_inspector_factory_t *factory = NULL; + char *dup = NULL; unsigned int i; SUHANDLE handle; SUBOOL ok = SU_FALSE; @@ -295,20 +296,18 @@ DEF_MSGCB(OPEN) msg->channel.ft = ft; /* Add applicable estimators */ - for (i = 0; i < new_insp->estimator_count; ++i) - SU_TRYCATCH( - PTR_LIST_APPEND_CHECK( - msg->estimator, - (void *) new_insp->estimator_list[i]->classptr) != -1, - goto done); + for (i = 0; i < new_insp->estimator_count; ++i) { + SU_TRY(dup = strdup(new_insp->estimator_list[i]->classptr->name)); + SU_TRYC(PTR_LIST_APPEND_CHECK(msg->estimator, dup)); + } + + dup = NULL; /* Add applicable spectrum sources */ - for (i = 0; i < new_insp->spectsrc_count; ++i) - SU_TRYCATCH( - PTR_LIST_APPEND_CHECK( - msg->spectsrc, - (void *) new_insp->spectsrc_list[i]->classptr) != -1, - goto done); + for (i = 0; i < new_insp->spectsrc_count; ++i) { + SU_TRY(dup = strdup(new_insp->spectsrc_list[i]->classptr->name)); + SU_TRYC(PTR_LIST_APPEND_CHECK(msg->spectsrc, dup)); + } if (msg->config != NULL) suscan_config_destroy(msg->config); diff --git a/analyzer/msg.c b/analyzer/msg.c index 363e1e5..cef30d0 100644 --- a/analyzer/msg.c +++ b/analyzer/msg.c @@ -410,13 +410,13 @@ suscan_analyzer_inspector_msg_serialize_open( cbor_pack_array_start(buffer, self->estimator_count) == 0, goto fail); for (i = 0; i < self->estimator_count; ++i) - SUSCAN_PACK(str, self->estimator_list[i]->name); + SUSCAN_PACK(str, self->estimator_list[i]); SU_TRYCATCH( cbor_pack_array_start(buffer, self->spectsrc_count) == 0, goto fail); for (i = 0; i < self->spectsrc_count; ++i) - SUSCAN_PACK(str, self->spectsrc_list[i]->name); + SUSCAN_PACK(str, self->spectsrc_list[i]); SUSCAN_PACK_BOILERPLATE_END; } @@ -461,15 +461,8 @@ suscan_analyzer_inspector_msg_deserialize_open( sizeof(struct suscan_estimator_class *)), goto fail); - for (i = 0; i < self->estimator_count; ++i) { - SUSCAN_UNPACK(str, name); - self->estimator_list[i] = suscan_estimator_class_lookup(name); - if (self->estimator_list[i] == NULL) - SU_WARNING("Estimator class `%s' not found\n", name); - - free(name); - name = NULL; - } + for (i = 0; i < self->estimator_count; ++i) + SUSCAN_UNPACK(str, self->estimator_list[i]); SU_TRYCATCH( cbor_unpack_array_start( @@ -486,16 +479,8 @@ suscan_analyzer_inspector_msg_deserialize_open( sizeof(struct suscan_spectsrc_class *)), goto fail); - for (i = 0; i < self->spectsrc_count; ++i) { - SUSCAN_UNPACK(str, name); - self->spectsrc_list[i] = suscan_spectsrc_class_lookup(name); - if (self->spectsrc_list[i] == NULL) - SU_WARNING("Spectrum source class `%s' not found\n", name); - - free(name); - name = NULL; - } - + for (i = 0; i < self->spectsrc_count; ++i) + SUSCAN_UNPACK(str, self->spectsrc_list[i]); SUSCAN_UNPACK_BOILERPLATE_FINALLY; @@ -1025,6 +1010,8 @@ suscan_analyzer_inspector_msg_take_spectrum( void suscan_analyzer_inspector_msg_destroy(struct suscan_analyzer_inspector_msg *msg) { + unsigned int i = 0; + switch (msg->kind) { case SUSCAN_ANALYZER_INSPECTOR_MSGKIND_GET_CONFIG: case SUSCAN_ANALYZER_INSPECTOR_MSGKIND_SET_CONFIG: @@ -1032,11 +1019,19 @@ suscan_analyzer_inspector_msg_destroy(struct suscan_analyzer_inspector_msg *msg) if (msg->config != NULL) suscan_config_destroy(msg->config); - if (msg->estimator_list != NULL) + if (msg->estimator_list != NULL) { + for (i = 0; i < msg->estimator_count; ++i) + if (msg->estimator_list[i] != NULL) + free(msg->estimator_list[i]); free(msg->estimator_list); + } - if (msg->spectsrc_list != NULL) + if (msg->spectsrc_list != NULL) { + for (i = 0; i < msg->spectsrc_count; ++i) + if (msg->spectsrc_list[i] != NULL) + free(msg->spectsrc_list[i]); free(msg->spectsrc_list); + } if (msg->class_name != NULL) free(msg->class_name); diff --git a/analyzer/msg.h b/analyzer/msg.h index 32f8981..aec0189 100644 --- a/analyzer/msg.h +++ b/analyzer/msg.h @@ -214,8 +214,8 @@ SUSCAN_SERIALIZABLE(suscan_analyzer_inspector_msg) { SUFLOAT equiv_fs; /* Channel rate */ SUFLOAT bandwidth; SUFLOAT lo; - PTR_LIST_CONST(struct suscan_estimator_class, estimator); - PTR_LIST_CONST(struct suscan_spectsrc_class, spectsrc); + PTR_LIST(char, estimator); + PTR_LIST(char, spectsrc); }; struct {