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

refactor ip_device_reader

This commit is contained in:
Pascal Bauer 2024-09-06 13:06:12 +02:00 committed by Niklas Eiling
parent 7fe15cbd05
commit aedeca5c3b
2 changed files with 11 additions and 10 deletions

View file

@ -20,21 +20,22 @@
class IpDeviceReader {
public:
const std::vector<std::string> devicetree_names;
std::vector<villas::kernel::devices::IpDevice> devices;
std::vector<villas::kernel::devices::IpDevice>
read(std::filesystem::path devices_directory) const {
std::vector<villas::kernel::devices::IpDevice> devices;
IpDeviceReader(std::filesystem::path devices_directory)
: devicetree_names(
villas::kernel::devices::utils::read_names_in_directory(
devices_directory)) {
for (auto devicetree_name : this->devicetree_names) {
const std::vector<std::string> devicetree_names =
villas::kernel::devices::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);
this->devices.push_back(device);
devices.push_back(device);
} catch (std::runtime_error &e) {
}
}
return devices;
}
};

View file

@ -39,8 +39,8 @@ void PlatformCard::connectVFIOtoIps(
// Read devices from Devicetree
const std::filesystem::path PLATFORM_DEVICES_DIRECTORY(
"/sys/bus/platform/devices");
auto dtr = IpDeviceReader(PLATFORM_DEVICES_DIRECTORY);
std::vector<IpDevice> devices = dtr.devices;
std::vector<IpDevice> devices =
IpDeviceReader().read(PLATFORM_DEVICES_DIRECTORY);
// Match devices and ips
DeviceIpMatcher matcher(devices, configuredIps);