1 #pragma once 2 3 #include "device.hpp" 4 #include "sdbusplus/async/match.hpp" 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 std::string getBusName(); 55 56 sdbusplus::async::context& ctx; 57 58 private: 59 sdbusplus::async::task<void> handleInterfaceAdded( 60 const std::string& service, const std::string& path, 61 const std::string& interface); 62 63 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 75 // the dbus name 76 const std::string serviceName; 77 78 sdbusplus::server::manager_t manager; 79 80 friend Software; 81 friend Device; 82 }; 83 84 }; // namespace phosphor::software::manager 85