1 #pragma once 2 3 #include <sdbusplus/server.hpp> 4 #include "activation.hpp" 5 #include "version.hpp" 6 7 namespace phosphor 8 { 9 namespace software 10 { 11 namespace updater 12 { 13 14 namespace MatchRules = sdbusplus::bus::match::rules; 15 16 /** @class ItemUpdater 17 * @brief Manages the activation of the BMC version items. 18 */ 19 class ItemUpdater 20 { 21 public: 22 ItemUpdater() = delete; 23 ~ItemUpdater() = default; 24 ItemUpdater(const ItemUpdater&) = delete; 25 ItemUpdater& operator=(const ItemUpdater&) = delete; 26 ItemUpdater(ItemUpdater&&) = delete; 27 ItemUpdater& operator=(ItemUpdater&&) = delete; 28 29 /* 30 * @brief Types of Activation status for image validation. 31 */ 32 enum class ActivationStatus 33 { 34 ready, 35 invalid, 36 active 37 }; 38 39 /** @brief Constructs ItemUpdater 40 * 41 * @param[in] bus - The Dbus bus object 42 */ 43 ItemUpdater(sdbusplus::bus::bus& bus) : 44 bus(bus), 45 versionMatch( 46 bus, 47 MatchRules::interfacesAdded() + 48 MatchRules::path("/xyz/openbmc_project/software"), 49 std::bind( 50 std::mem_fn(&ItemUpdater::createActivation), 51 this, 52 std::placeholders::_1)) 53 { 54 processBMCImage(); 55 }; 56 57 /** 58 * @brief Create and populate the active BMC Version. 59 */ 60 void processBMCImage(); 61 62 private: 63 /** @brief Callback function for Software.Version match. 64 * @details Creates an Activation dbus object. 65 * 66 * @param[in] msg - Data associated with subscribed signal 67 */ 68 void createActivation(sdbusplus::message::message& msg); 69 70 /** 71 * @brief Validates the presence of SquashFS iamge in the image dir. 72 * 73 * @param[in] versionId - The software version ID. 74 * @param[out] result - ActivationStatus Enum. 75 * ready if validation was successful. 76 * invalid if validation fail. 77 * active if image is the current version. 78 * 79 */ 80 ActivationStatus validateSquashFSImage(const std::string& versionId); 81 82 /** @brief Persistent sdbusplus DBus bus connection. */ 83 sdbusplus::bus::bus& bus; 84 85 /** @brief Persistent map of Activation dbus objects and their 86 * version id */ 87 std::map<std::string, std::unique_ptr<Activation>> activations; 88 89 /** @brief Persistent map of Version dbus objects and their 90 * version id */ 91 std::map<std::string, std::unique_ptr<phosphor::software:: 92 manager::Version>> versions; 93 94 /** @brief sdbusplus signal match for Software.Version */ 95 sdbusplus::bus::match_t versionMatch; 96 97 }; 98 99 100 101 } // namespace updater 102 } // namespace software 103 } // namespace phosphor 104