blob: 6d5de67dfb341ed37b55477e5f3b44e418ee7a2f [file] [log] [blame]
Lei YU01539e72019-07-31 10:57:38 +08001#pragma once
2
3#include "config.h"
4
Lei YU91029442019-08-01 15:57:31 +08005#include "types.hpp"
6
Lei YU01539e72019-07-31 10:57:38 +08007#include <sdbusplus/server.hpp>
Lei YU91029442019-08-01 15:57:31 +08008#include <xyz/openbmc_project/Association/Definitions/server.hpp>
Lei YU01539e72019-07-31 10:57:38 +08009#include <xyz/openbmc_project/Software/Activation/server.hpp>
10#include <xyz/openbmc_project/Software/ExtendedVersion/server.hpp>
11
12namespace phosphor
13{
14namespace software
15{
16namespace updater
17{
18
Lei YU12c9f4c2019-09-11 15:08:15 +080019namespace sdbusRule = sdbusplus::bus::match::rules;
20
Lei YU01539e72019-07-31 10:57:38 +080021using ActivationInherit = sdbusplus::server::object::object<
22 sdbusplus::xyz::openbmc_project::Software::server::ExtendedVersion,
Lei YU91029442019-08-01 15:57:31 +080023 sdbusplus::xyz::openbmc_project::Software::server::Activation,
24 sdbusplus::xyz::openbmc_project::Association::server::Definitions>;
Lei YU01539e72019-07-31 10:57:38 +080025
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 */
31class Activation : public ActivationInherit
32{
33 public:
Lei YU12c9f4c2019-09-11 15:08:15 +080034 using Status = Activations;
Lei YU01539e72019-07-31 10:57:38 +080035 /** @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
Lei YU91029442019-08-01 15:57:31 +080042 * @param[in] assocs - Association objects
Lei YU01539e72019-07-31 10:57:38 +080043 */
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::
Lei YU91029442019-08-01 15:57:31 +080047 Activations activationStatus,
48 const AssociationList& assocs) :
Lei YU01539e72019-07-31 10:57:38 +080049 ActivationInherit(bus, path.c_str(), true),
Lei YU12c9f4c2019-09-11 15:08:15 +080050 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))
Lei YU01539e72019-07-31 10:57:38 +080058 {
59 // Set Properties.
60 extendedVersion(extVersion);
61 activation(activationStatus);
Lei YU91029442019-08-01 15:57:31 +080062 associations(assocs);
Lei YU01539e72019-07-31 10:57:38 +080063
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
Lei YU12c9f4c2019-09-11 15:08:15 +080088 /** @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
Lei YUd0bbfa92019-09-11 16:10:54 +0800102 /**
103 * @brief Delete the version from Image Manager and the
104 * untar image from image upload dir.
105 */
106 void deleteImageManagerObject();
107
Lei YU12c9f4c2019-09-11 15:08:15 +0800108 /** @brief Start PSU update */
109 void startActivation();
110
111 /** @brief Finish PSU update */
112 void finishActivation();
113
Lei YU01539e72019-07-31 10:57:38 +0800114 /** @brief Persistent sdbusplus DBus bus connection */
115 sdbusplus::bus::bus& bus;
116
117 /** @brief Persistent DBus object path */
118 std::string path;
119
Lei YU12c9f4c2019-09-11 15:08:15 +0800120 /** @brief Used to subscribe to dbus systemd signals */
121 sdbusplus::bus::match_t systemdSignals;
122
123 /** @brief The PSU update systemd unit */
124 std::string psuUpdateUnit;
Lei YU01539e72019-07-31 10:57:38 +0800125};
126
127} // namespace updater
128} // namespace software
129} // namespace phosphor