1 #pragma once
2 
3 #include <sdbusplus/bus.hpp>
4 #include "xyz/openbmc_project/Software/Version/server.hpp"
5 #include "xyz/openbmc_project/Common/FilePath/server.hpp"
6 
7 namespace openpower
8 {
9 namespace software
10 {
11 namespace updater
12 {
13 
14 class ItemUpdater;
15 
16 using VersionInherit = sdbusplus::server::object::object<
17         sdbusplus::xyz::openbmc_project::Software::server::Version,
18         sdbusplus::xyz::openbmc_project::Common::server::FilePath>;
19 
20 /** @class Version
21  *  @brief OpenBMC version software management implementation.
22  *  @details A concrete implementation for xyz.openbmc_project.Software.Version
23  *  D-Bus API.
24  */
25 class Version : public VersionInherit
26 {
27     public:
28         /** @brief Constructs Version Software Manager.
29          *
30          * @param[in] bus            - The D-Bus bus object
31          * @param[in] objPath        - The D-Bus object path
32          * @param[in] versionString  - The version string
33          * @param[in] versionPurpose - The version purpose
34          * @param[in] filePath       - The image filesystem path
35          */
36         Version(sdbusplus::bus::bus& bus,
37                 const std::string& objPath,
38                 const std::string& versionString,
39                 VersionPurpose versionPurpose,
40                 const std::string& filePath) :
41                         VersionInherit(bus, (objPath).c_str(), true)
42         {
43             // Set properties.
44             purpose(versionPurpose);
45             version(versionString);
46             path(filePath);
47 
48             // Emit deferred signal.
49             emit_object_added();
50         }
51 
52         /**
53          * @brief Read the manifest file to get the value of the key.
54          *
55          * @param[in] filePath - The path to the file which contains the value
56          *                       of keys.
57          * @param[in] keys     - A map of keys with empty values.
58          *
59          * @return The map of keys with filled values.
60          **/
61         static std::map<std::string, std::string> getValue(
62                 const std::string& filePath,
63                 std::map<std::string, std::string> keys);
64 
65         /**
66          * @brief Calculate the version id from the version string.
67          *
68          * @details The version id is a unique 8 hexadecimal digit id
69          *          calculated from the version string.
70          *
71          * @param[in] version - The image version string (e.g. v1.99.10-19).
72          *
73          * @return The id.
74          */
75         static std::string getId(const std::string& version);
76 };
77 
78 } // namespace updater
79 } // namespace software
80 } // namespace openpower
81