Matt Spinler | 23818bb | 2018-05-23 11:00:15 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Matt Spinler | 23818bb | 2018-05-23 11:00:15 -0500 | [diff] [blame] | 3 | #include "dbus.hpp" |
| 4 | #include "interfaces.hpp" |
| 5 | |
Matt Spinler | 66e0707 | 2018-09-12 10:36:14 -0500 | [diff] [blame] | 6 | #include <experimental/filesystem> |
| 7 | |
Matt Spinler | 23818bb | 2018-05-23 11:00:15 -0500 | [diff] [blame] | 8 | namespace ibm |
| 9 | { |
| 10 | namespace logging |
| 11 | { |
| 12 | |
| 13 | namespace fs = std::experimental::filesystem; |
| 14 | |
| 15 | /** |
| 16 | * @class Callout |
| 17 | * |
| 18 | * This class provides information about a callout by utilizing the |
| 19 | * xyz.openbmc_project.Inventory.Decorator.Asset and |
| 20 | * xyz.openbmc_project.Common.ObjectPath interfaces. |
| 21 | * |
| 22 | * It also has the ability to persist and restore its data. |
| 23 | */ |
| 24 | class Callout : public CalloutObject |
| 25 | { |
| 26 | public: |
| 27 | Callout() = delete; |
| 28 | Callout(const Callout&) = delete; |
| 29 | Callout& operator=(const Callout&) = delete; |
| 30 | Callout(Callout&&) = default; |
| 31 | Callout& operator=(Callout&&) = default; |
| 32 | ~Callout() = default; |
| 33 | |
| 34 | /** |
| 35 | * Constructor |
| 36 | * |
| 37 | * Populates the Asset D-Bus properties with data from the property map. |
| 38 | * |
| 39 | * @param[in] bus - D-Bus object |
| 40 | * @param[in] objectPath - object path |
| 41 | * @param[in] inventoryPath - inventory path of the callout |
| 42 | * @param[in] id - which callout this is |
| 43 | * @param[in] timestamp - timestamp when the log was created |
| 44 | * @param[in] properties - the properties for the Asset interface. |
| 45 | */ |
| 46 | Callout(sdbusplus::bus::bus& bus, const std::string& objectPath, |
| 47 | const std::string& inventoryPath, size_t id, uint64_t timestamp, |
| 48 | const DbusPropertyMap& properties); |
| 49 | /** |
| 50 | * Constructor |
| 51 | * |
| 52 | * This version is for when the object is being restored and does |
| 53 | * not take the properties map. |
| 54 | * |
| 55 | * @param[in] bus - D-Bus object |
| 56 | * @param[in] objectPath - object path |
| 57 | * @param[in] id - which callout this is |
| 58 | * @param[in] timestamp - timestamp when the log was created |
| 59 | * @param[in] properties - the properties for the Asset interface. |
| 60 | */ |
| 61 | Callout(sdbusplus::bus::bus& bus, const std::string& objectPath, size_t id, |
| 62 | uint64_t timestamp); |
| 63 | |
| 64 | /** |
| 65 | * Returns the callout ID |
| 66 | * |
| 67 | * @return id - the ID |
| 68 | */ |
| 69 | inline auto id() const |
| 70 | { |
| 71 | return entryID; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Sets the callout ID |
| 76 | * |
| 77 | * @param[in] id - the ID |
| 78 | */ |
| 79 | inline void id(uint32_t id) |
| 80 | { |
| 81 | entryID = id; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Returns the timestamp |
| 86 | * |
| 87 | * @return timestamp |
| 88 | */ |
| 89 | inline auto ts() const |
| 90 | { |
| 91 | return timestamp; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Sets the timestamp |
| 96 | * |
| 97 | * @param[in] ts - the timestamp |
| 98 | */ |
| 99 | inline void ts(uint64_t ts) |
| 100 | { |
| 101 | timestamp = ts; |
| 102 | } |
| 103 | |
Matt Spinler | ef3b86f | 2018-05-23 11:19:10 -0500 | [diff] [blame] | 104 | /** |
| 105 | * Serializes the class instance into a file in the |
| 106 | * directory passed in. The filename will match the |
| 107 | * ID value passed into the constructor. |
| 108 | * |
| 109 | * @param[in] - the directory to save the file in. |
| 110 | */ |
| 111 | void serialize(const fs::path& dir); |
| 112 | |
| 113 | /** |
| 114 | * Loads the class members in from a file written by a previous |
| 115 | * call to serialize(). The filename it uses is the ID |
| 116 | * value passed into the constructor in the directory |
| 117 | * passed to this function. |
| 118 | * |
| 119 | * @param[in] dir - the directory to look for the file in |
| 120 | * |
| 121 | * @return bool - true if the deserialization was successful, |
| 122 | * false if it wasn't |
| 123 | */ |
| 124 | bool deserialize(const fs::path& dir); |
| 125 | |
Matt Spinler | 23818bb | 2018-05-23 11:00:15 -0500 | [diff] [blame] | 126 | private: |
| 127 | /** |
Matt Spinler | ef3b86f | 2018-05-23 11:19:10 -0500 | [diff] [blame] | 128 | * Returns the fully qualified filename to use for the serialization |
| 129 | * data. The file is the ID value, like "0", in the base directory |
| 130 | * passed in. |
| 131 | * |
| 132 | * @param[in] baseDir - the directory the file will be in |
| 133 | * |
| 134 | * @return path - the filename |
| 135 | */ |
| 136 | inline auto getFilePath(const fs::path& baseDir) |
| 137 | { |
| 138 | return baseDir / std::to_string(entryID); |
| 139 | } |
| 140 | |
| 141 | /** |
Matt Spinler | 23818bb | 2018-05-23 11:00:15 -0500 | [diff] [blame] | 142 | * The unique identifier for the callout, as error logs can have |
| 143 | * multiple callouts. They start at 0. |
| 144 | */ |
| 145 | size_t entryID; |
| 146 | |
| 147 | /** |
| 148 | * The timestamp of when the error log was created. |
| 149 | * Used for ensuring the callout data is being restored for |
| 150 | * the correct error log. |
| 151 | */ |
| 152 | uint64_t timestamp; |
| 153 | }; |
Matt Spinler | 66e0707 | 2018-09-12 10:36:14 -0500 | [diff] [blame] | 154 | } // namespace logging |
| 155 | } // namespace ibm |