diff --git a/include/villas/config_helper.h b/include/villas/config_helper.hpp similarity index 81% rename from include/villas/config_helper.h rename to include/villas/config_helper.hpp index 1706eb8ea..23ae8cb5d 100644 --- a/include/villas/config_helper.h +++ b/include/villas/config_helper.hpp @@ -30,28 +30,21 @@ #include -#ifdef __cplusplus -extern "C" { -#endif - #ifdef LIBCONFIG_FOUND -/* Convert a libconfig object to a jansson object */ +/** Convert a libconfig object to a jansson object */ json_t *config_to_json(config_setting_t *cfg); -/* Convert a jansson object into a libconfig object. */ +/** Convert a jansson object into a libconfig object. */ int json_to_config(json_t *json, config_setting_t *parent); #endif /* LIBCONFIG_FOUND */ -/* Create a JSON object from command line parameters. */ -json_t *json_load_cli(int argc, const char *argv[]); - int json_object_extend_str(json_t *orig, const char *str); void json_object_extend_key_value(json_t *obj, const char *key, const char *value); -/* Merge two JSON objects recursively. */ +void json_object_extend_key_value_token(json_t *obj, const char *key, const char *value); + +/** Merge two JSON objects recursively. */ int json_object_extend(json_t *orig, json_t *merge); -#ifdef __cplusplus -} -#endif +json_t * json_load_cli(int argc, const char *argv[]); diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 2049755a0..3d5278e8e 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -41,6 +41,7 @@ endif() set(LIB_SRC super_node.cpp + config_helper.cpp memory/heap.c memory/hugepage.c memory/managed.c @@ -56,7 +57,6 @@ set(LIB_SRC stats.c mapping.c shmem.c - config_helper.c signal.c pool.c queue.c diff --git a/lib/config_helper.c b/lib/config_helper.cpp similarity index 94% rename from lib/config_helper.c rename to lib/config_helper.cpp index 6c3b7471a..945c72640 100644 --- a/lib/config_helper.c +++ b/lib/config_helper.cpp @@ -20,10 +20,13 @@ * along with this program. If not, see . *********************************************************************************/ +#include +#include + #include #include -#include +#include #include #ifdef LIBCONFIG_FOUND @@ -168,7 +171,7 @@ int json_to_config(json_t *json, config_setting_t *parent) void json_object_extend_key_value_token(json_t *obj, const char *key, const char *value) { char *str = strdup(value); - char *delim = ","; + const char *delim = ","; char *lasts; char *token = strtok_r(str, delim, &lasts); @@ -189,7 +192,7 @@ void json_object_extend_key_value(json_t *obj, const char *key, const char *valu double real; long integer; - json_t *arr, *new, *existing, *subobj; + json_t *arr, *add, *existing, *subobj; /* Is the key pointing to an object? */ subobj = obj; @@ -203,10 +206,10 @@ void json_object_extend_key_value(json_t *obj, const char *key, const char *valu if (existing) subobj = existing; else { - new = json_object(); - json_object_set(subobj, key1, new); + add = json_object(); + json_object_set(subobj, key1, add); - subobj = new; + subobj = add; } key1 = key2; @@ -216,35 +219,35 @@ void json_object_extend_key_value(json_t *obj, const char *key, const char *valu /* Try to parse as integer */ integer = strtol(value, &end, 0); if (*end == 0) { - new = json_integer(integer); + add = json_integer(integer); goto success; } /* Try to parse as floating point */ real = strtod(value, &end); if (*end == 0) { - new = json_real(real); + add = json_real(real); goto success; } /* Try to parse special types */ if (!strcmp(value, "true")) { - new = json_true(); + add = json_true(); goto success; } if (!strcmp(value, "false")) { - new = json_false(); + add = json_false(); goto success; } if (!strcmp(value, "null")) { - new = json_null(); + add = json_null(); goto success; } /* Fallback to string */ - new = json_string(value); + add = json_string(value); success: /* Does the key already exist? @@ -259,10 +262,10 @@ success: json_array_append(arr, existing); } - json_array_append(arr, new); + json_array_append(arr, add); } else - json_object_set(subobj, key1, new); + json_object_set(subobj, key1, add); } json_t * json_load_cli(int argc, const char *argv[]) diff --git a/lib/super_node.cpp b/lib/super_node.cpp index dc2aa3aee..ebdac6b70 100644 --- a/lib/super_node.cpp +++ b/lib/super_node.cpp @@ -34,7 +34,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/villas-hook.cpp b/src/villas-hook.cpp index d8dbc0312..034cf4122 100644 --- a/src/villas-hook.cpp +++ b/src/villas-hook.cpp @@ -40,7 +40,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/villas-pipe.cpp b/src/villas-pipe.cpp index 7413ed245..3d9d53e3d 100644 --- a/src/villas-pipe.cpp +++ b/src/villas-pipe.cpp @@ -34,7 +34,7 @@ #include #include -#include +#include #include #include #include diff --git a/tests/unit/config_json.cpp b/tests/unit/config_json.cpp index 5dd1c1e63..7e9150343 100644 --- a/tests/unit/config_json.cpp +++ b/tests/unit/config_json.cpp @@ -28,7 +28,7 @@ #include #include -#include +#include const char *cfg_example = "test : \n" "{\n" diff --git a/tests/unit/json.cpp b/tests/unit/json.cpp index 4fcf6e21d..052aca395 100644 --- a/tests/unit/json.cpp +++ b/tests/unit/json.cpp @@ -25,7 +25,7 @@ #include #include -#include +#include using str = std::basic_string, criterion::allocator>; diff --git a/tools/conf2json.cpp b/tools/conf2json.cpp index 3a6fb4077..548bc32c8 100644 --- a/tools/conf2json.cpp +++ b/tools/conf2json.cpp @@ -26,7 +26,7 @@ #include #include -#include +#include #include #include