Commit fddb9415 authored by Steffen Vogel's avatar Steffen Vogel 🎅🏼

Merge branch 'cpp-remove-legacy' into develop

parents f2f79382 bdb05841
......@@ -28,10 +28,6 @@
#include <villas/crypt.h>
#ifdef __cplusplus
extern "C" {
#endif
struct advio {
CURL *curl;
FILE *file;
......@@ -85,7 +81,3 @@ void arewind(AFILE *file);
int adownload(AFILE *af, int resume);
int aupload(AFILE *af, int resume);
#ifdef __cplusplus
}
#endif
/** Workaround for differently named atomic types in C/C++
*
* @file
* @author Georg Reinke <georg.reinke@rwth-aachen.de>
* @copyright 2014-2019, Institute for Automation of Complex Power Systems, EONERC
* @license GNU General Public License (version 3)
*
* VILLAScommon
*
* 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 <villas/common.h>
#ifdef __cplusplus
#include <atomic>
typedef std::atomic_int atomic_int;
typedef std::atomic_size_t atomic_size_t;
typedef std::atomic<enum state> atomic_state;
#else
#include <stdatomic.h>
typedef _Atomic enum state atomic_state;
#endif /* __cplusplus */
......@@ -29,10 +29,6 @@
#include <villas/common.h>
#ifdef __cplusplus
extern "C" {
#endif
struct buffer {
enum state state;
......@@ -52,7 +48,3 @@ 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);
#ifdef __cplusplus
}
#endif
......@@ -23,10 +23,6 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
/* Common states for most objects in VILLAScommon (paths, nodes, hooks, plugins) */
enum state {
STATE_DESTROYED = 0,
......@@ -57,7 +53,3 @@ typedef int (*dtor_cb_t)(void *);
/** Convert state enum to human readable string. */
const char * state_print(enum state s);
#ifdef __cplusplus
}
#endif
......@@ -26,10 +26,6 @@
#include <villas/config.h>
#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);
......@@ -60,7 +56,3 @@ json_t *json_loadfd(int input, size_t flags, json_error_t *error);
#define htobe32(x) OSSwapHostToBigInt32(x)
#define htobe64(x) OSSwapHostToBigInt64(x)
#endif /* __MACH__ */
#ifdef __cplusplus
}
#endif
......@@ -193,7 +193,7 @@ public:
}
};
} // namespace utils
} // namespace villas
} /* namespace utils */
} /* namespace villas */
#endif
......@@ -25,17 +25,9 @@
#include <stdio.h>
#include <openssl/sha.h>
#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
......@@ -49,5 +49,5 @@ public:
}
};
} // namespace dsp
} // namespace villas
} /* namespace dsp */
} /* namespace villas */
......@@ -52,5 +52,5 @@ public:
}
};
} // namespace dsp
} // namespace villas
} /* namespace dsp */
} /* namespace villas */
......@@ -53,5 +53,5 @@ public:
double calculate(double setpoint, double pv);
};
} // namespace dsp
} // namespace villas
} /* namespace dsp */
} /* namespace villas */
......@@ -23,7 +23,7 @@
#pragma once
#include <villas/utils.h>
#include <villas/utils.hpp>
namespace villas {
namespace dsp {
......@@ -77,5 +77,5 @@ public:
}
};
} // namespace dsp
} // namespace villas
} /* namespace dsp */
} /* namespace villas */
......@@ -144,4 +144,4 @@ public:
}
};
} // namespace villas
} /* namespace villas */
......@@ -294,4 +294,4 @@ protected:
};
} // namespacae graph
} // namespace villas
} /* namespace villas */
......@@ -54,4 +54,4 @@ private:
};
} // namespacae graph
} // namespace villas
} /* namespace villas */
......@@ -52,4 +52,4 @@ private:
};
} // namespacae graph
} // namespace villas
} /* namespace villas */
......@@ -28,10 +28,6 @@
#include <jansson.h>
#ifdef __cplusplus
extern "C" {
#endif
#define HIST_HEIGHT (LOG_WIDTH - 55)
#define HIST_SEQ 17
......@@ -107,7 +103,3 @@ int hist_dump_json(const struct hist *h, FILE *f);
/** Build a libjansson / JSON object of the histogram. */
json_t * hist_json(const struct hist *h);
#ifdef __cplusplus
}
#endif
......@@ -55,4 +55,4 @@ public:
json_t * decode();
};
} // namespace villas
} /* namespace villas */
......@@ -30,10 +30,6 @@
#include <string.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#if WITH_CAP
#include <sys/capability.h>
......@@ -92,8 +88,4 @@ int kernel_get_cpu_frequency(uint64_t *freq);
/** Set SMP affinity of IRQ */
int kernel_irq_setaffinity(unsigned irq, uintmax_t aff , uintmax_t *old);
#ifdef __cplusplus
}
#endif
/** @} */
......@@ -31,5 +31,5 @@ namespace kernel {
/** Get the version of the kernel. */
utils::Version getVersion();
} // namespace villas
} // namespace kernel
} /* namespace villas */
} /* namespace kernel */
......@@ -32,10 +32,6 @@
#define PCI_SLOT(devfn) (((devfn) >> 3) & 0x1f)
#define PCI_FUNC(devfn) ((devfn) & 0x07)
#ifdef __cplusplus
extern "C" {
#endif
struct pci_device {
struct {
int vendor;
......@@ -93,8 +89,4 @@ int pci_get_iommu_group(const struct pci_device *d);
size_t pci_get_regions(const struct pci_device *d, struct pci_region** regions);
#ifdef __cplusplus
}
#endif
/** @} */
......@@ -47,8 +47,8 @@ void setPriority(int priority);
*/
bool isPreemptible();
} // namespace villas
} // namespace kernel
} // namespace rt
} /* namespace villas */
} /* namespace kernel */
} /* namespace rt */
/** @} */
......@@ -162,4 +162,4 @@ private:
/** @} */
} // namespace villas
} /* namespace villas */
......@@ -34,10 +34,6 @@
#include <villas/common.h>
#ifdef __cplusplus
extern "C" {
#endif
#define LIST_CHUNKSIZE 16
/** Static list initialization */
......@@ -135,7 +131,3 @@ void vlist_extend(struct vlist *l, size_t len, void *val);
/** Remove all elements for which the callback returns a non-zero return code. */
void vlist_filter(struct vlist *l, dtor_cb_t cb);
#ifdef __cplusplus
}
#endif
......@@ -27,10 +27,6 @@
#include <jansson.h>
#ifdef __cplusplus
extern "C" {
#endif
/* The log level which is passed as first argument to print() */
enum log_level {
LOG_LVL_DEBUG,
......@@ -103,7 +99,3 @@ void serror(const char *fmt, ...)
/** Print configuration error and exit. */
void jerror(json_error_t *err, const char *fmt, ...)
__attribute__ ((format(printf, 2, 3)));
#ifdef __cplusplus
}
#endif
......@@ -81,4 +81,4 @@ public:
std::string getLevelName() const;
};
} // namespace villas
} /* namespace villas */
......@@ -61,5 +61,5 @@ using OpalSink_mt = OpalSink<std::mutex>;
using OpalSink_st = OpalSink<spdlog::details::null_mutex>;
} // namespace node
} // namespace villas
} /* namespace node */
} /* namespace villas */
......@@ -329,4 +329,4 @@ private:
static std::map<int, std::unique_ptr<HostDmaRamAllocator>> allocators;
};
} // namespace villas
} /* namespace villas */
......@@ -271,4 +271,4 @@ private:
static MemoryManager* instance;
};
} // namespace villas
} /* namespace villas */
......@@ -135,5 +135,5 @@ protected:
}
};
} // namespace plugin
} // namespace villas
} /* namespace plugin */
} /* namespace villas */
......@@ -28,10 +28,6 @@
#include <time.h>
#ifdef __cplusplus
extern "C" {
#endif
/** We can choose between two periodic task implementations */
//#define PERIODIC_TASK_IMPL NANOSLEEP
#define TIMERFD 1
......@@ -90,7 +86,3 @@ 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
......@@ -62,4 +62,4 @@ public:
}
};
} // namespace villas
} /* namespace villas */
......@@ -28,10 +28,6 @@
#include <time.h>
#ifdef __cplusplus
extern "C" {
#endif
/** Compare two timestamps. Return zero if they are equal */
ssize_t time_cmp(const struct timespec *a, const struct timespec *b);
......@@ -52,7 +48,3 @@ 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
......@@ -68,4 +68,4 @@ public:
int run();
};
} // namespace villas
} /* namespace villas */
......@@ -34,10 +34,6 @@
#include <villas/kernel/kernel.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef bit_TSC
#define bit_TSC (1 << 4)
#endif
......@@ -103,7 +99,3 @@ static uint64_t tsc_now(struct tsc *t)
int tsc_init(struct tsc *t);
uint64_t tsc_rate_to_cycles(struct tsc *t, double rate);
#ifdef __cplusplus
}
#endif
/** Various helper functions.
*
* @file
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
* @copyright 2014-2019, Institute for Automation of Complex Power Systems, EONERC
* @license GNU General Public License (version 3)
*
* VILLAScommon
*
* 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
#ifdef __cplusplus
extern "C" {
#endif
#include <stdlib.h>
#include <stdint.h>
#include <sched.h>
#include <assert.h>
#include <sys/types.h>
#include <signal.h>
#include <villas/config.h>
#include <villas/log.h>
#ifdef __GNUC__
#define LIKELY(x) __builtin_expect((x),1)
#define UNLIKELY(x) __builtin_expect((x),0)
#else
#define LIKELY(x) (x)
#define UNLIKELY(x) (x)
#endif
/* Some color escape codes for pretty log messages */
#define CLR(clr, str) "\e[" XSTR(clr) "m" str "\e[0m"
#define CLR_GRY(str) CLR(30, str) /**< Print str in gray */
#define CLR_RED(str) CLR(31, str) /**< Print str in red */
#define CLR_GRN(str) CLR(32, str) /**< Print str in green */
#define CLR_YEL(str) CLR(33, str) /**< Print str in yellow */
#define CLR_BLU(str) CLR(34, str) /**< Print str in blue */
#define CLR_MAG(str) CLR(35, str) /**< Print str in magenta */
#define CLR_CYN(str) CLR(36, str) /**< Print str in cyan */
#define CLR_WHT(str) CLR(37, str) /**< Print str in white */
#define CLR_BLD(str) CLR( 1, str) /**< Print str in bold */
/* CPP stringification */
#define XSTR(x) STR(x)
#define STR(x) #x
#define CONCAT_DETAIL(x, y) x##y
#define CONCAT(x, y) CONCAT_DETAIL(x, y)
#define UNIQUE(x) CONCAT(x, __COUNTER__)
#ifdef ALIGN
#undef ALIGN
#endif
#define ALIGN(x, a) ALIGN_MASK(x, (uintptr_t) (a) - 1)
#define ALIGN_MASK(x, m) (((uintptr_t) (x) + (m)) & ~(m))
#define IS_ALIGNED(x, a) (ALIGN(x, a) == (uintptr_t) x)
#ifdef __cplusplus
#define SWAP(x,y) do {\
auto &_x = x; \
auto &_y = y; \
x = _y; \
y = _x; \
} while(0)
#else
#define SWAP(x,y) do {\
__auto_type _x = x; \
__auto_type _y = y; \
x = _y; \
y = _x; \
} while(0)
#endif
/** Round-up integer division */
#define CEIL(x, y) (((x) + (y) - 1) / (y))
/** Get nearest up-rounded power of 2 */
#define LOG2_CEIL(x) (1 << (log2i((x) - 1) + 1))
/** Check if the number is a power of 2 */
#define IS_POW2(x) (((x) != 0) && !((x) & ((x) - 1)))
/** Calculate the number of elements in an array. */
#define ARRAY_LEN(a) ( sizeof (a) / sizeof (a)[0] )
/* Return the bigger value */
#ifdef MAX
#undef MAX
#endif
#define MAX(a, b) ({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a > _b ? _a : _b; })
/* Return the smaller value */
#ifdef MIN
#undef MIN
#endif
#define MIN(a, b) ({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a < _b ? _a : _b; })
#ifndef offsetof
#define offsetof(type, member) __builtin_offsetof(type, member)
#endif
#ifndef container_of
#define container_of(ptr, type, member) ({ const typeof( ((type *) 0)->member ) *__mptr = (ptr); \
(type *) ( (char *) __mptr - offsetof(type, member) ); \
})
#endif
#define BITS_PER_LONGLONG (sizeof(long long) * 8)
/* Some helper macros */
#define BITMASK(h, l) (((~0ULL) << (l)) & (~0ULL >> (BITS_PER_LONGLONG - 1 - (h))))
#define BIT(nr) (1UL << (nr))
/** Normal random variate generator using the Box-Muller method
*
* @param m Mean
* @param s Standard deviation
* @return Normal variate random variable (Gaussian)
*/
double box_muller(float m, float s);
/** Double precission uniform random variable */
double randf();
/** Concat formatted string to an existing string.
*
* This function uses realloc() to resize the destination.
* Please make sure to only on dynamic allocated destionations!!!
*
* @param dest A pointer to a malloc() allocated memory region
* @param fmt A format string like for printf()
* @param ... Optional parameters like for printf()
* @retval The the new value of the dest buffer.
*/
char * strcatf(char **dest, const char *fmt, ...)
__attribute__ ((format(printf, 2, 3)));
/** Variadic version of strcatf() */
char * vstrcatf(char **dest, const char *fmt, va_list va)
__attribute__ ((format(printf, 2, 0)));
char * strf(const char *fmt, ...);
char * vstrf(const char *fmt, va_list va);
/** Allocate and initialize memory. */
void * alloc(size_t bytes);
/** Allocate and copy memory. */
void * memdup(const void *src, size_t bytes);
/** Call quit() in the main thread. */
void die();
/** Check assertion and exit if failed. */
#ifndef assert
#define assert(exp) do { \
if (!EXPECT(exp, 0)) \
error("Assertion failed: '%s' in %s(), %s:%d", \
XSTR(exp), __FUNCTION__, __BASE_FILE__, __LINE__); \
} while (0)
#endif
/** Get log2 of long long integers */
static inline int log2i(long long x) {
if (x == 0)
return 1;
return sizeof(x) * 8 - __builtin_clzll(x) - 1;
}
/** Send signal \p sig to main thread. */
void killme(int sig);
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