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 <nlohmann/json.hpp> 12 #include <sdbusplus/asio/connection.hpp> 13 #include <sdbusplus/asio/object_server.hpp> 14 15 #include <flat_map> 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 const std::vector<std::filesystem::path>& configurationDirectories, 25 const std::filesystem::path& schemaDirectory); 26 27 // disable copy 28 EntityManager(const EntityManager&) = delete; 29 EntityManager& operator=(const EntityManager&) = delete; 30 31 // disable move 32 EntityManager(EntityManager&&) = delete; 33 EntityManager& operator=(EntityManager&&) = delete; 34 35 ~EntityManager() = default; 36 37 std::shared_ptr<sdbusplus::asio::connection> systemBus; 38 sdbusplus::asio::object_server objServer; 39 std::shared_ptr<sdbusplus::asio::dbus_interface> entityIface; 40 Configuration configuration; 41 nlohmann::json lastJson; 42 nlohmann::json systemConfiguration; 43 Topology topology; 44 boost::asio::io_context& io; 45 46 dbus_interface::EMDBusInterface dbus_interface; 47 48 power::PowerStatusMonitor powerStatus; 49 50 void propertiesChangedCallback(); 51 void registerCallback(const std::string& path); 52 void publishNewConfiguration(const size_t& instance, size_t count, 53 boost::asio::steady_timer& timer, 54 nlohmann::json newConfiguration); 55 void postToDbus(const nlohmann::json& newConfiguration); 56 void postBoardToDBus(const std::string& boardId, 57 const nlohmann::json::object_t& boardConfig, 58 std::map<std::string, std::string>& newBoards); 59 void postExposesRecordsToDBus( 60 nlohmann::json& item, size_t& exposesIndex, 61 const std::string& boardNameOrig, std::string jsonPointerPath, 62 const std::string& jsonPointerPathBoard, const std::string& boardPath, 63 const std::string& boardType); 64 65 // @returns false on error 66 bool postConfigurationRecord( 67 const std::string& name, nlohmann::json& config, 68 const std::string& boardNameOrig, const std::string& itemType, 69 const std::string& jsonPointerPath, const std::string& ifacePath); 70 71 void pruneConfiguration(bool powerOff, const std::string& name, 72 const nlohmann::json& device); 73 74 void handleCurrentConfigurationJson(); 75 76 private: 77 std::unique_ptr<sdbusplus::bus::match_t> nameOwnerChangedMatch = nullptr; 78 std::unique_ptr<sdbusplus::bus::match_t> interfacesAddedMatch = nullptr; 79 std::unique_ptr<sdbusplus::bus::match_t> interfacesRemovedMatch = nullptr; 80 81 bool scannedPowerOff = false; 82 bool scannedPowerOn = false; 83 84 bool propertiesChangedInProgress = false; 85 boost::asio::steady_timer propertiesChangedTimer; 86 size_t propertiesChangedInstance = 0; 87 88 std::flat_map<std::string, sdbusplus::bus::match_t, std::less<>> 89 dbusMatches; 90 91 void startRemovedTimer(boost::asio::steady_timer& timer, 92 nlohmann::json& systemConfiguration); 93 void initFilters(const std::unordered_set<std::string>& probeInterfaces); 94 }; 95