xref: /openbmc/dbus-sensors/src/leakdetector/LeakDetectionManager.hpp (revision 15dde8641baa1cb902d17f9857effb081e384944)
1 #include "EntityManagerInterface.hpp"
2 #include "LeakEvents.hpp"
3 #include "LeakGPIODetector.hpp"
4 
5 #include <sdbusplus/async.hpp>
6 #include <sdbusplus/message/native_types.hpp>
7 #include <xyz/openbmc_project/Configuration/GPIOLeakDetector/client.hpp>
8 
9 #include <memory>
10 #include <optional>
11 #include <string>
12 #include <unordered_map>
13 
14 namespace leak
15 {
16 
17 class DetectionManager;
18 
19 using GPIODetectorConfigIntf =
20     sdbusplus::client::xyz::openbmc_project::configuration::GPIOLeakDetector<>;
21 
22 class DetectionManager
23 {
24   public:
25     DetectionManager() = delete;
26 
27     explicit DetectionManager(sdbusplus::async::context& ctx);
28 
29   private:
30     using detector_map_t =
31         std::unordered_map<std::string, std::unique_ptr<GPIODetector>>;
32 
33     /** @brief  Process new interfaces added to inventory */
34     auto processInventoryAdded(
35         const sdbusplus::message::object_path& objectPath,
36         const std::string& interfaceName) -> void;
37 
38     /** @brief Process interfaces removed from inventory */
39     auto processInventoryRemoved(
40         const sdbusplus::message::object_path& objectPath,
41         const std::string& interfaceName) -> void;
42 
43     /** @brief Process the config add asynchronously */
44     auto processConfigAddedAsync(sdbusplus::message::object_path objectPath)
45         -> sdbusplus::async::task<>;
46 
47     /** @brief Get the detector configuration from the Entity Manager */
48     auto getDetectorConfig(sdbusplus::message::object_path objectPath)
49         -> sdbusplus::async::task<std::optional<config::DetectorConfig>>;
50 
51     sdbusplus::async::context& ctx;
52     Events leakEvents;
53     entity_manager::EntityManagerInterface entityManager;
54     detector_map_t detectors;
55 };
56 
57 } // namespace leak
58