James Feist | 1df06a4 | 2019-04-11 14:23:04 -0700 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2018 Intel Corporation |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | */ |
Brad Bishop | e45d8c7 | 2022-05-25 15:12:53 -0400 | [diff] [blame] | 16 | /// \file entity_manager.hpp |
James Feist | 1df06a4 | 2019-04-11 14:23:04 -0700 | [diff] [blame] | 17 | |
| 18 | #pragma once |
| 19 | |
Christopher Meis | f725257 | 2025-06-11 13:22:05 +0200 | [diff] [blame] | 20 | #include "configuration.hpp" |
Alexander Hansen | 57604ed | 2025-06-27 13:22:28 +0200 | [diff] [blame] | 21 | #include "dbus_interface.hpp" |
Alexander Hansen | 0ab32b3 | 2025-06-27 14:50:33 +0200 | [diff] [blame] | 22 | #include "power_status_monitor.hpp" |
Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 23 | #include "topology.hpp" |
James Feist | 733f765 | 2019-11-13 14:32:29 -0800 | [diff] [blame] | 24 | |
James Feist | 733f765 | 2019-11-13 14:32:29 -0800 | [diff] [blame] | 25 | #include <boost/container/flat_map.hpp> |
James Feist | 1a99658 | 2019-05-14 15:10:06 -0700 | [diff] [blame] | 26 | #include <nlohmann/json.hpp> |
Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 27 | #include <sdbusplus/asio/connection.hpp> |
James Feist | 4dc617b | 2020-05-01 09:54:47 -0700 | [diff] [blame] | 28 | #include <sdbusplus/asio/object_server.hpp> |
James Feist | 8c505da | 2020-05-28 10:06:33 -0700 | [diff] [blame] | 29 | |
James Feist | 1df06a4 | 2019-04-11 14:23:04 -0700 | [diff] [blame] | 30 | #include <string> |
| 31 | |
Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 32 | class EntityManager |
| 33 | { |
| 34 | public: |
| 35 | explicit EntityManager( |
Alexander Hansen | a555acf | 2025-06-27 11:59:10 +0200 | [diff] [blame] | 36 | std::shared_ptr<sdbusplus::asio::connection>& systemBus, |
| 37 | boost::asio::io_context& io); |
Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 38 | |
Alexander Hansen | 3b7678c | 2025-07-22 18:33:23 +0200 | [diff] [blame] | 39 | // disable copy |
| 40 | EntityManager(const EntityManager&) = delete; |
| 41 | EntityManager& operator=(const EntityManager&) = delete; |
| 42 | |
| 43 | // disable move |
| 44 | EntityManager(EntityManager&&) = delete; |
| 45 | EntityManager& operator=(EntityManager&&) = delete; |
| 46 | |
| 47 | ~EntityManager() = default; |
| 48 | |
Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 49 | std::shared_ptr<sdbusplus::asio::connection> systemBus; |
| 50 | sdbusplus::asio::object_server objServer; |
| 51 | std::shared_ptr<sdbusplus::asio::dbus_interface> entityIface; |
Christopher Meis | f725257 | 2025-06-11 13:22:05 +0200 | [diff] [blame] | 52 | Configuration configuration; |
Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 53 | nlohmann::json lastJson; |
| 54 | nlohmann::json systemConfiguration; |
| 55 | Topology topology; |
Alexander Hansen | a555acf | 2025-06-27 11:59:10 +0200 | [diff] [blame] | 56 | boost::asio::io_context& io; |
Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 57 | |
Alexander Hansen | 57604ed | 2025-06-27 13:22:28 +0200 | [diff] [blame] | 58 | dbus_interface::EMDBusInterface dbus_interface; |
| 59 | |
Alexander Hansen | 0ab32b3 | 2025-06-27 14:50:33 +0200 | [diff] [blame] | 60 | power::PowerStatusMonitor powerStatus; |
| 61 | |
Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 62 | void propertiesChangedCallback(); |
| 63 | void registerCallback(const std::string& path); |
| 64 | void publishNewConfiguration(const size_t& instance, size_t count, |
| 65 | boost::asio::steady_timer& timer, |
| 66 | nlohmann::json newConfiguration); |
| 67 | void postToDbus(const nlohmann::json& newConfiguration); |
| 68 | void pruneConfiguration(bool powerOff, const std::string& name, |
| 69 | const nlohmann::json& device); |
| 70 | |
Alexander Hansen | ad28e40 | 2025-06-25 12:38:20 +0200 | [diff] [blame] | 71 | void handleCurrentConfigurationJson(); |
Alexander Hansen | 0f7bd78 | 2025-06-27 13:39:53 +0200 | [diff] [blame] | 72 | |
| 73 | private: |
| 74 | std::unique_ptr<sdbusplus::bus::match_t> nameOwnerChangedMatch = nullptr; |
| 75 | std::unique_ptr<sdbusplus::bus::match_t> interfacesAddedMatch = nullptr; |
| 76 | std::unique_ptr<sdbusplus::bus::match_t> interfacesRemovedMatch = nullptr; |
Alexander Hansen | 95ab18f | 2025-06-27 13:58:10 +0200 | [diff] [blame] | 77 | |
| 78 | bool scannedPowerOff = false; |
| 79 | bool scannedPowerOn = false; |
| 80 | |
Alexander Hansen | 16d4002 | 2025-06-27 14:22:56 +0200 | [diff] [blame] | 81 | bool propertiesChangedInProgress = false; |
Alexander Hansen | b1340da | 2025-06-27 14:29:13 +0200 | [diff] [blame] | 82 | boost::asio::steady_timer propertiesChangedTimer; |
Alexander Hansen | fc1b1e2 | 2025-06-27 14:34:11 +0200 | [diff] [blame] | 83 | size_t propertiesChangedInstance = 0; |
Alexander Hansen | 16d4002 | 2025-06-27 14:22:56 +0200 | [diff] [blame] | 84 | |
Alexander Hansen | 6080318 | 2025-06-27 14:41:28 +0200 | [diff] [blame] | 85 | boost::container::flat_map<std::string, sdbusplus::bus::match_t> |
| 86 | dbusMatches; |
| 87 | |
Alexander Hansen | 95ab18f | 2025-06-27 13:58:10 +0200 | [diff] [blame] | 88 | void startRemovedTimer(boost::asio::steady_timer& timer, |
| 89 | nlohmann::json& systemConfiguration); |
Christopher Meis | f725257 | 2025-06-11 13:22:05 +0200 | [diff] [blame] | 90 | void initFilters(const std::unordered_set<std::string>& probeInterfaces); |
Christopher Meis | cf6a75b | 2025-06-03 07:53:50 +0200 | [diff] [blame] | 91 | }; |