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

Merge branch 'fix-libext' into 'develop'

Fix libvillas-ext linking problems

See merge request !17
This commit is contained in:
Steffen Vogel 2017-04-26 14:50:52 +02:00
commit a7a621ebe5
18 changed files with 159 additions and 76 deletions

19
include/villas/atomic.h Normal file
View file

@ -0,0 +1,19 @@
/** Workaround for differently named atomic types in C/C++
*
* @file
* @author Georg Reinke <georg.reinke@rwth-aachen.de>
* @copyright 2017, Institute for Automation of Complex Power Systems, EONERC
*********************************************************************************/
#ifdef __cplusplus
#include <atomic>
typedef std::atomic_int atomic_int;
typedef std::atomic_size_t atomic_size_t;
#else
#include <stdatomic.h>
#endif

View file

@ -22,6 +22,7 @@
#include <string.h>
#include <stdbool.h>
#include "log_config.h"
#include "queue.h"
#include "list.h"
#include "super_node.h"
@ -111,4 +112,4 @@ int hook_cmp_priority(const void *a, const void *b);
* hooks = [ "print" ]
* }
*/
int hook_parse_list(struct list *list, config_setting_t *cfg, struct path *p);
int hook_parse_list(struct list *list, config_setting_t *cfg, struct path *p);

View file

@ -7,11 +7,15 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <stdarg.h>
#include <time.h>
#include <libconfig.h>
#include "common.h"
#include "log_config.h"
#ifdef __GNUC__
#define INDENT int __attribute__ ((__cleanup__(log_outdent), unused)) _old_indent = log_indent(1);
@ -81,6 +85,10 @@ struct log {
FILE *file;
};
/** The global log instance. */
struct log *global_log;
struct log default_log;
/** Initialize log object */
int log_init(struct log *l, int level, long faciltities);
@ -118,9 +126,6 @@ void log_outdent(int *);
*/
int log_set_facility_expression(struct log *l, const char *expression);
/** Parse logging configuration. */
int log_parse(struct log *l, config_setting_t *cfg);
/** Logs variadic messages to stdout.
*
* @param lvl The log level
@ -164,6 +169,6 @@ void error(const char *fmt, ...)
void serror(const char *fmt, ...)
__attribute__ ((format(printf, 1, 2)));
/** Print configuration error and exit. */
void cerror(config_setting_t *cfg, const char *fmt, ...)
__attribute__ ((format(printf, 2, 3)));
#ifdef __cplusplus
}
#endif

View file

@ -0,0 +1,22 @@
/** Logging routines that depend on libconfig.
*
* @file
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
* @copyright 2017, Institute for Automation of Complex Power Systems, EONERC
*********************************************************************************/
#pragma once
struct log;
#include <libconfig.h>
#include "log.h"
/** Parse logging configuration. */
int log_parse(struct log *l, config_setting_t *cfg);
/** Print configuration error and exit. */
void cerror(config_setting_t *cfg, const char *fmt, ...)
__attribute__ ((format(printf, 2, 3)));

View file

@ -33,11 +33,12 @@
#pragma once
#include <stddef.h>
#include <stdint.h>
#include <stdatomic.h>
#include <unistd.h>
#include "atomic.h"
#include "common.h"
/* Forward declarations */

View file

@ -7,10 +7,15 @@
#pragma once
#include "atomic.h"
#ifdef __cplusplus
extern "C" {
#endif
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <stdatomic.h>
#include <time.h>
#include <sys/types.h>
@ -81,3 +86,7 @@ int sample_get_data_format(struct sample *s, int idx);
/** Set number representation for a single value of a sample. */
int sample_set_data_format(struct sample *s, int idx, enum sample_data_format fmt);
#ifdef __cplusplus
}
#endif

View file

@ -13,6 +13,10 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "pool.h"
#include "queue.h"
#include "queue_signalled.h"
@ -80,3 +84,7 @@ int shmem_shared_write(struct shmem_shared *shm, struct sample *smps[], unsigned
size_t shmem_total_size(int insize, int outsize, int sample_size);
/** @} */
#ifdef __cplusplus
}
#endif

View file

