mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
added new conversion helper for libconfig => libjansson objects
This commit is contained in:
parent
399f29c496
commit
3a734eb80c
3 changed files with 49 additions and 3 deletions
|
@ -103,7 +103,15 @@ int strftimespec(char *s, size_t max, const char *format, struct timespec *ts)
|
|||
* @param set A cpu bitmask
|
||||
* @return The opaque cpu_set_t datatype
|
||||
*/
|
||||
cpu_set_t to_cpu_set(int set);
|
||||
cpu_set_t integer_to_cpuset(int set);
|
||||
|
||||
#ifdef WITH_JANSSON
|
||||
#include <jansson.h>
|
||||
|
||||
/* Convert a libconfig object to a libjansson object */
|
||||
json_t * config_to_json(config_setting_t *cfg);
|
||||
|
||||
#endif
|
||||
|
||||
/** Allocate and initialize memory. */
|
||||
void * alloc(size_t bytes);
|
||||
|
|
40
lib/utils.c
40
lib/utils.c
|
@ -124,7 +124,7 @@ char * vstrcatf(char **dest, const char *fmt, va_list ap)
|
|||
return *dest;
|
||||
}
|
||||
|
||||
cpu_set_t to_cpu_set(int set)
|
||||
cpu_set_t integer_to_cpuset(int set)
|
||||
{
|
||||
cpu_set_t cset;
|
||||
|
||||
|
@ -138,6 +138,44 @@ cpu_set_t to_cpu_set(int set)
|
|||
return cset;
|
||||
}
|
||||
|
||||
#ifdef WITH_JANSSON
|
||||
json_t * config_to_json(config_setting_t *cfg)
|
||||
{
|
||||
switch (config_setting_type(cfg)) {
|
||||
case CONFIG_TYPE_INT: return json_integer(config_setting_get_int(cfg));
|
||||
case CONFIG_TYPE_INT64: return json_integer(config_setting_get_int64(cfg));
|
||||
case CONFIG_TYPE_FLOAT: return json_real(config_setting_get_float(cfg));
|
||||
case CONFIG_TYPE_STRING: return json_string(config_setting_get_string(cfg));
|
||||
case CONFIG_TYPE_BOOL: return json_boolean(config_setting_get_bool(cfg));
|
||||
|
||||
case CONFIG_TYPE_ARRAY:
|
||||
case CONFIG_TYPE_LIST: {
|
||||
json_t *json = json_array();
|
||||
|
||||
for (int i = 0; i < config_setting_length(cfg); i++)
|
||||
json_array_append_new(json, config_to_json(config_setting_get_elem(cfg, i)));
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
case CONFIG_TYPE_GROUP: {
|
||||
json_t *json = json_object();
|
||||
|
||||
for (int i = 0; i < config_setting_length(cfg); i++)
|
||||
json_object_set_new(json,
|
||||
config_setting_name(config_setting_get_elem(cfg, i)),
|
||||
config_to_json(config_setting_get_elem(cfg, i))
|
||||
);
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
default:
|
||||
return json_object();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void * alloc(size_t bytes)
|
||||
{
|
||||
void *p = malloc(bytes);
|
||||
|
|
|
@ -78,7 +78,7 @@ static void realtime_init()
|
|||
|
||||
/* Pin threads to CPUs by setting the affinity */
|
||||
if (settings.affinity) {
|
||||
cpu_set_t cset = to_cpu_set(settings.affinity);
|
||||
cpu_set_t cset = integer_to_cpuset(settings.affinity);
|
||||
if (sched_setaffinity(0, sizeof(cset), &cset))
|
||||
serror("Failed to set CPU affinity to '%#x'", settings.affinity);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue