mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
refactor: Move loading of ips to a function.
Signed-off-by: Pascal Bauer <pascal.bauer@rwth-aachen.de>
This commit is contained in:
parent
c01d5b2167
commit
fad17d5f3e
3 changed files with 54 additions and 33 deletions
|
@ -10,6 +10,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
|
@ -56,5 +57,14 @@ protected:
|
|||
Logger logger;
|
||||
};
|
||||
|
||||
class CardFactory {
|
||||
private:
|
||||
static Logger getStaticLogger() { return villas::Log::get("card:factory"); }
|
||||
|
||||
public:
|
||||
static void loadIps(std::shared_ptr<Card> card, json_t *json_ips,
|
||||
const std::filesystem::path &searchPath);
|
||||
};
|
||||
|
||||
} // namespace fpga
|
||||
} // namespace villas
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <villas/exceptions.hpp>
|
||||
#include <villas/fpga/card.hpp>
|
||||
|
||||
using namespace villas;
|
||||
|
@ -125,3 +126,45 @@ bool Card::mapMemoryBlock(const std::shared_ptr<MemoryBlock> block) {
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CardFactory::loadIps(std::shared_ptr<Card> card, json_t *json_ips,
|
||||
const std::filesystem::path &searchPath) {
|
||||
auto logger = getStaticLogger();
|
||||
|
||||
// Load IPs from a separate json file
|
||||
if (!json_is_string(json_ips)) {
|
||||
logger->debug("FPGA IP cores config item is not a string.");
|
||||
throw ConfigError(json_ips, "node-config-fpga-ips",
|
||||
"FPGA IP cores config item is not a string.");
|
||||
}
|
||||
|
||||
if (!searchPath.empty()) {
|
||||
std::filesystem::path json_ips_path =
|
||||
searchPath / json_string_value(json_ips);
|
||||
logger->debug("searching for FPGA IP cors config at {}",
|
||||
json_ips_path.string());
|
||||
json_ips = json_load_file(json_ips_path.c_str(), 0, nullptr);
|
||||
} else {
|
||||
json_ips = json_load_file(json_string_value(json_ips), 0, nullptr);
|
||||
}
|
||||
|
||||
if (json_ips == nullptr) {
|
||||
json_ips = json_load_file(json_string_value(json_ips), 0, nullptr);
|
||||
logger->debug("searching for FPGA IP cors config at {}",
|
||||
json_string_value(json_ips));
|
||||
if (json_ips == nullptr) {
|
||||
throw ConfigError(json_ips, "node-config-fpga-ips",
|
||||
"Failed to find FPGA IP cores config");
|
||||
}
|
||||
}
|
||||
|
||||
if (not json_is_object(json_ips))
|
||||
throw ConfigError(json_ips, "node-config-fpga-ips",
|
||||
"FPGA IP core list must be an object!");
|
||||
|
||||
ip::CoreFactory::make(card.get(), json_ips);
|
||||
|
||||
if (card->ips.empty())
|
||||
throw ConfigError(json_ips, "node-config-fpga-ips",
|
||||
"Cannot initialize IPs of FPGA card {}", card->name);
|
||||
};
|
||||
|
|
|
@ -93,39 +93,7 @@ PCIeCardFactory::make(json_t *json_card, std::string card_name,
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
// Load IPs from a separate json file
|
||||
if (!json_is_string(json_ips)) {
|
||||
logger->debug("FPGA IP cores config item is not a string.");
|
||||
throw ConfigError(json_ips, "node-config-fpga-ips",
|
||||
"FPGA IP cores config item is not a string.");
|
||||
}
|
||||
if (!searchPath.empty()) {
|
||||
std::filesystem::path json_ips_path =
|
||||
searchPath / json_string_value(json_ips);
|
||||
logger->debug("searching for FPGA IP cors config at {}",
|
||||
json_ips_path.string());
|
||||
json_ips = json_load_file(json_ips_path.c_str(), 0, nullptr);
|
||||
} else {
|
||||
json_ips = json_load_file(json_string_value(json_ips), 0, nullptr);
|
||||
}
|
||||
if (json_ips == nullptr) {
|
||||
json_ips = json_load_file(json_string_value(json_ips), 0, nullptr);
|
||||
logger->debug("searching for FPGA IP cors config at {}",
|
||||
json_string_value(json_ips));
|
||||
if (json_ips == nullptr) {
|
||||
throw ConfigError(json_ips, "node-config-fpga-ips",
|
||||
"Failed to find FPGA IP cores config");
|
||||
}
|
||||
}
|
||||
|
||||
if (not json_is_object(json_ips))
|
||||
throw ConfigError(json_ips, "node-config-fpga-ips",
|
||||
"FPGA IP core list must be an object!");
|
||||
|
||||
ip::CoreFactory::make(card.get(), json_ips);
|
||||
if (card->ips.empty())
|
||||
throw ConfigError(json_ips, "node-config-fpga-ips",
|
||||
"Cannot initialize IPs of FPGA card {}", card_name);
|
||||
CardFactory::loadIps(card, json_ips, searchPath);
|
||||
|
||||
if (not card->check())
|
||||
throw RuntimeError("Checking of FPGA card {} failed", card_name);
|
||||
|
|
Loading…
Add table
Reference in a new issue