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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

101 lines
2.5 KiB
C++
Raw Permalink Normal View History

/* Sample value remapping for path source muxing.
*
2022-03-15 09:18:01 -04:00
* Author: Steffen Vogel <post@steffenvogel.de>
2022-03-15 09:28:57 -04:00
* SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
2022-07-04 18:20:03 +02:00
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <jansson.h>
#include <memory>
2020-03-04 12:41:55 +01:00
#include <villas/common.hpp>
#include <villas/node_list.hpp>
#include <villas/stats.hpp>
2020-09-10 11:15:33 +02:00
#define RE_MAPPING_INDEX "[a-zA-Z0-9_]+"
#define RE_MAPPING_RANGE "(" RE_MAPPING_INDEX ")(?:-(" RE_MAPPING_INDEX "))?"
#define RE_MAPPING_STATS "stats\\.([a-z]+)\\.([a-z]+)"
#define RE_MAPPING_HDR "hdr\\.(sequence|length)"
#define RE_MAPPING_TS "ts\\.(origin|received)"
#define RE_MAPPING_DATA1 "data\\[" RE_MAPPING_RANGE "\\]"
#define RE_MAPPING_DATA2 "(?:data\\.)?(" RE_MAPPING_INDEX ")"
#define RE_MAPPING \
"(?:(" RE_NODE_NAME ")\\.(?:" RE_MAPPING_STATS "|" RE_MAPPING_HDR \
"|" RE_MAPPING_TS "|" RE_MAPPING_DATA1 "|" RE_MAPPING_DATA2 \
")|(" RE_NODE_NAME ")(?:\\[" RE_MAPPING_RANGE "\\])?)"
namespace villas {
namespace node {
// Forward declarations
class Node;
struct Sample;
class Signal;
2018-08-06 10:10:17 +02:00
class MappingEntry {
2018-08-06 10:10:17 +02:00
public:
using Ptr = std::shared_ptr<MappingEntry>;
enum class Type { UNKNOWN, DATA, STATS, HEADER, TIMESTAMP };
enum class HeaderType { LENGTH, SEQUENCE };
enum class TimestampType { ORIGIN, RECEIVED };
Node *node; // The node to which this mapping refers.
enum Type type; // The mapping type. Selects one of the union fields below.
2018-08-06 10:10:17 +02:00
/* 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;
2021-05-10 00:12:30 +02:00
unsigned offset; // Offset of this mapping entry within sample::data
union {
struct {
int offset;
Signal *signal;
2020-09-10 11:15:33 +02:00
2020-09-10 13:22:33 +02:00
char *first;
char *last;
} data;
struct {
enum Stats::Metric metric;
enum Stats::Type type;
} stats;
struct {
enum HeaderType type;
2018-08-06 10:10:17 +02:00
} header;
struct {
enum TimestampType type;
2018-08-06 10:10:17 +02:00
} timestamp;
};
2020-09-10 11:15:33 +02:00
std::string nodeName; // Used for between parse and prepare only.
MappingEntry();
2020-09-10 13:22:33 +02:00
int prepare(NodeList &nodes);
2020-09-10 13:22:33 +02:00
int update(struct Sample *remapped, const struct Sample *original) const;
int parse(json_t *json);
int parseString(const std::string &str);
2018-08-02 10:46:03 +02:00
std::string toString(unsigned index) const;
Signal::Ptr toSignal(unsigned index) const;
};
} // namespace node
} // namespace villas