#include "entity_manager_interface.hpp" #include #include #include #include #include #include #include namespace entity_manager { PHOSPHOR_LOG2_USING; namespace rules_intf = sdbusplus::bus::match::rules; using BasicVariantType = std::variant, std::vector, std::string, int64_t, uint64_t, double, int32_t, uint32_t, int16_t, uint16_t, uint8_t, bool>; using BaseConfigMap = std::flat_map; using ConfigData = std::flat_map; using ManagedObjectType = std::flat_map; EntityManagerInterface::EntityManagerInterface( sdbusplus::async::context& ctx, const interface_list_t& interfaceNames, Callback_t addedCallback, Callback_t removedCallback) : ctx(ctx), interfaceNames(interfaceNames), addedCallback(std::move(addedCallback)), removedCallback(std::move(removedCallback)) { ctx.spawn(handleInventoryAdded()); ctx.spawn(handleInventoryRemoved()); } auto EntityManagerInterface::handleInventoryGet() -> sdbusplus::async::task<> { if (!addedCallback) { error("addedCallback is not set"); co_return; } using InventoryIntf = sdbusplus::client::xyz::openbmc_project::inventory::Item<>; constexpr auto entityManager = sdbusplus::async::proxy() .service(serviceName) .path(InventoryIntf::namespace_path) .interface("org.freedesktop.DBus.ObjectManager"); for (const auto& [objectPath, interfaceConfig] : co_await entityManager.call(ctx, "GetManagedObjects")) { for (const auto& interfaceName : interfaceNames) { if (interfaceConfig.contains(interfaceName)) { co_await addedCallback(objectPath, interfaceName); } } } co_return; } auto EntityManagerInterface::handleInventoryAdded() -> sdbusplus::async::task<> { if (!addedCallback) { error("addedCallback is not set"); co_return; } auto addedMatch = sdbusplus::async::match( ctx, rules_intf::interfacesAdded() + rules_intf::sender(serviceName)); while (!ctx.stop_requested()) { auto result = co_await addedMatch .next(); auto& [objectPath, inventoryData] = result; for (const auto& interfaceName : interfaceNames) { if (inventoryData.contains(interfaceName)) { co_await addedCallback(objectPath, interfaceName); } } } co_return; } auto EntityManagerInterface::handleInventoryRemoved() -> sdbusplus::async::task<> { if (!removedCallback) { error("removedCallback is not set"); co_return; } auto removedMatch = sdbusplus::async::match( ctx, rules_intf::interfacesRemoved() + rules_intf::sender(serviceName)); while (!ctx.stop_requested()) { auto result = co_await removedMatch .next(); auto& [objectPath, interfaces] = result; for (const auto& interfaceName : interfaceNames) { if (std::ranges::find(interfaces, interfaceName) != interfaces.end()) { co_await removedCallback(objectPath, interfaceName); } } } co_return; } } // namespace entity_manager