xref: /openbmc/phosphor-bmc-code-mgmt/common/include/software.hpp (revision 37a301437cd5dfcd36dc8ecb1769163b262493b4)
1 #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 #include <xyz/openbmc_project/Software/Version/client.hpp>
12 
13 #include <string>
14 
15 namespace phosphor::software::device
16 {
17 class Device;
18 }
19 
20 namespace phosphor::software
21 {
22 
23 using SoftwareActivationBlocksTransition = sdbusplus::aserver::xyz::
24     openbmc_project::software::ActivationBlocksTransition<Software>;
25 
26 using SoftwareVersion =
27     sdbusplus::aserver::xyz::openbmc_project::software::Version<Software>;
28 using SoftwareActivation =
29     sdbusplus::aserver::xyz::openbmc_project::software::Activation<Software>;
30 using SoftwareAssociationDefinitions =
31     sdbusplus::aserver::xyz::openbmc_project::association::Definitions<
32         Software>;
33 
34 // This represents a software version running on the device.
35 class 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'
55     // @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 
61     // Return the version purpose
62     SoftwareVersion::VersionPurpose getPurpose();
63 
64     // This should populate 'softwareAssociationDefinitions'
65     // @param isRunning             if the software version is currently running
66     // on the device. Otherwise the software is assumed to be activating (not
67     // yet running).
68     sdbusplus::async::task<> createInventoryAssociations(bool isRunning);
69 
70     // object path of this software
71     sdbusplus::message::object_path objectPath;
72 
73     // The device we are associated to, meaning this software is either running
74     // on the device, or could potentially run on that device (update).
75     device::Device& parentDevice;
76 
77     // The software id
78     const std::string swid;
79 
80     // This is only required during the activation of the new fw
81     // and is deleted again afterwards.
82     // This member is public since the device specific update function
83     // needs to update the progress.
84     std::unique_ptr<sdbusplus::aserver::xyz::openbmc_project::software::
85                         ActivationProgress<Software>>
86         softwareActivationProgress = nullptr;
87 
88     static long int getRandomId();
89 
90   protected:
91     // @returns        a random software id (swid) for that device
92     static std::string getRandomSoftwareId(device::Device& parent);
93 
94   private:
95     Software(sdbusplus::async::context& ctx, device::Device& parent,
96              const std::string& swid);
97 
98     // Dbus interface to prevent power state transition during update.
99     std::unique_ptr<SoftwareActivationBlocksTransition>
100         activationBlocksTransition = nullptr;
101 
102     // The software update dbus interface is not always present.
103     // It is constructed if the software version is able to be updated.
104     // For the new software version, this interface is constructed after the
105     // update has taken effect
106     std::unique_ptr<update::SoftwareUpdate> updateIntf = nullptr;
107 
108     // We do not know the software version until we parse the PLDM package.
109     // Since the Activation interface needs to be available
110     // before then, this is nullptr until we get to know the version.
111     std::unique_ptr<SoftwareVersion> version = nullptr;
112 
113     // This represents our association to the inventory item in case
114     // this software is currently on the device.
115     std::unique_ptr<SoftwareAssociationDefinitions> associationDefinitions =
116         nullptr;
117 
118     sdbusplus::async::context& ctx;
119 
120     friend update::SoftwareUpdate;
121 };
122 
123 }; // namespace phosphor::software
124