blob: 59ba63ce85aaf1380fed99f2c82805f2e2705076 [file] [log] [blame]
Tomáš Pecka991e4d52021-01-11 10:03:14 +01001/*
2 * Copyright (C) 2021 CESNET, https://photonics.cesnet.cz/
3 *
4 * Written by Tomáš Pecka <tomas.pecka@fit.cvut.cz>
5 *
6 */
7
8#pragma once
9
10#include <map>
11#include <sdbus-c++/sdbus-c++.h>
12#include <string>
13#include <variant>
14#include "utils/log-fwd.h"
15
16namespace velia::system {
17
18class RAUC {
19public:
20 using SlotProperties = std::map<std::string, std::variant<std::string, uint64_t, uint32_t>>;
21
Tomáš Peckad51d4cb2021-02-03 14:15:49 +010022 RAUC(sdbus::IConnection& signalConnection, sdbus::IConnection& methodConnection, std::function<void(const std::string&)> operCb, std::function<void(int32_t, const std::string&)> progressCb, std::function<void(int32_t, const std::string&)> completedCb);
Tomáš Pecka991e4d52021-01-11 10:03:14 +010023 std::string primarySlot() const;
24 std::map<std::string, SlotProperties> slotStatus() const;
Tomáš Pecka9cc00942021-01-14 22:45:10 +010025 void install(const std::string& source);
Jan Kundrát3795cab2022-07-13 18:08:19 +020026 void mark(const std::string& how, const std::string& what);
Tomáš Peckac764b762021-01-23 21:46:21 +010027 std::string operation() const;
28 std::string lastError() const;
Tomáš Pecka991e4d52021-01-11 10:03:14 +010029
30private:
Tomáš Peckad51d4cb2021-02-03 14:15:49 +010031 /* We have two objects on two connections here intentionally. On a D-Bus signal PropertyChanged we invoke a callback that does something
32 * with Sysrepo's operational datastore in velia::system::Firmware class. While executing this code, sdbus-c++'s mutex (sdbus-c++ src/SdBus.h, sdbusMutex_) is locked.
33 * However, this operational datastore change invokes a code, that (again) calls a D-Bus method via sdbus-c++ on the same sdbus::IProxy object.
34 * Calling method on this object would require to acquire the same mutex that is already held, which results in deadlock.
35 * Therefore, we maintain two separate connections to the same D-Bus object. The first one is used for handling signal callbacks and
36 * the second is only for calling the D-Bus methods.
37 */
38 std::shared_ptr<sdbus::IProxy> m_dbusObjectProxySignals, m_dbusObjectProxyMethods;
Tomáš Pecka9cc00942021-01-14 22:45:10 +010039 std::function<void(const std::string&)> m_operCb;
40 std::function<void(int32_t, const std::string&)> m_progressCb;
41 std::function<void(int32_t, const std::string&)> m_completedCb;
Tomáš Pecka991e4d52021-01-11 10:03:14 +010042 velia::Log m_log;
43};
44
45}