| Alexander Hansen | 4e1142d | 2025-07-25 17:07:27 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 | 
 | 2 | // SPDX-FileCopyrightText: Copyright 2018 Intel Corporation | 
| James Feist | 1df06a4 | 2019-04-11 14:23:04 -0700 | [diff] [blame] | 3 |  | 
 | 4 | #pragma once | 
 | 5 |  | 
| Christopher Meis | f725257 | 2025-06-11 13:22:05 +0200 | [diff] [blame] | 6 | #include "configuration.hpp" | 
| Alexander Hansen | 57604ed | 2025-06-27 13:22:28 +0200 | [diff] [blame] | 7 | #include "dbus_interface.hpp" | 
| Alexander Hansen | 0ab32b3 | 2025-06-27 14:50:33 +0200 | [diff] [blame] | 8 | #include "power_status_monitor.hpp" | 
| Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 9 | #include "topology.hpp" | 
| James Feist | 733f765 | 2019-11-13 14:32:29 -0800 | [diff] [blame] | 10 |  | 
| James Feist | 733f765 | 2019-11-13 14:32:29 -0800 | [diff] [blame] | 11 | #include <boost/container/flat_map.hpp> | 
| James Feist | 1a99658 | 2019-05-14 15:10:06 -0700 | [diff] [blame] | 12 | #include <nlohmann/json.hpp> | 
| Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 13 | #include <sdbusplus/asio/connection.hpp> | 
| James Feist | 4dc617b | 2020-05-01 09:54:47 -0700 | [diff] [blame] | 14 | #include <sdbusplus/asio/object_server.hpp> | 
| James Feist | 8c505da | 2020-05-28 10:06:33 -0700 | [diff] [blame] | 15 |  | 
| James Feist | 1df06a4 | 2019-04-11 14:23:04 -0700 | [diff] [blame] | 16 | #include <string> | 
 | 17 |  | 
| Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 18 | class EntityManager | 
 | 19 | { | 
 | 20 |   public: | 
 | 21 |     explicit EntityManager( | 
| Alexander Hansen | a555acf | 2025-06-27 11:59:10 +0200 | [diff] [blame] | 22 |         std::shared_ptr<sdbusplus::asio::connection>& systemBus, | 
 | 23 |         boost::asio::io_context& io); | 
| Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 24 |  | 
| Alexander Hansen | 3b7678c | 2025-07-22 18:33:23 +0200 | [diff] [blame] | 25 |     // 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 Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 35 |     std::shared_ptr<sdbusplus::asio::connection> systemBus; | 
 | 36 |     sdbusplus::asio::object_server objServer; | 
 | 37 |     std::shared_ptr<sdbusplus::asio::dbus_interface> entityIface; | 
| Christopher Meis | f725257 | 2025-06-11 13:22:05 +0200 | [diff] [blame] | 38 |     Configuration configuration; | 
| Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 39 |     nlohmann::json lastJson; | 
 | 40 |     nlohmann::json systemConfiguration; | 
 | 41 |     Topology topology; | 
| Alexander Hansen | a555acf | 2025-06-27 11:59:10 +0200 | [diff] [blame] | 42 |     boost::asio::io_context& io; | 
| Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 43 |  | 
| Alexander Hansen | 57604ed | 2025-06-27 13:22:28 +0200 | [diff] [blame] | 44 |     dbus_interface::EMDBusInterface dbus_interface; | 
 | 45 |  | 
| Alexander Hansen | 0ab32b3 | 2025-06-27 14:50:33 +0200 | [diff] [blame] | 46 |     power::PowerStatusMonitor powerStatus; | 
 | 47 |  | 
| Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 48 |     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 Hansen | 4fcd946 | 2025-07-30 17:44:44 +0200 | [diff] [blame] | 54 |     void postBoardToDBus(const std::string& boardId, | 
 | 55 |                          const nlohmann::json& boardConfig, | 
 | 56 |                          std::map<std::string, std::string>& newBoards); | 
| Alexander Hansen | 4fa4012 | 2025-07-30 18:26:35 +0200 | [diff] [blame] | 57 |     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 Hansen | 4fcd946 | 2025-07-30 17:44:44 +0200 | [diff] [blame] | 62 |  | 
| Alexander Hansen | 5aa65d8 | 2025-07-31 14:08:42 +0200 | [diff] [blame] | 63 |     // @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 Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 69 |     void pruneConfiguration(bool powerOff, const std::string& name, | 
 | 70 |                             const nlohmann::json& device); | 
 | 71 |  | 
| Alexander Hansen | ad28e40 | 2025-06-25 12:38:20 +0200 | [diff] [blame] | 72 |     void handleCurrentConfigurationJson(); | 
| Alexander Hansen | 0f7bd78 | 2025-06-27 13:39:53 +0200 | [diff] [blame] | 73 |  | 
 | 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 Hansen | 95ab18f | 2025-06-27 13:58:10 +0200 | [diff] [blame] | 78 |  | 
 | 79 |     bool scannedPowerOff = false; | 
 | 80 |     bool scannedPowerOn = false; | 
 | 81 |  | 
| Alexander Hansen | 16d4002 | 2025-06-27 14:22:56 +0200 | [diff] [blame] | 82 |     bool propertiesChangedInProgress = false; | 
| Alexander Hansen | b1340da | 2025-06-27 14:29:13 +0200 | [diff] [blame] | 83 |     boost::asio::steady_timer propertiesChangedTimer; | 
| Alexander Hansen | fc1b1e2 | 2025-06-27 14:34:11 +0200 | [diff] [blame] | 84 |     size_t propertiesChangedInstance = 0; | 
| Alexander Hansen | 16d4002 | 2025-06-27 14:22:56 +0200 | [diff] [blame] | 85 |  | 
| Alexander Hansen | 6080318 | 2025-06-27 14:41:28 +0200 | [diff] [blame] | 86 |     boost::container::flat_map<std::string, sdbusplus::bus::match_t> | 
 | 87 |         dbusMatches; | 
 | 88 |  | 
| Alexander Hansen | 95ab18f | 2025-06-27 13:58:10 +0200 | [diff] [blame] | 89 |     void startRemovedTimer(boost::asio::steady_timer& timer, | 
 | 90 |                            nlohmann::json& systemConfiguration); | 
| Christopher Meis | f725257 | 2025-06-11 13:22:05 +0200 | [diff] [blame] | 91 |     void initFilters(const std::unordered_set<std::string>& probeInterfaces); | 
| Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 92 | }; |