blob: 0e8558aebe21e56ad05b8e88042ba35f2ad5857d [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>;
16
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050017/** @class ItemUpdater
18 * @brief Manages the activation of the version items.
19 */
Michael Tritzdd961b62017-05-17 14:07:03 -050020class ItemUpdater : public ItemUpdaterInherit
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050021{
22 public:
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050023 /** @brief Constructs ItemUpdater
24 *
25 * @param[in] bus - The Dbus bus object
Michael Tritzdd961b62017-05-17 14:07:03 -050026 * @param[in] path - The Dbus path
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050027 */
Michael Tritzdd961b62017-05-17 14:07:03 -050028 ItemUpdater(sdbusplus::bus::bus& bus, const std::string& path) :
29 ItemUpdaterInherit(bus, path.c_str()),
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050030 busItem(bus),
31 versionMatch(
32 bus,
33 "type='signal',"
34 "member='InterfacesAdded',"
35 "path='/xyz/openbmc_project/software',"
36 "interface='org.freedesktop.DBus.ObjectManager'",
37 createActivation,
38 this)
39 {
40 }
41
42 private:
43 /** @brief Callback function for Software.Version match.
44 * @details Creates an Activation dbus object.
45 *
46 * @param[in] msg - Data associated with subscribed signal
47 * @param[in] userData - Pointer to this object instance
48 * @param[out] retError - Required param
49 */
50 static int createActivation(sd_bus_message* msg,
51 void* userData,
52 sd_bus_error* retError);
53
Saqib Khan7254f0e2017-04-10 21:45:37 -050054 /**
55 * @brief Get the extended version from the specified file.
56 *
57 * @param[in] manifestFilePath - File to read.
58 *
59 * @return The extended version.
60 */
61 static std::string getExtendedVersion(const std::string&
62 manifestFilePath);
Saqib Khana8ade7e2017-04-12 10:27:56 -050063 /**
64 * @brief Validates the presence of SquashFS iamge in the image dir.
65 *
66 * @param[in] versionId - The software version ID.
67 * @param[out] result - 0 --> if validation was successful
68 * - -1--> Otherwise
69 */
70 static int validateSquashFSImage(const std::string& versionId);
Saqib Khan7254f0e2017-04-10 21:45:37 -050071
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050072 /** @brief Persistent sdbusplus DBus bus connection. */
73 sdbusplus::bus::bus& busItem;
74
75 /** @brief Persistent map of Activation dbus objects and their
76 * version id */
Adriana Kobylak268616b2017-04-05 15:23:30 -050077 std::map<std::string, std::unique_ptr<Activation>> activations;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050078
79 /** @brief sdbusplus signal match for Software.Version */
80 sdbusplus::server::match::match versionMatch;
Michael Tritzdd961b62017-05-17 14:07:03 -050081
82 /** @brief Host factory reset - clears PNOR partitions for each
83 * Activation dbus object */
84 void reset() override;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050085};
86
Adriana Kobylakbefe5ce2017-04-05 15:57:44 -050087} // namespace updater
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050088} // namespace software
89} // namespace openpower