mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
mapping: fix intialization
This commit is contained in:
parent
f5e74e3dbf
commit
6b4e9bbcbd
3 changed files with 50 additions and 13 deletions
|
@ -45,6 +45,7 @@ struct signal;
|
|||
struct vlist;
|
||||
|
||||
enum class MappingType {
|
||||
UNKNOWN,
|
||||
DATA,
|
||||
STATS,
|
||||
HEADER,
|
||||
|
@ -62,7 +63,7 @@ enum class MappingTimestampType {
|
|||
};
|
||||
|
||||
struct mapping_entry {
|
||||
const char *node_name;
|
||||
char *node_name;
|
||||
struct vnode *node; /**< The node to which this mapping refers. */
|
||||
|
||||
enum MappingType type; /**< The mapping type. Selects one of the union fields below. */
|
||||
|
@ -79,8 +80,8 @@ struct mapping_entry {
|
|||
int offset;
|
||||
struct signal *signal;
|
||||
|
||||
const char *first;
|
||||
const char *last;
|
||||
char *first;
|
||||
char *last;
|
||||
} data;
|
||||
|
||||
struct {
|
||||
|
@ -100,9 +101,13 @@ struct mapping_entry {
|
|||
|
||||
int mapping_entry_prepare(struct mapping_entry *me, struct vlist *nodes);
|
||||
|
||||
int mapping_entry_update(const struct mapping_entry *e, struct sample *remapped, const struct sample *original);
|
||||
int mapping_entry_update(const struct mapping_entry *me, struct sample *remapped, const struct sample *original);
|
||||
|
||||
int mapping_entry_parse(struct mapping_entry *e, json_t *cfg);
|
||||
int mapping_entry_init(struct mapping_entry *me);
|
||||
|
||||
int mapping_entry_destroy(struct mapping_entry *me);
|
||||
|
||||
int mapping_entry_parse(struct mapping_entry *me, json_t *cfg);
|
||||
|
||||
int mapping_entry_parse_str(struct mapping_entry *e, const std::string &str);
|
||||
|
||||
|
|
|
@ -44,28 +44,29 @@ int mapping_entry_parse_str(struct mapping_entry *me, const std::string &str)
|
|||
|
||||
if (mr[1].matched)
|
||||
me->node_name = strdup(mr.str(1).c_str());
|
||||
|
||||
|
||||
if (mr[9].matched)
|
||||
me->node_name = strdup(mr.str(9).c_str());
|
||||
|
||||
if (mr[6].matched) {
|
||||
me->data.first = strdup(mr.str(6).c_str());
|
||||
|
||||
if (mr[7].matched)
|
||||
me->data.last = strdup(mr.str(7).c_str());
|
||||
me->data.last = mr[7].matched
|
||||
? strdup(mr.str(7).c_str())
|
||||
: nullptr;
|
||||
|
||||
me->type = MappingType::DATA;
|
||||
}
|
||||
else if (mr[10].matched) {
|
||||
me->data.first = strdup(mr.str(10).c_str());
|
||||
|
||||
if (mr[11].matched)
|
||||
me->data.last = strdup(mr.str(11).c_str());
|
||||
me->data.last = mr[11].matched
|
||||
? strdup(mr.str(11).c_str())
|
||||
: nullptr;
|
||||
|
||||
me->type = MappingType::DATA;
|
||||
}
|
||||
else if (mr[8].matched) {
|
||||
me->data.first = strdup(mr.str(8).c_str());
|
||||
me->data.last = nullptr;
|
||||
|
||||
me->type = MappingType::DATA;
|
||||
}
|
||||
|
@ -106,10 +107,28 @@ int mapping_entry_parse_str(struct mapping_entry *me, const std::string &str)
|
|||
return 0;
|
||||
|
||||
invalid_format:
|
||||
|
||||
|
||||
throw RuntimeError("Failed to parse mapping expression: {}", str);
|
||||
}
|
||||
|
||||
int mapping_entry_init(struct mapping_entry *me)
|
||||
{
|
||||
me->type = MappingType::UNKNOWN;
|
||||
|
||||
me->node = nullptr;
|
||||
me->node_name = nullptr;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mapping_entry_destroy(struct mapping_entry *me)
|
||||
{
|
||||
if (me->node_name)
|
||||
free(me->node_name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mapping_entry_parse(struct mapping_entry *me, json_t *cfg)
|
||||
{
|
||||
const char *str;
|
||||
|
@ -143,6 +162,10 @@ int mapping_list_parse(struct vlist *ml, json_t *cfg)
|
|||
if (!me)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
ret = mapping_entry_init(me);
|
||||
if (ret)
|
||||
goto out;
|
||||
|
||||
ret = mapping_entry_parse(me, json_entry);
|
||||
if (ret)
|
||||
goto out;
|
||||
|
@ -218,6 +241,9 @@ int mapping_update(const struct mapping_entry *me, struct sample *remapped, cons
|
|||
|
||||
len = MIN((unsigned) me->length, original->length - me->data.offset);
|
||||
break;
|
||||
|
||||
case MappingType::UNKNOWN:
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (me->offset + len > remapped->length)
|
||||
|
@ -379,6 +405,9 @@ int mapping_entry_to_str(const struct mapping_entry *me, unsigned index, char **
|
|||
else
|
||||
strcatf(str, "data[%u]", index);
|
||||
break;
|
||||
|
||||
case MappingType::UNKNOWN:
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -86,6 +86,9 @@ int signal_init_from_mapping(struct signal *s, const struct mapping_entry *me, u
|
|||
if (me->data.signal->unit)
|
||||
s->name = strdup(me->data.signal->unit);
|
||||
break;
|
||||
|
||||
case MappingType::UNKNOWN:
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Reference in a new issue