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