blob: 30452156e23fea34b5423e73df7c1bdd07726b0a [file] [log] [blame]
Tomáš Pecka991e4d52021-01-11 10:03:14 +01001#pragma once
2
3#include <memory>
Tomáš Pecka9cc00942021-01-14 22:45:10 +01004#include <mutex>
Tomáš Pecka991e4d52021-01-11 10:03:14 +01005#include <sdbus-c++/sdbus-c++.h>
6#include <string>
Tomáš Pecka9cc00942021-01-14 22:45:10 +01007#include <thread>
Tomáš Pecka991e4d52021-01-11 10:03:14 +01008#include "system/RAUC.h"
9
10/** @brief Mimics the RAUC DBus behaviour */
11class DBusRAUCServer {
12public:
Tomáš Pecka9cc00942021-01-14 22:45:10 +010013 enum class InstallBehaviour {
14 OK,
15 FAILURE,
16 };
17
Tomáš Pecka991e4d52021-01-11 10:03:14 +010018 explicit DBusRAUCServer(sdbus::IConnection& connection, std::string primarySlot, const std::map<std::string, velia::system::RAUC::SlotProperties>& status);
Tomáš Pecka9cc00942021-01-14 22:45:10 +010019 ~DBusRAUCServer();
20
21 void installBundleBehaviour(InstallBehaviour b);
Tomáš Pecka991e4d52021-01-11 10:03:14 +010022
23private:
24 using DBusSlotStatus = sdbus::Struct<std::string, std::map<std::string, sdbus::Variant>>;
25
Tomáš Pecka9cc00942021-01-14 22:45:10 +010026 void installBundle();
27 void installBundleOK();
28 void installBundleError();
29
Tomáš Pecka991e4d52021-01-11 10:03:14 +010030 std::unique_ptr<sdbus::IObject> m_manager;
31 std::string m_primarySlot;
32 std::vector<DBusSlotStatus> m_status;
Tomáš Pecka9cc00942021-01-14 22:45:10 +010033 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áš Pecka991e4d52021-01-11 10:03:14 +010041};