blob: 6409698659e6f89e1bfcddaf6382b2f15ad9ade0 [file] [log] [blame]
Adriana Kobylak2d8fa222017-03-15 12:34:32 -05001#pragma once
2
3#include <sdbusplus/server.hpp>
4#include "activation.hpp"
Michael Tritzdd961b62017-05-17 14:07:03 -05005#include <xyz/openbmc_project/Common/FactoryReset/server.hpp>
Saqib Khance148702017-06-11 12:01:58 -05006#include "version.hpp"
Adriana Kobylak2d8fa222017-03-15 12:34:32 -05007
8namespace openpower
9{
10namespace software
11{
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -050012namespace updater
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050013{
14
Michael Tritzdd961b62017-05-17 14:07:03 -050015using ItemUpdaterInherit = sdbusplus::server::object::object<
16 sdbusplus::xyz::openbmc_project::Common::server::FactoryReset>;
Patrick Williams3accb322017-05-30 16:29:52 -050017namespace MatchRules = sdbusplus::bus::match::rules;
Michael Tritzdd961b62017-05-17 14:07:03 -050018
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050019/** @class ItemUpdater
20 * @brief Manages the activation of the version items.
21 */
Michael Tritzdd961b62017-05-17 14:07:03 -050022class ItemUpdater : public ItemUpdaterInherit
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050023{
24 public:
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050025 /** @brief Constructs ItemUpdater
26 *
27 * @param[in] bus - The Dbus bus object
Michael Tritzdd961b62017-05-17 14:07:03 -050028 * @param[in] path - The Dbus path
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050029 */
Michael Tritzdd961b62017-05-17 14:07:03 -050030 ItemUpdater(sdbusplus::bus::bus& bus, const std::string& path) :
31 ItemUpdaterInherit(bus, path.c_str()),
Adriana Kobylakd6a549e2017-05-10 16:23:01 -050032 bus(bus),
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050033 versionMatch(
34 bus,
Patrick Williams3accb322017-05-30 16:29:52 -050035 MatchRules::interfacesAdded() +
36 MatchRules::path("/xyz/openbmc_project/software"),
37 std::bind(
38 std::mem_fn(&ItemUpdater::createActivation),
39 this,
40 std::placeholders::_1))
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050041 {
42 }
43
Saqib Khan81bac882017-06-08 12:17:01 -050044 /** @brief Sets the given priority free by incrementing
45 * any existing priority with the same value by 1
46 *
47 * @param[in] value - The priority that needs to be set free.
48 *
49 * @return None
50 */
51 void freePriority(uint8_t value);
52
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050053 private:
54 /** @brief Callback function for Software.Version match.
55 * @details Creates an Activation dbus object.
56 *
57 * @param[in] msg - Data associated with subscribed signal
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050058 */
Patrick Williams3accb322017-05-30 16:29:52 -050059 void createActivation(sdbusplus::message::message& msg);
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050060
Saqib Khan7254f0e2017-04-10 21:45:37 -050061 /**
62 * @brief Get the extended version from the specified file.
63 *
64 * @param[in] manifestFilePath - File to read.
65 *
66 * @return The extended version.
67 */
68 static std::string getExtendedVersion(const std::string&
69 manifestFilePath);
Saqib Khana8ade7e2017-04-12 10:27:56 -050070 /**
71 * @brief Validates the presence of SquashFS iamge in the image dir.
72 *
Adriana Kobylak5ba6b102017-05-19 09:41:27 -050073 * @param[in] filePath - The path to the SquashfFS image.
Saqib Khana8ade7e2017-04-12 10:27:56 -050074 * @param[out] result - 0 --> if validation was successful
75 * - -1--> Otherwise
76 */
Adriana Kobylak5ba6b102017-05-19 09:41:27 -050077 static int validateSquashFSImage(const std::string& filePath);
Saqib Khan7254f0e2017-04-10 21:45:37 -050078
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050079 /** @brief Persistent sdbusplus DBus bus connection. */
Adriana Kobylakd6a549e2017-05-10 16:23:01 -050080 sdbusplus::bus::bus& bus;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050081
82 /** @brief Persistent map of Activation dbus objects and their
83 * version id */
Adriana Kobylak268616b2017-04-05 15:23:30 -050084 std::map<std::string, std::unique_ptr<Activation>> activations;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050085
Saqib Khance148702017-06-11 12:01:58 -050086 /** @brief Persistent map of Version dbus objects and their
87 * version id */
88 std::map<std::string, std::unique_ptr<Version>> versions;
89
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050090 /** @brief sdbusplus signal match for Software.Version */
Patrick Williams3accb322017-05-30 16:29:52 -050091 sdbusplus::bus::match_t versionMatch;
Michael Tritzdd961b62017-05-17 14:07:03 -050092
93 /** @brief Host factory reset - clears PNOR partitions for each
94 * Activation dbus object */
95 void reset() override;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050096};
97
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -050098} // namespace updater
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050099} // namespace software
100} // namespace openpower