mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-16 00:00:02 +01:00
90 lines
No EOL
1.7 KiB
C
90 lines
No EOL
1.7 KiB
C
/** Override a value of the sample with a header, timestamp or statistic value.
|
|
*
|
|
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
|
* @copyright 2017, Institute for Automation of Complex Power Systems, EONERC
|
|
*********************************************************************************/
|
|
|
|
/** @addtogroup hooks Hook functions
|
|
* @{
|
|
*/
|
|
|
|
#include "plugin.h"
|
|
#include "mapping.h"
|
|
#include "list.h"
|
|
#include "utils.h"
|
|
#include "path.h"
|
|
|
|
struct map {
|
|
struct mapping mapping;
|
|
|
|
struct stats *stats;
|
|
};
|
|
|
|
static int hook_map(struct hook *h, int when, struct sample *smps[], size_t *cnt)
|
|
{
|
|
int ret;
|
|
struct map *p = (struct map *) h->_vd;
|
|
|
|
switch (when) {
|
|
case HOOK_INIT:
|
|
mapping_init(&p->mapping);
|
|
break;
|
|
|
|
case HOOK_DESTROY:
|
|
mapping_destroy(&p->mapping);
|
|
break;
|
|
|
|
case HOOK_PARSE: {
|
|
config_setting_t *cfg_mapping;
|
|
|
|
cfg_mapping = config_setting_lookup(h->cfg, "mapping");
|
|
|
|
if (!config_setting_is_array(cfg_mapping))
|
|
return -1;
|
|
|
|
ret = mapping_parse(&p->mapping, cfg_mapping);
|
|
if (ret)
|
|
return ret;
|
|
|
|
break;
|
|
}
|
|
|
|
case HOOK_READ: {
|
|
struct sample *tmp[*cnt];
|
|
|
|
if (*cnt <= 0)
|
|
return 0;
|
|
|
|
ret = sample_alloc(smps[0]->pool, tmp, *cnt);
|
|
if (ret != *cnt)
|
|
return ret;
|
|
|
|
for (int i = 0; i < *cnt; i++) {
|
|
mapping_remap(&p->mapping, smps[i], tmp[i], NULL);
|
|
|
|
SWAP(smps[i], tmp[i]);
|
|
}
|
|
|
|
sample_free(tmp, *cnt);
|
|
break;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static struct plugin p = {
|
|
.name = "map",
|
|
.description = "Remap values and / or add data generated by this instace.",
|
|
.type = PLUGIN_TYPE_HOOK,
|
|
.hook = {
|
|
.priority = 99,
|
|
.size = sizeof(struct map),
|
|
.cb = hook_map,
|
|
.when = HOOK_STORAGE | HOOK_READ | HOOK_PARSE
|
|
}
|
|
};
|
|
|
|
REGISTER_PLUGIN(&p);
|
|
|
|
/** @} */ |