xref: /openbmc/phosphor-bmc-code-mgmt/test/common/exampledevice/example_device.hpp (revision c1b36628298d7799677680e70d455f85acf83650)
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 
15 class ExampleDevice;
16 
17 class ExampleCodeUpdater : public phosphor::software::manager::SoftwareManager
18 {
19   public:
20     ExampleCodeUpdater(sdbusplus::async::context& ctx,
21                        long uniqueSuffix = getRandomId());
22 
23     // @param createDevice  create an ExampleDevice. Prerequisite for param
24     // 'swVersion'.
25     // @param swVersion     if this is nullptr, do not create the software
26     // version.
27     ExampleCodeUpdater(sdbusplus::async::context& ctx, bool createDevice,
28                        const char* swVersion);
29 
30     std::unique_ptr<ExampleDevice>& getDevice();
31 
32     sdbusplus::async::task<bool> initDevice(const std::string& service,
33                                             const std::string& path,
34                                             SoftwareConfig& config) final;
35 
36     using SoftwareManager::getBusName;
37 
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 
50 class ExampleSoftware : public Software
51 {
52   public:
53     using Software::createInventoryAssociation;
54     using Software::getPurpose;
55     using Software::objectPath;
56     ExampleSoftware(sdbusplus::async::context& ctx, ExampleDevice& parent);
57 };
58 
59 class ExampleDevice : public Device
60 {
61   public:
62     using Device::softwareCurrent;
63     using Device::softwarePending;
64 
65     static SoftwareConfig defaultConfig;
66 
67     ExampleDevice(sdbusplus::async::context& ctx,
68                   phosphor::software::manager::SoftwareManager* parent,
69                   const SoftwareConfig& config = defaultConfig);
70 
71     sdbusplus::async::task<bool> updateDevice(const uint8_t* image,
72                                               size_t image_size) override;
73 
74     bool deviceSpecificUpdateFunctionCalled = false;
75 };
76 
77 } // namespace phosphor::software::example_device
78