blob: 7961a8b801de970198778c9d787e19e513aed9b6 [file] [log] [blame]
Tomáš Peckaccd80c32020-06-22 14:44:32 +02001#pragma once
2
3#include <memory>
4#include <mutex>
5#include <sdbus-c++/sdbus-c++.h>
6#include <string>
7
8/** @brief Mimics the systemd dbus behaviour */
9class DbusSystemdServer {
10public:
11 using UnitStruct = sdbus::Struct<std::string, std::string, std::string, std::string, std::string, std::string, sdbus::ObjectPath, uint32_t, std::string, sdbus::ObjectPath>;
12
13 explicit DbusSystemdServer(sdbus::IConnection& connection);
14
Tomáš Peckaf2391d62020-11-06 14:02:00 +010015 void createUnit(sdbus::IConnection& connection, const std::string& unitName, const sdbus::ObjectPath& objPath, const std::string& activeState, const std::string& subState);
Tomáš Peckaccd80c32020-06-22 14:44:32 +020016 void changeUnitState(const sdbus::ObjectPath& objPath, const std::string& activeState, const std::string& subState);
17
18private:
19 struct Unit {
Tomáš Peckaf2391d62020-11-06 14:02:00 +010020 Unit(std::string unitName, std::unique_ptr<sdbus::IObject> object, std::string activeState, std::string subState);
Tomáš Peckaccd80c32020-06-22 14:44:32 +020021
Tomáš Peckaf2391d62020-11-06 14:02:00 +010022 std::string m_unitName;
Tomáš Peckaccd80c32020-06-22 14:44:32 +020023 std::unique_ptr<sdbus::IObject> m_object;
24 std::string m_activeState;
25 std::string m_subState;
26 };
27
28 std::unique_ptr<sdbus::IObject> m_manager;
29 std::map<sdbus::ObjectPath, Unit> m_units;
30
31 std::vector<UnitStruct> ListUnits();
Tomáš Peckaf2391d62020-11-06 14:02:00 +010032};