xref: /openbmc/ibm-logging/callout.hpp (revision ef3b86f2a297e3408824d059e2a9991302fe2c3e)
123818bb0SMatt Spinler #pragma once
223818bb0SMatt Spinler 
323818bb0SMatt Spinler #include <experimental/filesystem>
423818bb0SMatt Spinler #include "dbus.hpp"
523818bb0SMatt Spinler #include "interfaces.hpp"
623818bb0SMatt Spinler 
723818bb0SMatt Spinler namespace ibm
823818bb0SMatt Spinler {
923818bb0SMatt Spinler namespace logging
1023818bb0SMatt Spinler {
1123818bb0SMatt Spinler 
1223818bb0SMatt Spinler namespace fs = std::experimental::filesystem;
1323818bb0SMatt Spinler 
1423818bb0SMatt Spinler /**
1523818bb0SMatt Spinler  *  @class Callout
1623818bb0SMatt Spinler  *
1723818bb0SMatt Spinler  *  This class provides information about a callout by utilizing the
1823818bb0SMatt Spinler  *  xyz.openbmc_project.Inventory.Decorator.Asset and
1923818bb0SMatt Spinler  *  xyz.openbmc_project.Common.ObjectPath interfaces.
2023818bb0SMatt Spinler  *
2123818bb0SMatt Spinler  *  It also has the ability to persist and restore its data.
2223818bb0SMatt Spinler  */
2323818bb0SMatt Spinler class Callout : public CalloutObject
2423818bb0SMatt Spinler {
2523818bb0SMatt Spinler   public:
2623818bb0SMatt Spinler     Callout() = delete;
2723818bb0SMatt Spinler     Callout(const Callout&) = delete;
2823818bb0SMatt Spinler     Callout& operator=(const Callout&) = delete;
2923818bb0SMatt Spinler     Callout(Callout&&) = default;
3023818bb0SMatt Spinler     Callout& operator=(Callout&&) = default;
3123818bb0SMatt Spinler     ~Callout() = default;
3223818bb0SMatt Spinler 
3323818bb0SMatt Spinler     /**
3423818bb0SMatt Spinler      * Constructor
3523818bb0SMatt Spinler      *
3623818bb0SMatt Spinler      * Populates the Asset D-Bus properties with data from the property map.
3723818bb0SMatt Spinler      *
3823818bb0SMatt Spinler      * @param[in] bus - D-Bus object
3923818bb0SMatt Spinler      * @param[in] objectPath - object path
4023818bb0SMatt Spinler      * @param[in] inventoryPath - inventory path of the callout
4123818bb0SMatt Spinler      * @param[in] id - which callout this is
4223818bb0SMatt Spinler      * @param[in] timestamp - timestamp when the log was created
4323818bb0SMatt Spinler      * @param[in] properties - the properties for the Asset interface.
4423818bb0SMatt Spinler      */
4523818bb0SMatt Spinler     Callout(sdbusplus::bus::bus& bus, const std::string& objectPath,
4623818bb0SMatt Spinler             const std::string& inventoryPath, size_t id, uint64_t timestamp,
4723818bb0SMatt Spinler             const DbusPropertyMap& properties);
4823818bb0SMatt Spinler     /**
4923818bb0SMatt Spinler      * Constructor
5023818bb0SMatt Spinler      *
5123818bb0SMatt Spinler      * This version is for when the object is being restored and does
5223818bb0SMatt Spinler      * not take the properties map.
5323818bb0SMatt Spinler      *
5423818bb0SMatt Spinler      * @param[in] bus - D-Bus object
5523818bb0SMatt Spinler      * @param[in] objectPath - object path
5623818bb0SMatt Spinler      * @param[in] id - which callout this is
5723818bb0SMatt Spinler      * @param[in] timestamp - timestamp when the log was created
5823818bb0SMatt Spinler      * @param[in] properties - the properties for the Asset interface.
5923818bb0SMatt Spinler      */
6023818bb0SMatt Spinler     Callout(sdbusplus::bus::bus& bus, const std::string& objectPath, size_t id,
6123818bb0SMatt Spinler             uint64_t timestamp);
6223818bb0SMatt Spinler 
6323818bb0SMatt Spinler     /**
6423818bb0SMatt Spinler      * Returns the callout ID
6523818bb0SMatt Spinler      *
6623818bb0SMatt Spinler      * @return id - the ID
6723818bb0SMatt Spinler      */
6823818bb0SMatt Spinler     inline auto id() const
6923818bb0SMatt Spinler     {
7023818bb0SMatt Spinler         return entryID;
7123818bb0SMatt Spinler     }
7223818bb0SMatt Spinler 
7323818bb0SMatt Spinler     /**
7423818bb0SMatt Spinler      * Sets the callout ID
7523818bb0SMatt Spinler      *
7623818bb0SMatt Spinler      * @param[in] id - the ID
7723818bb0SMatt Spinler      */
7823818bb0SMatt Spinler     inline void id(uint32_t id)
7923818bb0SMatt Spinler     {
8023818bb0SMatt Spinler         entryID = id;
8123818bb0SMatt Spinler     }
8223818bb0SMatt Spinler 
8323818bb0SMatt Spinler     /**
8423818bb0SMatt Spinler      * Returns the timestamp
8523818bb0SMatt Spinler      *
8623818bb0SMatt Spinler      * @return timestamp
8723818bb0SMatt Spinler      */
8823818bb0SMatt Spinler     inline auto ts() const
8923818bb0SMatt Spinler     {
9023818bb0SMatt Spinler         return timestamp;
9123818bb0SMatt Spinler     }
9223818bb0SMatt Spinler 
9323818bb0SMatt Spinler     /**
9423818bb0SMatt Spinler      * Sets the timestamp
9523818bb0SMatt Spinler      *
9623818bb0SMatt Spinler      * @param[in] ts - the timestamp
9723818bb0SMatt Spinler      */
9823818bb0SMatt Spinler     inline void ts(uint64_t ts)
9923818bb0SMatt Spinler     {
10023818bb0SMatt Spinler         timestamp = ts;
10123818bb0SMatt Spinler     }
10223818bb0SMatt Spinler 
103*ef3b86f2SMatt Spinler     /**
104*ef3b86f2SMatt Spinler      * Serializes the class instance into a file in the
105*ef3b86f2SMatt Spinler      * directory passed in.  The filename will match the
106*ef3b86f2SMatt Spinler      * ID value passed into the constructor.
107*ef3b86f2SMatt Spinler      *
108*ef3b86f2SMatt Spinler      * @param[in] - the directory to save the file  in.
109*ef3b86f2SMatt Spinler      */
110*ef3b86f2SMatt Spinler     void serialize(const fs::path& dir);
111*ef3b86f2SMatt Spinler 
112*ef3b86f2SMatt Spinler     /**
113*ef3b86f2SMatt Spinler      * Loads the class members in from a file written by a previous
114*ef3b86f2SMatt Spinler      * call to serialize().  The filename it uses is the ID
115*ef3b86f2SMatt Spinler      * value passed into the constructor in the directory
116*ef3b86f2SMatt Spinler      * passed to this function.
117*ef3b86f2SMatt Spinler      *
118*ef3b86f2SMatt Spinler      * @param[in] dir - the directory to look for the file in
119*ef3b86f2SMatt Spinler      *
120*ef3b86f2SMatt Spinler      * @return bool - true if the deserialization was successful,
121*ef3b86f2SMatt Spinler      *                false if it wasn't
122*ef3b86f2SMatt Spinler      */
123*ef3b86f2SMatt Spinler     bool deserialize(const fs::path& dir);
124*ef3b86f2SMatt Spinler 
12523818bb0SMatt Spinler   private:
12623818bb0SMatt Spinler     /**
127*ef3b86f2SMatt Spinler      * Returns the fully qualified filename to use for the serialization
128*ef3b86f2SMatt Spinler      * data.  The file is the ID value, like "0", in the base directory
129*ef3b86f2SMatt Spinler      * passed in.
130*ef3b86f2SMatt Spinler      *
131*ef3b86f2SMatt Spinler      * @param[in] baseDir - the directory the file will be in
132*ef3b86f2SMatt Spinler      *
133*ef3b86f2SMatt Spinler      * @return path - the filename
134*ef3b86f2SMatt Spinler      */
135*ef3b86f2SMatt Spinler     inline auto getFilePath(const fs::path& baseDir)
136*ef3b86f2SMatt Spinler     {
137*ef3b86f2SMatt Spinler         return baseDir / std::to_string(entryID);
138*ef3b86f2SMatt Spinler     }
139*ef3b86f2SMatt Spinler 
140*ef3b86f2SMatt Spinler     /**
14123818bb0SMatt Spinler      * The unique identifier for the callout, as error logs can have
14223818bb0SMatt Spinler      * multiple callouts.  They start at 0.
14323818bb0SMatt Spinler      */
14423818bb0SMatt Spinler     size_t entryID;
14523818bb0SMatt Spinler 
14623818bb0SMatt Spinler     /**
14723818bb0SMatt Spinler      * The timestamp of when the error log was created.
14823818bb0SMatt Spinler      * Used for ensuring the callout data is being restored for
14923818bb0SMatt Spinler      * the correct error log.
15023818bb0SMatt Spinler      */
15123818bb0SMatt Spinler     uint64_t timestamp;
15223818bb0SMatt Spinler };
15323818bb0SMatt Spinler }
15423818bb0SMatt Spinler }
155