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 // 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 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. 78 std::unique_ptr<sdbusplus::aserver::xyz::openbmc_project::software:: 79 ActivationProgress<Software>> 80 softwareActivationProgress = nullptr; 81 82 static long int getRandomId(); 83 84 protected: 85 // object path of this software 86 const sdbusplus::message::object_path objectPath; 87 88 // @returns the version purpose 89 // @returns std::nullopt in case the version has not been set 90 std::optional<SoftwareVersion::VersionPurpose> getPurpose(); 91 92 // @returns a random software id (swid) for that device 93 static std::string getRandomSoftwareId(device::Device& parent); 94 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 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; 129 friend device::Device; 130 }; 131 132 }; // namespace phosphor::software 133