PEL: Add repository to save PELs
Create the Repository class that can save PELs in (and later retrieve
them from) the filesystem. It provides an add() method that can add
a PEL object to the repository.
Now, when the Manager class sees an OpenBMC event log created with the
RAWPEL metadata in the AdditionalData property that points at a file
that contains a PEL, it can save that PEL. Before the PEL is saved, the
log ID and commit timestamp fields in the PEL will be updated - the log
ID to a unique value, and the timestamp to the current time.
Change-Id: I8dbaddf0f155bcb6d40b933294ada83feb75ce53
diff --git a/extensions/openpower-pels/repository.hpp b/extensions/openpower-pels/repository.hpp
new file mode 100644
index 0000000..5b15506
--- /dev/null
+++ b/extensions/openpower-pels/repository.hpp
@@ -0,0 +1,62 @@
+#pragma once
+#include "bcd_time.hpp"
+#include "pel.hpp"
+
+#include <algorithm>
+#include <filesystem>
+
+namespace openpower
+{
+namespace pels
+{
+
+/**
+ * @class Repository
+ *
+ * The class handles saving and retrieving PELs on the BMC.
+ */
+class Repository
+{
+ public:
+ Repository() = delete;
+ ~Repository() = default;
+ Repository(const Repository&) = default;
+ Repository& operator=(const Repository&) = default;
+ Repository(Repository&&) = default;
+ Repository& operator=(Repository&&) = default;
+
+ /**
+ * @brief Constructor
+ *
+ * @param[in] basePath - the base filesystem path for the repository
+ */
+ Repository(const std::filesystem::path& basePath);
+
+ /**
+ * @brief Adds a PEL to the repository
+ *
+ * Throws File.Error.Open or File.Error.Write exceptions on failure
+ *
+ * @param[in] pel - the PEL to add
+ */
+ void add(std::unique_ptr<PEL>& pel);
+
+ /**
+ * @brief Generates the filename to use for the PEL ID and BCDTime.
+ *
+ * @param[in] pelID - the PEL ID
+ * @param[in] time - the BCD time
+ *
+ * @return string - A filename string of <BCD_time>_<pelID>
+ */
+ static std::string getPELFilename(uint32_t pelID, const BCDTime& time);
+
+ private:
+ /**
+ * @brief The filesystem path to the PEL logs.
+ */
+ const std::filesystem::path _logPath;
+};
+
+} // namespace pels
+} // namespace openpower