1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-16 00:00:02 +01:00
VILLASnode/lib/hooks/map.c

111 lines
2.5 KiB
C
Raw Normal View History

/** 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
2017-04-27 12:56:43 +02:00
* @license GNU General Public License (version 3)
*
* VILLASnode
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
2017-04-27 12:56:43 +02:00
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
2017-04-27 12:56:43 +02:00
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************************/
/** @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;
};
2017-03-27 12:26:11 +02:00
static int map_init(struct hook *h)
{
2017-03-27 12:26:11 +02:00
struct map *p = h->_vd;
return mapping_init(&p->mapping);
}
static int map_destroy(struct hook *h)
{
struct map *p = h->_vd;
return mapping_destroy(&p->mapping);
}
static int map_parse(struct hook *h, config_setting_t *cfg)
{
int ret;
struct map *p = h->_vd;
2017-03-27 12:26:11 +02:00
config_setting_t *cfg_mapping;
2017-03-27 12:26:11 +02:00
cfg_mapping = config_setting_lookup(cfg, "mapping");
if (!cfg_mapping || !config_setting_is_array(cfg_mapping))
2017-03-27 12:26:11 +02:00
return -1;
2017-03-27 12:26:11 +02:00
ret = mapping_parse(&p->mapping, cfg_mapping);
if (ret)
return ret;
return 0;
}
static int map_read(struct hook *h, struct sample *smps[], size_t *cnt)
{
int ret;
struct map *p = h->_vd;
struct sample *tmp[*cnt];
if (*cnt <= 0)
return 0;
2017-04-06 12:12:56 +02:00
ret = sample_alloc((struct pool *) ((char* ) smps[0] + smps[0]->pool_off), tmp, *cnt);
2017-03-27 12:26:11 +02:00
if (ret != *cnt)
return ret;
for (int i = 0; i < *cnt; i++) {
mapping_remap(&p->mapping, smps[i], tmp[i], NULL);
2017-03-27 12:26:11 +02:00
SWAP(smps[i], tmp[i]);
}
sample_free(tmp, *cnt);
return 0;
}
static struct plugin p = {
.name = "map",
.description = "Remap values and / or add header, timestamp values to the sample",
.type = PLUGIN_TYPE_HOOK,
.hook = {
.priority = 99,
2017-03-27 12:26:11 +02:00
.init = map_init,
.destroy= map_destroy,
.parse = map_parse,
.read = map_read,
.size = sizeof(struct map)
}
};
REGISTER_PLUGIN(&p);
2017-04-06 12:12:56 +02:00
/** @} */