blob: 14737fb3e0ed8655b9e29b68f97b77768581f8f6 [file] [log] [blame]
Gunnar Millsec1b41c2017-05-02 12:20:36 -05001#pragma once
2
3#include <sdbusplus/server.hpp>
4#include "activation.hpp"
5
6namespace phosphor
7{
8namespace software
9{
10namespace updater
11{
12
Patrick Williamse75d10f2017-05-30 16:56:32 -050013namespace MatchRules = sdbusplus::bus::match::rules;
14
Gunnar Millsec1b41c2017-05-02 12:20:36 -050015/** @class ItemUpdater
16 * @brief Manages the activation of the BMC version items.
17 */
18class 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 Khan35e83f32017-05-22 11:37:32 -050028 /*
29 * @brief Types of Activation status for image validation.
30 */
31 enum class ActivationStatus
32 {
33 ready,
34 invalid,
35 active
36 };
37
Gunnar Millsec1b41c2017-05-02 12:20:36 -050038 /** @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 Williamse75d10f2017-05-30 16:56:32 -050046 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 Millsec1b41c2017-05-02 12:20:36 -050054
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 Millsec1b41c2017-05-02 12:20:36 -050060 */
Patrick Williamse75d10f2017-05-30 16:56:32 -050061 void createActivation(sdbusplus::message::message& msg);
Gunnar Millsec1b41c2017-05-02 12:20:36 -050062
Saqib Khan35e83f32017-05-22 11:37:32 -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 - 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 Millsec1b41c2017-05-02 12:20:36 -050075 /** @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 Williamse75d10f2017-05-30 16:56:32 -050083 sdbusplus::bus::match_t versionMatch;
Gunnar Millsec1b41c2017-05-02 12:20:36 -050084
85};
86
87
88
89} // namespace updater
90} // namespace software
91} // namespace phosphor