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