1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

refactoring: full identifiers

This commit is contained in:
Steffen Vogel 2018-08-06 10:10:17 +02:00
parent 3cca02d1c0
commit ce8c90e1c2
3 changed files with 63 additions and 54 deletions

View file

@ -27,64 +27,75 @@
#include <villas/stats.h>
#include <villas/common.h>
#include <villas/list.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Forward declarations */
struct stats;
struct node;
struct sample;
struct signal;
struct list;
enum mapping_type {
MAPPING_TYPE_DATA,
MAPPING_TYPE_STATS,
MAPPING_TYPE_HEADER,
MAPPING_TYPE_TIMESTAMP
};
enum mapping_stats_type {
MAPPING_STATS_TYPE_LAST,
MAPPING_STATS_TYPE_HIGHEST,
MAPPING_STATS_TYPE_LOWEST,
MAPPING_STATS_TYPE_MEAN,
MAPPING_STATS_TYPE_VAR,
MAPPING_STATS_TYPE_STDDEV,
MAPPING_STATS_TYPE_TOTAL
};
enum mapping_header_type {
MAPPING_HEADER_TYPE_LENGTH,
MAPPING_HEADER_TYPE_SEQUENCE
};
enum mapping_timestamp_type {
MAPPING_TIMESTAMP_TYPE_ORIGIN,
MAPPING_TIMESTAMP_TYPE_RECEIVED,
MAPPING_TIMESTAMP_TYPE_SEND
};
struct mapping_entry {
struct node *node;
struct node *node; /**< The node to which this mapping refers. */
enum mapping_type type; /**< The mapping type. Selects one of the union fields below. */
/** The number of values which is covered by this mapping entry.
*
* A value of 0 indicates that all remaining values starting from the offset of a sample should be mapped.
*/
int length;
int offset; /**< Offset of this mapping entry within sample::data */
int length; /**< The number of values which is covered by this mapping entry. */
enum {
MAPPING_TYPE_DATA,
MAPPING_TYPE_STATS,
MAPPING_TYPE_HDR,
MAPPING_TYPE_TS
} type;
union {
struct {
int offset;
struct signal *signal;
} data;
struct {
enum stats_id id;
enum stats_type {
MAPPING_STATS_TYPE_LAST,
MAPPING_STATS_TYPE_HIGHEST,
MAPPING_STATS_TYPE_LOWEST,
MAPPING_STATS_TYPE_MEAN,
MAPPING_STATS_TYPE_VAR,
MAPPING_STATS_TYPE_STDDEV,
MAPPING_STATS_TYPE_TOTAL
} type;
enum mapping_stats_type type;
} stats;
struct {
enum header_type {
MAPPING_HDR_LENGTH,
MAPPING_HDR_SEQUENCE,
MAPPING_HDR_FORMAT
} id;
} hdr;
enum mapping_header_type type;
} header;
struct {
enum timestamp_type {
MAPPING_TS_ORIGIN,
MAPPING_TS_RECEIVED,
MAPPING_TS_SEND
} id;
} ts;
enum mapping_timestamp_type type;
} timestamp;
};
};

View file

