| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #pragma once |
| 5 | |
| 6 | #include "iappregistry.h" |
| 7 | |
| 8 | #include <mutex> |
| 9 | #include <string> |
| 10 | #include <unordered_set> |
| 11 | #include <vector> |
| 12 | |
| 13 | class AppRegistry final : public IAppRegistry |
| 14 | { |
| 15 | public: |
| 16 | void addObserver(std::shared_ptr<IAppRegistry::Observer> observer) override; |
| 17 | void removeObserver( |
| 18 | std::shared_ptr<IAppRegistry::Observer> const &observer) override; |
| 19 | |
| 20 | void add(std::string const &app) override; |
| 21 | void remove(std::string const &app) override; |
| 22 | bool registered(std::string const &app) override; |
| 23 | |
| 24 | private: |
| 25 | void notifyRegisteredApp(std::string const &app); |
| 26 | void notifyUnregisteredApp(std::string const &app); |
| 27 | |
| 28 | std::vector<std::shared_ptr<IAppRegistry::Observer>> observers_; |
| 29 | std::mutex obMutex_; |
| 30 | |
| 31 | std::unordered_set<std::string> registry_; |
| 32 | std::mutex regMutex_; |
| 33 | }; |