Alexander Hansen | cc37235 | 2025-01-14 14:15:39 +0100 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "device.hpp" |
Alexander Hansen | cec1475 | 2025-05-08 13:11:03 +0200 | [diff] [blame^] | 4 | #include "sdbusplus/async/match.hpp" |
Alexander Hansen | cc37235 | 2025-01-14 14:15:39 +0100 | [diff] [blame] | 5 | |
| 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 | |
| 15 | using namespace phosphor::software::config; |
| 16 | using namespace phosphor::software::device; |
| 17 | |
| 18 | namespace phosphor::software::manager |
| 19 | { |
| 20 | |
| 21 | // This is the base class for the code updater |
| 22 | // Every code updater can inherit from this |
| 23 | class 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 Hansen | 9017479 | 2025-05-08 10:14:54 +0200 | [diff] [blame] | 57 | sdbusplus::async::task<void> handleInterfaceAdded( |
| 58 | const std::string& service, const std::string& path, |
| 59 | const std::string& interface); |
| 60 | |
Alexander Hansen | cec1475 | 2025-05-08 13:11:03 +0200 | [diff] [blame^] | 61 | 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 Hansen | cc37235 | 2025-01-14 14:15:39 +0100 | [diff] [blame] | 73 | // 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 |