Expand conf namespace
Put rest of conf.hpp in the conf namespace. This is
largely a sed replace, and wrapping from_json in
conf namespace as it failed to build.
Change-Id: I9fe5c7b2fface44618c43af2367035afc39bcb64
Signed-off-by: James Feist <james.feist@linux.intel.com>
diff --git a/conf.hpp b/conf.hpp
index 14e1cc9..9d65154 100644
--- a/conf.hpp
+++ b/conf.hpp
@@ -9,8 +9,8 @@
namespace conf
{
+
constexpr int64_t inheritValueFromDbus = std::numeric_limits<int64_t>::lowest();
-} // namespace conf
/*
* General sensor structure used for configuration.
@@ -58,3 +58,5 @@
};
using PIDConf = std::map<std::string, struct ControllerInfo>;
+
+} // namespace conf
diff --git a/dbus/dbusconfiguration.cpp b/dbus/dbusconfiguration.cpp
index 3c5be34..a0177f5 100644
--- a/dbus/dbusconfiguration.cpp
+++ b/dbus/dbusconfiguration.cpp
@@ -32,9 +32,9 @@
static constexpr bool DEBUG = false; // enable to print found configuration
-extern std::map<std::string, struct SensorConfig> sensorConfig;
-extern std::map<int64_t, PIDConf> zoneConfig;
-extern std::map<int64_t, struct ZoneConfig> zoneDetailsConfig;
+extern std::map<std::string, struct conf::SensorConfig> sensorConfig;
+extern std::map<int64_t, conf::PIDConf> zoneConfig;
+extern std::map<int64_t, struct conf::ZoneConfig> zoneDetailsConfig;
constexpr const char* pidConfigurationInterface =
"xyz.openbmc_project.Configuration.Pid";
@@ -315,7 +315,7 @@
for (const std::string& zone : zones)
{
size_t index = getZoneIndex(zone, foundZones);
- PIDConf& conf = zoneConfig[index];
+ conf::PIDConf& conf = zoneConfig[index];
std::vector<std::string> sensorNames =
std::get<std::vector<std::string>>(base.at("Inputs"));
@@ -395,7 +395,7 @@
}
}
- struct ControllerInfo& info =
+ struct conf::ControllerInfo& info =
conf[std::get<std::string>(base.at("Name"))];
info.inputs = std::move(inputs);
@@ -462,7 +462,7 @@
for (const std::string& zone : zones)
{
size_t index = getZoneIndex(zone, foundZones);
- PIDConf& conf = zoneConfig[index];
+ conf::PIDConf& conf = zoneConfig[index];
std::vector<std::string> inputs;
std::vector<std::string> sensorNames =
@@ -504,7 +504,7 @@
{
continue;
}
- struct ControllerInfo& info =
+ struct conf::ControllerInfo& info =
conf[std::get<std::string>(base.at("Name"))];
info.inputs = std::move(inputs);
diff --git a/dbus/dbuspassive.cpp b/dbus/dbuspassive.cpp
index 206adbe..ee165b9 100644
--- a/dbus/dbuspassive.cpp
+++ b/dbus/dbuspassive.cpp
@@ -27,7 +27,7 @@
std::unique_ptr<ReadInterface> DbusPassive::createDbusPassive(
sdbusplus::bus::bus& bus, const std::string& type, const std::string& id,
- DbusHelperInterface* helper, const SensorConfig* info)
+ DbusHelperInterface* helper, const conf::SensorConfig* info)
{
if (helper == nullptr)
{
diff --git a/dbus/dbuspassive.hpp b/dbus/dbuspassive.hpp
index fa9dab7..8cff245 100644
--- a/dbus/dbuspassive.hpp
+++ b/dbus/dbuspassive.hpp
@@ -37,7 +37,7 @@
static std::unique_ptr<ReadInterface>
createDbusPassive(sdbusplus::bus::bus& bus, const std::string& type,
const std::string& id, DbusHelperInterface* helper,
- const SensorConfig* info);
+ const conf::SensorConfig* info);
DbusPassive(sdbusplus::bus::bus& bus, const std::string& type,
const std::string& id, DbusHelperInterface* helper,
diff --git a/main.cpp b/main.cpp
index 012eca4..d896300 100644
--- a/main.cpp
+++ b/main.cpp
@@ -46,11 +46,11 @@
#endif
/* The YAML converted sensor list. */
-std::map<std::string, struct SensorConfig> sensorConfig = {};
+std::map<std::string, struct conf::SensorConfig> sensorConfig = {};
/* The YAML converted PID list. */
-std::map<int64_t, PIDConf> zoneConfig = {};
+std::map<int64_t, conf::PIDConf> zoneConfig = {};
/* The YAML converted Zone configuration. */
-std::map<int64_t, struct ZoneConfig> zoneDetailsConfig = {};
+std::map<int64_t, struct conf::ZoneConfig> zoneDetailsConfig = {};
/** the swampd daemon will check for the existence of this file. */
constexpr auto jsonConfigurationPath = "/usr/share/swampd/config.json";
diff --git a/pid/builder.cpp b/pid/builder.cpp
index 2faa1cc..1fbfbd4 100644
--- a/pid/builder.cpp
+++ b/pid/builder.cpp
@@ -36,8 +36,8 @@
}
std::unordered_map<int64_t, std::unique_ptr<PIDZone>>
- buildZones(std::map<int64_t, PIDConf>& zonePids,
- std::map<int64_t, struct ZoneConfig>& zoneConfigs,
+ buildZones(std::map<int64_t, conf::PIDConf>& zonePids,
+ std::map<int64_t, struct conf::ZoneConfig>& zoneConfigs,
SensorManager& mgr, sdbusplus::bus::bus& modeControlBus)
{
std::unordered_map<int64_t, std::unique_ptr<PIDZone>> zones;
@@ -60,7 +60,7 @@
throw std::runtime_error(err);
}
- const PIDConf& pidConfig = zi.second;
+ const conf::PIDConf& pidConfig = zi.second;
auto zone = std::make_unique<PIDZone>(
zoneId, zoneConf->second.minThermalOutput,
@@ -74,7 +74,7 @@
{
std::vector<std::string> inputs;
std::string name = pit.first;
- const struct ControllerInfo* info = &pit.second;
+ const struct conf::ControllerInfo* info = &pit.second;
std::cerr << "PID name: " << name << "\n";
diff --git a/pid/builder.hpp b/pid/builder.hpp
index 2b28663..e500503 100644
--- a/pid/builder.hpp
+++ b/pid/builder.hpp
@@ -8,6 +8,6 @@
#include <unordered_map>
std::unordered_map<int64_t, std::unique_ptr<PIDZone>>
- buildZones(std::map<int64_t, PIDConf>& zonePids,
- std::map<int64_t, struct ZoneConfig>& zoneConfigs,
+ buildZones(std::map<int64_t, conf::PIDConf>& zonePids,
+ std::map<int64_t, struct conf::ZoneConfig>& zoneConfigs,
SensorManager& mgr, sdbusplus::bus::bus& modeControlBus);
diff --git a/pid/buildjson.cpp b/pid/buildjson.cpp
index b620439..d31b6bc 100644
--- a/pid/buildjson.cpp
+++ b/pid/buildjson.cpp
@@ -24,7 +24,9 @@
using json = nlohmann::json;
-void from_json(const json& j, ControllerInfo& c)
+namespace conf
+{
+void from_json(const json& j, conf::ControllerInfo& c)
{
j.at("type").get_to(c.type);
j.at("inputs").get_to(c.inputs);
@@ -67,22 +69,24 @@
j.at("negativeHysteresis").get_to(c.pidInfo.negativeHysteresis);
}
}
+} // namespace conf
-std::pair<std::map<int64_t, PIDConf>, std::map<int64_t, struct ZoneConfig>>
+std::pair<std::map<int64_t, conf::PIDConf>,
+ std::map<int64_t, struct conf::ZoneConfig>>
buildPIDsFromJson(const json& data)
{
// zone -> pids
- std::map<int64_t, PIDConf> pidConfig;
+ std::map<int64_t, conf::PIDConf> pidConfig;
// zone -> configs
- std::map<int64_t, struct ZoneConfig> zoneConfig;
+ std::map<int64_t, struct conf::ZoneConfig> zoneConfig;
/* TODO: if zones is empty, that's invalid. */
auto zones = data["zones"];
for (const auto& zone : zones)
{
int64_t id;
- PIDConf thisZone;
- struct ZoneConfig thisZoneConfig;
+ conf::PIDConf thisZone;
+ struct conf::ZoneConfig thisZoneConfig;
/* TODO: using at() throws a specific exception we can catch */
id = zone["id"];
@@ -93,7 +97,7 @@
for (const auto& pid : pids)
{
auto name = pid["name"];
- auto item = pid.get<ControllerInfo>();
+ auto item = pid.get<conf::ControllerInfo>();
thisZone[name] = item;
}
diff --git a/pid/buildjson.hpp b/pid/buildjson.hpp
index 626c982..d4e86a7 100644
--- a/pid/buildjson.hpp
+++ b/pid/buildjson.hpp
@@ -14,5 +14,6 @@
* @param[in] data - the json data
* @return the pidConfig, and the zoneConfig
*/
-std::pair<std::map<int64_t, PIDConf>, std::map<int64_t, struct ZoneConfig>>
+std::pair<std::map<int64_t, conf::PIDConf>,
+ std::map<int64_t, struct conf::ZoneConfig>>
buildPIDsFromJson(const json& data);
diff --git a/sensors/builder.cpp b/sensors/builder.cpp
index adffd81..1a74adb 100644
--- a/sensors/builder.cpp
+++ b/sensors/builder.cpp
@@ -38,7 +38,7 @@
static DbusHelper helper;
SensorManager
- buildSensors(const std::map<std::string, struct SensorConfig>& config)
+ buildSensors(const std::map<std::string, struct conf::SensorConfig>& config)
{
SensorManager mgmr;
auto& hostSensorBus = mgmr.getHostBus();
@@ -50,7 +50,7 @@
std::unique_ptr<WriteInterface> wi;
std::string name = it.first;
- const struct SensorConfig* info = &it.second;
+ const struct conf::SensorConfig* info = &it.second;
std::cerr << "Sensor: " << name << " " << info->type << " ";
std::cerr << info->readPath << " " << info->writePath << "\n";
diff --git a/sensors/builder.hpp b/sensors/builder.hpp
index d646223..224d467 100644
--- a/sensors/builder.hpp
+++ b/sensors/builder.hpp
@@ -9,5 +9,5 @@
/**
* Build the sensors and associate them with a SensorManager.
*/
-SensorManager
- buildSensors(const std::map<std::string, struct SensorConfig>& config);
+SensorManager buildSensors(
+ const std::map<std::string, struct conf::SensorConfig>& config);
diff --git a/sensors/buildjson.cpp b/sensors/buildjson.cpp
index d62edfd..42a9286 100644
--- a/sensors/buildjson.cpp
+++ b/sensors/buildjson.cpp
@@ -23,7 +23,9 @@
using json = nlohmann::json;
-void from_json(const json& j, SensorConfig& s)
+namespace conf
+{
+void from_json(const json& j, conf::SensorConfig& s)
{
j.at("type").get_to(s.type);
j.at("readPath").get_to(s.readPath);
@@ -72,11 +74,12 @@
j.at("timeout").get_to(s.timeout);
}
}
+} // namespace conf
-std::map<std::string, struct SensorConfig>
+std::map<std::string, struct conf::SensorConfig>
buildSensorsFromJson(const json& data)
{
- std::map<std::string, struct SensorConfig> config;
+ std::map<std::string, struct conf::SensorConfig> config;
auto sensors = data["sensors"];
/* TODO: If no sensors, this is invalid, and we should except here or during
@@ -84,7 +87,7 @@
*/
for (const auto& sensor : sensors)
{
- config[sensor["name"]] = sensor.get<struct SensorConfig>();
+ config[sensor["name"]] = sensor.get<struct conf::SensorConfig>();
}
return config;
diff --git a/sensors/buildjson.hpp b/sensors/buildjson.hpp
index c5aacc7..0a38b93 100644
--- a/sensors/buildjson.hpp
+++ b/sensors/buildjson.hpp
@@ -16,5 +16,5 @@
* @param[in] data - the json data
* @return a map of sensors.
*/
-std::map<std::string, struct SensorConfig>
+std::map<std::string, struct conf::SensorConfig>
buildSensorsFromJson(const json& data);
diff --git a/test/dbus_passive_unittest.cpp b/test/dbus_passive_unittest.cpp
index 92a30af..2fc3471 100644
--- a/test/dbus_passive_unittest.cpp
+++ b/test/dbus_passive_unittest.cpp
@@ -29,7 +29,7 @@
std::string id = "id";
DbusHelperMock helper;
- auto info = SensorConfig();
+ auto info = conf::SensorConfig();
std::unique_ptr<ReadInterface> ri =
DbusPassive::createDbusPassive(bus_mock, type, id, &helper, &info);
@@ -76,7 +76,7 @@
EXPECT_CALL(helper, thresholdsAsserted(_, StrEq("asdf"), StrEq(path)))
.WillOnce(Return(false));
- auto info = SensorConfig();
+ auto info = conf::SensorConfig();
ri = DbusPassive::createDbusPassive(bus_mock, type, id, &helper, &info);
passive = reinterpret_cast<DbusPassive*>(ri.get());
EXPECT_FALSE(passive == nullptr);
diff --git a/test/pid_json_unittest.cpp b/test/pid_json_unittest.cpp
index 098d9da..c8a1f61 100644
--- a/test/pid_json_unittest.cpp
+++ b/test/pid_json_unittest.cpp
@@ -8,8 +8,8 @@
// There is a zone key, but it's empty.
// This is technically invalid.
- std::map<int64_t, PIDConf> pidConfig;
- std::map<int64_t, struct ZoneConfig> zoneConfig;
+ std::map<int64_t, conf::PIDConf> pidConfig;
+ std::map<int64_t, struct conf::ZoneConfig> zoneConfig;
auto j2 = R"(
{
@@ -27,8 +27,8 @@
{
// Parse a valid configuration with one zone and one PID.
- std::map<int64_t, PIDConf> pidConfig;
- std::map<int64_t, struct ZoneConfig> zoneConfig;
+ std::map<int64_t, conf::PIDConf> pidConfig;
+ std::map<int64_t, struct conf::ZoneConfig> zoneConfig;
auto j2 = R"(
{