Tomáš Pecka | cb7a5f8 | 2021-01-20 15:12:00 +0100 | [diff] [blame] | 1 | /* |
| 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áš Pecka | af8f063 | 2021-01-27 16:45:55 +0100 | [diff] [blame] | 10 | #include <mutex> |
Tomáš Pecka | cb7a5f8 | 2021-01-20 15:12:00 +0100 | [diff] [blame] | 11 | #include <sdbus-c++/sdbus-c++.h> |
| 12 | #include <sysrepo-cpp/Session.hpp> |
| 13 | #include "system/RAUC.h" |
| 14 | #include "utils/log-fwd.h" |
| 15 | |
| 16 | namespace velia::system { |
| 17 | |
Tomáš Pecka | 594a676 | 2021-01-29 11:06:08 +0100 | [diff] [blame] | 18 | class Firmware { |
Tomáš Pecka | cb7a5f8 | 2021-01-20 15:12:00 +0100 | [diff] [blame] | 19 | public: |
Tomáš Pecka | d51d4cb | 2021-02-03 14:15:49 +0100 | [diff] [blame] | 20 | Firmware(std::shared_ptr<::sysrepo::Connection> srConn, sdbus::IConnection& dbusConnectionSignals, sdbus::IConnection& dbusConnectionMethods); |
Tomáš Pecka | cb7a5f8 | 2021-01-20 15:12:00 +0100 | [diff] [blame] | 21 | |
| 22 | private: |
Tomáš Pecka | cb7a5f8 | 2021-01-20 15:12:00 +0100 | [diff] [blame] | 23 | std::shared_ptr<RAUC> m_rauc; |
Tomáš Pecka | af8f063 | 2021-01-27 16:45:55 +0100 | [diff] [blame] | 24 | std::mutex m_mtx; //! @brief locks access to cached elements that are shared from multiple threads |
| 25 | std::string m_installStatus, m_installMessage; |
Tomáš Pecka | 92b14e4 | 2021-01-27 17:33:11 +0100 | [diff] [blame] | 26 | std::map<std::string, std::string> m_slotStatusCache; |
Tomáš Pecka | cb7a5f8 | 2021-01-20 15:12:00 +0100 | [diff] [blame] | 27 | velia::Log m_log; |
Tomáš Pecka | 92b14e4 | 2021-01-27 17:33:11 +0100 | [diff] [blame] | 28 | 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áš Pecka | cb7a5f8 | 2021-01-20 15:12:00 +0100 | [diff] [blame] | 37 | }; |
| 38 | } |