diff options
author | Deepak Kodihalli <dkodihal@in.ibm.com> | 2017-06-12 04:33:29 -0500 |
---|---|---|
committer | Patrick Williams <patrick@stwcx.xyz> | 2017-06-26 02:33:34 +0000 |
commit | 72654f10e45056ab55b77d835e2bfd01e8d98480 (patch) | |
tree | a81c82f786690244abf0a8be2185e6c775cabac5 /elog_serialize.cpp | |
parent | 979632aeb629b4cb62aed276f7422c34cd7983bc (diff) | |
download | phosphor-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.cpp')
-rw-r--r-- | elog_serialize.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/elog_serialize.cpp b/elog_serialize.cpp new file mode 100644 index 0000000..0468e11 --- /dev/null +++ b/elog_serialize.cpp @@ -0,0 +1,35 @@ +#include <cereal/types/string.hpp> +#include <cereal/types/vector.hpp> +#include <cereal/types/tuple.hpp> +#include <cereal/archives/binary.hpp> +#include <fstream> +#include "elog_serialize.hpp" + +namespace phosphor +{ +namespace logging +{ + +fs::path serialize(const Entry& e, const fs::path& dir) +{ + auto path = dir / std::to_string(e.id()); + std::ofstream os(path.c_str(), std::ios::binary); + cereal::BinaryOutputArchive oarchive(os); + oarchive(e); + return path; +} + +bool deserialize(const fs::path& path, Entry& e) +{ + if (fs::exists(path)) + { + std::ifstream is(path.c_str(), std::ios::in | std::ios::binary); + cereal::BinaryInputArchive iarchive(is); + iarchive(e); + return true; + } + return false; +} + +} // namespace logging +} // namespace phosphor |