control: Add a parameter store to Manager
Add a map of names to PropertyVariantValues to the Manager class that
actions can set and read. This allows one action to use a value from
this parameter map that another action has previously set.
A future use of this is to store a throttle temperature that has to be
calculated, which net_target_increase can then use to make decisions on.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: Ibefb97ed667d6b19ce71113d13efe08a1d3ff81f
diff --git a/control/json/manager.cpp b/control/json/manager.cpp
index 372fb78..d7e3b06 100644
--- a/control/json/manager.cpp
+++ b/control/json/manager.cpp
@@ -55,6 +55,7 @@
std::map<std::string,
std::map<std::string, std::map<std::string, PropertyVariantType>>>
Manager::_objects;
+std::unordered_map<std::string, PropertyVariantType> Manager::_parameters;
Manager::Manager(const sdeventplus::Event& event) :
_bus(util::SDBusPlus::getBus()), _event(event),
diff --git a/control/json/manager.hpp b/control/json/manager.hpp
index 5e5b33c..30bc310 100644
--- a/control/json/manager.hpp
+++ b/control/json/manager.hpp
@@ -431,6 +431,47 @@
*/
void load();
+ /**
+ * @brief Sets a value in the parameter map.
+ *
+ * @param[in] name - The parameter name
+ * @param[in] value - The parameter value
+ */
+ static void setParameter(const std::string& name,
+ const PropertyVariantType& value)
+ {
+ _parameters[name] = value;
+ }
+
+ /**
+ * @brief Returns a value from the parameter map
+ *
+ * @param[in] name - The parameter name
+ *
+ * @return The parameter value, or std::nullopt if not found
+ */
+ static std::optional<PropertyVariantType>
+ getParameter(const std::string& name)
+ {
+ auto it = _parameters.find(name);
+ if (it != _parameters.end())
+ {
+ return it->second;
+ }
+
+ return std::nullopt;
+ }
+
+ /**
+ * @brief Deletes a parameter from the parameter map
+ *
+ * @param[in] name - The parameter name
+ */
+ static void deleteParameter(const std::string& name)
+ {
+ _parameters.erase(name);
+ }
+
private:
/* The sdbusplus bus object to use */
sdbusplus::bus::bus& _bus;
@@ -478,6 +519,13 @@
std::map<configKey, std::unique_ptr<Event>> _events;
/**
+ * @brief A map of parameter names and values that are something
+ * other than just D-Bus property values that other actions
+ * can set and use.
+ */
+ static std::unordered_map<std::string, PropertyVariantType> _parameters;
+
+ /**
* @brief Callback for power state changes
*
* @param[in] powerStateOn - Whether the power state is on or not