xref: /openbmc/phosphor-bmc-code-mgmt/common/include/software_manager.hpp (revision 994a77ff25aeb28b2cce7142d081af767f9eb542)
1 #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 
14 using namespace phosphor::software::config;
15 using namespace phosphor::software::device;
16 
17 namespace phosphor::software::manager
18 {
19 
20 // This is the base class for the code updater
21 // Every code updater can inherit from this
22 class 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     // this is appended to the common prefix to construct the dbus name
57     std::string serviceNameSuffix;
58 
59     sdbusplus::server::manager_t manager;
60 
61     friend Software;
62     friend Device;
63 };
64 
65 }; // namespace phosphor::software::manager
66