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