Match DBus Trigger with phosphor-dbus-interfaces
Matched Trigger DBus interface to the one defined in
phosphor-dbus-interfaces repository. Changed enum (int) type to
string to reflect enum type defined in Trigger.yaml.
Fixed style in boost_build_1.74.0.sh script.
Tested:
- Passed unit tests
- Verified manually Trigger DBus object in witherspoon image
on QEMU
Change-Id: I87175fc285afd182d1383da5879f89233b9de6a0
Signed-off-by: Wludzik, Jozef <jozef.wludzik@intel.com>
diff --git a/scripts/boost_build_1.74.0.sh b/scripts/boost_build_1.74.0.sh
index 074e72c..2775b7c 100755
--- a/scripts/boost_build_1.74.0.sh
+++ b/scripts/boost_build_1.74.0.sh
@@ -13,5 +13,5 @@
./b2 install --prefix=build
fi
-echo -e "Please, set BOOST_ROOT to `pwd`/build, e.g.:\n" \
- "export BOOST_ROOT=`pwd`/build"
+echo -e "Please, set BOOST_ROOT to $(pwd)/build, e.g.:\n" \
+ "export BOOST_ROOT=$(pwd)/build"
diff --git a/src/interfaces/trigger_types.hpp b/src/interfaces/trigger_types.hpp
index eb0f7c4..f99cd3c 100644
--- a/src/interfaces/trigger_types.hpp
+++ b/src/interfaces/trigger_types.hpp
@@ -18,13 +18,27 @@
critical
};
-inline Severity toSeverity(int x)
+namespace details
{
- return utils::toEnum<Severity, Severity::ok, Severity::critical>(x);
+constexpr std::array<std::pair<std::string_view, Severity>, 3>
+ convDataSeverity = {std::make_pair("Ok", Severity::ok),
+ std::make_pair("Warning", Severity::warning),
+ std::make_pair("Critical", Severity::critical)};
+
+} // namespace details
+
+inline Severity stringToSeverity(const std::string& str)
+{
+ return utils::stringToEnum(details::convDataSeverity, str);
}
-using ThresholdParam = std::tuple<std::string, std::underlying_type_t<Severity>,
- std::variant<double>, uint64_t>;
+inline std::string severityToString(Severity v)
+{
+ return std::string(utils::enumToString(details::convDataSeverity, v));
+}
+
+using ThresholdParam =
+ std::tuple<std::string, std::string, std::variant<double>, uint64_t>;
} // namespace discrete
namespace numeric
@@ -45,19 +59,43 @@
increasing
};
-inline Type toType(int x)
+namespace details
{
- return utils::toEnum<Type, Type::lowerCritical, Type::upperCritical>(x);
+
+constexpr std::array<std::pair<std::string_view, Type>, 4> convDataType = {
+ std::make_pair("LowerCritical", Type::lowerCritical),
+ std::make_pair("LowerWarning", Type::lowerWarning),
+ std::make_pair("UpperWarning", Type::upperWarning),
+ std::make_pair("UpperCritical", Type::upperCritical)};
+
+constexpr std::array<std::pair<std::string_view, Direction>, 3>
+ convDataDirection = {std::make_pair("Either", Direction::either),
+ std::make_pair("Decreasing", Direction::decreasing),
+ std::make_pair("Increasing", Direction::increasing)};
+
+} // namespace details
+
+inline Type stringToType(const std::string& str)
+{
+ return utils::stringToEnum(details::convDataType, str);
}
-inline Direction toDirection(int x)
+inline std::string typeToString(Type v)
{
- return utils::toEnum<Direction, Direction::either, Direction::increasing>(
- x);
+ return std::string(utils::enumToString(details::convDataType, v));
}
-using ThresholdParam = std::tuple<std::underlying_type_t<Type>, uint64_t,
- std::underlying_type_t<Direction>, double>;
+inline Direction stringToDirection(const std::string& str)
+{
+ return utils::stringToEnum(details::convDataDirection, str);
+}
+
+inline std::string directionToString(Direction v)
+{
+ return std::string(utils::enumToString(details::convDataDirection, v));
+}
+
+using ThresholdParam = std::tuple<std::string, uint64_t, std::string, double>;
} // namespace numeric
using TriggerThresholdParams =
diff --git a/src/trigger_factory.cpp b/src/trigger_factory.cpp
index d8484c2..7953cd9 100644
--- a/src/trigger_factory.cpp
+++ b/src/trigger_factory.cpp
@@ -34,18 +34,19 @@
const auto& params =
std::get<std::vector<numeric::ThresholdParam>>(thresholdParams);
- for (const auto& [type, dwellTime, direction, value] : params)
+ for (const auto& [typeStr, dwellTime, directionStr, value] : params)
{
+ numeric::Type type = numeric::stringToType(typeStr);
std::vector<std::unique_ptr<interfaces::TriggerAction>> actions;
if (logToJournal)
{
- actions.emplace_back(std::make_unique<action::LogToJournal>(
- numeric::toType(type), value));
+ actions.emplace_back(
+ std::make_unique<action::LogToJournal>(type, value));
}
if (logToRedfish)
{
- actions.emplace_back(std::make_unique<action::LogToRedfish>(
- numeric::toType(type), value));
+ actions.emplace_back(
+ std::make_unique<action::LogToRedfish>(type, value));
}
if (updateReport)
{
@@ -56,7 +57,7 @@
thresholds.emplace_back(std::make_shared<NumericThreshold>(
bus->get_io_context(), sensors, sensorNames, std::move(actions),
std::chrono::milliseconds(dwellTime),
- numeric::toDirection(direction), value));
+ numeric::stringToDirection(directionStr), value));
}
return std::make_unique<Trigger>(
diff --git a/tests/src/params/trigger_params.hpp b/tests/src/params/trigger_params.hpp
index 9aed64d..6d34d3b 100644
--- a/tests/src/params/trigger_params.hpp
+++ b/tests/src/params/trigger_params.hpp
@@ -71,10 +71,10 @@
std::vector<std::string> reportNamesProperty = {"Report1"};
TriggerThresholdParams thresholdsProperty =
std::vector<numeric::ThresholdParam>{
- {static_cast<int>(numeric::Type::lowerCritical),
+ {numeric::typeToString(numeric::Type::lowerCritical),
std::chrono::milliseconds(10).count(),
- static_cast<int>(numeric::Direction::decreasing), 0.0},
- {static_cast<int>(numeric::Type::upperCritical),
+ numeric::directionToString(numeric::Direction::decreasing), 0.0},
+ {numeric::typeToString(numeric::Type::upperCritical),
std::chrono::milliseconds(10).count(),
- static_cast<int>(numeric::Direction::increasing), 90.0}};
+ numeric::directionToString(numeric::Direction::increasing), 90.0}};
};