blob: 4bfbb1e57d38ccb70d99ece37c52565f2ddef691 [file] [log] [blame]
Alexander Hansenaa300642025-02-04 15:51:52 +01001#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
12namespace phosphor::software::example_device
13{
14
Alexander Hansenade5c5a2025-07-29 13:38:24 +020015class ExampleDevice;
16
Alexander Hansenaa300642025-02-04 15:51:52 +010017class ExampleCodeUpdater : public phosphor::software::manager::SoftwareManager
18{
19 public:
20 ExampleCodeUpdater(sdbusplus::async::context& ctx,
21 long uniqueSuffix = getRandomId());
22
Alexander Hansend880e4d2025-08-08 11:24:28 +020023 // @param createDevice create an ExampleDevice. Prerequisite for param
24 // 'swVersion'.
Alexander Hansenade5c5a2025-07-29 13:38:24 +020025 // @param swVersion if this is nullptr, do not create the software
26 // version.
Alexander Hansend880e4d2025-08-08 11:24:28 +020027 ExampleCodeUpdater(sdbusplus::async::context& ctx, bool createDevice,
28 const char* swVersion);
Alexander Hansenade5c5a2025-07-29 13:38:24 +020029
30 std::unique_ptr<ExampleDevice>& getDevice();
31
Alexander Hansenaa300642025-02-04 15:51:52 +010032 sdbusplus::async::task<bool> initDevice(const std::string& service,
33 const std::string& path,
34 SoftwareConfig& config) final;
35
Alexander Hansenade5c5a2025-07-29 13:38:24 +020036 using SoftwareManager::getBusName;
37
Alexander Hansenaa300642025-02-04 15:51:52 +010038 private:
39 static long getRandomId();
40};
41
42const std::string exampleName = "ExampleSoftware";
43
44const uint32_t exampleVendorIANA = 0x0000a015;
45const std::string exampleCompatibleHardware = "com.example.CompatibleDevice";
46
47const std::string exampleInvObjPath =
48 "/xyz/openbmc_project/inventory/system/board/ExampleBoard/ExampleDevice";
49
Alexander Hansenade5c5a2025-07-29 13:38:24 +020050class ExampleSoftware : public Software
51{
52 public:
53 using Software::createInventoryAssociation;
Alexander Hansen18b5e612025-08-08 11:35:40 +020054 using Software::getPurpose;
Alexander Hansenade5c5a2025-07-29 13:38:24 +020055 using Software::objectPath;
56 ExampleSoftware(sdbusplus::async::context& ctx, ExampleDevice& parent);
57};
58
Alexander Hansenaa300642025-02-04 15:51:52 +010059class ExampleDevice : public Device
60{
61 public:
Alexander Hansenade5c5a2025-07-29 13:38:24 +020062 using Device::softwareCurrent;
Alexander Hansenaa300642025-02-04 15:51:52 +010063 using Device::softwarePending;
Alexander Hansenaa300642025-02-04 15:51:52 +010064
65 static SoftwareConfig defaultConfig;
66
67 ExampleDevice(sdbusplus::async::context& ctx,
68 phosphor::software::manager::SoftwareManager* parent,
69 const SoftwareConfig& config = defaultConfig);
70
Alexander Hansenaa300642025-02-04 15:51:52 +010071 sdbusplus::async::task<bool> updateDevice(const uint8_t* image,
72 size_t image_size) override;
Alexander Hansenaa300642025-02-04 15:51:52 +010073
74 bool deviceSpecificUpdateFunctionCalled = false;
75};
76
77} // namespace phosphor::software::example_device