blob: c21b94e666e8e59ec3f402402c6c9bf28c822acb [file] [log] [blame]
Alexander Hansen4e1142d2025-07-25 17:07:27 +02001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright 2018 Intel Corporation
James Feist1df06a42019-04-11 14:23:04 -07003
4#pragma once
5
Christopher Meisf7252572025-06-11 13:22:05 +02006#include "configuration.hpp"
Alexander Hansen57604ed2025-06-27 13:22:28 +02007#include "dbus_interface.hpp"
Alexander Hansen0ab32b32025-06-27 14:50:33 +02008#include "power_status_monitor.hpp"
Christopher Meiscf6a75b2025-06-03 07:53:50 +02009#include "topology.hpp"
James Feist733f7652019-11-13 14:32:29 -080010
James Feist733f7652019-11-13 14:32:29 -080011#include <boost/container/flat_map.hpp>
James Feist1a996582019-05-14 15:10:06 -070012#include <nlohmann/json.hpp>
Christopher Meiscf6a75b2025-06-03 07:53:50 +020013#include <sdbusplus/asio/connection.hpp>
James Feist4dc617b2020-05-01 09:54:47 -070014#include <sdbusplus/asio/object_server.hpp>
James Feist8c505da2020-05-28 10:06:33 -070015
James Feist1df06a42019-04-11 14:23:04 -070016#include <string>
17
Christopher Meiscf6a75b2025-06-03 07:53:50 +020018class EntityManager
19{
20 public:
21 explicit EntityManager(
Alexander Hansena555acf2025-06-27 11:59:10 +020022 std::shared_ptr<sdbusplus::asio::connection>& systemBus,
Alexander Hansen8290ca42025-08-04 15:27:22 +020023 boost::asio::io_context& io,
24 const std::vector<std::filesystem::path>& configurationDirectories);
Christopher Meiscf6a75b2025-06-03 07:53:50 +020025
Alexander Hansen3b7678c2025-07-22 18:33:23 +020026 // disable copy
27 EntityManager(const EntityManager&) = delete;
28 EntityManager& operator=(const EntityManager&) = delete;
29
30 // disable move
31 EntityManager(EntityManager&&) = delete;
32 EntityManager& operator=(EntityManager&&) = delete;
33
34 ~EntityManager() = default;
35
Christopher Meiscf6a75b2025-06-03 07:53:50 +020036 std::shared_ptr<sdbusplus::asio::connection> systemBus;
37 sdbusplus::asio::object_server objServer;
38 std::shared_ptr<sdbusplus::asio::dbus_interface> entityIface;
Christopher Meisf7252572025-06-11 13:22:05 +020039 Configuration configuration;
Christopher Meiscf6a75b2025-06-03 07:53:50 +020040 nlohmann::json lastJson;
41 nlohmann::json systemConfiguration;
42 Topology topology;
Alexander Hansena555acf2025-06-27 11:59:10 +020043 boost::asio::io_context& io;
Christopher Meiscf6a75b2025-06-03 07:53:50 +020044
Alexander Hansen57604ed2025-06-27 13:22:28 +020045 dbus_interface::EMDBusInterface dbus_interface;
46
Alexander Hansen0ab32b32025-06-27 14:50:33 +020047 power::PowerStatusMonitor powerStatus;
48
Christopher Meiscf6a75b2025-06-03 07:53:50 +020049 void propertiesChangedCallback();
50 void registerCallback(const std::string& path);
51 void publishNewConfiguration(const size_t& instance, size_t count,
52 boost::asio::steady_timer& timer,
53 nlohmann::json newConfiguration);
54 void postToDbus(const nlohmann::json& newConfiguration);
Alexander Hansen4fcd9462025-07-30 17:44:44 +020055 void postBoardToDBus(const std::string& boardId,
56 const nlohmann::json& boardConfig,
57 std::map<std::string, std::string>& newBoards);
Alexander Hansen4fa40122025-07-30 18:26:35 +020058 void postExposesRecordsToDBus(
59 nlohmann::json& item, size_t& exposesIndex,
60 const std::string& boardNameOrig, std::string jsonPointerPath,
61 const std::string& jsonPointerPathBoard, const std::string& boardPath,
62 const std::string& boardType);
Alexander Hansen4fcd9462025-07-30 17:44:44 +020063
Alexander Hansen5aa65d82025-07-31 14:08:42 +020064 // @returns false on error
65 bool postConfigurationRecord(
66 const std::string& name, nlohmann::json& config,
67 const std::string& boardNameOrig, const std::string& itemType,
68 const std::string& jsonPointerPath, const std::string& ifacePath);
69
Christopher Meiscf6a75b2025-06-03 07:53:50 +020070 void pruneConfiguration(bool powerOff, const std::string& name,
71 const nlohmann::json& device);
72
Alexander Hansenad28e402025-06-25 12:38:20 +020073 void handleCurrentConfigurationJson();
Alexander Hansen0f7bd782025-06-27 13:39:53 +020074
75 private:
76 std::unique_ptr<sdbusplus::bus::match_t> nameOwnerChangedMatch = nullptr;
77 std::unique_ptr<sdbusplus::bus::match_t> interfacesAddedMatch = nullptr;
78 std::unique_ptr<sdbusplus::bus::match_t> interfacesRemovedMatch = nullptr;
Alexander Hansen95ab18f2025-06-27 13:58:10 +020079
80 bool scannedPowerOff = false;
81 bool scannedPowerOn = false;
82
Alexander Hansen16d40022025-06-27 14:22:56 +020083 bool propertiesChangedInProgress = false;
Alexander Hansenb1340da2025-06-27 14:29:13 +020084 boost::asio::steady_timer propertiesChangedTimer;
Alexander Hansenfc1b1e22025-06-27 14:34:11 +020085 size_t propertiesChangedInstance = 0;
Alexander Hansen16d40022025-06-27 14:22:56 +020086
Alexander Hansen60803182025-06-27 14:41:28 +020087 boost::container::flat_map<std::string, sdbusplus::bus::match_t>
88 dbusMatches;
89
Alexander Hansen95ab18f2025-06-27 13:58:10 +020090 void startRemovedTimer(boost::asio::steady_timer& timer,
91 nlohmann::json& systemConfiguration);
Christopher Meisf7252572025-06-11 13:22:05 +020092 void initFilters(const std::unordered_set<std::string>& probeInterfaces);
Christopher Meiscf6a75b2025-06-03 07:53:50 +020093};