Tomáš Pecka | ccd80c3 | 2020-06-22 14:44:32 +0200 | [diff] [blame] | 1 | #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 */ |
| 9 | class DbusSystemdServer { |
| 10 | public: |
| 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áš Pecka | f2391d6 | 2020-11-06 14:02:00 +0100 | [diff] [blame] | 15 | void createUnit(sdbus::IConnection& connection, const std::string& unitName, const sdbus::ObjectPath& objPath, const std::string& activeState, const std::string& subState); |
Tomáš Pecka | ccd80c3 | 2020-06-22 14:44:32 +0200 | [diff] [blame] | 16 | void changeUnitState(const sdbus::ObjectPath& objPath, const std::string& activeState, const std::string& subState); |
| 17 | |
| 18 | private: |
| 19 | struct Unit { |
Tomáš Pecka | f2391d6 | 2020-11-06 14:02:00 +0100 | [diff] [blame] | 20 | Unit(std::string unitName, std::unique_ptr<sdbus::IObject> object, std::string activeState, std::string subState); |
Tomáš Pecka | ccd80c3 | 2020-06-22 14:44:32 +0200 | [diff] [blame] | 21 | |
Tomáš Pecka | f2391d6 | 2020-11-06 14:02:00 +0100 | [diff] [blame] | 22 | std::string m_unitName; |
Tomáš Pecka | ccd80c3 | 2020-06-22 14:44:32 +0200 | [diff] [blame] | 23 | 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áš Pecka | f2391d6 | 2020-11-06 14:02:00 +0100 | [diff] [blame] | 32 | }; |