blob: c55d0f6d476e8093982151a0e4b621cc538741d2 [file] [log] [blame]
Tomáš Peckaccd80c32020-06-22 14:44:32 +02001/*
2 * Copyright (C) 2020 CESNET, https://photonics.cesnet.cz/
3 *
4 * Written by Tomáš Pecka <tomas.pecka@fit.cvut.cz>
5 *
6*/
7#pragma once
8
9#include <memory>
10#include <sdbus-c++/sdbus-c++.h>
11#include <set>
Tomáš Pecka261c8862020-11-05 11:23:08 +010012#include "health/inputs/AbstractInput.h"
13#include "health/manager/StateManager.h"
Tomáš Peckaccd80c32020-06-22 14:44:32 +020014
Tomáš Pecka261c8862020-11-05 11:23:08 +010015namespace velia::health {
Tomáš Peckaccd80c32020-06-22 14:44:32 +020016
17/**
18 * Register
19 */
20class DbusSystemdInput : public AbstractInput {
21public:
Tomáš Peckaf2391d62020-11-06 14:02:00 +010022 DbusSystemdInput(std::shared_ptr<AbstractManager> manager, const std::set<std::string>& ignoredUnits, sdbus::IConnection& connection);
23 DbusSystemdInput(std::shared_ptr<AbstractManager> manager, const std::set<std::string>& ignoredUnits, sdbus::IConnection& connection, const std::string& busname, const std::string& managerObjectPath, const std::string& managerIface, const std::string& unitIface);
Tomáš Peckaccd80c32020-06-22 14:44:32 +020024 ~DbusSystemdInput() override;
25
26private:
27 velia::Log m_log;
28
29 std::string m_busName;
30 std::string m_unitIface;
31 std::unique_ptr<sdbus::IProxy> m_proxyManager;
32
33 /** List of registered unit watchers */
34 std::map<sdbus::ObjectPath, std::unique_ptr<sdbus::IProxy>> m_proxyUnits;
35
36 /** List of units in failed state. */
37 std::set<std::string> m_failedUnits;
38
Tomáš Pecka8ce88352020-11-04 19:14:13 +010039 /** Current unit state. */
40 std::map<std::string, std::pair<std::string, std::string>> m_unitState;
41
Tomáš Peckaccd80c32020-06-22 14:44:32 +020042 void registerSystemdUnit(sdbus::IConnection& connection, const std::string& unitName, const sdbus::ObjectPath& unitObjectPath);
43 void onUnitStateChange(const std::string& name, const std::string& activeState, const std::string& nSubState);
44};
45
Tomáš Pecka8ce88352020-11-04 19:14:13 +010046}