presence: Policy generation framework
Add the framework necessary to construct the presence methods policy
specific to the type of policy to be applied against all methods. This
uses the policy type to index into a map of types-to-functions where the
function will return the pointer associated to the entry based on the
policy type.
Tested:
Supported redundancy policies produce no errors
Unsupported redundancy policies throw exception
Change-Id: I2805deb96a29828564b76bd66eb52032fdcf72f7
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/presence/json_config.hpp b/presence/json_config.hpp
index c41b8d5..b027dba 100644
--- a/presence/json_config.hpp
+++ b/presence/json_config.hpp
@@ -19,9 +19,17 @@
using json = nlohmann::json;
using policies = std::vector<std::unique_ptr<RedundancyPolicy>>;
+
+constexpr auto fanPolicyFanPos = 0;
+constexpr auto fanPolicySensorListPos = 1;
+using fanPolicy = std::tuple<Fan, std::vector<std::unique_ptr<PresenceSensor>>>;
+
// Presence method handler function
using methodHandler = std::function<
std::unique_ptr<PresenceSensor>(size_t, const json&)>;
+// Presence redundancy policy handler function
+using rpolicyHandler = std::function<
+ std::unique_ptr<RedundancyPolicy>(const fanPolicy&)>;
class JsonConfig
{
@@ -55,13 +63,16 @@
static policies _policies;
/* List of Fan objects to have presence policies */
- std::vector<Fan> _fans;
+ std::vector<fanPolicy> _fans;
/* Presence methods mapping to their associated handler function */
static const std::map<std::string, methodHandler> _methods;
- /* List of fan presence sensors */
- std::vector<std::unique_ptr<PresenceSensor>> _sensors;
+ /**
+ * Presence redundancy policy mapping to their associated handler
+ * function
+ */
+ static const std::map<std::string, rpolicyHandler> _rpolicies;
/**
* @brief Process the json config to extract the defined fan presence
@@ -70,6 +81,13 @@
* @param[in] jsonConf - parsed json configuration data
*/
void process(const json& jsonConf);
+
+ /**
+ * @brief Add to the list of policies of presence detection
+ *
+ * @param[in] rpolicy - policy to add
+ */
+ void addPolicy(const json& rpolicy);
};
/**
@@ -101,6 +119,33 @@
} // namespace method
+/**
+ * Redundancy policies for fan presence detection function declarations
+ */
+namespace rpolicy
+{
+ /**
+ * @brief Create an `Anyof` redundancy policy on the created presence
+ * sensors for a fan
+ *
+ * @param[in] fan - fan policy object with the presence sensors for the fan
+ *
+ * @return - An `Anyof` redundancy policy
+ */
+ std::unique_ptr<RedundancyPolicy> getAnyof(const fanPolicy& fan);
+
+ /**
+ * @brief Create a `Fallback` redundancy policy on the created presence
+ * sensors for a fan
+ *
+ * @param[in] fan - fan policy object with the presence sensors for the fan
+ *
+ * @return - A `Fallback` redundancy policy
+ */
+ std::unique_ptr<RedundancyPolicy> getFallback(const fanPolicy& fan);
+
+} // namespace policy
+
} // namespace presence
} // namespace fan
} // namespace phosphor