blob: 99c64c98e6b9c0c31a956faa6aa4b9f1b1a7b665 [file] [log] [blame]
Gunnar Mills392f2942017-04-12 11:04:37 -05001#pragma once
2
3#include <sdbusplus/bus.hpp>
4#include "xyz/openbmc_project/Software/Version/server.hpp"
Gunnar Millsef4781f2017-04-19 11:28:24 -05005#include "xyz/openbmc_project/Common/FilePath/server.hpp"
Leonel Gonzaleze4233682017-07-07 14:38:25 -05006#include <functional>
Gunnar Mills392f2942017-04-12 11:04:37 -05007
8namespace phosphor
9{
10namespace software
11{
12namespace manager
13{
14
Leonel Gonzaleze4233682017-07-07 14:38:25 -050015typedef std::function<void(std::string)> eraseFunc;
16
Gunnar Mills392f2942017-04-12 11:04:37 -050017using VersionInherit = sdbusplus::server::object::object<
Gunnar Millsa4fcb682017-10-06 13:14:12 -050018 sdbusplus::xyz::openbmc_project::Software::server::Version,
19 sdbusplus::xyz::openbmc_project::Common::server::FilePath>;
Gunnar Mills392f2942017-04-12 11:04:37 -050020
21/** @class Version
22 * @brief OpenBMC version software management implementation.
23 * @details A concrete implementation for xyz.openbmc_project.Software.Version
Gunnar Millsa4fcb682017-10-06 13:14:12 -050024 * D-Bus API.
Gunnar Mills392f2942017-04-12 11:04:37 -050025 */
26class Version : public VersionInherit
27{
28 public:
29 /** @brief Constructs Version Software Manager
30 *
Gunnar Millsa4fcb682017-10-06 13:14:12 -050031 * @param[in] bus - The D-Bus bus object
32 * @param[in] objPath - The D-Bus object path
33 * @param[in] versionString - The version string
Gunnar Millscebd1022017-04-17 16:10:15 -050034 * @param[in] versionPurpose - The version purpose
Gunnar Millsef4781f2017-04-19 11:28:24 -050035 * @param[in] filePath - The image filesystem path
Gunnar Mills392f2942017-04-12 11:04:37 -050036 */
37 Version(sdbusplus::bus::bus& bus,
38 const std::string& objPath,
Gunnar Millsa4fcb682017-10-06 13:14:12 -050039 const std::string& versionString,
Gunnar Millsef4781f2017-04-19 11:28:24 -050040 VersionPurpose versionPurpose,
Eddie James9440f492017-08-30 11:34:16 -050041 const std::string& filePath) : VersionInherit(
Gunnar Millsa4fcb682017-10-06 13:14:12 -050042 bus, (objPath).c_str(), true),
43 versionStr(versionString)
Gunnar Mills392f2942017-04-12 11:04:37 -050044 {
45 // Set properties.
Gunnar Millscebd1022017-04-17 16:10:15 -050046 purpose(versionPurpose);
Gunnar Millsa4fcb682017-10-06 13:14:12 -050047 version(versionString);
Gunnar Millsef4781f2017-04-19 11:28:24 -050048 path(filePath);
Gunnar Mills392f2942017-04-12 11:04:37 -050049 // Emit deferred signal.
50 emit_object_added();
51 }
52
53 /**
Gunnar Millscebd1022017-04-17 16:10:15 -050054 * @brief Read the manifest file to get the value of the key.
Gunnar Mills392f2942017-04-12 11:04:37 -050055 *
Gunnar Millscebd1022017-04-17 16:10:15 -050056 * @return The value of the key.
Gunnar Mills392f2942017-04-12 11:04:37 -050057 **/
Gunnar Millscebd1022017-04-17 16:10:15 -050058 static std::string getValue(const std::string& manifestFilePath,
59 std::string key);
Gunnar Mills392f2942017-04-12 11:04:37 -050060
61 /**
Gunnar Millsa4fcb682017-10-06 13:14:12 -050062 * @brief Calculate the version id from the version string.
63 *
64 * @details The version id is a unique 8 hexadecimal digit id
65 * calculated from the version string.
66 *
67 * @param[in] version - The image's version string (e.g. v1.99.10-19).
Gunnar Mills392f2942017-04-12 11:04:37 -050068 *
69 * @return The id.
Gunnar Millsa4fcb682017-10-06 13:14:12 -050070 */
Gunnar Mills392f2942017-04-12 11:04:37 -050071 static std::string getId(const std::string& version);
Gunnar Millscebd1022017-04-17 16:10:15 -050072
Saqib Khanba239882017-05-26 08:41:54 -050073 /**
Gunnar Millsa4fcb682017-10-06 13:14:12 -050074 * @brief Get the active BMC version string.
Saqib Khanba239882017-05-26 08:41:54 -050075 *
Gunnar Millsa4fcb682017-10-06 13:14:12 -050076 * @param[in] releaseFilePath - The path to the file which contains
77 * the release version string.
Saqib Khan1eef62d2017-08-10 15:29:34 -050078 *
Gunnar Millsa4fcb682017-10-06 13:14:12 -050079 * @return The version string (e.g. v1.99.10-19).
Saqib Khanba239882017-05-26 08:41:54 -050080 */
Saqib Khan1eef62d2017-08-10 15:29:34 -050081 static std::string getBMCVersion(const std::string& releaseFilePath);
Eddie James6d873712017-09-01 11:29:07 -050082
83 /* @brief Check if this version matches the currently running version
84 *
85 * @return - Returns true if this version matches the currently running
86 * version.
87 */
88 bool isFunctional();
89
90 private:
91 /** @brief This Version's version string */
92 const std::string versionStr;
Gunnar Mills392f2942017-04-12 11:04:37 -050093};
94
95} // namespace manager
96} // namespace software
97} // namespace phosphor