xref: /openbmc/pldm/libpldmresponder/platform_config.hpp (revision 3c99e773aba9a3622523479d0044f542e9e16e26)
1 #pragma once
2 #include "common/utils.hpp"
3 #include "pldmd/handler.hpp"
4 
5 namespace pldm
6 {
7 namespace responder
8 {
9 
10 namespace platform_config
11 {
12 using namespace pldm::utils;
13 
14 using SystemTypeCallback = std::function<void(const std::string&, bool)>;
15 
16 class Handler : public CmdHandler
17 {
18   public:
Handler(const fs::path sysDirPath={})19     Handler(const fs::path sysDirPath = {}) : sysDirPath(sysDirPath)
20     {
21         systemCompatibleMatchCallBack =
22             std::make_unique<sdbusplus::bus::match_t>(
23                 pldm::utils::DBusHandler::getBus(),
24                 sdbusplus::bus::match::rules::interfacesAdded() +
25                     sdbusplus::bus::match::rules::sender(
26                         "xyz.openbmc_project.EntityManager"),
27                 std::bind(&Handler::systemCompatibleCallback, this,
28                           std::placeholders::_1));
29         sysTypeCallback = nullptr;
30     }
31 
32     /** @brief Interface to get the system type information using Dbus query
33      *
34      *  @return - the system type information
35      */
36     virtual std::optional<std::filesystem::path> getPlatformName();
37 
38     /** @brief D-Bus Interface added signal match for Entity Manager */
39     void systemCompatibleCallback(sdbusplus::message_t& msg);
40 
41     /** @brief Registers the callback from other objects */
42     void registerSystemTypeCallback(SystemTypeCallback callback);
43 
44   private:
45     /** @brief Interface to get the first available directory
46      *         from the received list
47      *
48      *  @param[in] dirPath  - Directory path to search system specific directory
49      *  @param[in] dirNames - System names retrieved from remote application
50      *  @return - The system type information
51      */
52     std::optional<std::string> getSysSpecificJsonDir(
53         const fs::path& dirPath, const std::vector<std::string>& dirNames);
54 
55     /** @brief system type/model */
56     std::string systemType;
57 
58     /** @brief D-Bus Interface added signal match for Entity Manager */
59     std::unique_ptr<sdbusplus::bus::match_t> systemCompatibleMatchCallBack;
60 
61     /** @brief Registered Callback */
62     SystemTypeCallback sysTypeCallback;
63 
64     /** @brief system specific json file directory path */
65     fs::path sysDirPath;
66 };
67 
68 } // namespace platform_config
69 
70 } // namespace responder
71 
72 } // namespace pldm
73