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 
13 namespace MatchRules = sdbusplus::bus::match::rules;
14 
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 
28         /*
29          * @brief Types of Activation status for image validation.
30          */
31         enum class ActivationStatus
32         {
33             ready,
34             invalid,
35             active
36         };
37 
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,
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         };
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
60          */
61         void createActivation(sdbusplus::message::message& msg);
62 
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 
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 */
83         sdbusplus::bus::match_t versionMatch;
84 
85 };
86 
87 
88 
89 } // namespace updater
90 } // namespace software
91 } // namespace phosphor
92