Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbc0b05b

Browse files
pointbazaarspinler
authored andcommitted
entity-manager: fix type for schema directory
Change the type of schema directory from`constexpr const char*` to `std::filesystem::path` and pass it throughthe appropriate functions instead of declaring in the header.This avoids e.g. testcases gaining a dependency on PACKAGE_DIR symboland allows them to pass in a different directory for schemas, as thepackage is usually not installed in a development / ci workflow.Tested:EM starts normally, configuration is loaded as expected and appears onDBus.```Nov 10 15:56:54 s8030-bmc-30303035c0c1 entity-manager[20982]: Inventory Added: MBX 1.57 ChassisNov 10 15:56:54 s8030-bmc-30303035c0c1 entity-manager[20982]: Inventory Added: Supermicro PWS 920P SQ 2Nov 10 15:56:54 s8030-bmc-30303035c0c1 entity-manager[20982]: Inventory Added: Tyan S8030 BaseboardNov 10 15:56:54 s8030-bmc-30303035c0c1 entity-manager[20982]: Inventory Added: Supermicro PWS 920P SQ 3```Change-Id: Iecc21ba0e1045bd8b37f4a0cc0e2ef25d06da18cSigned-off-by: Alexander Hansen <alexander.hansen@9elements.com>
1 parentae71a61 commitbc0b05b

File tree

7 files changed

+29
-17
lines changed

7 files changed

+29
-17
lines changed

‎src/entity_manager/configuration.cpp‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
#include<vector>
1717

1818
Configuration::Configuration(
19-
const std::vector<std::filesystem::path>& configurationDirectories) :
19+
const std::vector<std::filesystem::path>& configurationDirectories,
20+
const std::filesystem::path& schemaDirectory) :
21+
schemaDirectory(schemaDirectory),
2022
configurationDirectories(configurationDirectories)
2123
{
2224
loadConfigurations();
@@ -39,8 +41,7 @@ void Configuration::loadConfigurations()
3941
return;
4042
}
4143

42-
std::ifstreamschemaStream(
43-
std::string(schemaDirectory) +"/" + globalSchema);
44+
std::ifstreamschemaStream(schemaDirectory /"global.json");
4445
if (!schemaStream.good())
4546
{
4647
lg2::error("Cannot open schema file, cannot validate JSON, exiting");

‎src/entity_manager/configuration.hpp‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@
55
#include<unordered_set>
66
#include<vector>
77

8-
constexprconstchar* globalSchema ="global.json";
98
constexprconstchar* currentConfiguration ="/var/configuration/system.json";
10-
constexprconstchar* schemaDirectory = PACKAGE_DIR"schemas";
119

1210
classConfiguration
1311
{
1412
public:
1513
explicitConfiguration(
16-
const std::vector<std::filesystem::path>& configurationDirectories);
14+
const std::vector<std::filesystem::path>& configurationDirectories,
15+
const std::filesystem::path& schemaDirectory);
1716
std::unordered_set<std::string> probeInterfaces;
1817
std::vector<nlohmann::json> configurations;
1918

19+
const std::filesystem::path schemaDirectory;
20+
2021
protected:
2122
voidloadConfigurations();
2223
voidfilterProbeInterfaces();

‎src/entity_manager/dbus_interface.cpp‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ const std::regex illegalDbusPathRegex("[^A-Za-z0-9_.]");
1818
const std::regexillegalDbusMemberRegex("[^A-Za-z0-9_]");
1919

2020
EMDBusInterface::EMDBusInterface(boost::asio::io_context& io,
21-
sdbusplus::asio::object_server& objServer) :
22-
io(io), objServer(objServer)
21+
sdbusplus::asio::object_server& objServer,
22+
const std::filesystem::path& schemaDirectory) :
23+
io(io), objServer(objServer), schemaDirectory(schemaDirectory)
2324
{}
2425

2526
voidtryIfaceInitialize(std::shared_ptr<sdbusplus::asio::dbus_interface>& iface)
@@ -234,8 +235,9 @@ void EMDBusInterface::populateInterfaceFromJson(
234235
}
235236

