Alexander Hansen | aa30064 | 2025-02-04 15:51:52 +0100 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "common/include/device.hpp" |
| 4 | #include "common/include/software_manager.hpp" |
| 5 | |
| 6 | #include <phosphor-logging/lg2.hpp> |
| 7 | #include <sdbusplus/async.hpp> |
| 8 | #include <sdbusplus/server.hpp> |
| 9 | #include <xyz/openbmc_project/Association/Definitions/server.hpp> |
| 10 | #include <xyz/openbmc_project/Software/Update/server.hpp> |
| 11 | |
| 12 | namespace phosphor::software::example_device |
| 13 | { |
| 14 | |
Alexander Hansen | ade5c5a | 2025-07-29 13:38:24 +0200 | [diff] [blame] | 15 | class ExampleDevice; |
| 16 | |
Alexander Hansen | aa30064 | 2025-02-04 15:51:52 +0100 | [diff] [blame] | 17 | class ExampleCodeUpdater : public phosphor::software::manager::SoftwareManager |
| 18 | { |
| 19 | public: |
| 20 | ExampleCodeUpdater(sdbusplus::async::context& ctx, |
| 21 | long uniqueSuffix = getRandomId()); |
| 22 | |
Alexander Hansen | d880e4d | 2025-08-08 11:24:28 +0200 | [diff] [blame] | 23 | // @param createDevice create an ExampleDevice. Prerequisite for param |
| 24 | // 'swVersion'. |
Alexander Hansen | ade5c5a | 2025-07-29 13:38:24 +0200 | [diff] [blame] | 25 | // @param swVersion if this is nullptr, do not create the software |
| 26 | // version. |
Alexander Hansen | d880e4d | 2025-08-08 11:24:28 +0200 | [diff] [blame] | 27 | ExampleCodeUpdater(sdbusplus::async::context& ctx, bool createDevice, |
| 28 | const char* swVersion); |
Alexander Hansen | ade5c5a | 2025-07-29 13:38:24 +0200 | [diff] [blame] | 29 | |
| 30 | std::unique_ptr<ExampleDevice>& getDevice(); |
| 31 | |
Alexander Hansen | aa30064 | 2025-02-04 15:51:52 +0100 | [diff] [blame] | 32 | sdbusplus::async::task<bool> initDevice(const std::string& service, |
| 33 | const std::string& path, |
| 34 | SoftwareConfig& config) final; |
| 35 | |
Alexander Hansen | ade5c5a | 2025-07-29 13:38:24 +0200 | [diff] [blame] | 36 | using SoftwareManager::getBusName; |
| 37 | |
Alexander Hansen | aa30064 | 2025-02-04 15:51:52 +0100 | [diff] [blame] | 38 | private: |
| 39 | static long getRandomId(); |
| 40 | }; |
| 41 | |
| 42 | const std::string exampleName = "ExampleSoftware"; |
| 43 | |
| 44 | const uint32_t exampleVendorIANA = 0x0000a015; |
| 45 | const std::string exampleCompatibleHardware = "com.example.CompatibleDevice"; |
| 46 | |
| 47 | const std::string exampleInvObjPath = |
| 48 | "/xyz/openbmc_project/inventory/system/board/ExampleBoard/ExampleDevice"; |
| 49 | |
Alexander Hansen | ade5c5a | 2025-07-29 13:38:24 +0200 | [diff] [blame] | 50 | class ExampleSoftware : public Software |
| 51 | { |
| 52 | public: |
| 53 | using Software::createInventoryAssociation; |
Alexander Hansen | 18b5e61 | 2025-08-08 11:35:40 +0200 | [diff] [blame^] | 54 | using Software::getPurpose; |
Alexander Hansen | ade5c5a | 2025-07-29 13:38:24 +0200 | [diff] [blame] | 55 | using Software::objectPath; |
| 56 | ExampleSoftware(sdbusplus::async::context& ctx, ExampleDevice& parent); |
| 57 | }; |
| 58 | |
Alexander Hansen | aa30064 | 2025-02-04 15:51:52 +0100 | [diff] [blame] | 59 | class ExampleDevice : public Device |
| 60 | { |
| 61 | public: |
Alexander Hansen | ade5c5a | 2025-07-29 13:38:24 +0200 | [diff] [blame] | 62 | using Device::softwareCurrent; |
Alexander Hansen | aa30064 | 2025-02-04 15:51:52 +0100 | [diff] [blame] | 63 | using Device::softwarePending; |
Alexander Hansen | aa30064 | 2025-02-04 15:51:52 +0100 | [diff] [blame] | 64 | |
| 65 | static SoftwareConfig defaultConfig; |
| 66 | |
| 67 | ExampleDevice(sdbusplus::async::context& ctx, |
| 68 | phosphor::software::manager::SoftwareManager* parent, |
| 69 | const SoftwareConfig& config = defaultConfig); |
| 70 | |
Alexander Hansen | aa30064 | 2025-02-04 15:51:52 +0100 | [diff] [blame] | 71 | sdbusplus::async::task<bool> updateDevice(const uint8_t* image, |
| 72 | size_t image_size) override; |
Alexander Hansen | aa30064 | 2025-02-04 15:51:52 +0100 | [diff] [blame] | 73 | |
| 74 | bool deviceSpecificUpdateFunctionCalled = false; |
| 75 | }; |
| 76 | |
| 77 | } // namespace phosphor::software::example_device |