@ -2,9 +2,9 @@ LIBEXT_NAME = libvillas-ext
LIBEXT_ABI_VERSION = 1
LIBEXT = $(BUILDDIR)/$(LIBEXT_NAME).so.$(LIBEXT_ABI_VERSION)
LIBEXT_SRCS += $(addprefix lib/, sample.c node.c queue.c queue_signalled.c \
memory.c shmem.c utils.c kernel/kernel.c log.c list.c \
plugin.c timing.c \
LIBEXT_SRCS += $(addprefix lib/, sample.c queue.c queue_signalled.c \
memory.c log.c shmem.c utils.c kernel/kernel.c list.c \
timing.c \
)
LIBEXT_LDFLAGS = -shared
@ -25,4 +25,4 @@ install-libvillas-ext: libvillas-ext
clean-libvillas-ext:
rm -rf $(BUILDDIR)/lib $(LIBEXT)
.PHONY: install-libvillas-ext clean-libvillas-ext $(LIBEXT_NAME)
.PHONY: install-libvillas-ext clean-libvillas-ext $(LIBEXT_NAME)

View file

@ -6,7 +6,7 @@ LIB = $(BUILDDIR)/$(LIB_NAME).so.$(LIB_ABI_VERSION)
LIB_SRCS += $(addprefix lib/nodes/, file.c cbuilder.c shmem.c) \
$(addprefix lib/kernel/, kernel.c rt.c) \
$(addprefix lib/, sample.c path.c node.c hook.c \
log.c utils.c super_node.c hist.c timing.c pool.c \
log.c log_config.c utils.c super_node.c hist.c timing.c pool.c \
list.c queue.c queue_signalled.c memory.c advio.c web.c api.c \
plugin.c node_type.c stats.c mapping.c sample_io.c shmem.c \
json.c crypt.c compat.c \
@ -94,4 +94,4 @@ install-libvillas: libvillas
clean-libvillas:
rm -rf $(BUILDDIR)/lib $(LIB)
.PHONY: install-libvillas clean-libvillas $(LIB_NAME)
.PHONY: install-libvillas clean-libvillas $(LIB_NAME)

View file

@ -8,6 +8,7 @@
#include "config.h"
#include "log.h"
#include "log_config.h"
#include "list.h"
#include "utils.h"
@ -283,4 +284,4 @@ int fpga_card_reset(struct fpga_card *c)
c->state = STATE_INITIALIZED;
return 0;
}
}

View file

@ -6,6 +6,7 @@
#include <libconfig.h>
#include "log_config.h"
#include "log.h"
#include "plugin.h"
@ -150,4 +151,4 @@ struct fpga_ip_type * fpga_ip_type_lookup(const char *vstr)
}
return NULL;
}
}

View file

@ -6,6 +6,7 @@
**********************************************************************************/
#include "log.h"
#include "log_config.h"
#include "plugin.h"
#include "fpga/ip.h"
@ -114,4 +115,4 @@ static struct plugin p = {
}
};
REGISTER_PLUGIN(&p)
REGISTER_PLUGIN(&p)

View file

@ -11,6 +11,7 @@
#include "utils.h"
#include "log.h"
#include "log_config.h"
#include "plugin.h"
#include "fpga/ip.h"

View file

@ -8,6 +8,7 @@
#include "list.h"
#include "log.h"
#include "log_config.h"
#include "plugin.h"
#include "fpga/ip.h"
@ -202,4 +203,4 @@ static struct plugin p = {
}
};
REGISTER_PLUGIN(&p)
REGISTER_PLUGIN(&p)

View file

