blob: 6b96f09055221319891de90f46b824f9d16193fb [file] [log] [blame]
Alexander Hansen0119cd72025-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
14// Need to declare this class to initialize the protected members of our base
15// class. This prevents "Conditional jump or move depends on uninitialised
16// value(s)" when properties are updated for the first time.
17class SoftwareActivationProgress :
18 public sdbusplus::aserver::xyz::openbmc_project::software::
19 ActivationProgress<Software>
20{
21 public:
22 SoftwareActivationProgress(sdbusplus::async::context& ctx,
23 const char* objPath);
24};
25
26using SoftwareActivationBlocksTransition = sdbusplus::aserver::xyz::
27 openbmc_project::software::ActivationBlocksTransition<Software>;
28
29using SoftwareVersion =
30 sdbusplus::aserver::xyz::openbmc_project::software::Version<Software>;
31using SoftwareActivation =
32 sdbusplus::aserver::xyz::openbmc_project::software::Activation<Software>;
33using SoftwareAssociationDefinitions =
34 sdbusplus::aserver::xyz::openbmc_project::association::Definitions<
35 Software>;
36
37class Device;
38
39// This represents a software version running on the device.
40class Software : private SoftwareActivation
41{
42 public:
43 Software(sdbusplus::async::context& ctx, const std::string& swid,
44 Device& parent);
45
46 // @returns object path of this software
47 sdbusplus::message::object_path getObjectPath() const;
48
49 // The software id
50 const std::string swid;
51
52 // Set the activation status of this software
53 // @param activation The activation status
54 void setActivation(sdbusplus::common::xyz::openbmc_project::software::
55 Activation::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 is only required during the activation of the new fw
63 // and is deleted again afterwards.
64 // This member is public since the device specific update function
65 // needs to update the progress.
66 std::unique_ptr<SoftwareActivationProgress> optSoftwareActivationProgress =
67 nullptr;
68
69 // This should populate 'optSoftwareUpdate'
70 // @param allowedApplyTimes When updates to this Version can be
71 // applied
72 void enableUpdate(const std::set<RequestedApplyTimes>& allowedApplyTimes);
73
74 // This should populate 'optSoftwareVersion'
75 // @param version the version string
76 void setVersion(const std::string& versionStr);
77
78 // This should populate 'optSoftwareAssociationDefinitions'
79 // @param isRunning if the software version is currently running
80 // on the device
81 // @param isActivating if the software version is currently
82 // activating (not yet running) on the device
83 sdbusplus::async::task<> setAssociationDefinitionsRunningActivating(
84 bool isRunning, bool isActivating);
85
86 // @returns this->parent
87 Device& getParentDevice();
88
89 protected:
90 // @returns a random software id (swid) for that device
91 static std::string getRandomSoftwareId(Device& parent);
92
93 private:
94 // @returns the object path for the a software with that swid
95 static std::string getObjPathFromSwid(const std::string& swid);
96
97 // The device we are associated to, meaning this software is either running
98 // on the device, or could potentially run on that device (update).
99 Device& parent;
100
101 // Dbus interface to prevent power state transition during update.
102 std::unique_ptr<SoftwareActivationBlocksTransition>
103 optActivationBlocksTransition = nullptr;
104
105 // The software update dbus interface is not always present.
106 // It is constructed if the software version is able to be updated.
107 // For the new software version, this interface is constructed after the
108 // update has taken effect
109 std::unique_ptr<SoftwareUpdate> optSoftwareUpdate = nullptr;
110
111 // We do not know the software version until we parse the PLDM package.
112 // Since the Activation interface needs to be available
113 // before then, this is nullptr until we get to know the version.
114 std::unique_ptr<SoftwareVersion> optSoftwareVersion = nullptr;
115
116 // This represents our association to the inventory item in case
117 // this software is currently on the device.
118 std::unique_ptr<SoftwareAssociationDefinitions>
119 optSoftwareAssociationDefinitions = nullptr;
120
121 sdbusplus::async::context& ctx;
122
123 friend SoftwareUpdate;
124};