From 5f4c7d69935a85f032d4984b9c8baab465f95106 Mon Sep 17 00:00:00 2001 From: Pascal Bauer Date: Wed, 4 Dec 2024 18:56:53 +0100 Subject: [PATCH 1/2] add from_directory method Signed-off-by: Pascal Bauer --- .../villas/kernel/devices/ip_device.hpp | 5 ++++- common/lib/kernel/devices/ip_device.cpp | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/common/include/villas/kernel/devices/ip_device.hpp b/common/include/villas/kernel/devices/ip_device.hpp index 2323fe12c..8fb2f7465 100644 --- a/common/include/villas/kernel/devices/ip_device.hpp +++ b/common/include/villas/kernel/devices/ip_device.hpp @@ -24,11 +24,14 @@ class IpDevice : public PlatformDevice { IpDevice() = delete; IpDevice( const std::filesystem::path valid_path) //! Dont allow unvalidated paths - : PlatformDevice(valid_path) {}; + : PlatformDevice(valid_path){}; public: size_t addr() const; std::string ip_name() const; + + static std::vector + from_directory(std::filesystem::path devices_directory); }; } // namespace devices diff --git a/common/lib/kernel/devices/ip_device.cpp b/common/lib/kernel/devices/ip_device.cpp index 3c321b6f6..7628242a3 100644 --- a/common/lib/kernel/devices/ip_device.cpp +++ b/common/lib/kernel/devices/ip_device.cpp @@ -12,6 +12,7 @@ #include #include +#include using villas::kernel::devices::IpDevice; @@ -52,3 +53,22 @@ bool IpDevice::is_path_valid(const std::filesystem::path unsafe_path) { return true; } + +std::vector +IpDevice::from_directory(std::filesystem::path devices_directory) { + std::vector devices; + + const std::vector devicetree_names = + villas::utils::read_names_in_directory(devices_directory); + + for (auto devicetree_name : devicetree_names) { + auto path_to_device = + devices_directory / std::filesystem::path(devicetree_name); + try { + auto device = villas::kernel::devices::IpDevice::from(path_to_device); + devices.push_back(device); + } catch (std::runtime_error &e) { + } + } + return devices; + } \ No newline at end of file From 625d618fcba7a0a5cfa76fe12b3230c07401746d Mon Sep 17 00:00:00 2001 From: Pascal Bauer Date: Wed, 4 Dec 2024 18:57:20 +0100 Subject: [PATCH 2/2] fix formatting Signed-off-by: Pascal Bauer --- common/include/villas/kernel/devices/platform_device.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/include/villas/kernel/devices/platform_device.hpp b/common/include/villas/kernel/devices/platform_device.hpp index 673694387..57c3ec915 100644 --- a/common/include/villas/kernel/devices/platform_device.hpp +++ b/common/include/villas/kernel/devices/platform_device.hpp @@ -29,13 +29,13 @@ class PlatformDevice : public Device { public: PlatformDevice(const std::filesystem::path path) : PlatformDevice(path, std::filesystem::path(PROBE_DEFAULT), - path / std::filesystem::path(OVERRIDE_DEFAULT)) {}; + path / std::filesystem::path(OVERRIDE_DEFAULT)){}; PlatformDevice(const std::filesystem::path path, const std::filesystem::path probe_path, const std::filesystem::path override_path) : m_path(path), m_probe_path(probe_path), - m_override_path(override_path) {}; + m_override_path(override_path){}; // Implement device interface std::optional> driver() const override;