blob: 09a0b0ff15b147514743c794ab446a3bcf1ef8d8 [file] [log] [blame]
Alexander Hansencc372352025-01-14 14:15:39 +01001#pragma once
2
3#include "software_update.hpp"
4
5#include <sdbusplus/async/context.hpp>
6#include <xyz/openbmc_project/Association/Definitions/aserver.hpp>
7#include <xyz/openbmc_project/Software/Activation/aserver.hpp>
8#include <xyz/openbmc_project/Software/ActivationBlocksTransition/aserver.hpp>
9#include <xyz/openbmc_project/Software/ActivationProgress/aserver.hpp>
10#include <xyz/openbmc_project/Software/Version/aserver.hpp>
11
12#include <string>
13
14namespace phosphor::software::device
15{
16class Device;
17}
18
19namespace phosphor::software
20{
21
22// Need to declare this class to initialize the protected members of our base
23// class. This prevents "Conditional jump or move depends on uninitialised
24// value(s)" when properties are updated for the first time.
25class SoftwareActivationProgress :
26 private sdbusplus::aserver::xyz::openbmc_project::software::
27 ActivationProgress<Software>
28{
29 public:
30 SoftwareActivationProgress(sdbusplus::async::context& ctx,
31 const char* objPath);
32
33 void setProgress(int progressArg);
34};
35
36using SoftwareActivationBlocksTransition = sdbusplus::aserver::xyz::
37 openbmc_project::software::ActivationBlocksTransition<Software>;
38
39using SoftwareVersion =
40 sdbusplus::aserver::xyz::openbmc_project::software::Version<Software>;
41using SoftwareActivation =
42 sdbusplus::aserver::xyz::openbmc_project::software::Activation<Software>;
43using SoftwareAssociationDefinitions =
44 sdbusplus::aserver::xyz::openbmc_project::association::Definitions<
45 Software>;
46
47// This represents a software version running on the device.
48class Software : private SoftwareActivation
49{
50 public:
51 Software(sdbusplus::async::context& ctx, device::Device& parent);
52
53 // Set the activation status of this software
54 // @param activation The activation status
55 void setActivation(SoftwareActivation::Activations activation);
56
57 // Add / remove the 'ActivationBlocksTransition' dbus interface.
58 // This dbus interface is only needed during the update process.
59 // @param enabled determines if the dbus interface should be there
60 void setActivationBlocksTransition(bool enabled);
61
62 // This should populate 'softwareUpdate'
63 // @param allowedApplyTimes When updates to this Version can be
64 // applied
65 void enableUpdate(const std::set<RequestedApplyTimes>& allowedApplyTimes);
66
67 // This should populate 'softwareVersion'
68 // @param version the version string
69 void setVersion(const std::string& versionStr);
70
71 // This should populate 'softwareAssociationDefinitions'
72 // @param isRunning if the software version is currently running
73 // on the device. Otherwise the software is assumed to be activating (not
74 // yet running).
75 sdbusplus::async::task<> createInventoryAssociations(bool isRunning);
76
77 // object path of this software
78 sdbusplus::message::object_path objectPath;
79
80 // The device we are associated to, meaning this software is either running
81 // on the device, or could potentially run on that device (update).
82 device::Device& parentDevice;
83
84 // The software id
85 const std::string swid;
86
87 // This is only required during the activation of the new fw
88 // and is deleted again afterwards.
89 // This member is public since the device specific update function
90 // needs to update the progress.
91 std::unique_ptr<SoftwareActivationProgress> softwareActivationProgress =
92 nullptr;
93
94 protected:
95 // @returns a random software id (swid) for that device
96 static std::string getRandomSoftwareId(device::Device& parent);
97
98 private:
99 Software(sdbusplus::async::context& ctx, device::Device& parent,
100 const std::string& swid);
101
102 // Dbus interface to prevent power state transition during update.
103 std::unique_ptr<SoftwareActivationBlocksTransition>
104 activationBlocksTransition = nullptr;
105
106 // The software update dbus interface is not always present.
107 // It is constructed if the software version is able to be updated.
108 // For the new software version, this interface is constructed after the
109 // update has taken effect
110 std::unique_ptr<update::SoftwareUpdate> updateIntf = nullptr;
111
112 // We do not know the software version until we parse the PLDM package.
113 // Since the Activation interface needs to be available
114 // before then, this is nullptr until we get to know the version.
115 std::unique_ptr<SoftwareVersion> version = nullptr;
116
117 // This represents our association to the inventory item in case
118 // this software is currently on the device.
119 std::unique_ptr<SoftwareAssociationDefinitions> associationDefinitions =
120 nullptr;
121
122 sdbusplus::async::context& ctx;
123
124 friend update::SoftwareUpdate;
125};
126
127}; // namespace phosphor::software