1 // SPDX-License-Identifier: Apache-2.0 2 // SPDX-FileCopyrightText: Copyright 2018 Intel Corporation 3 4 #pragma once 5 6 #include "configuration.hpp" 7 #include "dbus_interface.hpp" 8 #include "power_status_monitor.hpp" 9 #include "topology.hpp" 10 11 #include <boost/container/flat_map.hpp> 12 #include <nlohmann/json.hpp> 13 #include <sdbusplus/asio/connection.hpp> 14 #include <sdbusplus/asio/object_server.hpp> 15 16 #include <string> 17 18 class EntityManager 19 { 20 public: 21 explicit EntityManager( 22 std::shared_ptr<sdbusplus::asio::connection>& systemBus, 23 boost::asio::io_context& io); 24 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 35 std::shared_ptr<sdbusplus::asio::connection> systemBus; 36 sdbusplus::asio::object_server objServer; 37 std::shared_ptr<sdbusplus::asio::dbus_interface> entityIface; 38 Configuration configuration; 39 nlohmann::json lastJson; 40 nlohmann::json systemConfiguration; 41 Topology topology; 42 boost::asio::io_context& io; 43 44 dbus_interface::EMDBusInterface dbus_interface; 45 46 power::PowerStatusMonitor powerStatus; 47 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); 54 void postBoardToDBus(const std::string& boardId, 55 const nlohmann::json& boardConfig, 56 std::map<std::string, std::string>& newBoards); 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); 62 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 69 void pruneConfiguration(bool powerOff, const std::string& name, 70 const nlohmann::json& device); 71 72 void handleCurrentConfigurationJson(); 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; 78 79 bool scannedPowerOff = false; 80 bool scannedPowerOn = false; 81 82 bool propertiesChangedInProgress = false; 83 boost::asio::steady_timer propertiesChangedTimer; 84 size_t propertiesChangedInstance = 0; 85 86 boost::container::flat_map<std::string, sdbusplus::bus::match_t> 87 dbusMatches; 88 89 void startRemovedTimer(boost::asio::steady_timer& timer, 90 nlohmann::json& systemConfiguration); 91 void initFilters(const std::unordered_set<std::string>& probeInterfaces); 92 }; 93