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

add from_directory method

Signed-off-by: Pascal Bauer <pascal.bauer@rwth-aachen.de>
This commit is contained in:
Pascal Bauer 2024-12-04 18:56:53 +01:00 committed by Steffen Vogel
parent ed6cd78b2f
commit 22a5f54428
2 changed files with 24 additions and 1 deletions

View file

@ -24,11 +24,14 @@ private:
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<villas::kernel::devices::IpDevice>
from_directory(std::filesystem::path devices_directory);
};
} // namespace devices

View file

@ -12,6 +12,7 @@
#include <villas/exceptions.hpp>
#include <villas/kernel/devices/ip_device.hpp>
#include <villas/utils.hpp>
using villas::kernel::devices::IpDevice;
@ -52,3 +53,22 @@ bool IpDevice::is_path_valid(const std::filesystem::path unsafe_path) {
return true;
}
std::vector<villas::kernel::devices::IpDevice>
IpDevice::from_directory(std::filesystem::path devices_directory) {
std::vector<villas::kernel::devices::IpDevice> devices;
const std::vector<std::string> 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;
}