blob: 4bc6d110d2b14ce198dfbeabfdd2e4504b3b1699 [file] [log] [blame]
James Feist1df06a42019-04-11 14:23:04 -07001/*
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 Bishope45d8c72022-05-25 15:12:53 -040016/// \file entity_manager.hpp
James Feist1df06a42019-04-11 14:23:04 -070017
18#pragma once
19
Christopher Meisf7252572025-06-11 13:22:05 +020020#include "configuration.hpp"
Alexander Hansen57604ed2025-06-27 13:22:28 +020021#include "dbus_interface.hpp"
Alexander Hansen0ab32b32025-06-27 14:50:33 +020022#include "power_status_monitor.hpp"
Christopher Meiscf6a75b2025-06-03 07:53:50 +020023#include "topology.hpp"
James Feist733f7652019-11-13 14:32:29 -080024
James Feist733f7652019-11-13 14:32:29 -080025#include <boost/container/flat_map.hpp>
James Feist1a996582019-05-14 15:10:06 -070026#include <nlohmann/json.hpp>
Christopher Meiscf6a75b2025-06-03 07:53:50 +020027#include <sdbusplus/asio/connection.hpp>
James Feist4dc617b2020-05-01 09:54:47 -070028#include <sdbusplus/asio/object_server.hpp>
James Feist8c505da2020-05-28 10:06:33 -070029
James Feist1df06a42019-04-11 14:23:04 -070030#include <string>
31
Christopher Meiscf6a75b2025-06-03 07:53:50 +020032class EntityManager
33{
34 public:
35 explicit EntityManager(
Alexander Hansena555acf2025-06-27 11:59:10 +020036 std::shared_ptr<sdbusplus::asio::connection>& systemBus,
37 boost::asio::io_context& io);
Christopher Meiscf6a75b2025-06-03 07:53:50 +020038
Alexander Hansen3b7678c2025-07-22 18:33:23 +020039 // 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 Meiscf6a75b2025-06-03 07:53:50 +020049 std::shared_ptr<sdbusplus::asio::connection> systemBus;
50 sdbusplus::asio::object_server objServer;
51 std::shared_ptr<sdbusplus::asio::dbus_interface> entityIface;
Christopher Meisf7252572025-06-11 13:22:05 +020052 Configuration configuration;
Christopher Meiscf6a75b2025-06-03 07:53:50 +020053 nlohmann::json lastJson;
54 nlohmann::json systemConfiguration;
55 Topology topology;
Alexander Hansena555acf2025-06-27 11:59:10 +020056 boost::asio::io_context& io;
Christopher Meiscf6a75b2025-06-03 07:53:50 +020057
Alexander Hansen57604ed2025-06-27 13:22:28 +020058 dbus_interface::EMDBusInterface dbus_interface;
59
Alexander Hansen0ab32b32025-06-27 14:50:33 +020060 power::PowerStatusMonitor powerStatus;
61
Christopher Meiscf6a75b2025-06-03 07:53:50 +020062 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 Hansenad28e402025-06-25 12:38:20 +020071 void handleCurrentConfigurationJson();
Alexander Hansen0f7bd782025-06-27 13:39:53 +020072
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 Hansen95ab18f2025-06-27 13:58:10 +020077
78 bool scannedPowerOff = false;
79 bool scannedPowerOn = false;
80
Alexander Hansen16d40022025-06-27 14:22:56 +020081 bool propertiesChangedInProgress = false;
Alexander Hansenb1340da2025-06-27 14:29:13 +020082 boost::asio::steady_timer propertiesChangedTimer;
Alexander Hansenfc1b1e22025-06-27 14:34:11 +020083 size_t propertiesChangedInstance = 0;
Alexander Hansen16d40022025-06-27 14:22:56 +020084
Alexander Hansen60803182025-06-27 14:41:28 +020085 boost::container::flat_map<std::string, sdbusplus::bus::match_t>
86 dbusMatches;
87
Alexander Hansen95ab18f2025-06-27 13:58:10 +020088 void startRemovedTimer(boost::asio::steady_timer& timer,
89 nlohmann::json& systemConfiguration);
Christopher Meisf7252572025-06-11 13:22:05 +020090 void initFilters(const std::unordered_set<std::string>& probeInterfaces);
Christopher Meiscf6a75b2025-06-03 07:53:50 +020091};