moved Priority class to enum class
The class was over-architected and inflexible. Converted to a simpler
enum class.
Signed-off-by: Zane Shelley <zshelle@us.ibm.com>
Change-Id: I0515753136d9f78a0d21b6c22794d521fb180df3
diff --git a/analyzer/callout.hpp b/analyzer/callout.hpp
index 0ec3241..2e04d48 100644
--- a/analyzer/callout.hpp
+++ b/analyzer/callout.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include <map>
#include <string>
namespace analyzer
@@ -10,76 +11,66 @@
/** @brief All callouts will have a priority indicating when to issue the
* required service action. */
-class Priority
+enum class Priority
{
- public:
/** Serivce is mandatory. */
- static const Priority HIGH;
+ HIGH,
/** Serivce medium priority callouts one at a time, in order, until the
* issue is resolved. */
- static const Priority MED;
+ MED,
/** Same as MED, except replace all A's as a group. */
- static const Priority MED_A;
+ MED_A,
- /** Same as MED, except replace all A's as a group. */
- static const Priority MED_B;
+ /** Same as MED, except replace all B's as a group. */
+ MED_B,
- /** Same as MED, except replace all A's as a group. */
- static const Priority MED_C;
+ /** Same as MED, except replace all C's as a group. */
+ MED_C,
/** If servicing all high and medium priority callouts did not resolve
* the issue, service low priority callouts one at a time, in order,
* until the issue is resolved. */
- static const Priority LOW;
-
- private:
- /**
- * @brief Constructor from components.
- *
- * At the moment, the priority values for the callout list user data
- * section are different from the priority values hard-coded in the
- * registry. Therefore, two different values must be stored.
- *
- * @param i_registry The string representation of a priority used in
- * registry callouts.
- * @param i_userData The string representation of a priority used in user
- * data callouts.
- */
- Priority(const std::string& i_registry, const std::string& i_userData) :
- iv_registry(i_registry), iv_userData(i_userData)
- {}
-
- private:
- /** The string representation of a priority used in registry callouts. */
- const std::string iv_registry;
-
- /** The string representation of a priority used in user data callouts. */
- const std::string iv_userData;
-
- public:
- /** iv_registry accessor */
- const std::string& getRegistryString() const
- {
- return iv_registry;
- }
-
- /** iv_userData accessor */
- const std::string& getUserDataString() const
- {
- return iv_userData;
- }
+ LOW,
};
-// clang-format off
-inline const Priority Priority::HIGH {"high", "H"};
-inline const Priority Priority::MED {"medium", "M"};
-inline const Priority Priority::MED_A{"medium_group_A","A"};
-inline const Priority Priority::MED_B{"medium_group_B","B"};
-inline const Priority Priority::MED_C{"medium_group_C","C"};
-inline const Priority Priority::LOW {"low", "L"};
-// clang-format on
+/** @return The string representation of the priority used in callouts. */
+inline std::string getString(Priority i_priority)
+{
+ // clang-format off
+ static const std::map<Priority, std::string> m =
+ {
+ {Priority::HIGH, "H"},
+ {Priority::MED, "M"},
+ {Priority::MED_A, "A"},
+ {Priority::MED_B, "B"},
+ {Priority::MED_C, "C"},
+ {Priority::LOW, "L"},
+ };
+ // clang-format on
+
+ return m.at(i_priority);
+}
+
+/** @return The string representation of the priority used in The callout FFDC.
+ */
+inline std::string getStringFFDC(Priority i_priority)
+{
+ // clang-format off
+ static const std::map<Priority, std::string> m =
+ {
+ {Priority::HIGH, "high"},
+ {Priority::MED, "medium"},
+ {Priority::MED_A, "medium_group_A"},
+ {Priority::MED_B, "medium_group_B"},
+ {Priority::MED_C, "medium_group_C"},
+ {Priority::LOW, "low"},
+ };
+ // clang-format on
+
+ return m.at(i_priority);
+}
/** @brief Container class for procedure callout service actions. */
class Procedure
diff --git a/analyzer/resolution.hpp b/analyzer/resolution.hpp
index cb2cc6e..fc717ca 100644
--- a/analyzer/resolution.hpp
+++ b/analyzer/resolution.hpp
@@ -36,8 +36,7 @@
* @param i_guard True, if guard is required. False, otherwise.
*/
HardwareCalloutResolution(const std::string& i_unitPath,
- const callout::Priority& i_priority,
- bool i_guard) :
+ callout::Priority i_priority, bool i_guard) :
iv_unitPath(i_unitPath),
iv_priority(i_priority), iv_guard(i_guard)
{}
@@ -72,8 +71,7 @@
*/
ConnectedCalloutResolution(const callout::BusType& i_busType,
const std::string& i_unitPath,
- const callout::Priority& i_priority,
- bool i_guard) :
+ callout::Priority i_priority, bool i_guard) :
iv_busType(i_busType),
iv_unitPath(i_unitPath), iv_priority(i_priority), iv_guard(i_guard)
{}
@@ -115,7 +113,7 @@
*/
BusCalloutResolution(const callout::BusType& i_busType,
const std::string& i_unitPath,
- const callout::Priority& i_priority, bool i_guard) :
+ callout::Priority i_priority, bool i_guard) :
iv_busType(i_busType),
iv_unitPath(i_unitPath), iv_priority(i_priority), iv_guard(i_guard)
{}
@@ -150,7 +148,7 @@
* @param i_guard The guard type for this callout.
*/
ClockCalloutResolution(const callout::ClockType& i_clockType,
- const callout::Priority& i_priority, bool i_guard) :
+ callout::Priority i_priority, bool i_guard) :
iv_clockType(i_clockType),
iv_priority(i_priority), iv_guard(i_guard)
{}
@@ -179,7 +177,7 @@
* @param i_priority The callout priority.
*/
ProcedureCalloutResolution(const callout::Procedure& i_procedure,
- const callout::Priority& i_priority) :
+ callout::Priority i_priority) :
iv_procedure(i_procedure),
iv_priority(i_priority)
{}
@@ -205,7 +203,7 @@
* @param i_priority The callout priority.
*/
PartCalloutResolution(const callout::PartType& i_part,
- const callout::Priority& i_priority) :
+ callout::Priority i_priority) :
iv_part(i_part),
iv_priority(i_priority)
{}
diff --git a/analyzer/service_data.cpp b/analyzer/service_data.cpp
index de2c0a7..c13bc8b 100644
--- a/analyzer/service_data.cpp
+++ b/analyzer/service_data.cpp
@@ -6,8 +6,7 @@
//------------------------------------------------------------------------------
void ServiceData::calloutTarget(pdbg_target* i_target,
- const callout::Priority& i_priority,
- bool i_guard)
+ callout::Priority i_priority, bool i_guard)
{
// Add the target to the callout list.
addTargetCallout(i_target, i_priority, i_guard);
@@ -16,7 +15,7 @@
nlohmann::json ffdc;
ffdc["Callout Type"] = "Hardware Callout";
ffdc["Target"] = util::pdbg::getPhysDevPath(i_target);
- ffdc["Priority"] = i_priority.getRegistryString();
+ ffdc["Priority"] = callout::getStringFFDC(i_priority);
ffdc["Guard"] = i_guard;
addCalloutFFDC(ffdc);
}
@@ -25,8 +24,7 @@
void ServiceData::calloutConnected(pdbg_target* i_rxTarget,
const callout::BusType& i_busType,
- const callout::Priority& i_priority,
- bool i_guard)
+ callout::Priority i_priority, bool i_guard)
{
// Get the endpoint target for the transfer side of the bus.
auto txTarget = util::pdbg::getConnectedTarget(i_rxTarget, i_busType);
@@ -40,7 +38,7 @@
ffdc["Bus Type"] = i_busType.getString();
ffdc["RX Target"] = util::pdbg::getPhysDevPath(i_rxTarget);
ffdc["TX Target"] = util::pdbg::getPhysDevPath(txTarget);
- ffdc["Priority"] = i_priority.getRegistryString();
+ ffdc["Priority"] = callout::getStringFFDC(i_priority);
ffdc["Guard"] = i_guard;
addCalloutFFDC(ffdc);
}
@@ -49,7 +47,7 @@
void ServiceData::calloutBus(pdbg_target* i_rxTarget,
const callout::BusType& i_busType,
- const callout::Priority& i_priority, bool i_guard)
+ callout::Priority i_priority, bool i_guard)
{
// Get the endpoint target for the transfer side of the bus.
auto txTarget = util::pdbg::getConnectedTarget(i_rxTarget, i_busType);
@@ -70,7 +68,7 @@
ffdc["Bus Type"] = i_busType.getString();
ffdc["RX Target"] = util::pdbg::getPhysDevPath(i_rxTarget);
ffdc["TX Target"] = util::pdbg::getPhysDevPath(txTarget);
- ffdc["Priority"] = i_priority.getRegistryString();
+ ffdc["Priority"] = callout::getStringFFDC(i_priority);
ffdc["Guard"] = i_guard;
addCalloutFFDC(ffdc);
}
@@ -78,7 +76,7 @@
//------------------------------------------------------------------------------
void ServiceData::calloutClock(const callout::ClockType& i_clockType,
- const callout::Priority& i_priority, bool)
+ callout::Priority i_priority, bool)
{
// Callout the clock target.
// TODO: For P10, the callout is simply the backplane. Also, there are no
@@ -91,33 +89,33 @@
nlohmann::json ffdc;
ffdc["Callout Type"] = "Clock Callout";
ffdc["Clock Type"] = i_clockType.getString();
- ffdc["Priority"] = i_priority.getRegistryString();
+ ffdc["Priority"] = callout::getStringFFDC(i_priority);
addCalloutFFDC(ffdc);
}
//------------------------------------------------------------------------------
void ServiceData::calloutProcedure(const callout::Procedure& i_procedure,
- const callout::Priority& i_priority)
+ callout::Priority i_priority)
{
// Add the actual callout to the service data.
nlohmann::json callout;
callout["Procedure"] = i_procedure.getString();
- callout["Priority"] = i_priority.getUserDataString();
+ callout["Priority"] = callout::getString(i_priority);
addCallout(callout);
// Add the callout FFDC.
nlohmann::json ffdc;
ffdc["Callout Type"] = "Procedure Callout";
ffdc["Procedure"] = i_procedure.getString();
- ffdc["Priority"] = i_priority.getRegistryString();
+ ffdc["Priority"] = callout::getStringFFDC(i_priority);
addCalloutFFDC(ffdc);
}
//------------------------------------------------------------------------------
void ServiceData::calloutPart(const callout::PartType& i_part,
- const callout::Priority& i_priority)
+ callout::Priority i_priority)
{
if (callout::PartType::PNOR == i_part)
{
@@ -135,7 +133,7 @@
nlohmann::json ffdc;
ffdc["Callout Type"] = "Part Callout";
ffdc["Part Type"] = i_part.getString();
- ffdc["Priority"] = i_priority.getRegistryString();
+ ffdc["Priority"] = callout::getStringFFDC(i_priority);
addCalloutFFDC(ffdc);
}
@@ -192,13 +190,12 @@
//------------------------------------------------------------------------------
void ServiceData::addTargetCallout(pdbg_target* i_target,
- const callout::Priority& i_priority,
- bool i_guard)
+ callout::Priority i_priority, bool i_guard)
{
nlohmann::json callout;
callout["LocationCode"] = util::pdbg::getLocationCode(i_target);
- callout["Priority"] = i_priority.getUserDataString();
+ callout["Priority"] = callout::getString(i_priority);
callout["Deconfigured"] = false;
callout["Guarded"] = false; // default
@@ -220,7 +217,7 @@
//------------------------------------------------------------------------------
-void ServiceData::addBackplaneCallout(const callout::Priority& i_priority)
+void ServiceData::addBackplaneCallout(callout::Priority i_priority)
{
// TODO: There isn't a device tree object for this. So will need to hardcode
// the location code for now. In the future, we will need a mechanism
@@ -229,7 +226,7 @@
nlohmann::json callout;
callout["LocationCode"] = "P0";
- callout["Priority"] = i_priority.getUserDataString();
+ callout["Priority"] = callout::getString(i_priority);
callout["Deconfigured"] = false;
callout["Guarded"] = false;
diff --git a/analyzer/service_data.hpp b/analyzer/service_data.hpp
index 44f31b9..90ebf2f 100644
--- a/analyzer/service_data.hpp
+++ b/analyzer/service_data.hpp
@@ -95,8 +95,8 @@
* @param i_priority The callout priority.
* @param i_guard True if guard is required. False, otherwise.
*/
- void calloutTarget(pdbg_target* i_target,
- const callout::Priority& i_priority, bool i_guard);
+ void calloutTarget(pdbg_target* i_target, callout::Priority i_priority,
+ bool i_guard);
/**
* @brief Add callout for a connected target on the other side of a bus.
@@ -107,7 +107,7 @@
*/
void calloutConnected(pdbg_target* i_rxTarget,
const callout::BusType& i_busType,
- const callout::Priority& i_priority, bool i_guard);
+ callout::Priority i_priority, bool i_guard);
/**
* @brief Add callout for an entire bus.
@@ -117,7 +117,7 @@
* @param i_guard True if guard is required. False, otherwise.
*/
void calloutBus(pdbg_target* i_rxTarget, const callout::BusType& i_busType,
- const callout::Priority& i_priority, bool i_guard);
+ callout::Priority i_priority, bool i_guard);
/**
* @brief Add callout for a clock.
@@ -126,7 +126,7 @@
* @param i_guard True if guard is required. False, otherwise.
*/
void calloutClock(const callout::ClockType& i_clockType,
- const callout::Priority& i_priority, bool i_guard);
+ callout::Priority i_priority, bool i_guard);
/**
* @brief Add callout for a service procedure.
@@ -134,7 +134,7 @@
* @param i_priority The callout priority.
*/
void calloutProcedure(const callout::Procedure& i_procedure,
- const callout::Priority& i_priority);
+ callout::Priority i_priority);
/**
* @brief Add callout for part type.
@@ -142,7 +142,7 @@
* @param i_priority The callout priority.
*/
void calloutPart(const callout::PartType& i_part,
- const callout::Priority& i_priority);
+ callout::Priority i_priority);
/** @brief Accessor to iv_calloutList. */
const nlohmann::json& getCalloutList() const
@@ -180,15 +180,15 @@
* @param i_priority The callout priority.
* @param i_guard True if guard is required. False, otherwise.
*/
- void addTargetCallout(pdbg_target* i_target,
- const callout::Priority& i_priority, bool i_guard);
+ void addTargetCallout(pdbg_target* i_target, callout::Priority i_priority,
+ bool i_guard);
/**
* @brief A simple helper function for all the callout functions that need
* to callout a the backplane (callout only, no FFDC).
* @param i_priority The callout priority.
*/
- void addBackplaneCallout(const callout::Priority& i_priority);
+ void addBackplaneCallout(callout::Priority i_priority);
};
} // namespace analyzer