blob: 75b2a68466fbee651aa327954bd78558e9aeef7b [file] [log] [blame]
Gunnar Millsec1b41c2017-05-02 12:20:36 -05001#pragma once
2
3#include <sdbusplus/server.hpp>
4#include "activation.hpp"
Saqib Khan705f1bf2017-06-09 23:58:38 -05005#include "version.hpp"
Gunnar Millsec1b41c2017-05-02 12:20:36 -05006
7namespace phosphor
8{
9namespace software
10{
11namespace updater
12{
13
Patrick Williamse75d10f2017-05-30 16:56:32 -050014namespace MatchRules = sdbusplus::bus::match::rules;
15
Gunnar Millsec1b41c2017-05-02 12:20:36 -050016/** @class ItemUpdater
17 * @brief Manages the activation of the BMC version items.
18 */
19class 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
Saqib Khan35e83f32017-05-22 11:37:32 -050029 /*
30 * @brief Types of Activation status for image validation.
31 */
32 enum class ActivationStatus
33 {
34 ready,
35 invalid,
36 active
37 };
38
Gunnar Millsec1b41c2017-05-02 12:20:36 -050039 /** @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,
Patrick Williamse75d10f2017-05-30 16:56:32 -050047 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 {
Saqib Khanba239882017-05-26 08:41:54 -050054 processBMCImage();
Patrick Williamse75d10f2017-05-30 16:56:32 -050055 };
Gunnar Millsec1b41c2017-05-02 12:20:36 -050056
Saqib Khan4c1aec02017-07-06 11:46:13 -050057 /** @brief Sets the given priority free by incrementing
58 * any existing priority with the same value by 1
59 *
60 * @param[in] value - The priority that needs to be set free.
61 *
62 * @return None
63 */
64 void freePriority(uint8_t value);
65
Saqib Khanba239882017-05-26 08:41:54 -050066 /**
67 * @brief Create and populate the active BMC Version.
68 */
69 void processBMCImage();
70
Gunnar Millsec1b41c2017-05-02 12:20:36 -050071 private:
72 /** @brief Callback function for Software.Version match.
73 * @details Creates an Activation dbus object.
74 *
75 * @param[in] msg - Data associated with subscribed signal
Gunnar Millsec1b41c2017-05-02 12:20:36 -050076 */
Patrick Williamse75d10f2017-05-30 16:56:32 -050077 void createActivation(sdbusplus::message::message& msg);
Gunnar Millsec1b41c2017-05-02 12:20:36 -050078
Saqib Khan35e83f32017-05-22 11:37:32 -050079 /**
80 * @brief Validates the presence of SquashFS iamge in the image dir.
81 *
Saqib Khan19177d32017-06-20 08:11:49 -050082 * @param[in] filePath - The path to the image dir.
Saqib Khan35e83f32017-05-22 11:37:32 -050083 * @param[out] result - ActivationStatus Enum.
84 * ready if validation was successful.
85 * invalid if validation fail.
86 * active if image is the current version.
87 *
88 */
Saqib Khan19177d32017-06-20 08:11:49 -050089 ActivationStatus validateSquashFSImage(const std::string& filePath);
Saqib Khan35e83f32017-05-22 11:37:32 -050090
Gunnar Millsec1b41c2017-05-02 12:20:36 -050091 /** @brief Persistent sdbusplus DBus bus connection. */
92 sdbusplus::bus::bus& bus;
93
94 /** @brief Persistent map of Activation dbus objects and their
95 * version id */
96 std::map<std::string, std::unique_ptr<Activation>> activations;
97
Saqib Khan705f1bf2017-06-09 23:58:38 -050098 /** @brief Persistent map of Version dbus objects and their
99 * version id */
100 std::map<std::string, std::unique_ptr<phosphor::software::
101 manager::Version>> versions;
102
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500103 /** @brief sdbusplus signal match for Software.Version */
Patrick Williamse75d10f2017-05-30 16:56:32 -0500104 sdbusplus::bus::match_t versionMatch;
Gunnar Millsec1b41c2017-05-02 12:20:36 -0500105
106};
107
108
109
110} // namespace updater
111} // namespace software
112} // namespace phosphor