blob: 7cc2e6ad707fe7332b650adc155beb548c3e0bc9 [file] [log] [blame]
Alexander Hansencc372352025-01-14 14:15:39 +01001#pragma once
2
3#include "device.hpp"
4
5#include <boost/asio/steady_timer.hpp>
6#include <phosphor-logging/lg2.hpp>
7#include <sdbusplus/asio/connection.hpp>
8#include <sdbusplus/asio/object_server.hpp>
9#include <sdbusplus/async/context.hpp>
10#include <sdbusplus/timer.hpp>
11
12#include <string>
13
14using namespace phosphor::software::config;
15using namespace phosphor::software::device;
16
17namespace phosphor::software::manager
18{
19
20// This is the base class for the code updater
21// Every code updater can inherit from this
22class SoftwareManager
23{
24 public:
25 SoftwareManager(sdbusplus::async::context& ctx,
26 const std::string& serviceNameSuffix);
27
28 // Fetches initial configuration from dbus and initializes devices.
29 // This should be called once by a code updater at startup.
30 // @param configurationInterfaces the dbus interfaces from which to fetch
31 // configuration
32 sdbusplus::async::task<> initDevices(
33 const std::vector<std::string>& configurationInterfaces);
34
35 // Map of EM config object path to device.
36 std::map<sdbusplus::message::object_path, std::unique_ptr<Device>> devices;
37
38 protected:
39 // This function receives a dbus name and object path for a single device,
40 // which was configured.
41 // The component code updater overrides this function and may create a
42 // device instance internally, or reject the configuration as invalid.
43 // @param service The dbus name where our configuration is
44 // @param config The common configuration properties which are shared
45 // by all devices.
46 // Also includes the object path to fetch other
47 // configuration properties.
48 // @returns true if the configuration was accepted
49 virtual sdbusplus::async::task<bool> initDevice(const std::string& service,
50 const std::string& path,
51 SoftwareConfig& config) = 0;
52
53 sdbusplus::async::context& ctx;
54
55 private:
56 // request the bus name on dbus after all configuration has been parsed
57 // and the devices have been initialized
58 // @returns the name on dbus
59 std::string setupBusName();
60
61 // this is appended to the common prefix to construct the dbus name
62 std::string serviceNameSuffix;
63
64 sdbusplus::server::manager_t manager;
65
66 friend Software;
67 friend Device;
68};
69
70}; // namespace phosphor::software::manager