xref: /openbmc/phosphor-bmc-code-mgmt/common/include/software.hpp (revision 7e446a407a579ec72f48009008ad2f83c01c2262)
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 // 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.
26 class 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 
37 using SoftwareActivationBlocksTransition = sdbusplus::aserver::xyz::
38     openbmc_project::software::ActivationBlocksTransition<Software>;
39 
40 using SoftwareVersion =
41     sdbusplus::aserver::xyz::openbmc_project::software::Version<Software>;
42 using SoftwareActivation =
43     sdbusplus::aserver::xyz::openbmc_project::software::Activation<Software>;
44 using SoftwareAssociationDefinitions =
45     sdbusplus::aserver::xyz::openbmc_project::association::Definitions<
46         Software>;
47 
48 // This represents a software version running on the device.
49 class 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'
69     // @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();
77 
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     static long int getRandomId();
102 
103   protected:
104     // @returns        a random software id (swid) for that device
105     static std::string getRandomSoftwareId(device::Device& parent);
106 
107   private:
108     Software(sdbusplus::async::context& ctx, device::Device& parent,
109              const std::string& swid);
110 
111     // Dbus interface to prevent power state transition during update.
112     std::unique_ptr<SoftwareActivationBlocksTransition>
113         activationBlocksTransition = nullptr;
114 
115     // The software update dbus interface is not always present.
116     // It is constructed if the software version is able to be updated.
117     // For the new software version, this interface is constructed after the
118     // update has taken effect
119     std::unique_ptr<update::SoftwareUpdate> updateIntf = nullptr;
120 
121     // We do not know the software version until we parse the PLDM package.
122     // Since the Activation interface needs to be available
123     // before then, this is nullptr until we get to know the version.
124     std::unique_ptr<SoftwareVersion> version = nullptr;
125 
126     // This represents our association to the inventory item in case
127     // this software is currently on the device.
128     std::unique_ptr<SoftwareAssociationDefinitions> associationDefinitions =
129         nullptr;
130 
131     sdbusplus::async::context& ctx;
132 
133     friend update::SoftwareUpdate;
134 };
135 
136 }; // namespace phosphor::software
137