presence: Reload json config on SIGHUP
Enable capturing the HUP signal to reload the json configuration. This
will reload and process the default json config file, updating the set
of policies to be the same set of policies from when fan presence was
started.
Tested:
Configuration is reloaded and processed after SIGHUP
Single set of policies exist that correlate to the json config
Change-Id: I761ac3779baf5b058308d7c565fd117fe052d61c
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/presence/json_config.hpp b/presence/json_config.hpp
index b027dba..a369bd5 100644
--- a/presence/json_config.hpp
+++ b/presence/json_config.hpp
@@ -4,6 +4,8 @@
#include <vector>
#include <memory>
#include <nlohmann/json.hpp>
+#include <filesystem>
+#include <sdeventplus/source/signal.hpp>
#include "config.h"
#include "rpolicy.hpp"
@@ -17,6 +19,7 @@
namespace presence
{
+namespace fs = std::filesystem;
using json = nlohmann::json;
using policies = std::vector<std::unique_ptr<RedundancyPolicy>>;
@@ -57,11 +60,24 @@
*/
static const policies& get();
+ /**
+ * @brief Callback function to handle receiving a HUP signal to
+ * reload the json configuration.
+ *
+ * @param[in] sigSrc - sd_event_source signal wrapper
+ * @param[in] sigInfo - signal info on signal fd
+ */
+ void sighupHandler(sdeventplus::source::Signal& sigSrc,
+ const struct signalfd_siginfo* sigInfo);
+
private:
/* Fan presence policies */
static policies _policies;
+ /* Default json configuration file */
+ const fs::path _defaultFile;
+
/* List of Fan objects to have presence policies */
std::vector<fanPolicy> _fans;
@@ -75,6 +91,11 @@
static const std::map<std::string, rpolicyHandler> _rpolicies;
/**
+ * @brief Load the json config file
+ */
+ void load();
+
+ /**
* @brief Process the json config to extract the defined fan presence
* policies.
*
@@ -83,11 +104,15 @@
void process(const json& jsonConf);
/**
- * @brief Add to the list of policies of presence detection
+ * @brief Get the redundancy policy of presence detection for a fan
*
- * @param[in] rpolicy - policy to add
+ * @param[in] rpolicy - policy type to construct
+ * @param[in] fpolicy - fan policy object
+ *
+ * @return - The constructed redundancy policy type for the fan
*/
- void addPolicy(const json& rpolicy);
+ std::unique_ptr<RedundancyPolicy> getPolicy(const json& rpolicy,
+ const fanPolicy& fpolicy);
};
/**