summaryrefslogtreecommitdiffstats
path: root/elog_serialize.hpp
diff options
context:
space:
mode:
authorDeepak Kodihalli <dkodihal@in.ibm.com>2017-06-12 04:33:29 -0500
committerPatrick Williams <patrick@stwcx.xyz>2017-06-26 02:33:34 +0000
commit72654f10e45056ab55b77d835e2bfd01e8d98480 (patch)
treea81c82f786690244abf0a8be2185e6c775cabac5 /elog_serialize.hpp
parent979632aeb629b4cb62aed276f7422c34cd7983bc (diff)
downloadphosphor-logging-72654f10e45056ab55b77d835e2bfd01e8d98480.tar.gz
phosphor-logging-72654f10e45056ab55b77d835e2bfd01e8d98480.zip
Persist error d-bus objects
Use Cereal to implement serialization and de-serialization of properties of error d-bus objects. Serialize and persist error d-bus objects as they are put on the bus. De-serialize and restore them (if persistent ones exist) when phosphor-log-manager starts up. Change-Id: I1f5df1abbe74bfdb86e3e82a78ff7115e90e2112 Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
Diffstat (limited to 'elog_serialize.hpp')
-rw-r--r--elog_serialize.hpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/elog_serialize.hpp b/elog_serialize.hpp
new file mode 100644
index 0000000..d1bcbfb
--- /dev/null
+++ b/elog_serialize.hpp
@@ -0,0 +1,78 @@
+#pragma once
+
+#include <string>
+#include <vector>
+#include <experimental/filesystem>
+#include "elog_entry.hpp"
+#include "config.h"
+
+namespace phosphor
+{
+namespace logging
+{
+
+namespace fs = std::experimental::filesystem;
+
+/** @brief Function required by Cereal to perform serialization.
+ * @tparam Archive - Cereal archive type (binary in our case).
+ * @param[in] a - reference to Cereal archive.
+ * @param[in] e - const reference to error entry.
+ */
+template<class Archive>
+void save(Archive& a, const Entry& e)
+{
+ a(e.id(), e.severity(), e.timestamp(),
+ e.message(), e.additionalData(), e.associations(), e.resolved());
+}
+
+/** @brief Function required by Cereal to perform deserialization.
+ * @tparam Archive - Cereal archive type (binary in our case).
+ * @param[in] a - reference to Cereal archive.
+ * @param[in] e - reference to error entry.
+ */
+template<class Archive>
+void load(Archive& a, Entry& e)
+{
+ using namespace
+ sdbusplus::xyz::openbmc_project::Logging::server;
+
+ uint32_t id{};
+ Entry::Level severity{};
+ uint64_t timestamp{};
+ std::string message{};
+ std::vector<std::string> additionalData{};
+ bool resolved{};
+ AssociationList associations{};
+
+ a(id, severity, timestamp, message,
+ additionalData, associations, resolved);
+
+ e.id(id);
+ e.severity(severity);
+ e.timestamp(timestamp);
+ e.message(message);
+ e.additionalData(additionalData);
+ e.sdbusplus::xyz::openbmc_project::
+ Logging::server::Entry::resolved(resolved);
+ e.associations(associations);
+}
+
+/** @brief Serialize and persist error d-bus object
+ * @param[in] a - const reference to error entry.
+ * @param[in] dir - pathname of directory where the serialized error will
+ * be placed.
+ * @return fs::path - pathname of persisted error file
+ */
+fs::path serialize(const Entry& e,
+ const fs::path& dir = fs::path(ERRLOG_PERSIST_PATH));
+
+/** @brief Deserialze a persisted error into a d-bus object
+ * @param[in] path - pathname of persisted error file
+ * @param[in] e - reference to error object which is the target of
+ * deserialization.
+ * @return bool - true if the deserialization was successful, false otherwise.
+ */
+bool deserialize(const fs::path& path, Entry& e);
+
+} // namespace logging
+} // namespace phosphor
OpenPOWER on IntegriCloud