blob: 28b1cffb8b0d52671c209780b624665099668a94 [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>
Alexander Hansende5e76f2025-02-20 16:30:11 +010011#include <xyz/openbmc_project/Software/Version/client.hpp>
Alexander Hansencc372352025-01-14 14:15:39 +010012
13#include <string>
14
15namespace phosphor::software::device
16{
17class Device;
18}
19
20namespace phosphor::software
21{
22
Alexander Hansencc372352025-01-14 14:15:39 +010023using SoftwareActivationBlocksTransition = sdbusplus::aserver::xyz::
24 openbmc_project::software::ActivationBlocksTransition<Software>;
25
26using SoftwareVersion =
27 sdbusplus::aserver::xyz::openbmc_project::software::Version<Software>;
28using SoftwareActivation =
29 sdbusplus::aserver::xyz::openbmc_project::software::Activation<Software>;
30using SoftwareAssociationDefinitions =
31 sdbusplus::aserver::xyz::openbmc_project::association::Definitions<
32 Software>;
33
34// This represents a software version running on the device.
35class Software : private SoftwareActivation
36{
37 public:
38 Software(sdbusplus::async::context& ctx, device::Device& parent);
39
40 // Set the activation status of this software
41 // @param activation The activation status
42 void setActivation(SoftwareActivation::Activations activation);
43
44 // Add / remove the 'ActivationBlocksTransition' dbus interface.
45 // This dbus interface is only needed during the update process.
46 // @param enabled determines if the dbus interface should be there
47 void setActivationBlocksTransition(bool enabled);
48
49 // This should populate 'softwareUpdate'
50 // @param allowedApplyTimes When updates to this Version can be
51 // applied
52 void enableUpdate(const std::set<RequestedApplyTimes>& allowedApplyTimes);
53
54 // This should populate 'softwareVersion'
Alexander Hansende5e76f2025-02-20 16:30:11 +010055 // @param version the version string
56 // @param versionPurpose which kind of software
57 void setVersion(const std::string& versionStr,
58 SoftwareVersion::VersionPurpose versionPurpose =
59 SoftwareVersion::VersionPurpose::Unknown);
60
Alexander Hansencc372352025-01-14 14:15:39 +010061 // This should populate 'softwareAssociationDefinitions'
62 // @param isRunning if the software version is currently running
63 // on the device. Otherwise the software is assumed to be activating (not
64 // yet running).
65 sdbusplus::async::task<> createInventoryAssociations(bool isRunning);
66
Alexander Hansencc372352025-01-14 14:15:39 +010067 // The device we are associated to, meaning this software is either running
68 // on the device, or could potentially run on that device (update).
69 device::Device& parentDevice;
70
71 // The software id
72 const std::string swid;
73
74 // This is only required during the activation of the new fw
75 // and is deleted again afterwards.
76 // This member is public since the device specific update function
77 // needs to update the progress.
Alexander Hansendf628192025-06-18 16:28:59 +020078 std::unique_ptr<sdbusplus::aserver::xyz::openbmc_project::software::
79 ActivationProgress<Software>>
80 softwareActivationProgress = nullptr;
Alexander Hansencc372352025-01-14 14:15:39 +010081
Alexander Hansenf2c95a02024-11-26 11:16:44 +010082 static long int getRandomId();
83
Alexander Hansencc372352025-01-14 14:15:39 +010084 protected:
Alexander Hansendbb70152025-08-07 15:42:27 +020085 // object path of this software
86 const sdbusplus::message::object_path objectPath;
87
Alexander Hansenb0cfda62025-07-18 16:30:32 +020088 // @returns the version purpose
89 // @returns std::nullopt in case the version has not been set
90 std::optional<SoftwareVersion::VersionPurpose> getPurpose();
91
Alexander Hansencc372352025-01-14 14:15:39 +010092 // @returns a random software id (swid) for that device
93 static std::string getRandomSoftwareId(device::Device& parent);
94
Alexander Hansen53c7c0e2025-07-29 12:37:13 +020095 // @param isRunning if the software version is currently running
96 // on the device. Otherwise the software is assumed to be activating (not
97 // yet running).
98 // @param objectPath The object path of the inventory item to
99 // associate with. We only ever associate to one inventory item.
100 void createInventoryAssociation(bool isRunning, std::string objectPath);
101
Alexander Hansencc372352025-01-14 14:15:39 +0100102 private:
103 Software(sdbusplus::async::context& ctx, device::Device& parent,
104 const std::string& swid);
105
106 // Dbus interface to prevent power state transition during update.
107 std::unique_ptr<SoftwareActivationBlocksTransition>
108 activationBlocksTransition = nullptr;
109
110 // The software update dbus interface is not always present.
111 // It is constructed if the software version is able to be updated.
112 // For the new software version, this interface is constructed after the
113 // update has taken effect
114 std::unique_ptr<update::SoftwareUpdate> updateIntf = nullptr;
115
116 // We do not know the software version until we parse the PLDM package.
117 // Since the Activation interface needs to be available
118 // before then, this is nullptr until we get to know the version.
119 std::unique_ptr<SoftwareVersion> version = nullptr;
120
121 // This represents our association to the inventory item in case
122 // this software is currently on the device.
123 std::unique_ptr<SoftwareAssociationDefinitions> associationDefinitions =
124 nullptr;
125
126 sdbusplus::async::context& ctx;
127
128 friend update::SoftwareUpdate;
Alexander Hansenb0cfda62025-07-18 16:30:32 +0200129 friend device::Device;
Alexander Hansencc372352025-01-14 14:15:39 +0100130};
131
132}; // namespace phosphor::software