blob: 0d81b02f47b6d3272ce4dabc116f044bee41aa3a [file] [log] [blame]
Tomáš Peckacb7a5f82021-01-20 15:12:00 +01001/*
2 * Copyright (C) 2021 CESNET, https://photonics.cesnet.cz/
3 *
4 * Written by Tomáš Pecka <tomas.pecka@cesnet.cz>
5 *
6 */
7#pragma once
8
9#include <filesystem>
Tomáš Peckaaf8f0632021-01-27 16:45:55 +010010#include <mutex>
Tomáš Peckacb7a5f82021-01-20 15:12:00 +010011#include <sdbus-c++/sdbus-c++.h>
12#include <sysrepo-cpp/Session.hpp>
13#include "system/RAUC.h"
14#include "utils/log-fwd.h"
15
16namespace velia::system {
17
Tomáš Pecka594a6762021-01-29 11:06:08 +010018class Firmware {
Tomáš Peckacb7a5f82021-01-20 15:12:00 +010019public:
Tomáš Peckad51d4cb2021-02-03 14:15:49 +010020 Firmware(std::shared_ptr<::sysrepo::Connection> srConn, sdbus::IConnection& dbusConnectionSignals, sdbus::IConnection& dbusConnectionMethods);
Tomáš Peckacb7a5f82021-01-20 15:12:00 +010021
22private:
Tomáš Peckacb7a5f82021-01-20 15:12:00 +010023 std::shared_ptr<RAUC> m_rauc;
Tomáš Peckaaf8f0632021-01-27 16:45:55 +010024 std::mutex m_mtx; //! @brief locks access to cached elements that are shared from multiple threads
25 std::string m_installStatus, m_installMessage;
Tomáš Pecka92b14e42021-01-27 17:33:11 +010026 std::map<std::string, std::string> m_slotStatusCache;
Tomáš Peckacb7a5f82021-01-20 15:12:00 +010027 velia::Log m_log;
Tomáš Pecka92b14e42021-01-27 17:33:11 +010028 std::shared_ptr<::sysrepo::Connection> m_srConn;
29 std::shared_ptr<::sysrepo::Session> m_srSessionOps, m_srSessionRPC;
30 /* Subscribe objects must be destroyed before shared_ptr<RAUC> and other objects that are used in the callbacks
31 * (m_slotStatusCache, m_installStatus, m_installMessage). If they're not, the objects might be already destroyed
32 * while executing the callback.
33 */
34 std::shared_ptr<::sysrepo::Subscribe> m_srSubscribeOps, m_srSubscribeRPC;
35
36 std::unique_lock<std::mutex> updateSlotStatus();
Tomáš Peckacb7a5f82021-01-20 15:12:00 +010037};
38}