blob: 216b1d7f68bd1874b335b42559209350689daded [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>
Adriana Kobylak2d8fa222017-03-15 12:34:32 -05006
7namespace openpower
8{
9namespace software
10{
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -050011namespace updater
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050012{
13
Michael Tritzdd961b62017-05-17 14:07:03 -050014using ItemUpdaterInherit = sdbusplus::server::object::object<
15 sdbusplus::xyz::openbmc_project::Common::server::FactoryReset>;
Patrick Williams3accb322017-05-30 16:29:52 -050016namespace MatchRules = sdbusplus::bus::match::rules;
Michael Tritzdd961b62017-05-17 14:07:03 -050017
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050018/** @class ItemUpdater
19 * @brief Manages the activation of the version items.
20 */
Michael Tritzdd961b62017-05-17 14:07:03 -050021class ItemUpdater : public ItemUpdaterInherit
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050022{
23 public:
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050024 /** @brief Constructs ItemUpdater
25 *
26 * @param[in] bus - The Dbus bus object
Michael Tritzdd961b62017-05-17 14:07:03 -050027 * @param[in] path - The Dbus path
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050028 */
Michael Tritzdd961b62017-05-17 14:07:03 -050029 ItemUpdater(sdbusplus::bus::bus& bus, const std::string& path) :
30 ItemUpdaterInherit(bus, path.c_str()),
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050031 busItem(bus),
32 versionMatch(
33 bus,
Patrick Williams3accb322017-05-30 16:29:52 -050034 MatchRules::interfacesAdded() +
35 MatchRules::path("/xyz/openbmc_project/software"),
36 std::bind(
37 std::mem_fn(&ItemUpdater::createActivation),
38 this,
39 std::placeholders::_1))
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050040 {
41 }
42
43 private:
44 /** @brief Callback function for Software.Version match.
45 * @details Creates an Activation dbus object.
46 *
47 * @param[in] msg - Data associated with subscribed signal
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050048 */
Patrick Williams3accb322017-05-30 16:29:52 -050049 void createActivation(sdbusplus::message::message& msg);
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050050
Saqib Khan7254f0e2017-04-10 21:45:37 -050051 /**
52 * @brief Get the extended version from the specified file.
53 *
54 * @param[in] manifestFilePath - File to read.
55 *
56 * @return The extended version.
57 */
58 static std::string getExtendedVersion(const std::string&
59 manifestFilePath);
Saqib Khana8ade7e2017-04-12 10:27:56 -050060 /**
61 * @brief Validates the presence of SquashFS iamge in the image dir.
62 *
63 * @param[in] versionId - The software version ID.
64 * @param[out] result - 0 --> if validation was successful
65 * - -1--> Otherwise
66 */
67 static int validateSquashFSImage(const std::string& versionId);
Saqib Khan7254f0e2017-04-10 21:45:37 -050068
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050069 /** @brief Persistent sdbusplus DBus bus connection. */
70 sdbusplus::bus::bus& busItem;
71
72 /** @brief Persistent map of Activation dbus objects and their
73 * version id */
Adriana Kobylak268616b2017-04-05 15:23:30 -050074 std::map<std::string, std::unique_ptr<Activation>> activations;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050075
76 /** @brief sdbusplus signal match for Software.Version */
Patrick Williams3accb322017-05-30 16:29:52 -050077 sdbusplus::bus::match_t versionMatch;
Michael Tritzdd961b62017-05-17 14:07:03 -050078
79 /** @brief Host factory reset - clears PNOR partitions for each
80 * Activation dbus object */
81 void reset() override;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050082};
83
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -050084} // namespace updater
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050085} // namespace software
86} // namespace openpower