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