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