blob: 1034766e3567d460a20fa40be7b6c466ad836a31 [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
Alexander Hansene2cd6752025-08-15 12:44:51 +020054 std::string getBusName();
55
Alexander Hansencc372352025-01-14 14:15:39 +010056 sdbusplus::async::context& ctx;
57
58 private:
Alexander Hansen90174792025-05-08 10:14:54 +020059 sdbusplus::async::task<void> handleInterfaceAdded(
60 const std::string& service, const std::string& path,
61 const std::string& interface);
62
Alexander Hansencec14752025-05-08 13:11:03 +020063 sdbusplus::async::task<void> handleInterfaceRemoved(
64 const sdbusplus::message::object_path& path);
65
66 sdbusplus::async::task<void> interfaceAddedMatch(
67 std::vector<std::string> interfaces);
68 sdbusplus::async::task<void> interfaceRemovedMatch(
69 std::vector<std::string> interfaces);
70
71 // DBus matches for interfaces added and interfaces removed
72 sdbusplus::async::match configIntfAddedMatch;
73 sdbusplus::async::match configIntfRemovedMatch;
74
Alexander Hansene2cd6752025-08-15 12:44:51 +020075 // the dbus name
76 const std::string serviceName;
Alexander Hansencc372352025-01-14 14:15:39 +010077
78 sdbusplus::server::manager_t manager;
79
80 friend Software;
81 friend Device;
82};
83
84}; // namespace phosphor::software::manager