Skip to content

Commit

Permalink
Remove explicit references to estimator / spectrum objects in messages
Browse files Browse the repository at this point in the history
  • Loading branch information
BatchDrake committed Sep 3, 2024
1 parent dd675d7 commit 06706a6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 37 deletions.
23 changes: 11 additions & 12 deletions analyzer/insp-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
41 changes: 18 additions & 23 deletions analyzer/msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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(
Expand All @@ -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;

Expand Down Expand Up @@ -1025,18 +1010,28 @@ 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:
case SUSCAN_ANALYZER_INSPECTOR_MSGKIND_OPEN:
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);
Expand Down
4 changes: 2 additions & 2 deletions analyzer/msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 06706a6

Please sign in to comment.