| Alexander Hansen | cc37235 | 2025-01-14 14:15:39 +0100 | [diff] [blame] | 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> | 
| Alexander Hansen | de5e76f | 2025-02-20 16:30:11 +0100 | [diff] [blame] | 11 | #include <xyz/openbmc_project/Software/Version/client.hpp> | 
| Alexander Hansen | cc37235 | 2025-01-14 14:15:39 +0100 | [diff] [blame] | 12 |  | 
|  | 13 | #include <string> | 
|  | 14 |  | 
|  | 15 | namespace phosphor::software::device | 
|  | 16 | { | 
|  | 17 | class Device; | 
|  | 18 | } | 
|  | 19 |  | 
|  | 20 | namespace phosphor::software | 
|  | 21 | { | 
|  | 22 |  | 
| Alexander Hansen | cc37235 | 2025-01-14 14:15:39 +0100 | [diff] [blame] | 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' | 
| Alexander Hansen | de5e76f | 2025-02-20 16:30:11 +0100 | [diff] [blame] | 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 |  | 
| Alexander Hansen | cc37235 | 2025-01-14 14:15:39 +0100 | [diff] [blame] | 61 | // 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 |  | 
| Alexander Hansen | cc37235 | 2025-01-14 14:15:39 +0100 | [diff] [blame] | 67 | // The device we are associated to, meaning this software is either running | 
|  | 68 | // on the device, or could potentially run on that device (update). | 
|  | 69 | device::Device& parentDevice; | 
|  | 70 |  | 
|  | 71 | // The software id | 
|  | 72 | const std::string swid; | 
|  | 73 |  | 
|  | 74 | // This is only required during the activation of the new fw | 
|  | 75 | // and is deleted again afterwards. | 
|  | 76 | // This member is public since the device specific update function | 
|  | 77 | // needs to update the progress. | 
| Alexander Hansen | df62819 | 2025-06-18 16:28:59 +0200 | [diff] [blame] | 78 | std::unique_ptr<sdbusplus::aserver::xyz::openbmc_project::software:: | 
|  | 79 | ActivationProgress<Software>> | 
|  | 80 | softwareActivationProgress = nullptr; | 
| Alexander Hansen | cc37235 | 2025-01-14 14:15:39 +0100 | [diff] [blame] | 81 |  | 
| Alexander Hansen | f2c95a0 | 2024-11-26 11:16:44 +0100 | [diff] [blame] | 82 | static long int getRandomId(); | 
|  | 83 |  | 
| Alexander Hansen | cc37235 | 2025-01-14 14:15:39 +0100 | [diff] [blame] | 84 | protected: | 
| Alexander Hansen | dbb7015 | 2025-08-07 15:42:27 +0200 | [diff] [blame] | 85 | // object path of this software | 
|  | 86 | const sdbusplus::message::object_path objectPath; | 
|  | 87 |  | 
| Alexander Hansen | b0cfda6 | 2025-07-18 16:30:32 +0200 | [diff] [blame] | 88 | // @returns the version purpose | 
|  | 89 | // @returns std::nullopt in case the version has not been set | 
|  | 90 | std::optional<SoftwareVersion::VersionPurpose> getPurpose(); | 
|  | 91 |  | 
| Alexander Hansen | cc37235 | 2025-01-14 14:15:39 +0100 | [diff] [blame] | 92 | // @returns        a random software id (swid) for that device | 
|  | 93 | static std::string getRandomSoftwareId(device::Device& parent); | 
|  | 94 |  | 
| Alexander Hansen | 53c7c0e | 2025-07-29 12:37:13 +0200 | [diff] [blame] | 95 | // @param isRunning             if the software version is currently running | 
|  | 96 | // on the device. Otherwise the software is assumed to be activating (not | 
|  | 97 | // yet running). | 
|  | 98 | // @param objectPath            The object path of the inventory item to | 
|  | 99 | // associate with. We only ever associate to one inventory item. | 
|  | 100 | void createInventoryAssociation(bool isRunning, std::string objectPath); | 
|  | 101 |  | 
| Alexander Hansen | cc37235 | 2025-01-14 14:15:39 +0100 | [diff] [blame] | 102 | private: | 
|  | 103 | Software(sdbusplus::async::context& ctx, device::Device& parent, | 
|  | 104 | const std::string& swid); | 
|  | 105 |  | 
|  | 106 | // Dbus interface to prevent power state transition during update. | 
|  | 107 | std::unique_ptr<SoftwareActivationBlocksTransition> | 
|  | 108 | activationBlocksTransition = nullptr; | 
|  | 109 |  | 
|  | 110 | // The software update dbus interface is not always present. | 
|  | 111 | // It is constructed if the software version is able to be updated. | 
|  | 112 | // For the new software version, this interface is constructed after the | 
|  | 113 | // update has taken effect | 
|  | 114 | std::unique_ptr<update::SoftwareUpdate> updateIntf = nullptr; | 
|  | 115 |  | 
|  | 116 | // We do not know the software version until we parse the PLDM package. | 
|  | 117 | // Since the Activation interface needs to be available | 
|  | 118 | // before then, this is nullptr until we get to know the version. | 
|  | 119 | std::unique_ptr<SoftwareVersion> version = nullptr; | 
|  | 120 |  | 
|  | 121 | // This represents our association to the inventory item in case | 
|  | 122 | // this software is currently on the device. | 
|  | 123 | std::unique_ptr<SoftwareAssociationDefinitions> associationDefinitions = | 
|  | 124 | nullptr; | 
|  | 125 |  | 
|  | 126 | sdbusplus::async::context& ctx; | 
|  | 127 |  | 
|  | 128 | friend update::SoftwareUpdate; | 
| Alexander Hansen | b0cfda6 | 2025-07-18 16:30:32 +0200 | [diff] [blame] | 129 | friend device::Device; | 
| Alexander Hansen | cc37235 | 2025-01-14 14:15:39 +0100 | [diff] [blame] | 130 | }; | 
|  | 131 |  | 
|  | 132 | }; // namespace phosphor::software |