| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #pragma once |
| 5 | |
| 6 | #include <memory> |
| 7 | #include <mutex> |
| 8 | #include <optional> |
| 9 | #include <string> |
| 10 | #include <unordered_map> |
| 11 | |
| 12 | class IAppRegistry; |
| 13 | |
| 14 | class ProcessRegistry final |
| 15 | { |
| 16 | public: |
| 17 | ProcessRegistry(std::shared_ptr<IAppRegistry> appRegistry) noexcept; |
| 18 | |
| 19 | void add(int PID, std::string const &app); |
| 20 | void remove(int PID); |
| 21 | |
| 22 | bool running(std::string const &app); |
| 23 | std::optional<std::string> findApp(int PID); |
| 24 | |
| 25 | private: |
| 26 | void registeredApp(std::string const &app); |
| 27 | void unregisteredApp(std::string const &app); |
| 28 | |
| 29 | class AppRegistryObserver; |
| 30 | std::shared_ptr<AppRegistryObserver> const appRegObserver_; |
| 31 | std::unordered_map<int, std::string> pidReg_; |
| 32 | std::unordered_map<std::string, int> appCounterReg_; |
| 33 | std::mutex mutex_; |
| 34 | }; |