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