blob: 33efb317ca7b8dbc4223fe726c177ec27d71b22d [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,
23 boost::asio::io_context& io);
Christopher Meiscf6a75b2025-06-03 07:53:50 +020024
Alexander Hansen3b7678c2025-07-22 18:33:23 +020025 // disable copy
26 EntityManager(const EntityManager&) = delete;
27 EntityManager& operator=(const EntityManager&) = delete;
28
29 // disable move
30 EntityManager(EntityManager&&) = delete;
31 EntityManager& operator=(EntityManager&&) = delete;
32
33 ~EntityManager() = default;
34
Christopher Meiscf6a75b2025-06-03 07:53:50 +020035 std::shared_ptr<sdbusplus::asio::connection> systemBus;
36 sdbusplus::asio::object_server objServer;
37 std::shared_ptr<sdbusplus::asio::dbus_interface> entityIface;
Christopher Meisf7252572025-06-11 13:22:05 +020038 Configuration configuration;
Christopher Meiscf6a75b2025-06-03 07:53:50 +020039 nlohmann::json lastJson;
40 nlohmann::json systemConfiguration;
41 Topology topology;
Alexander Hansena555acf2025-06-27 11:59:10 +020042 boost::asio::io_context& io;
Christopher Meiscf6a75b2025-06-03 07:53:50 +020043
Alexander Hansen57604ed2025-06-27 13:22:28 +020044 dbus_interface::EMDBusInterface dbus_interface;
45
Alexander Hansen0ab32b32025-06-27 14:50:33 +020046 power::PowerStatusMonitor powerStatus;
47
Christopher Meiscf6a75b2025-06-03 07:53:50 +020048 void propertiesChangedCallback();
49 void registerCallback(const std::string& path);
50 void publishNewConfiguration(const size_t& instance, size_t count,
51 boost::asio::steady_timer& timer,
52 nlohmann::json newConfiguration);
53 void postToDbus(const nlohmann::json& newConfiguration);
Alexander Hansen4fcd9462025-07-30 17:44:44 +020054 void postBoardToDBus(const std::string& boardId,
55 const nlohmann::json& boardConfig,
56 std::map<std::string, std::string>& newBoards);
Alexander Hansen4fa40122025-07-30 18:26:35 +020057 void postExposesRecordsToDBus(
58 nlohmann::json& item, size_t& exposesIndex,
59 const std::string& boardNameOrig, std::string jsonPointerPath,
60 const std::string& jsonPointerPathBoard, const std::string& boardPath,
61 const std::string& boardType);
Alexander Hansen4fcd9462025-07-30 17:44:44 +020062
Alexander Hansen5aa65d82025-07-31 14:08:42 +020063 // @returns false on error
64 bool postConfigurationRecord(
65 const std::string& name, nlohmann::json& config,
66 const std::string& boardNameOrig, const std::string& itemType,
67 const std::string& jsonPointerPath, const std::string& ifacePath);
68
Christopher Meiscf6a75b2025-06-03 07:53:50 +020069 void pruneConfiguration(bool powerOff, const std::string& name,
70 const nlohmann::json& device);
71
Alexander Hansenad28e402025-06-25 12:38:20 +020072 void handleCurrentConfigurationJson();
Alexander Hansen0f7bd782025-06-27 13:39:53 +020073
74 private:
75 std::unique_ptr<sdbusplus::bus::match_t> nameOwnerChangedMatch = nullptr;
76 std::unique_ptr<sdbusplus::bus::match_t> interfacesAddedMatch = nullptr;
77 std::unique_ptr<sdbusplus::bus::match_t> interfacesRemovedMatch = nullptr;
Alexander Hansen95ab18f2025-06-27 13:58:10 +020078
79 bool scannedPowerOff = false;
80 bool scannedPowerOn = false;
81
Alexander Hansen16d40022025-06-27 14:22:56 +020082 bool propertiesChangedInProgress = false;
Alexander Hansenb1340da2025-06-27 14:29:13 +020083 boost::asio::steady_timer propertiesChangedTimer;
Alexander Hansenfc1b1e22025-06-27 14:34:11 +020084 size_t propertiesChangedInstance = 0;
Alexander Hansen16d40022025-06-27 14:22:56 +020085
Alexander Hansen60803182025-06-27 14:41:28 +020086 boost::container::flat_map<std::string, sdbusplus::bus::match_t>
87 dbusMatches;
88
Alexander Hansen95ab18f2025-06-27 13:58:10 +020089 void startRemovedTimer(boost::asio::steady_timer& timer,
90 nlohmann::json& systemConfiguration);
Christopher Meisf7252572025-06-11 13:22:05 +020091 void initFilters(const std::unordered_set<std::string>& probeInterfaces);
Christopher Meiscf6a75b2025-06-03 07:53:50 +020092};