1 #pragma once
2 
3 #include "config.h"
4 
5 #include "types.hpp"
6 
7 #include <sdbusplus/server.hpp>
8 #include <xyz/openbmc_project/Association/Definitions/server.hpp>
9 #include <xyz/openbmc_project/Software/Activation/server.hpp>
10 #include <xyz/openbmc_project/Software/ExtendedVersion/server.hpp>
11 
12 namespace phosphor
13 {
14 namespace software
15 {
16 namespace updater
17 {
18 
19 namespace sdbusRule = sdbusplus::bus::match::rules;
20 
21 using ActivationInherit = sdbusplus::server::object::object<
22     sdbusplus::xyz::openbmc_project::Software::server::ExtendedVersion,
23     sdbusplus::xyz::openbmc_project::Software::server::Activation,
24     sdbusplus::xyz::openbmc_project::Association::server::Definitions>;
25 
26 /** @class Activation
27  *  @brief OpenBMC activation software management implementation.
28  *  @details A concrete implementation for
29  *  xyz.openbmc_project.Software.Activation DBus API.
30  */
31 class Activation : public ActivationInherit
32 {
33   public:
34     using Status = Activations;
35     /** @brief Constructs Activation Software Manager
36      *
37      * @param[in] bus    - The Dbus bus object
38      * @param[in] path   - The Dbus object path
39      * @param[in] versionId  - The software version id
40      * @param[in] extVersion - The extended version
41      * @param[in] activationStatus - The status of Activation
42      * @param[in] assocs - Association objects
43      */
44     Activation(sdbusplus::bus::bus& bus, const std::string& path,
45                const std::string& versionId, const std::string& extVersion,
46                sdbusplus::xyz::openbmc_project::Software::server::Activation::
47                    Activations activationStatus,
48                const AssociationList& assocs) :
49         ActivationInherit(bus, path.c_str(), true),
50         versionId(versionId), bus(bus), path(path),
51         systemdSignals(
52             bus,
53             sdbusRule::type::signal() + sdbusRule::member("JobRemoved") +
54                 sdbusRule::path("/org/freedesktop/systemd1") +
55                 sdbusRule::interface("org.freedesktop.systemd1.Manager"),
56             std::bind(&Activation::unitStateChange, this,
57                       std::placeholders::_1))
58     {
59         // Set Properties.
60         extendedVersion(extVersion);
61         activation(activationStatus);
62         associations(assocs);
63 
64         // Emit deferred signal.
65         emit_object_added();
66     }
67 
68     /** @brief Overloaded Activation property setter function
69      *
70      * @param[in] value - One of Activation::Activations
71      *
72      * @return Success or exception thrown
73      */
74     Activations activation(Activations value) override;
75 
76     /** @brief Activation */
77     using ActivationInherit::activation;
78 
79     /** @brief Overloaded requestedActivation property setter function
80      *
81      * @param[in] value - One of Activation::RequestedActivations
82      *
83      * @return Success or exception thrown
84      */
85     RequestedActivations
86         requestedActivation(RequestedActivations value) override;
87 
88     /** @brief Version id */
89     std::string versionId;
90 
91   private:
92     /** @brief Check if systemd state change is relevant to this object
93      *
94      * Instance specific interface to handle the detected systemd state
95      * change
96      *
97      * @param[in]  msg       - Data associated with subscribed signal
98      *
99      */
100     void unitStateChange(sdbusplus::message::message& msg);
101 
102     /** @brief Start PSU update */
103     void startActivation();
104 
105     /** @brief Finish PSU update */
106     void finishActivation();
107 
108     /** @brief Persistent sdbusplus DBus bus connection */
109     sdbusplus::bus::bus& bus;
110 
111     /** @brief Persistent DBus object path */
112     std::string path;
113 
114     /** @brief Used to subscribe to dbus systemd signals */
115     sdbusplus::bus::match_t systemdSignals;
116 
117     /** @brief The PSU update systemd unit */
118     std::string psuUpdateUnit;
119 };
120 
121 } // namespace updater
122 } // namespace software
123 } // namespace phosphor
124