Tomáš Pecka | 991e4d5 | 2021-01-11 10:03:14 +0100 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <memory> |
Tomáš Pecka | 9cc0094 | 2021-01-14 22:45:10 +0100 | [diff] [blame] | 4 | #include <mutex> |
Tomáš Pecka | 991e4d5 | 2021-01-11 10:03:14 +0100 | [diff] [blame] | 5 | #include <sdbus-c++/sdbus-c++.h> |
| 6 | #include <string> |
Tomáš Pecka | 9cc0094 | 2021-01-14 22:45:10 +0100 | [diff] [blame] | 7 | #include <thread> |
Tomáš Pecka | 991e4d5 | 2021-01-11 10:03:14 +0100 | [diff] [blame] | 8 | #include "system/RAUC.h" |
| 9 | |
| 10 | /** @brief Mimics the RAUC DBus behaviour */ |
| 11 | class DBusRAUCServer { |
| 12 | public: |
Tomáš Pecka | 9cc0094 | 2021-01-14 22:45:10 +0100 | [diff] [blame] | 13 | enum class InstallBehaviour { |
| 14 | OK, |
| 15 | FAILURE, |
| 16 | }; |
| 17 | |
Tomáš Pecka | 991e4d5 | 2021-01-11 10:03:14 +0100 | [diff] [blame] | 18 | explicit DBusRAUCServer(sdbus::IConnection& connection, std::string primarySlot, const std::map<std::string, velia::system::RAUC::SlotProperties>& status); |
Tomáš Pecka | 9cc0094 | 2021-01-14 22:45:10 +0100 | [diff] [blame] | 19 | ~DBusRAUCServer(); |
| 20 | |
| 21 | void installBundleBehaviour(InstallBehaviour b); |
Tomáš Pecka | 991e4d5 | 2021-01-11 10:03:14 +0100 | [diff] [blame] | 22 | |
| 23 | private: |
| 24 | using DBusSlotStatus = sdbus::Struct<std::string, std::map<std::string, sdbus::Variant>>; |
| 25 | |
Tomáš Pecka | 9cc0094 | 2021-01-14 22:45:10 +0100 | [diff] [blame] | 26 | void installBundle(); |
| 27 | void installBundleOK(); |
| 28 | void installBundleError(); |
| 29 | |
Tomáš Pecka | 991e4d5 | 2021-01-11 10:03:14 +0100 | [diff] [blame] | 30 | std::unique_ptr<sdbus::IObject> m_manager; |
| 31 | std::string m_primarySlot; |
| 32 | std::vector<DBusSlotStatus> m_status; |
Tomáš Pecka | 9cc0094 | 2021-01-14 22:45:10 +0100 | [diff] [blame] | 33 | std::string m_propOperation, m_propLastError; |
| 34 | sdbus::Struct<int32_t, std::string, int32_t> m_propProgress; |
| 35 | |
| 36 | InstallBehaviour m_installBehaviour; |
| 37 | |
| 38 | std::thread m_installThread; |
| 39 | std::mutex m_mtx; |
| 40 | bool m_operationInProgress; |
Tomáš Pecka | 991e4d5 | 2021-01-11 10:03:14 +0100 | [diff] [blame] | 41 | }; |