blob: 2993707a8bb0dc25866e984abe01d6c83e2dc643 [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
67 // object path of this software
68 sdbusplus::message::object_path objectPath;
69
70 // The device we are associated to, meaning this software is either running
71 // on the device, or could potentially run on that device (update).
72 device::Device& parentDevice;
73
74 // The software id
75 const std::string swid;
76
77 // This is only required during the activation of the new fw
78 // and is deleted again afterwards.
79 // This member is public since the device specific update function
80 // needs to update the progress.
Alexander Hansendf628192025-06-18 16:28:59 +020081 std::unique_ptr<sdbusplus::aserver::xyz::openbmc_project::software::
82 ActivationProgress<Software>>
83 softwareActivationProgress = nullptr;
Alexander Hansencc372352025-01-14 14:15:39 +010084
Alexander Hansenf2c95a02024-11-26 11:16:44 +010085 static long int getRandomId();
86
Alexander Hansencc372352025-01-14 14:15:39 +010087 protected:
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
95 private:
96 Software(sdbusplus::async::context& ctx, device::Device& parent,
97 const std::string& swid);
98
99 // Dbus interface to prevent power state transition during update.
100 std::unique_ptr<SoftwareActivationBlocksTransition>
101 activationBlocksTransition = nullptr;
102
103 // The software update dbus interface is not always present.
104 // It is constructed if the software version is able to be updated.
105 // For the new software version, this interface is constructed after the
106 // update has taken effect
107 std::unique_ptr<update::SoftwareUpdate> updateIntf = nullptr;
108
109 // We do not know the software version until we parse the PLDM package.
110 // Since the Activation interface needs to be available
111 // before then, this is nullptr until we get to know the version.
112 std::unique_ptr<SoftwareVersion> version = nullptr;
113
114 // This represents our association to the inventory item in case
115 // this software is currently on the device.
116 std::unique_ptr<SoftwareAssociationDefinitions> associationDefinitions =
117 nullptr;
118
119 sdbusplus::async::context& ctx;
120
121 friend update::SoftwareUpdate;
Alexander Hansenb0cfda62025-07-18 16:30:32 +0200122 friend device::Device;
Alexander Hansencc372352025-01-14 14:15:39 +0100123};
124
125}; // namespace phosphor::software