From 4ec3cf030b9bfa6495dc19c7a5dda771ee5c66b0 Mon Sep 17 00:00:00 2001 From: Sonja Kolen Date: Thu, 28 Jun 2018 13:42:50 +0200 Subject: [PATCH] Added extern "C" wrapper in all headers of libvillas to use it in C++ code --- include/villas/advio.h | 8 +++ include/villas/api.h | 8 +++ include/villas/api/session.h | 8 +++ include/villas/atomic.h | 1 + include/villas/bitset.h | 10 +++- include/villas/buffer.h | 14 +++-- include/villas/common.h | 8 +++ include/villas/compat.h | 16 ++++++ include/villas/config.h | 69 ++++++++++++++++++++++++ include/villas/config.h.in | 11 ++++ include/villas/config_helper.h | 12 ++++- include/villas/crypt.h | 8 +++ include/villas/format_type.h | 8 +++ include/villas/formats/csv.h | 7 +++ include/villas/formats/json-reserve.h | 8 +++ include/villas/formats/json.h | 8 +++ include/villas/formats/msg.h | 8 +++ include/villas/formats/msg_format.h | 67 ++++++++++++----------- include/villas/formats/protobuf.h | 8 +++ include/villas/formats/raw.h | 29 ++++++---- include/villas/formats/villas_binary.h | 13 ++++- include/villas/formats/villas_human.h | 8 +++ include/villas/hist.h | 50 ++++++++++-------- include/villas/hook.h | 22 +++++--- include/villas/hook_type.h | 7 +++ include/villas/io.h | 22 +++++--- include/villas/kernel/if.h | 8 +++ include/villas/kernel/kernel.h | 10 +++- include/villas/kernel/nl-private.h | 63 +++++++++++----------- include/villas/kernel/nl.h | 10 +++- include/villas/kernel/rt.h | 8 +++ include/villas/kernel/tc.h | 8 +++ include/villas/kernel/tc_netem.h | 8 +++ include/villas/list.h | 8 +++ include/villas/log_config.h | 9 ++++ include/villas/mapping.h | 17 ++++-- include/villas/memory.h | 30 +++++++---- include/villas/node.h | 9 ++++ include/villas/node_type.h | 8 +++ include/villas/nodes/amqp.h | 10 +++- include/villas/nodes/cbuilder.h | 8 +++ include/villas/nodes/comedi.h | 52 ++++++++++-------- include/villas/nodes/file.h | 39 ++++++++------ include/villas/nodes/iec61850.h | 8 +++ include/villas/nodes/iec61850_sv.h | 8 +++ include/villas/nodes/influxdb.h | 10 +++- include/villas/nodes/loopback.h | 10 +++- include/villas/nodes/mqtt.h | 8 +++ include/villas/nodes/nanomsg.h | 10 +++- include/villas/nodes/ngsi.h | 32 ++++++----- include/villas/nodes/opal.h | 10 +++- include/villas/nodes/shmem.h | 20 ++++--- include/villas/nodes/signal_generator.h | 36 ++++++++----- include/villas/nodes/socket.h | 36 ++++++++----- include/villas/nodes/stats.h | 10 +++- include/villas/nodes/test_rtt.h | 26 +++++---- include/villas/nodes/websocket.h | 70 ++++++++++++++----------- include/villas/nodes/zeromq.h | 16 ++++-- include/villas/path.h | 50 ++++++++++-------- include/villas/plugin.h | 8 +++ include/villas/pool.h | 28 +++++----- include/villas/queue.h | 10 ++++ include/villas/queue_signalled.h | 8 +++ include/villas/sample.h | 10 ++-- include/villas/signal.h | 10 +++- include/villas/stats.h | 26 +++++---- include/villas/super_node.h | 38 ++++++++------ include/villas/table.h | 18 +++++-- include/villas/task.h | 29 ++++++---- include/villas/timing.h | 8 +++ include/villas/utils.h | 10 ++++ include/villas/web.h | 20 ++++--- 72 files changed, 977 insertions(+), 349 deletions(-) create mode 100644 include/villas/config.h diff --git a/include/villas/advio.h b/include/villas/advio.h index afbf3b14b..d9eb904cf 100644 --- a/include/villas/advio.h +++ b/include/villas/advio.h @@ -28,6 +28,10 @@ #include "crypt.h" +#ifdef __cplusplus +extern "C"{ +#endif + struct advio { CURL *curl; FILE *file; @@ -81,3 +85,7 @@ void arewind(AFILE *file); int adownload(AFILE *af, int resume); int aupload(AFILE *af, int resume); + +#ifdef __cplusplus +} +#endif diff --git a/include/villas/api.h b/include/villas/api.h index b56627306..6a9a1a37b 100644 --- a/include/villas/api.h +++ b/include/villas/api.h @@ -33,6 +33,10 @@ #include "api/session.h" +#ifdef __cplusplus +extern "C"{ +#endif + /* Forward declarations */ struct lws; struct super_node; @@ -81,3 +85,7 @@ int api_stop(struct api *a); int api_ws_protocol_cb(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len); int api_http_protocol_cb(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/include/villas/api/session.h b/include/villas/api/session.h index 55835a8b4..65dfac659 100644 --- a/include/villas/api/session.h +++ b/include/villas/api/session.h @@ -30,6 +30,10 @@ #include #include +#ifdef __cplusplus +extern "C"{ +#endif + enum api_version { API_VERSION_UNKOWN = 0, API_VERSION_1 = 1 @@ -70,3 +74,7 @@ int api_session_destroy(struct api_session *s); int api_session_run_command(struct api_session *s, json_t *req, json_t **resp); char * api_session_name(struct api_session *s); + +#ifdef __cplusplus +} +#endif diff --git a/include/villas/atomic.h b/include/villas/atomic.h index 0eba94d48..ea3a7f8a4 100644 --- a/include/villas/atomic.h +++ b/include/villas/atomic.h @@ -21,6 +21,7 @@ * along with this program. If not, see . *********************************************************************************/ + #include "common.h" #ifdef __cplusplus diff --git a/include/villas/bitset.h b/include/villas/bitset.h index 757774361..7e61147cd 100644 --- a/include/villas/bitset.h +++ b/include/villas/bitset.h @@ -26,6 +26,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + struct bitset { char *set; size_t dimension; @@ -62,4 +66,8 @@ int bitset_test(struct bitset *b, size_t bit); int bitset_cmp(struct bitset *a, struct bitset *b); /** Return an human readable representation of the bit set */ -char * bitset_dump(struct bitset *b); +char *bitset_dump(struct bitset *b); + +#ifdef __cplusplus +} +#endif diff --git a/include/villas/buffer.h b/include/villas/buffer.h index 8899f5fb0..77f679d67 100644 --- a/include/villas/buffer.h +++ b/include/villas/buffer.h @@ -29,9 +29,13 @@ #include "common.h" +#ifdef __cplusplus +extern "C" { +#endif + struct buffer { enum state state; - + char *buf; size_t len; size_t size; @@ -40,11 +44,15 @@ struct buffer { int buffer_init(struct buffer *b, size_t size); int buffer_destroy(struct buffer *b); - + void buffer_clear(struct buffer *b); int buffer_append(struct buffer *b, const char *data, size_t len); int buffer_parse_json(struct buffer *b, json_t **j); -int buffer_append_json(struct buffer *b, json_t *j); \ No newline at end of file +int buffer_append_json(struct buffer *b, json_t *j); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/include/villas/common.h b/include/villas/common.h index 41457b2e7..d6ac417a2 100644 --- a/include/villas/common.h +++ b/include/villas/common.h @@ -23,6 +23,10 @@ #pragma once +#ifdef __cplusplus +extern "C"{ +#endif + /* Common states for most objects in VILLASnode (paths, nodes, hooks, plugins) */ enum state { STATE_DESTROYED = 0, @@ -36,3 +40,7 @@ enum state { STATE_UNLOADED = 5, /* alias for STATE_STARTED used by struct plugin */ STATE_CLOSED = 5 /* alias for STATE_STARTED used by struct io */ }; + +#ifdef __cplusplus +} +#endif diff --git a/include/villas/compat.h b/include/villas/compat.h index ad574fda2..c5a2275d5 100644 --- a/include/villas/compat.h +++ b/include/villas/compat.h @@ -22,13 +22,25 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + #if JANSSON_VERSION_HEX < 0x020A00 size_t json_dumpb(const json_t *json, char *buffer, size_t size, size_t flags); #endif +#ifdef __cplusplus +} +#endif + #ifdef __MACH__ #include + #ifdef __cplusplus + extern "C"{ + #endif + #define le16toh(x) OSSwapLittleToHostInt16(x) #define le32toh(x) OSSwapLittleToHostInt32(x) #define le64toh(x) OSSwapLittleToHostInt64(x) @@ -42,4 +54,8 @@ size_t json_dumpb(const json_t *json, char *buffer, size_t size, size_t flags); #define htobe16(x) OSSwapHostToBigInt16(x) #define htobe32(x) OSSwapHostToBigInt32(x) #define htobe64(x) OSSwapHostToBigInt64(x) + + #ifdef __cplusplus + } + #endif #endif /* __MACH__ */ diff --git a/include/villas/config.h b/include/villas/config.h new file mode 100644 index 000000000..082579cd8 --- /dev/null +++ b/include/villas/config.h @@ -0,0 +1,69 @@ +/** Static server configuration + * + * This file contains some compiled-in settings. + * This settings are not part of the configuration file. + * + * @file + * @author Steffen Vogel + * @copyright 2017, Institute for Automation of Complex Power Systems, EONERC + * @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 . + *********************************************************************************/ + + + +#pragma once + +#ifdef __cplusplus +extern "C"{ +#endif + +/* Paths */ +#define PLUGIN_PATH PREFIX "/share/villas/node/plugins" +#define WEB_PATH PREFIX "/share/villas/node/web" +#define SYSFS_PATH "/sys" +#define PROCFS_PATH "/proc" + +/** Default number of values in a sample */ +#define DEFAULT_SAMPLELEN 64 +#define DEFAULT_QUEUELEN 1024 + +/** Number of hugepages which are requested from the the kernel. + * @see https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt */ +#define DEFAULT_NR_HUGEPAGES 100 + +/** Width of log output in characters */ +#define LOG_WIDTH 80 +#define LOG_HEIGHT 25 + +/** Socket priority */ +#define SOCKET_PRIO 7 + +/* Protocol numbers */ +#define IPPROTO_VILLAS 137 +#define ETH_P_VILLAS 0xBABE + +#define USER_AGENT "VILLASnode (" BUILDID ")" + +/* Required kernel version */ +#define KERNEL_VERSION_MAJ 3 +#define KERNEL_VERSION_MIN 6 + + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/include/villas/config.h.in b/include/villas/config.h.in index 68d56ee8c..082579cd8 100644 --- a/include/villas/config.h.in +++ b/include/villas/config.h.in @@ -24,8 +24,14 @@ * along with this program. If not, see . *********************************************************************************/ + + #pragma once +#ifdef __cplusplus +extern "C"{ +#endif + /* Paths */ #define PLUGIN_PATH PREFIX "/share/villas/node/plugins" #define WEB_PATH PREFIX "/share/villas/node/web" @@ -56,3 +62,8 @@ /* Required kernel version */ #define KERNEL_VERSION_MAJ 3 #define KERNEL_VERSION_MIN 6 + + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/include/villas/config_helper.h b/include/villas/config_helper.h index 6be9afe4b..abed550f7 100644 --- a/include/villas/config_helper.h +++ b/include/villas/config_helper.h @@ -27,14 +27,18 @@ #include "sample.h" +#ifdef __cplusplus +extern "C" { +#endif + /* Convert a libconfig object to a jansson object */ -json_t * config_to_json(config_setting_t *cfg); +json_t *config_to_json(config_setting_t *cfg); /* Convert a jansson object into a libconfig object. */ int json_to_config(json_t *json, config_setting_t *parent); /* Create a JSON object from command line parameters. */ -json_t * json_load_cli(int argc, char *argv[]); +json_t *json_load_cli(int argc, char *argv[]); int json_object_extend_str(json_t *orig, const char *str); @@ -42,3 +46,7 @@ void json_object_extend_key_value(json_t *obj, const char *key, const char *valu /* Merge two JSON objects recursively. */ int json_object_extend(json_t *orig, json_t *merge); + +#ifdef __cplusplus +} +#endif diff --git a/include/villas/crypt.h b/include/villas/crypt.h index 9b5c7843b..29b99410e 100644 --- a/include/villas/crypt.h +++ b/include/villas/crypt.h @@ -25,9 +25,17 @@ #include #include +#ifdef __cplusplus +extern "C"{ +#endif + /** Calculate SHA1 hash of complete file \p f and place it into \p sha1. * * @param sha1[out] Must be SHA_DIGEST_LENGTH (20) in size. * @retval 0 Everything was okay. */ int sha1sum(FILE *f, unsigned char *sha1); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/include/villas/format_type.h b/include/villas/format_type.h index 805b930a3..d1a4a7cb5 100644 --- a/include/villas/format_type.h +++ b/include/villas/format_type.h @@ -25,6 +25,10 @@ #include +#ifdef __cplusplus +extern "C"{ +#endif + /* Forward declarations */ struct sample; struct io; @@ -104,3 +108,7 @@ struct format_type { }; struct format_type * format_type_lookup(const char *name); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/include/villas/formats/csv.h b/include/villas/formats/csv.h index d32c93f52..f9f944131 100644 --- a/include/villas/formats/csv.h +++ b/include/villas/formats/csv.h @@ -25,6 +25,9 @@ #include +#ifdef __cplusplus +extern "C" { +#endif /* Forward declarations. */ struct sample; @@ -32,3 +35,7 @@ void csv_header(struct io *io); int csv_sscan(struct io *io, char *buf, size_t len, size_t *rbytes, struct sample *smps[], unsigned cnt); int csv_sprint(struct io *io, char *buf, size_t len, size_t *rbytes, struct sample *smps[], unsigned cnt); + +#ifdef __cplusplus +} +#endif diff --git a/include/villas/formats/json-reserve.h b/include/villas/formats/json-reserve.h index 71280af59..c715bc659 100644 --- a/include/villas/formats/json-reserve.h +++ b/include/villas/formats/json-reserve.h @@ -24,6 +24,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + /* Forward declarations */ struct sample; struct io; @@ -33,3 +37,7 @@ int json_reserve_sscan(struct io *io, char *buf, size_t len, size_t *rbytes, str int json_reserve_print(struct io *io, struct sample *smps[], unsigned cnt); int json_reserve_scan(struct io *io, struct sample *smps[], unsigned cnt); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/include/villas/formats/json.h b/include/villas/formats/json.h index 50fb60aee..ea73e0ff6 100644 --- a/include/villas/formats/json.h +++ b/include/villas/formats/json.h @@ -24,6 +24,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + /* Forward declarations */ struct sample; @@ -32,3 +36,7 @@ int json_sscan(struct io *io, char *buf, size_t len, size_t *wbytes, struct samp int json_print(struct io *io, struct sample *smps[], unsigned cnt); int json_scan(struct io *io, struct sample *smps[], unsigned cnt); + +#ifdef __cplusplus +} +#endif diff --git a/include/villas/formats/msg.h b/include/villas/formats/msg.h index c10498c12..2d88ec92a 100644 --- a/include/villas/formats/msg.h +++ b/include/villas/formats/msg.h @@ -22,6 +22,10 @@ #pragma once +#ifdef __cplusplus +extern "C" { +#endif + /* Forward declaration */ struct msg; struct sample; @@ -53,3 +57,7 @@ int msg_to_sample(struct msg *msg, struct sample *smp); /** Copy fields form \p smp into \p msg. */ int msg_from_sample(struct msg *msg, struct sample *smp); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/include/villas/formats/msg_format.h b/include/villas/formats/msg_format.h index 45930fae8..99069089a 100644 --- a/include/villas/formats/msg_format.h +++ b/include/villas/formats/msg_format.h @@ -25,68 +25,73 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + /** The current version number for the message format */ -#define MSG_VERSION 2 +#define MSG_VERSION 2 /** @todo Implement more message types */ -#define MSG_TYPE_DATA 0 /**< Message contains float / integer values */ -#define MSG_TYPE_START 1 /**< Message marks the beginning of a new simulation case */ -#define MSG_TYPE_STOP 2 /**< Message marks the end of a simulation case */ +#define MSG_TYPE_DATA 0 /**< Message contains float / integer values */ +#define MSG_TYPE_START 1 /**< Message marks the beginning of a new simulation case */ +#define MSG_TYPE_STOP 2 /**< Message marks the end of a simulation case */ /** The total size in bytes of a message */ -#define MSG_LEN(values) (sizeof(struct msg) + MSG_DATA_LEN(values)) +#define MSG_LEN(values) (sizeof(struct msg) + MSG_DATA_LEN(values)) /** The length of \p values values in bytes. */ -#define MSG_DATA_LEN(values) (sizeof(float) * (values)) +#define MSG_DATA_LEN(values) (sizeof(float) * (values)) /** The offset to the first data value in a message. */ -#define MSG_DATA_OFFSET(msg) ((char *) (msg) + offsetof(struct msg, data)) +#define MSG_DATA_OFFSET(msg) ((char *) (msg) + offsetof(struct msg, data)) /** Initialize a message with default values */ #define MSG_INIT(len, seq) (struct msg) {\ - .version = MSG_VERSION, \ - .type = MSG_TYPE_DATA, \ - .length = len, \ - .sequence = seq, \ + .version = MSG_VERSION, \ + .type = MSG_TYPE_DATA, \ + .length = len, \ + .sequence = seq, \ } /** The timestamp of a message in struct timespec format */ -#define MSG_TS(msg) (struct timespec) { \ - .tv_sec = (msg)->ts.sec, \ - .tv_nsec = (msg)->ts.nsec \ +#define MSG_TS(msg) (struct timespec) { \ + .tv_sec = (msg)->ts.sec, \ + .tv_nsec = (msg)->ts.nsec \ } /** This message format is used by all clients * * @diafile msg_format.dia **/ -struct msg -{ +struct msg { #if BYTE_ORDER == BIG_ENDIAN - unsigned version: 4; /**< Specifies the format of the remaining message (see MGS_VERSION) */ - unsigned type : 2; /**< Data or control message (see MSG_TYPE_*) */ - unsigned rsvd1 : 2; /**< Reserved bits */ + unsigned version: 4; /**< Specifies the format of the remaining message (see MGS_VERSION) */ + unsigned type : 2; /**< Data or control message (see MSG_TYPE_*) */ + unsigned rsvd1 : 2; /**< Reserved bits */ #elif BYTE_ORDER == LITTLE_ENDIAN - unsigned rsvd1 : 2; /**< Reserved bits */ - unsigned type : 2; /**< Data or control message (see MSG_TYPE_*) */ - unsigned version: 4; /**< Specifies the format of the remaining message (see MGS_VERSION) */ -#else - #error Invalid byte-order + unsigned rsvd1 : 2; /**< Reserved bits */ + unsigned type : 2; /**< Data or control message (see MSG_TYPE_*) */ + unsigned version: 4; /**< Specifies the format of the remaining message (see MGS_VERSION) */ #endif - uint8_t resv2; /**< An id which identifies the source of this sample. */ - uint16_t length; /**< The number of values in msg::data[]. */ - uint32_t sequence; /**< The sequence number is incremented by one for consecutive messages. */ + uint8_t resv2; /**< An id which identifies the source of this sample. */ + uint16_t length; /**< The number of values in msg::data[]. */ + uint32_t sequence; /**< The sequence number is incremented by one for consecutive messages. */ /** A timestamp per message. */ struct { - uint32_t sec; /**< Seconds since 1970-01-01 00:00:00 */ - uint32_t nsec; /**< Nanoseconds of the current second. */ + uint32_t sec; /**< Seconds since 1970-01-01 00:00:00 */ + uint32_t nsec; /**< Nanoseconds of the current second. */ } ts; /** The message payload. */ union { - float f; /**< Floating point values. */ - uint32_t i; /**< Integer values. */ + float f; /**< Floating point values. */ + uint32_t i; /**< Integer values. */ } data[]; } __attribute__((packed)); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/include/villas/formats/protobuf.h b/include/villas/formats/protobuf.h index 49f171555..343920189 100644 --- a/include/villas/formats/protobuf.h +++ b/include/villas/formats/protobuf.h @@ -25,6 +25,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + /* Forward declarations */ struct sample; @@ -33,3 +37,7 @@ int protobuf_sprint(struct io *io, char *buf, size_t len, size_t *wbytes, struct /** Read struct sample's from buffer \p buf into samples \p smps. */ int protobuf_sscan(struct io *io, char *buf, size_t len, size_t *rbytes, struct sample *smps[], unsigned cnt); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/include/villas/formats/raw.h b/include/villas/formats/raw.h index 7d0b1e3b9..d10eea879 100644 --- a/include/villas/formats/raw.h +++ b/include/villas/formats/raw.h @@ -25,32 +25,36 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + /* Forward declarations */ struct sample; enum raw_flags { - RAW_FAKE = (1 << 16), /**< Treat the first three values as: sequenceno, seconds, nanoseconds */ + RAW_FAKE = (1 << 16), /**< Treat the first three values as: sequenceno, seconds, nanoseconds */ - RAW_BE_INT = (1 << 17), /**< Byte-order for integer data: big-endian if set. */ - RAW_BE_FLT = (1 << 18), /**< Byte-order for floating point data: big-endian if set. */ - RAW_BE_HDR = (1 << 19), /**< Byte-order for fake header fields: big-endian if set. */ + RAW_BE_INT = (1 << 17), /**< Byte-order for integer data: big-endian if set. */ + RAW_BE_FLT = (1 << 18), /**< Byte-order for floating point data: big-endian if set. */ + RAW_BE_HDR = (1 << 19), /**< Byte-order for fake header fields: big-endian if set. */ /** Byte-order for all fields: big-endian if set. */ - RAW_BE = RAW_BE_INT | RAW_BE_FLT | RAW_BE_HDR, + RAW_BE = RAW_BE_INT | RAW_BE_FLT | RAW_BE_HDR, /** Mix floating and integer types. * * io_raw_sscan() parses all values as single / double precission fp. * io_raw_sprint() uses sample::format to determine the type. */ - RAW_AUTO = (1 << 22), - RAW_FLT = (1 << 23), /**< Data-type: floating point otherwise integer. */ + RAW_AUTO = (1 << 22), + RAW_FLT = (1 << 23), /**< Data-type: floating point otherwise integer. */ //RAW_1 = (0 << 24), /**< Pack each value as a single bit. */ - RAW_8 = (3 << 24), /**< Pack each value as a byte. */ - RAW_16 = (4 << 24), /**< Pack each value as a word. */ - RAW_32 = (5 << 24), /**< Pack each value as a double word. */ - RAW_64 = (6 << 24) /**< Pack each value as a quad word. */ + RAW_8 = (3 << 24), /**< Pack each value as a byte. */ + RAW_16 = (4 << 24), /**< Pack each value as a word. */ + RAW_32 = (5 << 24), /**< Pack each value as a double word. */ + RAW_64 = (6 << 24) /**< Pack each value as a quad word. */ }; /** Copy / read struct msg's from buffer \p buf to / fram samples \p smps. */ @@ -58,3 +62,6 @@ int raw_sprint(struct io *io, char *buf, size_t len, size_t *wbytes, struct samp /** Read struct sample's from buffer \p buf into samples \p smps. */ int raw_sscan(struct io *io, char *buf, size_t len, size_t *rbytes, struct sample *smps[], unsigned cnt); +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/include/villas/formats/villas_binary.h b/include/villas/formats/villas_binary.h index 79dd248e4..ff520919f 100644 --- a/include/villas/formats/villas_binary.h +++ b/include/villas/formats/villas_binary.h @@ -25,17 +25,26 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + /* Forward declarations. */ struct sample; struct msg; struct io; enum villas_binary_flags { - VILLAS_BINARY_WEB = (1 << 16) /**< Use webmsg format (everying little endian) */ + VILLAS_BINARY_WEB = (1 << 16) /**< Use webmsg format (everying little endian) */ }; /** Copy / read struct msg's from buffer \p buf to / fram samples \p smps. */ -int villas_binary_sprint(struct io *io, char *buf, size_t len, size_t *wbytes, struct sample *smps[], unsigned cnt); +int +villas_binary_sprint(struct io *io, char *buf, size_t len, size_t *wbytes, struct sample *smps[], unsigned cnt); /** Read struct sample's from buffer \p buf into samples \p smps. */ int villas_binary_sscan(struct io *io, char *buf, size_t len, size_t *rbytes, struct sample *smps[], unsigned cnt); + +#ifdef __cplusplus +} +#endif diff --git a/include/villas/formats/villas_human.h b/include/villas/formats/villas_human.h index 01ced6032..c372b14ef 100644 --- a/include/villas/formats/villas_human.h +++ b/include/villas/formats/villas_human.h @@ -25,6 +25,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + /* Forward declarations */ struct io; struct sample; @@ -33,3 +37,7 @@ void villas_human_header(struct io *io); int villas_human_print(struct io *io, struct sample *smps[], unsigned cnt); int villas_human_scan(struct io *io, struct sample *smps[], unsigned cnt); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/include/villas/hist.h b/include/villas/hist.h index 935908576..ca8a4d10a 100644 --- a/include/villas/hist.h +++ b/include/villas/hist.h @@ -28,39 +28,43 @@ #include -#define HIST_HEIGHT (LOG_WIDTH - 55) -#define HIST_SEQ 17 +#ifdef __cplusplus +extern "C" { +#endif + +#define HIST_HEIGHT (LOG_WIDTH - 55) +#define HIST_SEQ 17 typedef uintmax_t hist_cnt_t; /** Histogram structure used to collect statistics. */ struct hist { - double resolution; /**< The distance between two adjacent buckets. */ + double resolution; /**< The distance between two adjacent buckets. */ - double high; /**< The value of the highest bucket. */ - double low; /**< The value of the lowest bucket. */ + double high; /**< The value of the highest bucket. */ + double low; /**< The value of the lowest bucket. */ - double highest; /**< The highest value observed (may be higher than #high). */ - double lowest; /**< The lowest value observed (may be lower than #low). */ - double last; /**< The last value which has been put into the buckets */ + double highest; /**< The highest value observed (may be higher than #high). */ + double lowest; /**< The lowest value observed (may be lower than #low). */ + double last; /**< The last value which has been put into the buckets */ - int length; /**< The number of buckets in #data. */ + int length; /**< The number of buckets in #data. */ - hist_cnt_t total; /**< Total number of counted values. */ - hist_cnt_t warmup; /**< Number of values which are used during warmup phase. */ + hist_cnt_t total; /**< Total number of counted values. */ + hist_cnt_t warmup; /**< Number of values which are used during warmup phase. */ - hist_cnt_t higher; /**< The number of values which are higher than #high. */ - hist_cnt_t lower; /**< The number of values which are lower than #low. */ + hist_cnt_t higher; /**< The number of values which are higher than #high. */ + hist_cnt_t lower; /**< The number of values which are lower than #low. */ - hist_cnt_t *data; /**< Pointer to dynamically allocated array of size length. */ + hist_cnt_t *data; /**< Pointer to dynamically allocated array of size length. */ - double _m[2], _s[2]; /**< Private variables for online variance calculation */ + double _m[2], _s[2]; /**< Private variables for online variance calculation */ }; -#define hist_last(h) ((h)->last) -#define hist_highest(h) ((h)->highest) -#define hist_lowest(h) ((h)->lowest) -#define hist_total(h) ((h)->total) +#define hist_last(h) ((h)->last) +#define hist_highest(h) ((h)->highest) +#define hist_lowest(h) ((h)->lowest) +#define hist_total(h) ((h)->total) /** Initialize struct hist with supplied values and allocate memory for buckets. */ int hist_init(struct hist *h, int buckets, hist_cnt_t warmup); @@ -93,7 +97,7 @@ void hist_plot(struct hist *h); * * @return The string containing the dump. The caller is responsible to free() the buffer. */ -char * hist_dump(struct hist *h); +char *hist_dump(struct hist *h); /** Prints Matlab struct containing all infos to file. */ int hist_dump_matlab(struct hist *h, FILE *f); @@ -102,4 +106,8 @@ int hist_dump_matlab(struct hist *h, FILE *f); int hist_dump_json(struct hist *h, FILE *f); /** Build a libjansson / JSON object of the histogram. */ -json_t * hist_json(struct hist *h); +json_t *hist_json(struct hist *h); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/include/villas/hook.h b/include/villas/hook.h index eadd4c281..66ec85e8d 100644 --- a/include/villas/hook.h +++ b/include/villas/hook.h @@ -37,6 +37,10 @@ #include "hook_type.h" #include "common.h" +#ifdef __cplusplus +extern "C" { +#endif + /* Forward declarations */ struct path; struct sample; @@ -44,17 +48,17 @@ struct list; /** Descriptor for user defined hooks. See hooks[]. */ struct hook { - enum state state; + enum state state; - struct path *path; - struct node *node; + struct path *path; + struct node *node; - struct hook_type *_vt; /**< C++ like Vtable pointer. */ - void *_vd; /**< Private data for this hook. This pointer can be used to pass data between consecutive calls of the callback. */ + struct hook_type *_vt; /**< C++ like Vtable pointer. */ + void *_vd; /**< Private data for this hook. This pointer can be used to pass data between consecutive calls of the callback. */ - int priority; /**< A priority to change the order of execution within one type of hook. */ + int priority; /**< A priority to change the order of execution within one type of hook. */ - json_t *cfg; /**< A JSON object containing the configuration of the hook. */ + json_t *cfg; /**< A JSON object containing the configuration of the hook. */ }; int hook_init(struct hook *h, struct hook_type *vt, struct path *p, struct node *n); @@ -96,3 +100,7 @@ int hook_cmp_priority(const void *a, const void *b); * } */ int hook_parse_list(struct list *list, json_t *cfg, struct path *p, struct node *n); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/include/villas/hook_type.h b/include/villas/hook_type.h index 6c6d7ec70..de1331a2e 100644 --- a/include/villas/hook_type.h +++ b/include/villas/hook_type.h @@ -39,6 +39,10 @@ #include +#ifdef __cplusplus +extern "C"{ +#endif + /* Forward declarations */ struct hook; struct sample; @@ -74,3 +78,6 @@ struct hook_type { struct hook_type * hook_type_lookup(const char *name); +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/include/villas/io.h b/include/villas/io.h index d24705a61..b471a0764 100644 --- a/include/villas/io.h +++ b/include/villas/io.h @@ -27,21 +27,25 @@ #include "common.h" #include "node.h" +#ifdef __cplusplus +extern "C" { +#endif + /* Forward declarations */ struct sample; struct format_type; enum io_flags { - IO_FLUSH = (1 << 8), /**< Flush the output stream after each chunk of samples. */ - IO_NONBLOCK = (1 << 9), /**< Dont block io_read() while waiting for new samples. */ - IO_NEWLINES = (1 << 10) /**< The samples of this format are newline delimited. */ + IO_FLUSH = (1 << 8), /**< Flush the output stream after each chunk of samples. */ + IO_NONBLOCK = (1 << 9), /**< Dont block io_read() while waiting for new samples. */ + IO_NEWLINES = (1 << 10) /**< The samples of this format are newline delimited. */ }; struct io { enum state state; int flags; - char delimiter; /**< Newline delimiter. */ - char separator; /**< Column separator (used by csv and villas.human formats only) */ + char delimiter; /**< Newline delimiter. */ + char separator; /**< Column separator (used by csv and villas.human formats only) */ struct { /** A format type can use this file handle or overwrite the @@ -106,8 +110,8 @@ int io_stream_fd(struct io *io); int io_stream_flush(struct io *io); -FILE * io_stream_input(struct io *io); -FILE * io_stream_output(struct io *io); +FILE *io_stream_input(struct io *io); +FILE *io_stream_output(struct io *io); /** Parse samples from the buffer \p buf with a length of \p len bytes. * @@ -134,3 +138,7 @@ int io_sscan(struct io *io, char *buf, size_t len, size_t *rbytes, struct sample * @retval <0 Something went wrong. */ int io_sprint(struct io *io, char *buf, size_t len, size_t *wbytes, struct sample *smps[], unsigned cnt); + +#ifdef __cplusplus +} +#endif diff --git a/include/villas/kernel/if.h b/include/villas/kernel/if.h index 4a6068ad5..1d6420098 100644 --- a/include/villas/kernel/if.h +++ b/include/villas/kernel/if.h @@ -33,6 +33,10 @@ #include +#ifdef __cplusplus +extern "C"{ +#endif + #define IF_IRQ_MAX 3 /**< Maxmimal number of IRQs of an interface */ #ifndef SO_MARK @@ -121,4 +125,8 @@ int if_get_irqs(struct interface *i); */ int if_set_affinity(struct interface *i, int affinity); + +#ifdef __cplusplus +} +#endif /** @} */ diff --git a/include/villas/kernel/kernel.h b/include/villas/kernel/kernel.h index 6b39dc40c..60ceb4312 100644 --- a/include/villas/kernel/kernel.h +++ b/include/villas/kernel/kernel.h @@ -28,6 +28,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + /* Forward declarations */ struct version; @@ -85,6 +89,10 @@ int kernel_get_page_size(); int kernel_get_hugepage_size(); /** Set SMP affinity of IRQ */ -int kernel_irq_setaffinity(unsigned irq, uintmax_t new, uintmax_t *old); +int kernel_irq_setaffinity(unsigned irq, uintmax_t new , uintmax_t *old ) ; + +#ifdef __cplusplus +} +#endif /** @} */ diff --git a/include/villas/kernel/nl-private.h b/include/villas/kernel/nl-private.h index 968cdb209..f67051dc7 100644 --- a/include/villas/kernel/nl-private.h +++ b/include/villas/kernel/nl-private.h @@ -1,45 +1,48 @@ #pragma once +#ifdef __cplusplus +extern "C" { +#endif + #define SCH_NETEM_ATTR_DIST 0x2000 -struct rtnl_netem_corr -{ - uint32_t nmc_delay; - uint32_t nmc_loss; - uint32_t nmc_duplicate; +struct rtnl_netem_corr { + uint32_t nmc_delay; + uint32_t nmc_loss; + uint32_t nmc_duplicate; }; -struct rtnl_netem_reo -{ - uint32_t nmro_probability; - uint32_t nmro_correlation; +struct rtnl_netem_reo { + uint32_t nmro_probability; + uint32_t nmro_correlation; }; -struct rtnl_netem_crpt -{ - uint32_t nmcr_probability; - uint32_t nmcr_correlation; +struct rtnl_netem_crpt { + uint32_t nmcr_probability; + uint32_t nmcr_correlation; }; -struct rtnl_netem_dist -{ - int16_t * dist_data; - size_t dist_size; +struct rtnl_netem_dist { + int16_t *dist_data; + size_t dist_size; }; -struct rtnl_netem -{ - uint32_t qnm_latency; - uint32_t qnm_limit; - uint32_t qnm_loss; - uint32_t qnm_gap; - uint32_t qnm_duplicate; - uint32_t qnm_jitter; - uint32_t qnm_mask; - struct rtnl_netem_corr qnm_corr; - struct rtnl_netem_reo qnm_ro; - struct rtnl_netem_crpt qnm_crpt; - struct rtnl_netem_dist qnm_dist; +struct rtnl_netem { + uint32_t qnm_latency; + uint32_t qnm_limit; + uint32_t qnm_loss; + uint32_t qnm_gap; + uint32_t qnm_duplicate; + uint32_t qnm_jitter; + uint32_t qnm_mask; + struct rtnl_netem_corr qnm_corr; + struct rtnl_netem_reo qnm_ro; + struct rtnl_netem_crpt qnm_crpt; + struct rtnl_netem_dist qnm_dist; }; void *rtnl_tc_data(struct rtnl_tc *tc); + +#ifdef __cplusplus +} +#endif diff --git a/include/villas/kernel/nl.h b/include/villas/kernel/nl.h index 879312cd9..894df4f9f 100644 --- a/include/villas/kernel/nl.h +++ b/include/villas/kernel/nl.h @@ -29,6 +29,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + /** Get index of outgoing interface for given destination address. * * @retval >=0 Interface index of outgoing interface. @@ -37,9 +41,13 @@ int nl_get_egress(struct nl_addr *addr); /** Get or create global netlink socket. */ -struct nl_sock * nl_init(); +struct nl_sock *nl_init(); /** Close and free global netlink socket. */ void nl_shutdown(); +#ifdef __cplusplus +} +#endif + /** @} */ diff --git a/include/villas/kernel/rt.h b/include/villas/kernel/rt.h index f1c8b5bc6..c6c5c0e9b 100644 --- a/include/villas/kernel/rt.h +++ b/include/villas/kernel/rt.h @@ -26,6 +26,10 @@ #pragma once +#ifdef __cplusplus +extern "C" { +#endif + int rt_init(int priority, int affinity); int rt_set_affinity(int affinity); @@ -43,4 +47,8 @@ int rt_lock_memory(); */ int rt_is_preemptible(); +#ifdef __cplusplus +} +#endif + /** @} */ diff --git a/include/villas/kernel/tc.h b/include/villas/kernel/tc.h index a64439be8..0b5afbbc3 100644 --- a/include/villas/kernel/tc.h +++ b/include/villas/kernel/tc.h @@ -37,6 +37,10 @@ #include +#ifdef __cplusplus +extern "C"{ +#endif + typedef uint32_t tc_hdl_t; struct interface; @@ -72,4 +76,8 @@ int tc_prio(struct interface *i, struct rtnl_qdisc **qd, tc_hdl_t handle, tc_hdl */ int tc_mark(struct interface *i, struct rtnl_cls **cls, tc_hdl_t flowid, uint32_t mark); +#ifdef __cplusplus +} +#endif + /** @} */ diff --git a/include/villas/kernel/tc_netem.h b/include/villas/kernel/tc_netem.h index 78dc10951..b6d0a86c4 100644 --- a/include/villas/kernel/tc_netem.h +++ b/include/villas/kernel/tc_netem.h @@ -37,6 +37,10 @@ #include +#ifdef __cplusplus +extern "C"{ +#endif + typedef uint32_t tc_hdl_t; struct interface; @@ -70,4 +74,8 @@ int tc_netem(struct interface *i, struct rtnl_qdisc **qd, tc_hdl_t handle, tc_hd int tc_netem_set_delay_distribution(struct rtnl_qdisc *qdisc, json_t *json); +#ifdef __cplusplus +} +#endif + /** @} */ diff --git a/include/villas/list.h b/include/villas/list.h index f3dd82bc8..e1d796628 100644 --- a/include/villas/list.h +++ b/include/villas/list.h @@ -19,6 +19,10 @@ #include "common.h" +#ifdef __cplusplus +extern "C"{ +#endif + #define LIST_CHUNKSIZE 16 /** Static list initialization */ @@ -120,3 +124,7 @@ int list_set(struct list *l, int index, void *value); * @retval >=0 Entry \p value was found at returned index. */ ssize_t list_index(struct list *l, void *value); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/include/villas/log_config.h b/include/villas/log_config.h index 86c2281ba..d7322fd0a 100644 --- a/include/villas/log_config.h +++ b/include/villas/log_config.h @@ -29,9 +29,18 @@ struct log; #include "log.h" +#ifdef __cplusplus +extern "C"{ +#endif + /** Parse logging configuration. */ int log_parse(struct log *l, json_t *cfg); /** Print configuration error and exit. */ void jerror(json_error_t *err, const char *fmt, ...) __attribute__ ((format(printf, 2, 3))); + + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/include/villas/mapping.h b/include/villas/mapping.h index 498d0e455..af26b3918 100644 --- a/include/villas/mapping.h +++ b/include/villas/mapping.h @@ -29,6 +29,10 @@ #include "common.h" #include "list.h" +#ifdef __cplusplus +extern "C" { +#endif + /* Forward declarations */ struct stats; struct node; @@ -38,8 +42,8 @@ struct list; struct mapping_entry { struct node *node; - int offset; /**< Offset of this mapping entry within sample::data */ - int length; /**< The number of values which is covered by this mapping entry. */ + int offset; /**< Offset of this mapping entry within sample::data */ + int length; /**< The number of values which is covered by this mapping entry. */ enum { MAPPING_TYPE_DATA, @@ -84,12 +88,17 @@ struct mapping_entry { }; }; -int mapping_remap(struct list *m, struct sample *remapped, struct sample *original, struct stats *s); +int +mapping_remap(struct list *m, struct sample *remapped, struct sample *original, struct stats *s); -int mapping_update(struct mapping_entry *e, struct sample *remapped, struct sample *new, struct stats *s); +int mapping_update(struct mapping_entry *e, struct sample *remapped, struct sample * new , struct stats *s ) ; int mapping_parse(struct mapping_entry *e, json_t *cfg, struct list *nodes); int mapping_parse_str(struct mapping_entry *e, const char *str, struct list *nodes); int mapping_parse_list(struct list *l, json_t *cfg, struct list *nodes); + +#ifdef __cplusplus +} +#endif diff --git a/include/villas/memory.h b/include/villas/memory.h index 9514d748d..a680b65ff 100644 --- a/include/villas/memory.h +++ b/include/villas/memory.h @@ -26,7 +26,11 @@ #pragma once -#define HUGEPAGESIZE (1 << 21) +#ifdef __cplusplus +extern "C" { +#endif + +#define HUGEPAGESIZE (1 << 21) struct memtype; @@ -34,10 +38,10 @@ typedef void *(*memzone_allocator_t)(struct memtype *mem, size_t len, size_t ali typedef int (*memzone_deallocator_t)(struct memtype *mem, void *ptr, size_t len); enum memtype_flags { - MEMORY_MMAP = (1 << 0), - MEMORY_DMA = (1 << 1), - MEMORY_HUGEPAGE = (1 << 2), - MEMORY_HEAP = (1 << 3) + MEMORY_MMAP = (1 << 0), + MEMORY_DMA = (1 << 1), + MEMORY_HUGEPAGE = (1 << 2), + MEMORY_HEAP = (1 << 3) }; struct memtype { @@ -59,15 +63,15 @@ enum memblock_flags { /** Descriptor of a memory block. Associated block always starts at * &m + sizeof(struct memblock). */ struct memblock { - struct memblock* prev; - struct memblock* next; + struct memblock *prev; + struct memblock *next; size_t len; /**0 If allocation was successful. */ -void * memory_alloc(struct memtype *m, size_t len); +void *memory_alloc(struct memtype *m, size_t len); -void * memory_alloc_aligned(struct memtype *m, size_t len, size_t alignment); +void *memory_alloc_aligned(struct memtype *m, size_t len, size_t alignment); int memory_free(struct memtype *m, void *ptr, size_t len); -struct memtype * memtype_managed_init(void *ptr, size_t len); +struct memtype *memtype_managed_init(void *ptr, size_t len); extern struct memtype memtype_heap; extern struct memtype memtype_hugepage; + +#ifdef __cplusplus +} +#endif diff --git a/include/villas/node.h b/include/villas/node.h index 06c0dcc09..8ec6f7523 100644 --- a/include/villas/node.h +++ b/include/villas/node.h @@ -26,6 +26,7 @@ * @{ */ + #pragma once #include @@ -38,6 +39,10 @@ #include "queue.h" #include "common.h" +#ifdef __cplusplus +extern "C"{ +#endif + struct node_direction { int enabled; int builtin; /**< This node should use built-in hooks by default. */ @@ -158,4 +163,8 @@ int node_write(struct node *n, struct sample *smps[], unsigned cnt); int node_fd(struct node *n); +#ifdef __cplusplus +} +#endif + /** @} */ diff --git a/include/villas/node_type.h b/include/villas/node_type.h index 5e6a47d4f..dcee596d0 100644 --- a/include/villas/node_type.h +++ b/include/villas/node_type.h @@ -24,6 +24,10 @@ * @{ *********************************************************************************/ +#ifdef __cplusplus +extern "C"{ +#endif + #pragma once #include @@ -168,4 +172,8 @@ const char * node_type_name(struct node_type *vt); struct node_type * node_type_lookup(const char *name); +#ifdef __cplusplus +} +#endif + /** @} */ diff --git a/include/villas/nodes/amqp.h b/include/villas/nodes/amqp.h index e23154108..aa453ec75 100644 --- a/include/villas/nodes/amqp.h +++ b/include/villas/nodes/amqp.h @@ -35,6 +35,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + /* Forward declarations */ struct format_type; @@ -64,7 +68,7 @@ struct amqp { }; /** @see node_type::print */ -char * amqp_print(struct node *n); +char *amqp_print(struct node *n); /** @see node_type::parse */ int amqp_parse(struct node *n, json_t *json); @@ -81,4 +85,8 @@ int amqp_read(struct node *n, struct sample *smps[], unsigned cnt); /** @see node_type::write */ int amqp_write(struct node *n, struct sample *smps[], unsigned cnt); +#ifdef __cplusplus +} +#endif + /** @} */ diff --git a/include/villas/nodes/cbuilder.h b/include/villas/nodes/cbuilder.h index c90e73db1..2513fb94e 100644 --- a/include/villas/nodes/cbuilder.h +++ b/include/villas/nodes/cbuilder.h @@ -33,6 +33,10 @@ #include +#ifdef __cplusplus +extern "C"{ +#endif + /* Forward declaration */ struct cbuilder; @@ -65,4 +69,8 @@ struct cbuilder { int eventfd; /**< Eventfd for synchronizing cbuilder_read() / cbuilder_write() access. */ }; +#ifdef __cplusplus +} +#endif + /** @} */ diff --git a/include/villas/nodes/comedi.h b/include/villas/nodes/comedi.h index 311874ca6..6cc282b64 100644 --- a/include/villas/nodes/comedi.h +++ b/include/villas/nodes/comedi.h @@ -35,6 +35,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + // whether to use read() or mmap() kernel interface #define COMEDI_USE_READ (1) //#define COMEDI_USE_READ (0) @@ -45,23 +49,23 @@ struct comedi_chanspec { }; struct comedi_direction { - int subdevice; ///< Comedi subdevice - int buffer_size; ///< Comedi's kernel buffer size in kB - int sample_size; ///< Size of a single measurement sample - int sample_rate_hz; ///< Sample rate in Hz - bool present; ///< Config present - bool enabled; ///< Card is started successfully - bool running; ///< Card is actively transfering samples - struct timespec started; ///< Timestamp when sampling started - struct timespec last_debug; ///< Timestamp of last debug output - size_t counter; ///< Number of villas samples transfered - struct comedi_chanspec *chanspecs; ///< Range and maxdata config of channels - unsigned *chanlist; ///< Channel list in comedi's packed format - size_t chanlist_len; ///< Number of channels for this direction + int subdevice; ///< Comedi subdevice + int buffer_size; ///< Comedi's kernel buffer size in kB + int sample_size; ///< Size of a single measurement sample + int sample_rate_hz; ///< Sample rate in Hz + bool present; ///< Config present + bool enabled; ///< Card is started successfully + bool running; ///< Card is actively transfering samples + struct timespec started; ///< Timestamp when sampling started + struct timespec last_debug; ///< Timestamp of last debug output + size_t counter; ///< Number of villas samples transfered + struct comedi_chanspec *chanspecs; ///< Range and maxdata config of channels + unsigned *chanlist; ///< Channel list in comedi's packed format + size_t chanlist_len; ///< Number of channels for this direction - char* buffer; - char* bufptr; + char *buffer; + char *bufptr; }; struct comedi { @@ -70,19 +74,19 @@ struct comedi { comedi_t *dev; #if COMEDI_USE_READ - char* buf; - char* bufptr; + char *buf; + char *bufptr; #else - char *map; - size_t bufpos; - size_t front; - size_t back; + char *map; + size_t bufpos; + size_t front; + size_t back; #endif }; /** @see node_type::print */ -char * comedi_print(struct node *n); +char *comedi_print(struct node *n); /** @see node_type::parse */ int comedi_parse(struct node *n, json_t *cfg); @@ -99,4 +103,8 @@ int comedi_read(struct node *n, struct sample *smps[], unsigned cnt); /** @see node_type::write */ int comedi_write(struct node *n, struct sample *smps[], unsigned cnt); +#ifdef __cplusplus +} +#endif + /** @} */ diff --git a/include/villas/nodes/file.h b/include/villas/nodes/file.h index da105b0b8..aa13409f8 100644 --- a/include/villas/nodes/file.h +++ b/include/villas/nodes/file.h @@ -33,19 +33,23 @@ #include #include -#define FILE_MAX_PATHLEN 512 +#ifdef __cplusplus +extern "C" { +#endif + +#define FILE_MAX_PATHLEN 512 struct file { - struct io io; /**< Format and file IO */ + struct io io; /**< Format and file IO */ struct format_type *format; - char *uri_tmpl; /**< Format string for file name. */ - char *uri; /**< Real file name. */ - char *mode; /**< File access mode. */ + char *uri_tmpl; /**< Format string for file name. */ + char *uri; /**< Real file name. */ + char *mode; /**< File access mode. */ - int flush; /**< Flush / upload file contents after each write. */ - struct task task; /**< Timer file descriptor. Blocks until 1 / rate seconds are elapsed. */ - double rate; /**< The read rate. */ + int flush; /**< Flush / upload file contents after each write. */ + struct task task; /**< Timer file descriptor. Blocks until 1 / rate seconds are elapsed. */ + double rate; /**< The read rate. */ enum epoch_mode { FILE_EPOCH_DIRECT, @@ -53,21 +57,21 @@ struct file { FILE_EPOCH_RELATIVE, FILE_EPOCH_ABSOLUTE, FILE_EPOCH_ORIGINAL - } epoch_mode; /**< Specifies how file::offset is calculated. */ + } epoch_mode; /**< Specifies how file::offset is calculated. */ enum { - FILE_EOF_EXIT, /**< Terminate when EOF is reached. */ - FILE_EOF_REWIND, /**< Rewind the file when EOF is reached. */ - FILE_EOF_WAIT /**< Blocking wait when EOF is reached. */ + FILE_EOF_EXIT, /**< Terminate when EOF is reached. */ + FILE_EOF_REWIND, /**< Rewind the file when EOF is reached. */ + FILE_EOF_WAIT /**< Blocking wait when EOF is reached. */ } eof; - struct timespec first; /**< The first timestamp in the file file::{read,write}::uri */ - struct timespec epoch; /**< The epoch timestamp from the configuration. */ - struct timespec offset; /**< An offset between the timestamp in the input file and the current time */ + struct timespec first; /**< The first timestamp in the file file::{read,write}::uri */ + struct timespec epoch; /**< The epoch timestamp from the configuration. */ + struct timespec offset; /**< An offset between the timestamp in the input file and the current time */ }; /** @see node_type::print */ -char * file_print(struct node *n); +char *file_print(struct node *n); /** @see node_type::parse */ int file_parse(struct node *n, json_t *cfg); @@ -84,4 +88,7 @@ int file_read(struct node *n, struct sample *smps[], unsigned cnt); /** @see node_type::write */ int file_write(struct node *n, struct sample *smps[], unsigned cnt); +#ifdef __cplusplus +} +#endif /** @} */ diff --git a/include/villas/nodes/iec61850.h b/include/villas/nodes/iec61850.h index 7dd31e4c2..9f7944b4b 100644 --- a/include/villas/nodes/iec61850.h +++ b/include/villas/nodes/iec61850.h @@ -38,6 +38,10 @@ #include #include +#ifdef __cplusplus +extern "C"{ +#endif + enum iec61850_type { /* According to IEC 61850-7-2 */ IEC61850_TYPE_BOOLEAN, @@ -107,4 +111,8 @@ int iec61850_receiver_stop(struct iec61850_receiver *r); int iec61850_receiver_destroy(struct iec61850_receiver *r); +#ifdef __cplusplus +} +#endif + /** @} */ diff --git a/include/villas/nodes/iec61850_sv.h b/include/villas/nodes/iec61850_sv.h index 8b43644e1..7213c20fb 100644 --- a/include/villas/nodes/iec61850_sv.h +++ b/include/villas/nodes/iec61850_sv.h @@ -40,6 +40,10 @@ #include #include +#ifdef __cplusplus +extern "C"{ +#endif + struct iec61850_sv { char *interface; int app_id; @@ -97,4 +101,8 @@ int iec61850_sv_write(struct node *n, struct sample *smps[], unsigned cnt); int iec61850_sv_fd(struct node *n); +#ifdef __cplusplus +} +#endif + /** @} */ diff --git a/include/villas/nodes/influxdb.h b/include/villas/nodes/influxdb.h index 919725b55..7eb4ea9b2 100644 --- a/include/villas/nodes/influxdb.h +++ b/include/villas/nodes/influxdb.h @@ -31,6 +31,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + /* Forward declarations */ struct node; struct sample; @@ -49,7 +53,7 @@ struct influxdb { }; /** @see node_type::print */ -char * influxdb_print(struct node *n); +char *influxdb_print(struct node *n); /** @see node_type::parse */ int influxdb_parse(struct node *n, json_t *cfg); @@ -63,4 +67,8 @@ int influxdb_close(struct node *n); /** @see node_type::write */ int influxdb_write(struct node *n, struct sample *smps[], unsigned cnt); +#ifdef __cplusplus +} +#endif + /** @} */ diff --git a/include/villas/nodes/loopback.h b/include/villas/nodes/loopback.h index cfbb5d33a..4560928c8 100644 --- a/include/villas/nodes/loopback.h +++ b/include/villas/nodes/loopback.h @@ -32,6 +32,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + /* Forward declarations */ struct node; struct sample; @@ -47,7 +51,7 @@ struct loopback { }; /** @see node_type::print */ -char * loopback_print(struct node *n); +char *loopback_print(struct node *n); /** @see node_type::parse */ int loopback_parse(struct node *n, json_t *cfg); @@ -64,4 +68,8 @@ int loopback_read(struct node *n, struct sample *smps[], unsigned cnt); /** @see node_type::write */ int loopback_write(struct node *n, struct sample *smps[], unsigned cnt); +#ifdef __cplusplus +} +#endif + /** @} */ diff --git a/include/villas/nodes/mqtt.h b/include/villas/nodes/mqtt.h index 22d12dd61..40713c8b2 100644 --- a/include/villas/nodes/mqtt.h +++ b/include/villas/nodes/mqtt.h @@ -34,6 +34,10 @@ #include #include +#ifdef __cplusplus +extern "C"{ +#endif + /* Forward declarations */ struct format_type; struct mosquitto; @@ -96,4 +100,8 @@ int mqtt_read(struct node *n, struct sample *smps[], unsigned cnt); /** @see node_type::write */ int mqtt_write(struct node *n, struct sample *smps[], unsigned cnt); +#ifdef __cplusplus +} +#endif + /** @} */ diff --git a/include/villas/nodes/nanomsg.h b/include/villas/nodes/nanomsg.h index 81feb12bf..e2c775d6a 100644 --- a/include/villas/nodes/nanomsg.h +++ b/include/villas/nodes/nanomsg.h @@ -33,6 +33,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + /** The maximum length of a packet which contains stuct msg. */ #define NANOMSG_MAX_PACKET_LEN 1500 @@ -55,7 +59,7 @@ struct nanomsg { }; /** @see node_type::print */ -char * nanomsg_print(struct node *n); +char *nanomsg_print(struct node *n); /** @see node_type::parse */ int nanomsg_parse(struct node *n, json_t *cfg); @@ -72,4 +76,8 @@ int nanomsg_read(struct node *n, struct sample *smps[], unsigned cnt); /** @see node_type::write */ int nanomsg_write(struct node *n, struct sample *smps[], unsigned cnt); +#ifdef __cplusplus +} +#endif + /** @} */ diff --git a/include/villas/nodes/ngsi.h b/include/villas/nodes/ngsi.h index 67c9bc766..486d3f3e4 100644 --- a/include/villas/nodes/ngsi.h +++ b/include/villas/nodes/ngsi.h @@ -43,25 +43,29 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + struct node; struct ngsi { - const char *endpoint; /**< The NGSI context broker endpoint URL. */ - const char *entity_id; /**< The context broker entity id related to this node */ - const char *entity_type; /**< The type of the entity */ - const char *access_token; /**< An optional authentication token which will be sent as HTTP header. */ + const char *endpoint; /**< The NGSI context broker endpoint URL. */ + const char *entity_id; /**< The context broker entity id related to this node */ + const char *entity_type; /**< The type of the entity */ + const char *access_token; /**< An optional authentication token which will be sent as HTTP header. */ - double timeout; /**< HTTP timeout in seconds */ - double rate; /**< Rate used for polling. */ + double timeout; /**< HTTP timeout in seconds */ + double rate; /**< Rate used for polling. */ - struct task task; /**< Timer for periodic events. */ - int ssl_verify; /**< Boolean flag whether SSL server certificates should be verified or not. */ + struct task task; /**< Timer for periodic events. */ + int ssl_verify; /**< Boolean flag whether SSL server certificates should be verified or not. */ - struct curl_slist *headers; /**< List of HTTP request headers for libcurl */ + struct curl_slist *headers; /**< List of HTTP request headers for libcurl */ - CURL *curl; /**< libcurl: handle */ + CURL *curl; /**< libcurl: handle */ - struct list mapping; /**< A mapping between indices of the VILLASnode samples and the attributes in ngsi::context */ + struct list mapping; /**< A mapping between indices of the VILLASnode samples and the attributes in ngsi::context */ }; /** Initialize global NGSI settings and maps shared memory regions. @@ -80,7 +84,7 @@ int ngsi_deinit(); int ngsi_parse(struct node *n, json_t *cfg); /** @see node_type::print */ -char * ngsi_print(struct node *n); +char *ngsi_print(struct node *n); /** @see node_type::open */ int ngsi_start(struct node *n); @@ -94,4 +98,8 @@ int ngsi_read(struct node *n, struct sample *smps[], unsigned cnt); /** @see node_type::write */ int ngsi_write(struct node *n, struct sample *smps[], unsigned cnt); +#ifdef __cplusplus +} +#endif + /** @} */ diff --git a/include/villas/nodes/opal.h b/include/villas/nodes/opal.h index f39668e9e..4584e270d 100644 --- a/include/villas/nodes/opal.h +++ b/include/villas/nodes/opal.h @@ -41,6 +41,10 @@ #include "AsyncApi.h" #include "OpalGenAsyncParamCtrl.h" +#ifdef __cplusplus +extern "C" { +#endif + struct opal { int reply; int mode; @@ -68,7 +72,7 @@ int opal_deinit(); int opal_parse(struct node *n, json_t *cfg); /** @see node_type::print */ -char * opal_print(struct node *n); +char *opal_print(struct node *n); /** Print global settings of the OPAL node type. */ int opal_print_global(); @@ -85,4 +89,8 @@ int opal_read(struct node *n, struct sample *smps[], unsigned cnt); /** @see node_type::write */ int opal_write(struct node *n, struct sample *smps[], unsigned cnt); +#ifdef __cplusplus +} +#endif + /** @} */ diff --git a/include/villas/nodes/shmem.h b/include/villas/nodes/shmem.h index dc156064f..00225b2b8 100644 --- a/include/villas/nodes/shmem.h +++ b/include/villas/nodes/shmem.h @@ -36,19 +36,23 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + /** Node-type for shared memory communication. * @see node_type */ struct shmem { - const char* out_name; /**< Name of the shm object for the output queue. */ - const char* in_name; /**< Name of the shm object for the input queue. */ - struct shmem_conf conf; /**< Interface configuration struct. */ - char **exec; /**< External program to execute on start. */ - struct shmem_int intf; /**< Shmem interface */ + const char *out_name; /**< Name of the shm object for the output queue. */ + const char *in_name; /**< Name of the shm object for the input queue. */ + struct shmem_conf conf; /**< Interface configuration struct. */ + char **exec; /**< External program to execute on start. */ + struct shmem_int intf; /**< Shmem interface */ }; /** @see node_type::print */ -char * shmem_print(struct node *n); +char *shmem_print(struct node *n); /** @see node_type::parse */ int shmem_parse(struct node *n, json_t *cfg); @@ -65,4 +69,8 @@ int shmem_read(struct node *n, struct sample *smps[], unsigned cnt); /** @see node_type::write */ int shmem_write(struct node *n, struct sample *smps[], unsigned cnt); +#ifdef __cplusplus +} +#endif + /** @} */ diff --git a/include/villas/nodes/signal_generator.h b/include/villas/nodes/signal_generator.h index 7c669aa16..6c08b99d4 100644 --- a/include/villas/nodes/signal_generator.h +++ b/include/villas/nodes/signal_generator.h @@ -32,6 +32,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + /* Forward declarations */ struct node; struct sample; @@ -51,29 +55,29 @@ enum signal_generator_type { * @see node_type */ struct signal_generator { - struct task task; /**< Timer for periodic events. */ - int rt; /**< Real-time mode? */ + struct task task; /**< Timer for periodic events. */ + int rt; /**< Real-time mode? */ enum signal_generator_type type; /**< Signal type */ - double rate; /**< Sampling rate. */ - double frequency; /**< Frequency of the generated signals. */ - double amplitude; /**< Amplitude of the generated signals. */ - double stddev; /**< Standard deviation of random signals (normal distributed). */ - double offset; /**< A constant bias. */ + double rate; /**< Sampling rate. */ + double frequency; /**< Frequency of the generated signals. */ + double amplitude; /**< Amplitude of the generated signals. */ + double stddev; /**< Standard deviation of random signals (normal distributed). */ + double offset; /**< A constant bias. */ - double *last; /**< The values from the previous period which are required for random walk. */ + double *last; /**< The values from the previous period which are required for random walk. */ - int values; /**< The number of values which will be emitted by this node. */ - int limit; /**< The number of values which should be generated by this node. <0 for infinitve. */ + int values; /**< The number of values which will be emitted by this node. */ + int limit; /**< The number of values which should be generated by this node. <0 for infinitve. */ - struct timespec started; /**< Point in time when this node was started. */ - int counter; /**< The number of packets already emitted. */ - int missed_steps; /**< Total number of missed steps. */ + struct timespec started; /**< Point in time when this node was started. */ + int counter; /**< The number of packets already emitted. */ + int missed_steps; /**< Total number of missed steps. */ }; /** @see node_type::print */ -char * signal_generator_print(struct node *n); +char *signal_generator_print(struct node *n); /** @see node_type::parse */ int signal_generator_parse(struct node *n, json_t *cfg); @@ -89,4 +93,8 @@ int signal_generator_read(struct node *n, struct sample *smps[], unsigned cnt); enum signal_generator_type signal_generator_lookup_type(const char *type); +#ifdef __cplusplus +} +#endif + /** @} */ diff --git a/include/villas/nodes/socket.h b/include/villas/nodes/socket.h index 345792823..3499c7329 100644 --- a/include/villas/nodes/socket.h +++ b/include/villas/nodes/socket.h @@ -50,6 +50,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + /* Forward declarations */ struct format_type; @@ -75,29 +79,29 @@ union sockaddr_union { }; struct socket { - int sd; /**< The socket descriptor */ - int mark; /**< Socket mark for netem, routing and filtering */ - int verify_source; /**< Verify the source address of incoming packets against socket::remote. */ + int sd; /**< The socket descriptor */ + int mark; /**< Socket mark for netem, routing and filtering */ + int verify_source; /**< Verify the source address of incoming packets against socket::remote. */ - enum socket_layer layer; /**< The OSI / IP layer which should be used for this socket */ + enum socket_layer layer; /**< The OSI / IP layer which should be used for this socket */ - union sockaddr_union local; /**< Local address of the socket */ - union sockaddr_union remote; /**< Remote address of the socket */ + union sockaddr_union local; /**< Local address of the socket */ + union sockaddr_union remote; /**< Remote address of the socket */ struct format_type *format; struct io io; /* Multicast options */ struct multicast { - int enabled; /**< Is multicast enabled? */ - unsigned char loop; /** Loopback multicast packets to local host? */ - unsigned char ttl; /**< The time to live for multicast packets. */ - struct ip_mreq mreq; /**< A multicast group to join. */ + int enabled; /**< Is multicast enabled? */ + unsigned char loop; /** Loopback multicast packets to local host? */ + unsigned char ttl; /**< The time to live for multicast packets. */ + struct ip_mreq mreq; /**< A multicast group to join. */ } multicast; #ifdef WITH_NETEM - struct rtnl_qdisc *tc_qdisc; /**< libnl3: Network emulator queuing discipline */ - struct rtnl_cls *tc_classifier; /**< libnl3: Firewall mark classifier */ + struct rtnl_qdisc *tc_qdisc; /**< libnl3: Network emulator queuing discipline */ + struct rtnl_cls *tc_classifier; /**< libnl3: Firewall mark classifier */ #endif /* WITH_NETEM */ }; @@ -124,7 +128,7 @@ int socket_read(struct node *n, struct sample *smps[], unsigned cnt); int socket_parse(struct node *n, json_t *cfg); /** @see node_type::print */ -char * socket_print(struct node *n); +char *socket_print(struct node *n); /** Generate printable socket address depending on the address family * @@ -134,7 +138,7 @@ char * socket_print(struct node *n); * @param sa A pointer to the socket address. * @return The buffer containing the textual representation of the address. The caller is responsible to free() this buffer! */ -char * socket_print_addr(struct sockaddr *saddr); +char *socket_print_addr(struct sockaddr *saddr); /** Parse a socket address depending on the address family * @@ -154,4 +158,8 @@ int socket_parse_addr(const char *str, struct sockaddr *sa, enum socket_layer la int socket_compare_addr(struct sockaddr *x, struct sockaddr *y); +#ifdef __cplusplus +} +#endif + /** @} */ diff --git a/include/villas/nodes/stats.h b/include/villas/nodes/stats.h index 27caf6621..89a161656 100644 --- a/include/villas/nodes/stats.h +++ b/include/villas/nodes/stats.h @@ -33,6 +33,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + /* Forward declarations */ struct node; struct sample; @@ -51,7 +55,7 @@ struct stats_node { int stats_node_init(struct super_node *sn); /** @see node_type::print */ -char * stats_node_print(struct node *n); +char *stats_node_print(struct node *n); /** @see node_type::parse */ int stats_node_parse(struct node *n, json_t *cfg); @@ -65,4 +69,8 @@ int stats_node_stop(struct node *n); /** @see node_type::read */ int stats_node_read(struct node *n, struct sample *smps[], unsigned cnt); +#ifdef __cplusplus +} +#endif + /** @} */ diff --git a/include/villas/nodes/test_rtt.h b/include/villas/nodes/test_rtt.h index a0e14e533..97b615a26 100644 --- a/include/villas/nodes/test_rtt.h +++ b/include/villas/nodes/test_rtt.h @@ -33,6 +33,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + /* Forward declarations */ struct test_rtt; struct node; @@ -41,29 +45,29 @@ struct sample; struct test_rtt_case { double rate; int values; - int limit; /**< The number of samples we take per test. */ + int limit; /**< The number of samples we take per test. */ char *filename; }; struct test_rtt { - struct task task; /**< The periodic task for test_rtt_read() */ - struct io io; /**< The format of the output file */ + struct task task; /**< The periodic task for test_rtt_read() */ + struct io io; /**< The format of the output file */ struct format_type *format; - double cooldown; /**< Number of seconds to wait beween tests. */ + double cooldown; /**< Number of seconds to wait beween tests. */ - int current; /**< Index of current test in test_rtt::cases */ + int current; /**< Index of current test in test_rtt::cases */ int counter; - struct list cases; /**< List of test cases */ + struct list cases; /**< List of test cases */ - char *output; /**< The directory where we place the results. */ - char *prefix; /**< An optional prefix in the filename. */ + char *output; /**< The directory where we place the results. */ + char *prefix; /**< An optional prefix in the filename. */ }; /** @see node_type::print */ -char * test_rtt_print(struct node *n); +char *test_rtt_print(struct node *n); /** @see node_type::parse */ int test_rtt_parse(struct node *n, json_t *cfg); @@ -80,4 +84,8 @@ int test_rtt_read(struct node *n, struct sample *smps[], unsigned cnt); /** @see node_type::write */ int test_rtt_write(struct node *n, struct sample *smps[], unsigned cnt); +#ifdef __cplusplus +} +#endif + /** @} */ diff --git a/include/villas/nodes/websocket.h b/include/villas/nodes/websocket.h index 6c61053b1..7ea510d4b 100644 --- a/include/villas/nodes/websocket.h +++ b/include/villas/nodes/websocket.h @@ -38,56 +38,60 @@ #include #include -#define DEFAULT_WEBSOCKET_QUEUELEN (DEFAULT_QUEUELEN * 64) -#define DEFAULT_WEBSOCKET_SAMPLELEN DEFAULT_SAMPLELEN +#ifdef __cplusplus +extern "C" { +#endif + +#define DEFAULT_WEBSOCKET_QUEUELEN (DEFAULT_QUEUELEN * 64) +#define DEFAULT_WEBSOCKET_SAMPLELEN DEFAULT_SAMPLELEN /* Forward declaration */ struct lws; /** Internal data per websocket node */ struct websocket { - struct list destinations; /**< List of websocket servers connect to in client mode (struct websocket_destination). */ + struct list destinations; /**< List of websocket servers connect to in client mode (struct websocket_destination). */ - struct pool pool; - struct queue_signalled queue; /**< For samples which are received from WebSockets */ + struct pool pool; + struct queue_signalled queue; /**< For samples which are received from WebSockets */ }; /* Internal datastructures */ struct websocket_connection { - enum websocket_connection_state { - WEBSOCKET_CONNECTION_STATE_DESTROYED, - WEBSOCKET_CONNECTION_STATE_INITIALIZED, - WEBSOCKET_CONNECTION_STATE_CONNECTING, - WEBSOCKET_CONNECTION_STATE_RECONNECTING, - WEBSOCKET_CONNECTION_STATE_ESTABLISHED, - WEBSOCKET_CONNECTION_STATE_SHUTDOWN, - WEBSOCKET_CONNECTION_STATE_ERROR - } state; /**< The current status of this connection. */ + enum websocket_connection_state { + WEBSOCKET_CONNECTION_STATE_DESTROYED, + WEBSOCKET_CONNECTION_STATE_INITIALIZED, + WEBSOCKET_CONNECTION_STATE_CONNECTING, + WEBSOCKET_CONNECTION_STATE_RECONNECTING, + WEBSOCKET_CONNECTION_STATE_ESTABLISHED, + WEBSOCKET_CONNECTION_STATE_SHUTDOWN, + WEBSOCKET_CONNECTION_STATE_ERROR + } state; /**< The current status of this connection. */ - enum { - WEBSOCKET_MODE_CLIENT, - WEBSOCKET_MODE_SERVER, - } mode; + enum { + WEBSOCKET_MODE_CLIENT, + WEBSOCKET_MODE_SERVER, + } mode; - struct lws *wsi; - struct node *node; - struct io io; - struct queue queue; /**< For samples which are sent to the WebSocket */ + struct lws *wsi; + struct node *node; + struct io io; + struct queue queue; /**< For samples which are sent to the WebSocket */ - struct format_type *format; - struct websocket_destination *destination; + struct format_type *format; + struct websocket_destination *destination; - struct { - struct buffer recv; /**< A buffer for reconstructing fragmented messags. */ - struct buffer send; /**< A buffer for contsructing messages before calling lws_write() */ - } buffers; + struct { + struct buffer recv; /**< A buffer for reconstructing fragmented messags. */ + struct buffer send; /**< A buffer for contsructing messages before calling lws_write() */ + } buffers; - char *_name; + char *_name; }; struct websocket_destination { - char *uri; - struct lws_client_connect_info info; + char *uri; + struct lws_client_connect_info info; }; int websocket_protocol_cb(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len); @@ -113,4 +117,8 @@ int websocket_read(struct node *n, struct sample *smps[], unsigned cnt); /** @see node_type::write */ int websocket_write(struct node *n, struct sample *smps[], unsigned cnt); +#ifdef __cplusplus +} +#endif + /** @} */ diff --git a/include/villas/nodes/zeromq.h b/include/villas/nodes/zeromq.h index afdf4a9b7..d883aaf07 100644 --- a/include/villas/nodes/zeromq.h +++ b/include/villas/nodes/zeromq.h @@ -35,8 +35,12 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + #if ZMQ_BUILD_DRAFT_API && (ZMQ_VERSION_MAJOR > 4 || (ZMQ_VERSION_MAJOR == 4 && ZMQ_VERSION_MINOR >= 2)) - #define ZMQ_BUILD_DISH 1 +#define ZMQ_BUILD_DISH 1 #endif /* Forward declarations */ @@ -68,19 +72,19 @@ struct zeromq { } pattern; struct { - void *socket; /**< ZeroMQ socket. */ + void *socket; /**< ZeroMQ socket. */ void *mon_socket; char *endpoint; } subscriber; struct { - void *socket; /**< ZeroMQ socket. */ + void *socket; /**< ZeroMQ socket. */ struct list endpoints; } publisher; }; /** @see node_type::print */ -char * zeromq_print(struct node *n); +char *zeromq_print(struct node *n); /** @see node_type::parse */ int zeromq_parse(struct node *n, json_t *cfg); @@ -103,4 +107,8 @@ int zeromq_read(struct node *n, struct sample *smps[], unsigned cnt); /** @see node_type::write */ int zeromq_write(struct node *n, struct sample *smps[], unsigned cnt); +#ifdef __cplusplus +} +#endif + /** @} */ diff --git a/include/villas/path.h b/include/villas/path.h index 1db52dcf4..cef9b76ab 100644 --- a/include/villas/path.h +++ b/include/villas/path.h @@ -41,6 +41,10 @@ #include "mapping.h" #include "task.h" +#ifdef __cplusplus +extern "C" { +#endif + /* Forward declarations */ struct stats; struct node; @@ -52,7 +56,7 @@ struct path_source { bool masked; struct pool pool; - struct list mappings; /**< List of mappings (struct mapping_entry). */ + struct list mappings; /**< List of mappings (struct mapping_entry). */ }; struct path_destination { @@ -63,15 +67,15 @@ struct path_destination { /** The register mode determines under which condition the path is triggered. */ enum path_mode { - PATH_MODE_ANY, /**< The path is triggered whenever one of the sources receives samples. */ - PATH_MODE_ALL /**< The path is triggered only after all sources have received at least 1 sample. */ + PATH_MODE_ANY, /**< The path is triggered whenever one of the sources receives samples. */ + PATH_MODE_ALL /**< The path is triggered only after all sources have received at least 1 sample. */ }; /** The datastructure for a path. */ struct path { - enum state state; /**< Path state. */ + enum state state; /**< Path state. */ - enum path_mode mode; /**< Determines when this path is triggered. */ + enum path_mode mode; /**< Determines when this path is triggered. */ struct { int nfds; @@ -82,27 +86,27 @@ struct path { struct sample *last_sample; int last_sequence; - struct list sources; /**< List of all incoming nodes (struct path_source). */ - struct list destinations; /**< List of all outgoing nodes (struct path_destination). */ - struct list hooks; /**< List of processing hooks (struct hook). */ + struct list sources; /**< List of all incoming nodes (struct path_source). */ + struct list destinations; /**< List of all outgoing nodes (struct path_destination). */ + struct list hooks; /**< List of processing hooks (struct hook). */ struct task timeout; - double rate; /**< A timeout for */ - int enabled; /**< Is this path enabled. */ - int poll; /**< Weather or not to use poll(2). */ - int reverse; /**< This path as a matching reverse path. */ - int builtin; /**< This path should use built-in hooks by default. */ - int queuelen; /**< The queue length for each path_destination::queue */ - int samplelen; /**< Will be calculated based on path::sources.mappings */ + double rate; /**< A timeout for */ + int enabled; /**< Is this path enabled. */ + int poll; /**< Weather or not to use poll(2). */ + int reverse; /**< This path as a matching reverse path. */ + int builtin; /**< This path should use built-in hooks by default. */ + int queuelen; /**< The queue length for each path_destination::queue */ + int samplelen; /**< Will be calculated based on path::sources.mappings */ - char *_name; /**< Singleton: A string which is used to print this path to screen. */ + char *_name; /**< Singleton: A string which is used to print this path to screen. */ - struct bitset mask; /**< A mask of path_sources which are enabled for poll(). */ - struct bitset received; /**< A mask of path_sources for which we already received samples. */ + struct bitset mask; /**< A mask of path_sources which are enabled for poll(). */ + struct bitset received; /**< A mask of path_sources for which we already received samples. */ - pthread_t tid; /**< The thread id for this path. */ - json_t *cfg; /**< A JSON object containing the configuration of the path. */ + pthread_t tid; /**< The thread id for this path. */ + json_t *cfg; /**< A JSON object containing the configuration of the path. */ }; /** Initialize internal data structures. */ @@ -150,7 +154,7 @@ void path_print_stats(struct path *p); * @param p A pointer to the path structure. * @return A pointer to a string containing a textual representation of the path. */ -const char * path_name(struct path *p); +const char *path_name(struct path *p); /** Reverse a path */ int path_reverse(struct path *p, struct path *r); @@ -168,4 +172,8 @@ int path_uses_node(struct path *p, struct node *n); */ int path_parse(struct path *p, json_t *cfg, struct list *nodes); +#ifdef __cplusplus +} +#endif + /** @} */ diff --git a/include/villas/plugin.h b/include/villas/plugin.h index 6a58b2d57..d373ab338 100644 --- a/include/villas/plugin.h +++ b/include/villas/plugin.h @@ -31,6 +31,10 @@ #include "node_type.h" #include "format_type.h" +#ifdef __cplusplus +extern "C"{ +#endif + /** @todo This is ugly as hell and broken on OS X / Clang anyway. */ #define REGISTER_PLUGIN(p) \ __attribute__((constructor(110))) static void UNIQUE(__ctor)() {\ @@ -95,3 +99,7 @@ void plugin_dump(enum plugin_type type); /** Find registered and loaded plugin with given name and type. */ struct plugin * plugin_lookup(enum plugin_type type, const char *name); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/include/villas/pool.h b/include/villas/pool.h index 15d7833db..662336d99 100644 --- a/include/villas/pool.h +++ b/include/villas/pool.h @@ -32,17 +32,21 @@ #include "common.h" #include "memory.h" +#ifdef __cplusplus +extern "C" { +#endif + /** A thread-safe memory pool */ struct pool { - off_t buffer_off; /**< Offset from the struct address to the underlying memory area */ + off_t buffer_off; /**< Offset from the struct address to the underlying memory area */ struct memtype *mem; enum state state; - size_t len; /**< Length of the underlying memory area */ + size_t len; /**< Length of the underlying memory area */ - size_t blocksz; /**< Length of a block in bytes */ - size_t alignment; /**< Alignment of a block in bytes */ + size_t blocksz; /**< Length of a block in bytes */ + size_t alignment; /**< Alignment of a block in bytes */ struct queue queue; /**< The queue which is used to keep track of free blocks */ }; @@ -69,26 +73,26 @@ int pool_destroy(struct pool *p); * This number can be smaller than the requested \p cnt blocks * in case the pool currently holds less than \p cnt blocks. */ -INLINE ssize_t pool_get_many(struct pool *p, void *blocks[], size_t cnt) -{ +INLINE ssize_t pool_get_many(struct pool *p, void *blocks[], size_t cnt) { return queue_pull_many(&p->queue, blocks, cnt); } /** Push \p cnt values which are giving by the array values to the stack. */ -INLINE ssize_t pool_put_many(struct pool *p, void *blocks[], size_t cnt) -{ +INLINE ssize_t pool_put_many(struct pool *p, void *blocks[], size_t cnt) { return queue_push_many(&p->queue, blocks, cnt); } /** Get a free memory block from pool. */ -INLINE void * pool_get(struct pool *p) -{ +INLINE void *pool_get(struct pool *p) { void *ptr; return queue_pull(&p->queue, &ptr) == 1 ? ptr : NULL; } /** Release a memory block back to the pool. */ -INLINE int pool_put(struct pool *p, void *buf) -{ +INLINE int pool_put(struct pool *p, void *buf) { return queue_push(&p->queue, buf); } + +#ifdef __cplusplus +} +#endif diff --git a/include/villas/queue.h b/include/villas/queue.h index ce1ab58d5..e75a95368 100644 --- a/include/villas/queue.h +++ b/include/villas/queue.h @@ -34,6 +34,8 @@ #pragma once + + #include #include #include @@ -41,6 +43,10 @@ #include "atomic.h" #include "common.h" +#ifdef __cplusplus +extern "C"{ +#endif + /* Forward declarations */ struct memtype; @@ -112,3 +118,7 @@ int queue_pull_many(struct queue *q, void *ptr[], size_t cnt); * @return -1 on failure. */ int queue_close(struct queue *q); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/include/villas/queue_signalled.h b/include/villas/queue_signalled.h index 4f9e012b4..2d2a44fb3 100644 --- a/include/villas/queue_signalled.h +++ b/include/villas/queue_signalled.h @@ -27,6 +27,10 @@ #include "queue.h" +#ifdef __cplusplus +extern "C"{ +#endif + enum queue_signalled_flags { /* Mode */ QUEUE_SIGNALLED_AUTO = (0 << 0), /**< We will choose the best method available on the platform */ @@ -80,3 +84,7 @@ int queue_signalled_close(struct queue_signalled *qs); /** Returns a file descriptor which can be used with poll / select to wait for new data */ int queue_signalled_fd(struct queue_signalled *qs); + +#ifdef __cplusplus +} +#endif diff --git a/include/villas/sample.h b/include/villas/sample.h index 149fcc4f5..4102f7f00 100644 --- a/include/villas/sample.h +++ b/include/villas/sample.h @@ -21,20 +21,22 @@ * along with this program. If not, see . *********************************************************************************/ + + #pragma once #include "atomic.h" -#ifdef __cplusplus -extern "C" { -#endif - #include #include #include #include #include +#ifdef __cplusplus +extern "C"{ +#endif + /* Forward declarations */ struct pool; diff --git a/include/villas/signal.h b/include/villas/signal.h index 56502e8f3..729cbb1f3 100644 --- a/include/villas/signal.h +++ b/include/villas/signal.h @@ -25,12 +25,16 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + /* Forward declarations */ struct list; struct node; struct signal { - char *name; /**< The name of the signal. */ + char *name; /**< The name of the signal. */ char *unit; int enabled; enum { @@ -46,3 +50,7 @@ int signal_parse(struct signal *s, json_t *cfg); int signal_parse_list(struct list *list, json_t *cfg); int signal_get_offset(const char *str, struct node *n); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/include/villas/stats.h b/include/villas/stats.h index e0e46f941..70b044f2d 100644 --- a/include/villas/stats.h +++ b/include/villas/stats.h @@ -29,6 +29,10 @@ #include "hist.h" +#ifdef __cplusplus +extern "C" { +#endif + /* Forward declarations */ struct sample; struct node; @@ -40,19 +44,19 @@ enum stats_format { }; enum stats_id { - STATS_SKIPPED, /**< Counter for skipped samples due to hooks. */ - STATS_TIME, /**< The processing time per sample within VILLAsnode. */ - STATS_REORDERED, /**< Counter for reordered samples. */ - STATS_GAP_SAMPLE, /**< Histogram for inter sample timestamps (as sent by remote). */ - STATS_GAP_RECEIVED, /**< Histogram for inter sample arrival time (as seen by this instance). */ - STATS_OWD, /**< Histogram for one-way-delay (OWD) of received samples. */ - STATS_COUNT /**< Just here to have an updated number of statistics. */ + STATS_SKIPPED, /**< Counter for skipped samples due to hooks. */ + STATS_TIME, /**< The processing time per sample within VILLAsnode. */ + STATS_REORDERED, /**< Counter for reordered samples. */ + STATS_GAP_SAMPLE, /**< Histogram for inter sample timestamps (as sent by remote). */ + STATS_GAP_RECEIVED, /**< Histogram for inter sample arrival time (as seen by this instance). */ + STATS_OWD, /**< Histogram for one-way-delay (OWD) of received samples. */ + STATS_COUNT /**< Just here to have an updated number of statistics. */ }; struct stats_delta { double values[STATS_COUNT]; - int update; /**< Bitmask of stats_id. Only those which are masked will be updated */ + int update; /**< Bitmask of stats_id. Only those which are masked will be updated */ }; struct stats { @@ -73,7 +77,7 @@ void stats_collect(struct stats *s, struct sample *smps[], size_t cnt); int stats_commit(struct stats *s); -json_t * stats_json(struct stats *s); +json_t *stats_json(struct stats *s); void stats_reset(struct stats *s); @@ -86,4 +90,8 @@ void stats_print(struct stats *s, FILE *f, enum stats_format fmt, int verbose); enum stats_id stats_lookup_id(const char *name); +#ifdef __cplusplus +} +#endif + #endif /* _STATS_H_ */ diff --git a/include/villas/super_node.h b/include/villas/super_node.h index 064c31cc9..4ff019119 100644 --- a/include/villas/super_node.h +++ b/include/villas/super_node.h @@ -29,33 +29,37 @@ #include "log.h" #include "common.h" +#ifdef __cplusplus +extern "C" { +#endif + /** Global configuration */ struct super_node { - int priority; /**< Process priority (lower is better) */ - int affinity; /**< Process affinity of the server and all created threads */ - int hugepages; /**< Number of hugepages to reserve. */ - double stats; /**< Interval for path statistics. Set to 0 to disable them. */ + int priority; /**< Process priority (lower is better) */ + int affinity; /**< Process affinity of the server and all created threads */ + int hugepages; /**< Number of hugepages to reserve. */ + double stats; /**< Interval for path statistics. Set to 0 to disable them. */ - struct list nodes; - struct list paths; - struct list plugins; + struct list nodes; + struct list paths; + struct list plugins; - struct log log; - struct api api; - struct web web; + struct log log; + struct api api; + struct web web; - char *name; /**< A name of this super node. Usually the hostname. */ + char *name; /**< A name of this super node. Usually the hostname. */ - enum state state; + enum state state; - char *uri; /**< URI of configuration */ + char *uri; /**< URI of configuration */ - json_t *cfg; /**< JSON representation of the configuration. */ + json_t *cfg; /**< JSON representation of the configuration. */ }; /* Compatibility with libconfig < 1.5 */ #if (LIBCONFIG_VER_MAJOR <= 1) && (LIBCONFIG_VER_MINOR < 5) - #define config_setting_lookup config_lookup_from +#define config_setting_lookup config_lookup_from #endif /** Inititalize configuration object before parsing the configuration. */ @@ -83,3 +87,7 @@ int super_node_stop(struct super_node *sn); /** Desctroy configuration object. */ int super_node_destroy(struct super_node *sn); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/include/villas/table.h b/include/villas/table.h index f11a0d5d9..9ecf0d8a1 100644 --- a/include/villas/table.h +++ b/include/villas/table.h @@ -25,18 +25,22 @@ * @{ */ +#ifdef __cplusplus +extern "C" { +#endif + struct table_column { - int width; /**< Width of the column. */ - char *title; /**< The title as shown in the table header. */ - char *format; /**< The format which is used to print the table rows. */ - char *unit; /**< An optional unit which will be shown in the table header. */ + int width; /**< Width of the column. */ + char *title; /**< The title as shown in the table header. */ + char *format; /**< The format which is used to print the table rows. */ + char *unit; /**< An optional unit which will be shown in the table header. */ enum { TABLE_ALIGN_LEFT, TABLE_ALIGN_RIGHT } align; - int _width; /**< The real width of this column. Calculated by table_header() */ + int _width; /**< The real width of this column. Calculated by table_header() */ }; struct table { @@ -54,4 +58,8 @@ void table_row(struct table *t, ...); /** Print the table footer. */ void table_footer(struct table *t); +#ifdef __cplusplus +} +#endif + /** @} */ diff --git a/include/villas/task.h b/include/villas/task.h index 141f2f7e2..30b029edd 100644 --- a/include/villas/task.h +++ b/include/villas/task.h @@ -28,27 +28,31 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + /** We can choose between two periodic task implementations */ //#define PERIODIC_TASK_IMPL NANOSLEEP -#define TIMERFD 1 -#define CLOCK_NANOSLEEP 2 -#define NANOSLEEP 3 +#define TIMERFD 1 +#define CLOCK_NANOSLEEP 2 +#define NANOSLEEP 3 #if defined(__MACH__) - #define PERIODIC_TASK_IMPL NANOSLEEP +#define PERIODIC_TASK_IMPL NANOSLEEP #elif defined(__linux__) - #define PERIODIC_TASK_IMPL TIMERFD +#define PERIODIC_TASK_IMPL TIMERFD #else - #error "Platform not supported" +#error "Platform not supported" #endif struct task { - int clock; /**< CLOCK_{MONOTONIC,REALTIME} */ + int clock; /**< CLOCK_{MONOTONIC,REALTIME} */ - struct timespec period; /**< The period of periodic invations of this task */ - struct timespec next; /**< The timer value for the next invocation */ + struct timespec period; /**< The period of periodic invations of this task */ + struct timespec next; /**< The timer value for the next invocation */ #if PERIODIC_TASK_IMPL == TIMERFD - int fd; /**< The timerfd_create(2) file descriptior. */ + int fd; /**< The timerfd_create(2) file descriptior. */ #endif }; @@ -73,3 +77,8 @@ int task_set_rate(struct task *t, double rate); * Note: currently not supported on all platforms. */ int task_fd(struct task *t); + +#ifdef __cplusplus +} +#endif + diff --git a/include/villas/timing.h b/include/villas/timing.h index 1ef49e123..dad07fad1 100644 --- a/include/villas/timing.h +++ b/include/villas/timing.h @@ -28,6 +28,10 @@ #include +#ifdef __cplusplus +extern "C"{ +#endif + /** Get delta between two timespec structs */ struct timespec time_diff(const struct timespec *start, const struct timespec *end); @@ -45,3 +49,7 @@ double time_to_double(const struct timespec *ts); /** Convert double containing seconds after 1970 to timespec. */ struct timespec time_from_double(double secs); + +#ifdef __cplusplus +} +#endif diff --git a/include/villas/utils.h b/include/villas/utils.h index ac753be84..942087fbb 100644 --- a/include/villas/utils.h +++ b/include/villas/utils.h @@ -33,6 +33,11 @@ #include #include +#ifdef __cplusplus +extern "C"{ +#endif + + #ifdef __GNUC__ #define LIKELY(x) __builtin_expect((x),1) #define UNLIKELY(x) __builtin_expect((x),0) @@ -275,3 +280,8 @@ pid_t spawn(const char *name, char *const argv[]); /** Determines the string length as printed on the screen (ignores escable sequences). */ size_t strlenp(const char *str); + + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/include/villas/web.h b/include/villas/web.h index a299146e4..cb65c8775 100644 --- a/include/villas/web.h +++ b/include/villas/web.h @@ -27,6 +27,10 @@ #include "common.h" +#ifdef __cplusplus +extern "C" { +#endif + /* Forward declarations */ struct api; @@ -35,13 +39,13 @@ struct web { enum state state; - struct lws_context *context; /**< The libwebsockets server context. */ - struct lws_vhost *vhost; /**< The libwebsockets vhost. */ + struct lws_context *context; /**< The libwebsockets server context. */ + struct lws_vhost *vhost; /**< The libwebsockets vhost. */ - int port; /**< Port of the build in HTTP / WebSocket server. */ - char *htdocs; /**< The root directory for files served via HTTP. */ - char *ssl_cert; /**< Path to the SSL certitifcate for HTTPS / WSS. */ - char *ssl_private_key; /**< Path to the SSL private key for HTTPS / WSS. */ + int port; /**< Port of the build in HTTP / WebSocket server. */ + char *htdocs; /**< The root directory for files served via HTTP. */ + char *ssl_cert; /**< Path to the SSL certitifcate for HTTPS / WSS. */ + char *ssl_private_key; /**< Path to the SSL private key for HTTPS / WSS. */ pthread_t thread; }; @@ -60,3 +64,7 @@ int web_stop(struct web *w); /** Parse HTTPd and WebSocket related options */ int web_parse(struct web *w, json_t *cfg); + +#ifdef __cplusplus +} +#endif