summaryrefslogtreecommitdiffstats
path: root/elog_serialize.hpp
blob: d1bcbfbf29b8cad77a5f0dedce1cb9ad85be4784 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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