mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
initial commit
Signed-off-by: Pascal Bauer <pascal.bauer@rwth-aachen.de>
This commit is contained in:
parent
f8b8b7af29
commit
585998761e
2 changed files with 92 additions and 0 deletions
53
common/include/villas/kernel/devices/platform_driver.hpp
Normal file
53
common/include/villas/kernel/devices/platform_driver.hpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
/* PlatformDriver
|
||||
*
|
||||
* Author: Pascal Bauer <pascal.bauer@rwth-aachen.de>
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2023-2024 Pascal Bauer <pascal.bauer@rwth-aachen.de>
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
namespace villas {
|
||||
namespace kernel {
|
||||
namespace devices {
|
||||
|
||||
class PlatformDevice;
|
||||
|
||||
class PlatformDriver {
|
||||
private:
|
||||
static constexpr char BIND_DEFAULT[] = "bind";
|
||||
static constexpr char UNBIND_DEFAULT[] = "unbind";
|
||||
|
||||
public:
|
||||
const std::filesystem::path path;
|
||||
|
||||
private:
|
||||
const std::filesystem::path bind_path;
|
||||
const std::filesystem::path unbind_path;
|
||||
|
||||
public:
|
||||
PlatformDriver(const std::filesystem::path path)
|
||||
: PlatformDriver(path, path / std::filesystem::path(BIND_DEFAULT),
|
||||
path / std::filesystem::path(UNBIND_DEFAULT)){};
|
||||
|
||||
PlatformDriver(const std::filesystem::path path,
|
||||
const std::filesystem::path bind_path,
|
||||
const std::filesystem::path unbind_path)
|
||||
: path(path), bind_path(bind_path), unbind_path(unbind_path){};
|
||||
|
||||
std::string name() const;
|
||||
void attach(const PlatformDevice &device) const;
|
||||
|
||||
private:
|
||||
void bind(const PlatformDevice &device) const;
|
||||
void unbind(const PlatformDevice &device) const;
|
||||
void override(const PlatformDevice &device) const;
|
||||
};
|
||||
|
||||
} // namespace devices
|
||||
} // namespace kernel
|
||||
} // namespace villas
|
39
common/lib/kernel/devices/platform_driver.cpp
Normal file
39
common/lib/kernel/devices/platform_driver.cpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
/* PlatformDriver
|
||||
*
|
||||
* Author: Pascal Bauer <pascal.bauer@rwth-aachen.de>
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2023-2024 Pascal Bauer <pascal.bauer@rwth-aachen.de>
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <villas/kernel/devices/platform_device.hpp>
|
||||
#include <villas/kernel/devices/utils.hpp>
|
||||
|
||||
using villas::kernel::devices::PlatformDevice,
|
||||
villas::kernel::devices::PlatformDriver;
|
||||
using villas::kernel::devices::utils::write_to_file;
|
||||
|
||||
std::string PlatformDriver::name() const {
|
||||
size_t pos = path.u8string().rfind('/');
|
||||
return path.u8string().substr(pos + 1);
|
||||
}
|
||||
|
||||
void PlatformDriver::bind(const PlatformDevice &device) const {
|
||||
write_to_file(device.name(), this->bind_path);
|
||||
};
|
||||
|
||||
void PlatformDriver::unbind(const PlatformDevice &device) const {
|
||||
write_to_file(device.name(), this->unbind_path);
|
||||
};
|
||||
|
||||
void PlatformDriver::override(const PlatformDevice &device) const {
|
||||
write_to_file(this->name(), device.override_path());
|
||||
};
|
||||
|
||||
void PlatformDriver::attach(const PlatformDevice &device) const {
|
||||
if (device.driver().has_value()) {
|
||||
device.driver().value().unbind(device);
|
||||
}
|
||||
this->override(device);
|
||||
device.probe();
|
||||
};
|
Loading…
Add table
Reference in a new issue