236237
// @brief: throws on error
237-
staticvoidaddObjectRuntimeValidateJson(const nlohmann::json& newData,
238-
const std::string* type)
238+
staticvoidaddObjectRuntimeValidateJson(
239+
const nlohmann::json& newData,const std::string* type,
240+
const std::filesystem::path& schemaDirectory)
239241
{
240242
ifconstexpr (!ENABLE_RUNTIME_VALIDATE_JSON)
241243
{
@@ -339,7 +341,7 @@ void EMDBusInterface::addObjectJson(
339341
lastIndex++;
340342
}
341343

342-
addObjectRuntimeValidateJson(newData, type);
344+
addObjectRuntimeValidateJson(newData, type, schemaDirectory);
343345

344346
if (foundNull)
345347
{

‎src/entity_manager/dbus_interface.hpp‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class EMDBusInterface
2323
{
2424
public:
2525
EMDBusInterface(boost::asio::io_context& io,
26-
sdbusplus::asio::object_server& objServer);
26+
sdbusplus::asio::object_server& objServer,
27+
const std::filesystem::path& schemaDirectory);
2728

2829
std::shared_ptr<sdbusplus::asio::dbus_interface>createInterface(
2930
const std::string& path,const std::string& interface,
@@ -68,6 +69,8 @@ class EMDBusInterface
6869
std::string,
6970
std::vector<std::weak_ptr<sdbusplus::asio::dbus_interface>>>
7071
inventory;
72+
73+
const std::filesystem::path schemaDirectory;
7174
};
7275

7376
voidtryIfaceInitialize(

‎src/entity_manager/entity_manager.cpp‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,14 @@ sdbusplus::asio::PropertyPermission getPermission(const std::string& interface)
5353
EntityManager::EntityManager(
5454
std::shared_ptr<sdbusplus::asio::connection>& systemBus,
5555
boost::asio::io_context& io,
56-
const std::vector<std::filesystem::path>& configurationDirectories) :
56+
const std::vector<std::filesystem::path>& configurationDirectories,
57+
const std::filesystem::path& schemaDirectory) :
5758
systemBus(systemBus),
5859
objServer(sdbusplus::asio::object_server(systemBus,/*skipManager=*/true)),
59-
configuration(configurationDirectories), lastJson(nlohmann::json::object()),
60+
configuration(configurationDirectories, schemaDirectory),
61+
lastJson(nlohmann::json::object()),
6062
systemConfiguration(nlohmann::json::object()), io(io),
61-
dbus_interface(io, objServer), powerStatus(*systemBus),
63+
dbus_interface(io, objServer, schemaDirectory), powerStatus(*systemBus),
6264
propertiesChangedTimer(io)
6365
{
6466
// All other objects that EntityManager currently support are under the

‎src/entity_manager/entity_manager.hpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ class EntityManager
2121
explicitEntityManager(
2222
std::shared_ptr<sdbusplus::asio::connection>& systemBus,
2323
boost::asio::io_context& io,
24-
const std::vector<std::filesystem::path>& configurationDirectories);
24+
const std::vector<std::filesystem::path>& configurationDirectories,
25+
const std::filesystem::path& schemaDirectory);
2526

2627
// disable copy
2728
EntityManager(const EntityManager&) =delete;

‎src/entity_manager/main.cpp‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ int main()
1313
const std::vector<std::filesystem::path> configurationDirectories = {
1414
PACKAGE_DIR"configurations", SYSCONF_DIR"configurations"};
1515

16+
const std::filesystem::pathschemaDirectory(PACKAGE_DIR"schemas");
17+
1618
boost::asio::io_context io;
1719
auto systemBus = std::make_shared<sdbusplus::asio::connection>(io);
1820
systemBus->request_name("xyz.openbmc_project.EntityManager");
19-
EntityManagerem(systemBus, io, configurationDirectories);
21+
EntityManagerem(systemBus, io, configurationDirectories, schemaDirectory);
2022

2123
boost::asio::post(io, [&]() { em.propertiesChangedCallback(); });
2224

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp