Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ find_package(OpenSSL 1.0.0 REQUIRED)
find_package(PkgConfig REQUIRED)
find_package(spdlog REQUIRED)
find_package(Threads REQUIRED)
find_package(nlohmann_json REQUIRED)
find_package(OpenMP)
find_package(IBVerbs)
find_package(RDMACM)
Expand Down
47 changes: 47 additions & 0 deletions common/include/villas/json.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* Json parsing and support code.
*
* Author: Philipp Jungkamp <philipp.jungkamp@rwth-aachen.de>
* SPDX-FileCopyrightText: 2024-2025 Institute for Automation of Complex Power Systems, RWTH Aachen University
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once

#include <fmt/ostream.h>
#include <nlohmann/json.hpp>

#include <villas/fs.hpp>

extern template class nlohmann::basic_json<>;

namespace villas {

using Json = nlohmann::json;
using JsonPointer = Json::json_pointer;

// forward declaration for villas/jansson.hpp compatibility header
class JanssonPtr;
void to_json(Json &json, JanssonPtr const &jansson);
void from_json(Json const &json, JanssonPtr &jansson);

struct LoadConfigFileOptions {
bool allow_libconfig = false;
bool allow_environment = false;
bool allow_include = false;
};

// load a configuration file
Json load_config_file(fs::path const &path, LoadConfigFileOptions const &opts);

}; // namespace villas

// forward declaration for libjansson's json_t
struct json_t;

// convert borrowed libjansson
void to_json(villas::Json &json, json_t const *jansson);

template <> // format nlohmann::json using operator<<
struct fmt::formatter<villas::Json> : ostream_formatter {};

template <> // format json_pointer using operator<<
struct fmt::formatter<villas::JsonPointer> : ostream_formatter {};
4 changes: 4 additions & 0 deletions common/include/villas/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ template <class... Ts> struct overloaded : Ts... {
// Explicit deduction guide (not needed as of C++20)
template <class... Ts> overloaded(Ts...) -> overloaded<Ts...>;

// glob-style filesystem pattern matching
std::vector<fs::path> glob(fs::path const &pattern,
std::span<const fs::path> searchDirectories);

void write_to_file(std::string data, const fs::path file);

namespace base64 {
Expand Down
2 changes: 2 additions & 0 deletions common/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ add_library(villas-common SHARED
cpuset.cpp
dsp/pid.cpp
hist.cpp
json.cpp
kernel/kernel.cpp
kernel/rt.cpp
list.cpp
Expand Down Expand Up @@ -55,6 +56,7 @@ target_include_directories(villas-common PUBLIC
)

target_link_libraries(villas-common PUBLIC
nlohmann_json::nlohmann_json
PkgConfig::JANSSON
PkgConfig::UUID
${OPENSSL_LIBRARIES}
Expand Down
Loading
Loading