| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #pragma once |
| 5 | |
| 6 | #include "ihelpermonitor.h" |
| 7 | #include <QByteArray> |
| 8 | #include <QObject> |
| 9 | #include <QtDBus> |
| 10 | #include <memory> |
| 11 | #include <mutex> |
| 12 | #include <vector> |
| 13 | |
| 14 | class ICryptoLayer; |
| 15 | |
| 16 | class HelperMonitor final |
| 17 | : public QObject |
| 18 | , public IHelperMonitor |
| 19 | { |
| 20 | Q_OBJECT |
| 21 | |
| 22 | public: |
| 23 | HelperMonitor(std::shared_ptr<ICryptoLayer> cryptoLayer, |
| 24 | QObject *parent = nullptr) noexcept; |
| 25 | |
| 26 | void addObserver(std::shared_ptr<IHelperMonitor::Observer> observer) override; |
| 27 | void removeObserver( |
| 28 | std::shared_ptr<IHelperMonitor::Observer> const &observer) override; |
| 29 | |
| 30 | void init() override; |
| 31 | |
| 32 | void watchApp(std::string const &app) override; |
| 33 | void forgetApp(std::string const &app) override; |
| 34 | |
| 35 | private slots: |
| 36 | void notifyAppExec(QByteArray const &appExe, QByteArray const &signature); |
| 37 | void notifyAppExit(QByteArray const &appExe, QByteArray const &signature); |
| 38 | |
| 39 | private: |
| 40 | std::shared_ptr<ICryptoLayer> cryptoLayer_; |
| 41 | std::unique_ptr<QDBusInterface> monitorInterface_; |
| 42 | std::vector<std::shared_ptr<IHelperMonitor::Observer>> observers_; |
| 43 | std::mutex mutex_; |
| 44 | }; |