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/signal.h

88 lines
2.7 KiB
C
Raw Permalink Normal View History

2018-03-21 16:59:19 +01:00
/** Signal meta data.
*
* @file
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
2020-01-20 17:17:00 +01:00
* @copyright 2014-2020, Institute for Automation of Complex Power Systems, EONERC
2018-03-21 16:59:19 +01: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.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************************/
#pragma once
#include <jansson.h>
2019-04-23 13:05:31 +02:00
#include <atomic>
#include <villas/signal_list.h>
#include <villas/signal_type.h>
#include <villas/signal_data.h>
/* "I" defined by complex.h collides with a define in OpenSSL */
#undef I
2018-03-21 16:59:19 +01:00
/* Forward declarations */
struct mapping_entry;
2018-03-21 16:59:19 +01:00
2018-08-06 10:24:45 +02:00
/** Signal descriptor.
*
* This data structure contains meta data about samples values in struct sample::data
*/
2018-03-21 16:59:19 +01:00
struct signal {
2018-08-06 11:14:45 +02:00
char *name; /**< The name of the signal. */
char *unit; /**< The unit of the signal. */
2018-08-06 10:24:45 +02:00
union signal_data init; /**< The initial value of the signal. */
2018-05-25 12:55:01 +02:00
int enabled;
2018-08-06 10:24:45 +02:00
2019-04-23 13:05:31 +02:00
std::atomic<int> refcnt; /**< Reference counter. */
2018-08-06 11:14:45 +02:00
2019-06-23 16:13:23 +02:00
enum SignalType type;
2018-03-21 16:59:19 +01:00
};
/** Initialize a signal with default values. */
int signal_init(struct signal *s) __attribute__ ((warn_unused_result));
2018-08-01 17:00:56 +02:00
/** Destroy a signal and release memory. */
int signal_destroy(struct signal *s) __attribute__ ((warn_unused_result));
/** Allocate memory for a new signal, and initialize it with provided values. */
struct signal * signal_create(const char *name, const char *unit, enum SignalType fmt) __attribute__ ((warn_unused_result));
/** Destroy and release memory of signal. */
int signal_free(struct signal *s) __attribute__ ((warn_unused_result));
2018-08-06 11:14:45 +02:00
/** Increase reference counter. */
int signal_incref(struct signal *s);
2018-08-06 11:14:45 +02:00
/** Decrease reference counter. */
int signal_decref(struct signal *s);
2018-08-06 11:14:45 +02:00
2018-08-20 18:31:27 +02:00
/** Copy a signal. */
struct signal * signal_copy(struct signal *s);
/** Parse signal description. */
2021-02-16 14:15:14 +01:00
int signal_parse(struct signal *s, json_t *json);
2021-07-06 18:30:46 +02:00
char * signal_print(const struct signal *s, const union signal_data *d = nullptr);
/** Initialize signal from a mapping_entry. */
int signal_init_from_mapping(struct signal *s, const struct mapping_entry *me, unsigned index);
2020-08-17 17:04:55 +02:00
/** Produce JSON representation of signal. */
json_t * signal_to_json(struct signal *s);