@ -96,4 +96,4 @@ static struct plugin p = {
REGISTER_PLUGIN(&p)
/** @} */
/** @} */

View file

@ -10,9 +10,9 @@
#include <time.h>
#include <errno.h>
#include "config.h"
#include "log.h"
#include "utils.h"
#include "config.h"
#include "timing.h"
#ifdef ENABLE_OPAL_ASYNC
@ -23,8 +23,8 @@
#endif
/** The global log instance. */
static struct log *log;
static struct log default_log = {
struct log *global_log;
struct log default_log = {
.level = V,
.facilities = LOG_ALL,
.file = NULL,
@ -66,7 +66,7 @@ static __thread int indent = 0;
int log_init(struct log *l, int level, long facilitites)
{
/* Register this log instance globally */
log = l;
global_log = l;
l->level = level;
l->facilities = facilitites;
@ -78,24 +78,6 @@ int log_init(struct log *l, int level, long facilitites)
return 0;
}
int log_parse(struct log *l, config_setting_t *cfg)
{
const char *facilities;
if (!config_setting_is_group(cfg))
cerror(cfg, "Setting 'log' must be a group.");
config_setting_lookup_int(cfg, "level", &l->level);
config_setting_lookup_string(cfg, "file", &l->path);
if (config_setting_lookup_string(cfg, "facilities", &facilities))
log_set_facility_expression(l, facilities);
l->state = STATE_PARSED;
return 0;
}
int log_start(struct log *l)
{
l->epoch = time_now();
@ -129,7 +111,7 @@ int log_destroy(struct log *l)
{
default_log.epoch = l->epoch;
log = NULL;
global_log = NULL;
l->state = STATE_DESTROYED;
@ -243,14 +225,14 @@ void line()
char buf[LOG_WIDTH];
memset(buf, 0x71, sizeof(buf));
log_print(log, "", "\b" ACS("%.*s"), LOG_WIDTH, buf);
log_print(global_log, "", "\b" ACS("%.*s"), LOG_WIDTH, buf);
}
void debug(long class, const char *fmt, ...)
{
va_list ap;
struct log *l = log ? log : &default_log;
struct log *l = global_log ? global_log : &default_log;
int lvl = class & 0xFF;
int fac = class & ~0xFF;
@ -266,7 +248,7 @@ void info(const char *fmt, ...)
{
va_list ap;
struct log *l = log ? log : &default_log;
struct log *l = global_log ? global_log : &default_log;
va_start(ap, fmt);
log_vprint(l, LOG_LVL_INFO, fmt, ap);
@ -277,7 +259,7 @@ void warn(const char *fmt, ...)
{
va_list ap;
struct log *l = log ? log : &default_log;
struct log *l = global_log ? global_log : &default_log;
va_start(ap, fmt);
log_vprint(l, LOG_LVL_WARN, fmt, ap);
@ -288,7 +270,7 @@ void stats(const char *fmt, ...)
{
va_list ap;
struct log *l = log ? log : &default_log;
struct log *l = global_log ? global_log : &default_log;
va_start(ap, fmt);
log_vprint(l, LOG_LVL_STATS, fmt, ap);
@ -299,7 +281,7 @@ void error(const char *fmt, ...)
{
va_list ap;
struct log *l = log ? log : &default_log;
struct log *l = global_log ? global_log : &default_log;
va_start(ap, fmt);
log_vprint(l, LOG_LVL_ERROR, fmt, ap);
@ -313,7 +295,7 @@ void serror(const char *fmt, ...)
va_list ap;
char *buf = NULL;
struct log *l = log ? log : &default_log;
struct log *l = global_log ? global_log : &default_log;
va_start(ap, fmt);
vstrcatf(&buf, fmt, ap);
@ -324,27 +306,3 @@ void serror(const char *fmt, ...)
free(buf);
die();
}
void cerror(config_setting_t *cfg, const char *fmt, ...)
{
va_list ap;
char *buf = NULL;
const char *file;
int line;
struct log *l = log ? log : &default_log;
va_start(ap, fmt);
vstrcatf(&buf, fmt, ap);
va_end(ap);
line = config_setting_source_line(cfg);
file = config_setting_source_file(cfg);
if (!file)
file = config_setting_get_hook(config_root_setting(cfg->config));
log_print(l, LOG_LVL_ERROR, "%s in %s:%u", buf, file, line);
free(buf);
die();
}

55
lib/log_config.c Normal file
View file

@ -0,0 +1,55 @@
/** Logging routines that depend on libconfig.
*
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
* @copyright 2017, Institute for Automation of Complex Power Systems, EONERC
*********************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "config.h"
#include "log.h"
#include "log_config.h"
#include "utils.h"
int log_parse(struct log *l, config_setting_t *cfg)
{
const char *facilities;
if (!config_setting_is_group(cfg))
cerror(cfg, "Setting 'log' must be a group.");
config_setting_lookup_int(cfg, "level", &l->level);
config_setting_lookup_string(cfg, "file", &l->path);
if (config_setting_lookup_string(cfg, "facilities", &facilities))
log_set_facility_expression(l, facilities);
l->state = STATE_PARSED;
return 0;
}
void cerror(config_setting_t *cfg, const char *fmt, ...)
{
va_list ap;
char *buf = NULL;
const char *file;
int line;
struct log *l = global_log ? global_log : &default_log;
va_start(ap, fmt);
vstrcatf(&buf, fmt, ap);
va_end(ap);
line = config_setting_source_line(cfg);
file = config_setting_source_file(cfg);
if (!file)
file = config_setting_get_hook(config_root_setting(cfg->config));
log_print(l, LOG_LVL_ERROR, "%s in %s:%u", buf, file, line);
free(buf);
die();
}

View file

@ -38,7 +38,7 @@ $(BUILDDIR)/src/%.o: src/%.c $(BUILDDIR)/defines | $$(dir $$@)
$(CC) $(SRC_CFLAGS) -c $< -o $@
# Build villas-shmem only with libvillas-ext (to ensure that libext contains everything needed)
$(BUILDDIR)/villas-shmem: $(BUILDDIR)/src/shmem.o $(LIBS) libvillas-ext
$(BUILDDIR)/villas-shmem: $(BUILDDIR)/src/shmem.o libvillas-ext
$(CC) $(SRC_LDFLAGS) $(BUILDDIR)/src/shmem.o $(filter-out -lvillas,$(SRC_LDLIBS)) -lvillas-ext -o $@
# Link target executables