@ -96,7 +96,7 @@ int mapping_parse_str(struct mapping_entry *me, const char *str, struct list *no
goto invalid_format;
}
else if (!strcmp(type, "hdr")) {
me->type = MAPPING_TYPE_HDR;
me->type = MAPPING_TYPE_HEADER;
me->length = 1;
field = strtok(NULL, ".");
@ -104,16 +104,14 @@ int mapping_parse_str(struct mapping_entry *me, const char *str, struct list *no
goto invalid_format;
if (!strcmp(field, "sequence"))
me->hdr.id = MAPPING_HDR_SEQUENCE;
me->header.type = MAPPING_HEADER_TYPE_SEQUENCE;
else if (!strcmp(field, "length"))
me->hdr.id = MAPPING_HDR_LENGTH;
else if (!strcmp(field, "format"))
me->hdr.id = MAPPING_HDR_FORMAT;
me->header.type = MAPPING_HEADER_TYPE_LENGTH;
else
goto invalid_format;
}
else if (!strcmp(type, "ts")) {
me->type = MAPPING_TYPE_TS;
me->type = MAPPING_TYPE_TIMESTAMP;
me->length = 2;
field = strtok(NULL, ".");
@ -121,11 +119,11 @@ int mapping_parse_str(struct mapping_entry *me, const char *str, struct list *no
goto invalid_format;
if (!strcmp(field, "origin"))
me->ts.id = MAPPING_TS_ORIGIN;
me->timestamp.type = MAPPING_TIMESTAMP_TYPE_ORIGIN;
else if (!strcmp(field, "received"))
me->ts.id = MAPPING_TS_RECEIVED;
me->timestamp.type = MAPPING_TIMESTAMP_TYPE_RECEIVED;
else if (!strcmp(field, "sent"))
me->ts.id = MAPPING_TS_SEND;
me->timestamp.type = MAPPING_TIMESTAMP_TYPE_SEND;
else
goto invalid_format;
}
@ -289,14 +287,14 @@ int mapping_update(struct mapping_entry *me, struct sample *remapped, struct sam
}
}
case MAPPING_TYPE_TS: {
case MAPPING_TYPE_TIMESTAMP: {
struct timespec *ts;
switch (me->ts.id) {
case MAPPING_TS_RECEIVED:
switch (me->timestamp.type) {
case MAPPING_TIMESTAMP_TYPE_RECEIVED:
ts = &original->ts.received;
break;
case MAPPING_TS_ORIGIN:
case MAPPING_TIMESTAMP_TYPE_ORIGIN:
ts = &original->ts.origin;
break;
default:
@ -312,14 +310,14 @@ int mapping_update(struct mapping_entry *me, struct sample *remapped, struct sam
break;
}
case MAPPING_TYPE_HDR:
sample_set_data_format(remapped, off, SAMPLE_DATA_FORMAT_INT);
case MAPPING_TYPE_HEADER:
switch (me->hdr.id) {
case MAPPING_HDR_LENGTH:
switch (me->header.type) {
case MAPPING_HEADER_TYPE_LENGTH:
remapped->data[off++].i = original->length;
break;
case MAPPING_HDR_SEQUENCE:
case MAPPING_HEADER_TYPE_SEQUENCE:
remapped->data[off++].i = original->sequence;
break;
case MAPPING_HDR_FORMAT:
@ -393,7 +391,7 @@ int mapping_to_str(struct mapping_entry *me, unsigned index, char **str)
break;
case MAPPING_TYPE_HEADER:
switch (me->hdr.type) {
switch (me->header.type) {
case MAPPING_HEADER_TYPE_LENGTH: type = "length"; break;
case MAPPING_HEADER_TYPE_SEQUENCE: type = "sequence"; break;
}
@ -402,7 +400,7 @@ int mapping_to_str(struct mapping_entry *me, unsigned index, char **str)
break;
case MAPPING_TYPE_TIMESTAMP:
switch (me->stats.type) {
switch (me->timestamp.type) {
case MAPPING_TIMESTAMP_TYPE_ORIGIN: type = "origin"; break;
case MAPPING_TIMESTAMP_TYPE_RECEIVED: type = "received"; break;
}

View file

@ -65,7 +65,7 @@ Test(mapping, parse_nodes)
ret = mapping_parse_str(&m, "apple.ts.origin", &nodes);
cr_assert_eq(ret, 0);
cr_assert_eq(m.node, list_lookup(&nodes, "apple"));
cr_assert_eq(m.type, MAPPING_TYPE_TS);
cr_assert_eq(m.type, MAPPING_TYPE_TIMESTAMP);
cr_assert_eq(m.ts.id, MAPPING_TS_ORIGIN);
ret = mapping_parse_str(&m, "cherry.stats.owd.mean", &nodes);
@ -114,12 +114,12 @@ Test(mapping, parse)
ret = mapping_parse_str(&m, "ts.origin", NULL);
cr_assert_eq(ret, 0);
cr_assert_eq(m.type, MAPPING_TYPE_TS);
cr_assert_eq(m.type, MAPPING_TYPE_TIMESTAMP);
cr_assert_eq(m.ts.id, MAPPING_TS_ORIGIN);
ret = mapping_parse_str(&m, "hdr.sequence", NULL);
cr_assert_eq(ret, 0);
cr_assert_eq(m.type, MAPPING_TYPE_HDR);
cr_assert_eq(m.type, MAPPING_TYPE_HEADER);
cr_assert_eq(m.hdr.id, MAPPING_HDR_SEQUENCE);
ret = mapping_parse_str(&m, "stats.owd.mean", NULL);