blob: d1bcbfbf29b8cad77a5f0dedce1cb9ad85be4784 [file] [log] [blame]
Deepak Kodihalli72654f12017-06-12 04:33:29 -05001#pragma once
2
3#include <string>
4#include <vector>
5#include <experimental/filesystem>
6#include "elog_entry.hpp"
7#include "config.h"
8
9namespace phosphor
10{
11namespace logging
12{
13
14namespace fs = std::experimental::filesystem;
15
16/** @brief Function required by Cereal to perform serialization.
17 * @tparam Archive - Cereal archive type (binary in our case).
18 * @param[in] a - reference to Cereal archive.
19 * @param[in] e - const reference to error entry.
20 */
21template<class Archive>
22void save(Archive& a, const Entry& e)
23{
24 a(e.id(), e.severity(), e.timestamp(),
25 e.message(), e.additionalData(), e.associations(), e.resolved());
26}
27
28/** @brief Function required by Cereal to perform deserialization.
29 * @tparam Archive - Cereal archive type (binary in our case).
30 * @param[in] a - reference to Cereal archive.
31 * @param[in] e - reference to error entry.
32 */
33template<class Archive>
34void load(Archive& a, Entry& e)
35{
36 using namespace
37 sdbusplus::xyz::openbmc_project::Logging::server;
38
39 uint32_t id{};
40 Entry::Level severity{};
41 uint64_t timestamp{};
42 std::string message{};
43 std::vector<std::string> additionalData{};
44 bool resolved{};
45 AssociationList associations{};
46
47 a(id, severity, timestamp, message,
48 additionalData, associations, resolved);
49
50 e.id(id);
51 e.severity(severity);
52 e.timestamp(timestamp);
53 e.message(message);
54 e.additionalData(additionalData);
55 e.sdbusplus::xyz::openbmc_project::
56 Logging::server::Entry::resolved(resolved);
57 e.associations(associations);
58}
59
60/** @brief Serialize and persist error d-bus object
61 * @param[in] a - const reference to error entry.
62 * @param[in] dir - pathname of directory where the serialized error will
63 * be placed.
64 * @return fs::path - pathname of persisted error file
65 */
66fs::path serialize(const Entry& e,
67 const fs::path& dir = fs::path(ERRLOG_PERSIST_PATH));
68
69/** @brief Deserialze a persisted error into a d-bus object
70 * @param[in] path - pathname of persisted error file
71 * @param[in] e - reference to error object which is the target of
72 * deserialization.
73 * @return bool - true if the deserialization was successful, false otherwise.
74 */
75bool deserialize(const fs::path& path, Entry& e);
76
77} // namespace logging
78} // namespace phosphor